Browse Source

Added common rendering quality controls to all samples.
Fixed quality for the Logo & LogoLarge textures.

Lasse Öörni 12 years ago
parent
commit
e4ed439148

+ 4 - 0
Bin/Data/Textures/Logo.xml

@@ -0,0 +1,4 @@
+<texture>
+    <quality low="0" />
+</texture>
+

+ 4 - 0
Bin/Data/Textures/LogoLarge.xml

@@ -0,0 +1,4 @@
+<texture>
+    <quality low="0" />
+</texture>
+

+ 1 - 2
Source/Samples/04_StaticScene/StaticScene.cpp

@@ -153,8 +153,7 @@ void StaticScene::SetupViewport()
 void StaticScene::MoveCamera(float timeStep)
 void StaticScene::MoveCamera(float timeStep)
 {
 {
     // Do not move if the UI has a focused element (the console)
     // Do not move if the UI has a focused element (the console)
-    UI* ui = GetSubsystem<UI>();
-    if (ui->GetFocusElement())
+    if (GetSubsystem<UI>()->GetFocusElement())
         return;
         return;
     
     
     Input* input = GetSubsystem<Input>();
     Input* input = GetSubsystem<Input>();

+ 1 - 2
Source/Samples/05_AnimatingScene/AnimatingScene.cpp

@@ -151,8 +151,7 @@ void AnimatingScene::SetupViewport()
 void AnimatingScene::MoveCamera(float timeStep)
 void AnimatingScene::MoveCamera(float timeStep)
 {
 {
     // Do not move if the UI has a focused element (the console)
     // Do not move if the UI has a focused element (the console)
-    UI* ui = GetSubsystem<UI>();
-    if (ui->GetFocusElement())
+    if (GetSubsystem<UI>()->GetFocusElement())
         return;
         return;
     
     
     Input* input = GetSubsystem<Input>();
     Input* input = GetSubsystem<Input>();

+ 7 - 7
Source/Samples/06_SkeletalAnimation/SkeletalAnimation.cpp

@@ -184,8 +184,7 @@ void SkeletalAnimation::SetupViewport()
 void SkeletalAnimation::MoveCamera(float timeStep)
 void SkeletalAnimation::MoveCamera(float timeStep)
 {
 {
     // Do not move if the UI has a focused element (the console)
     // Do not move if the UI has a focused element (the console)
-    UI* ui = GetSubsystem<UI>();
-    if (ui->GetFocusElement())
+    if (GetSubsystem<UI>()->GetFocusElement())
         return;
         return;
     
     
     Input* input = GetSubsystem<Input>();
     Input* input = GetSubsystem<Input>();
@@ -213,6 +212,10 @@ void SkeletalAnimation::MoveCamera(float timeStep)
         cameraNode_->TranslateRelative(Vector3::LEFT * MOVE_SPEED * timeStep);
         cameraNode_->TranslateRelative(Vector3::LEFT * MOVE_SPEED * timeStep);
     if (input->GetKeyDown('D'))
     if (input->GetKeyDown('D'))
         cameraNode_->TranslateRelative(Vector3::RIGHT * MOVE_SPEED * timeStep);
         cameraNode_->TranslateRelative(Vector3::RIGHT * MOVE_SPEED * timeStep);
+    
+    // Toggle debug geometry with space
+    if (input->GetKeyPress(KEY_SPACE))
+        drawDebug_ = !drawDebug_;
 }
 }
 
 
 void SkeletalAnimation::SubscribeToEvents()
 void SkeletalAnimation::SubscribeToEvents()
@@ -235,16 +238,13 @@ void SkeletalAnimation::HandleUpdate(StringHash eventType, VariantMap& eventData
     
     
     // Move the camera, scale movement with time step
     // Move the camera, scale movement with time step
     MoveCamera(timeStep);
     MoveCamera(timeStep);
-    
-    // Check for space pressed and toggle debug geometry
-    if (GetSubsystem<Input>()->GetKeyPress(KEY_SPACE))
-        drawDebug_ = !drawDebug_;
 }
 }
 
 
 void SkeletalAnimation::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
 void SkeletalAnimation::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
 {
 {
     // If draw debug mode is enabled, draw viewport debug geometry, which will show eg. drawable bounding boxes and skeleton
     // If draw debug mode is enabled, draw viewport debug geometry, which will show eg. drawable bounding boxes and skeleton
-    // bones. Disable depth test so that we can see the bones properly
+    // bones. Note that debug geometry has to be separately requested each frame. Disable depth test so that we can see the
+    // bones properly
     if (drawDebug_)
     if (drawDebug_)
         GetSubsystem<Renderer>()->DrawDebugGeometry(false);
         GetSubsystem<Renderer>()->DrawDebugGeometry(false);
 }
 }

+ 5 - 6
Source/Samples/07_Billboards/Billboards.cpp

@@ -240,8 +240,7 @@ void Billboards::SetupViewport()
 void Billboards::MoveCamera(float timeStep)
 void Billboards::MoveCamera(float timeStep)
 {
 {
     // Do not move if the UI has a focused element (the console)
     // Do not move if the UI has a focused element (the console)
-    UI* ui = GetSubsystem<UI>();
-    if (ui->GetFocusElement())
+    if (GetSubsystem<UI>()->GetFocusElement())
         return;
         return;
     
     
     Input* input = GetSubsystem<Input>();
     Input* input = GetSubsystem<Input>();
@@ -269,6 +268,10 @@ void Billboards::MoveCamera(float timeStep)
         cameraNode_->TranslateRelative(Vector3::LEFT * MOVE_SPEED * timeStep);
         cameraNode_->TranslateRelative(Vector3::LEFT * MOVE_SPEED * timeStep);
     if (input->GetKeyDown('D'))
     if (input->GetKeyDown('D'))
         cameraNode_->TranslateRelative(Vector3::RIGHT * MOVE_SPEED * timeStep);
         cameraNode_->TranslateRelative(Vector3::RIGHT * MOVE_SPEED * timeStep);
+    
+    // Toggle debug geometry with space
+    if (input->GetKeyPress(KEY_SPACE))
+        drawDebug_ = !drawDebug_;
 }
 }
 
 
 void Billboards::AnimateScene(float timeStep)
 void Billboards::AnimateScene(float timeStep)
@@ -322,10 +325,6 @@ void Billboards::HandleUpdate(StringHash eventType, VariantMap& eventData)
     // Move the camera and animate the scene, scale movement with time step
     // Move the camera and animate the scene, scale movement with time step
     MoveCamera(timeStep);
     MoveCamera(timeStep);
     AnimateScene(timeStep);
     AnimateScene(timeStep);
-    
-    // Check for space pressed and toggle debug geometry
-    if (GetSubsystem<Input>()->GetKeyPress(KEY_SPACE))
-        drawDebug_ = !drawDebug_;
 }
 }
 
 
 void Billboards::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)
 void Billboards::HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData)

+ 14 - 27
Source/Samples/08_Decals/Decals.cpp

@@ -174,7 +174,7 @@ void Decals::CreateUI()
         "Use WASD keys to move\n"
         "Use WASD keys to move\n"
         "LMB = paint decal, RMB = rotate view\n"
         "LMB = paint decal, RMB = rotate view\n"
         "Space to toggle debug geometry\n"
         "Space to toggle debug geometry\n"
-        "O to toggle occlusion culling"
+        "7 to toggle occlusion culling"
     );
     );
     instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
     instructionText->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
 
 
@@ -195,13 +195,15 @@ void Decals::SetupViewport()
 
 
 void Decals::MoveCamera(float timeStep)
 void Decals::MoveCamera(float timeStep)
 {
 {
-    // Do not move if the UI has a focused element (the console)
+    // Right mouse button controls mouse cursor visibility: hide when pressed
     UI* ui = GetSubsystem<UI>();
     UI* ui = GetSubsystem<UI>();
+    Input* input = GetSubsystem<Input>();
+    ui->GetCursor()->SetVisible(!input->GetMouseButtonDown(MOUSEB_RIGHT));
+    
+    // Do not move if the UI has a focused element (the console)
     if (ui->GetFocusElement())
     if (ui->GetFocusElement())
         return;
         return;
     
     
-    Input* input = GetSubsystem<Input>();
-    
     // Movement speed as world units per second
     // Movement speed as world units per second
     const float MOVE_SPEED = 20.0f;
     const float MOVE_SPEED = 20.0f;
     // Mouse sensitivity as degrees per pixel
     // Mouse sensitivity as degrees per pixel
@@ -229,6 +231,14 @@ void Decals::MoveCamera(float timeStep)
         cameraNode_->TranslateRelative(Vector3::LEFT * MOVE_SPEED * timeStep);
         cameraNode_->TranslateRelative(Vector3::LEFT * MOVE_SPEED * timeStep);
     if (input->GetKeyDown('D'))
     if (input->GetKeyDown('D'))
         cameraNode_->TranslateRelative(Vector3::RIGHT * MOVE_SPEED * timeStep);
         cameraNode_->TranslateRelative(Vector3::RIGHT * MOVE_SPEED * timeStep);
+    
+    // Toggle debug geometry with space
+    if (input->GetKeyPress(KEY_SPACE))
+        drawDebug_ = !drawDebug_;
+    
+    // Paint decal with the left mousebutton; cursor must be visible
+    if (ui->GetCursor()->IsVisible() && input->GetMouseButtonPress(MOUSEB_LEFT))
+        PaintDecal();
 }
 }
 
 
 void Decals::PaintDecal()
 void Decals::PaintDecal()
@@ -291,29 +301,6 @@ void Decals::HandleUpdate(StringHash eventType, VariantMap& eventData)
     // Take the frame time step, which is stored as a float
     // Take the frame time step, which is stored as a float
     float timeStep = eventData[P_TIMESTEP].GetFloat();
     float timeStep = eventData[P_TIMESTEP].GetFloat();
     
     
-    Input* input = GetSubsystem<Input>();
-    
-    // Right mouse button controls mouse cursor visibility: hide when pressed
-    UI* ui = GetSubsystem<UI>();
-    ui->GetCursor()->SetVisible(!input->GetMouseButtonDown(MOUSEB_RIGHT));
-    
-    // Paint a decal when the left mouse button is pressed
-    if (input->GetMouseButtonPress(MOUSEB_LEFT))
-        PaintDecal();
-    
-    // Check for space pressed and toggle debug geometry
-    if (input->GetKeyPress(KEY_SPACE))
-        drawDebug_ = !drawDebug_;
-    
-    // Check for toggling of occlusion
-    if (input->GetKeyPress('O'))
-    {
-        Renderer* renderer = GetSubsystem<Renderer>();
-        // 5000 is the default amount of maximum triangles to software-rasterize for occlusion, so EORing acts as a toggle
-        renderer->SetMaxOccluderTriangles(renderer->GetMaxOccluderTriangles() ^ 5000);
-    }
-    
-    
     // Move the camera, scale movement with time step
     // Move the camera, scale movement with time step
     MoveCamera(timeStep);
     MoveCamera(timeStep);
 }
 }

+ 75 - 4
Source/Samples/Sample.inl

@@ -25,6 +25,7 @@
 #include "DebugHud.h"
 #include "DebugHud.h"
 #include "Engine.h"
 #include "Engine.h"
 #include "InputEvents.h"
 #include "InputEvents.h"
+#include "Renderer.h"
 #include "ResourceCache.h"
 #include "ResourceCache.h"
 #include "Texture2D.h"
 #include "Texture2D.h"
 #include "UI.h"
 #include "UI.h"
@@ -120,19 +121,89 @@ void Sample::HandleKeyDown(StringHash eventType, VariantMap& eventData)
     using namespace KeyDown;
     using namespace KeyDown;
 
 
     int key = eventData[P_KEY].GetInt();
     int key = eventData[P_KEY].GetInt();
+
+    // Close console (if open) or when ESC is pressed
     if (key == KEY_ESC)
     if (key == KEY_ESC)
     {
     {
-        if (!GetSubsystem<UI>()->GetFocusElement())
+        Console* console = GetSubsystem<Console>();
+        if (!console->IsVisible())
             engine_->Exit();
             engine_->Exit();
         else
         else
-            GetSubsystem<Console>()->SetVisible(false);
+            console->SetVisible(false);
     }
     }
 
 
-    // Toggle console when F1 down.
+    // Toggle console with F1
     if (key == KEY_F1)
     if (key == KEY_F1)
         GetSubsystem<Console>()->Toggle();
         GetSubsystem<Console>()->Toggle();
     
     
-    // Toggle debug HUD when F2 down.
+    // Toggle debug HUD with F2
     if (key == KEY_F2)
     if (key == KEY_F2)
         GetSubsystem<DebugHud>()->ToggleAll();
         GetSubsystem<DebugHud>()->ToggleAll();
+    
+    // Common rendering quality controls, only when UI has no focused element
+    UIElement* focusElement = GetSubsystem<UI>()->GetFocusElement();
+    if (!focusElement)
+    {
+        Renderer* renderer = GetSubsystem<Renderer>();
+        
+        // Texture quality
+        if (key == '1')
+        {
+            int quality = renderer->GetTextureQuality();
+            ++quality;
+            if (quality > QUALITY_HIGH)
+                quality = QUALITY_LOW;
+            renderer->SetTextureQuality(quality);
+        }
+        
+        // Material quality
+        if (key == '2')
+        {
+            int quality = renderer->GetMaterialQuality();
+            ++quality;
+            if (quality > QUALITY_HIGH)
+                quality = QUALITY_LOW;
+            renderer->SetMaterialQuality(quality);
+        }
+        
+        // Specular lighting
+        if (key == '3')
+            renderer->SetSpecularLighting(!renderer->GetSpecularLighting());
+        
+        // Shadow rendering
+        if (key == '4')
+            renderer->SetDrawShadows(!renderer->GetDrawShadows());
+        
+        // Shadow map resolution
+        if (key == '5')
+        {
+            int shadowMapSize = renderer->GetShadowMapSize();
+            shadowMapSize *= 2;
+            if (shadowMapSize > 2048)
+                shadowMapSize = 512;
+            renderer->SetShadowMapSize(shadowMapSize);
+        }
+        
+        // Shadow depth and filtering quality
+        if (key == '6')
+        {
+            int quality = renderer->GetShadowQuality();
+            ++quality;
+            if (quality > SHADOWQUALITY_HIGH_24BIT)
+                quality = SHADOWQUALITY_LOW_16BIT;
+            renderer->SetShadowQuality(quality);
+        }
+        
+        // Occlusion culling
+        if (key == '7')
+        {
+            bool occlusion = renderer->GetMaxOccluderTriangles() > 0;
+            occlusion = !occlusion;
+            renderer->SetMaxOccluderTriangles(occlusion ? 5000 : 0);
+        }
+        
+        // Instancing
+        if (key == '8')
+            renderer->SetDynamicInstancing(!renderer->GetDynamicInstancing());
+    }
 }
 }