Browse Source

Removed automatic viewport reset on setting rendertarget to eliminate redundant API calls. However Graphics::ResetRenderTargets() resets the viewport.

Lasse Öörni 14 years ago
parent
commit
9e871c1987

+ 0 - 2
Docs/Reference.dox

@@ -495,8 +495,6 @@ Finally note that due to OpenGL framebuffer object limitations an extra framebuf
 
 - On Direct3D9 the depth-stencil surface can be equal or larger in size than the color rendertarget. On OpenGL the sizes must always match. Furthermore, OpenGL can not use the backbuffer depth-stencil surface when rendering to a texture. To overcome these limitations, Graphics will create correctly sized depth-stencil surfaces on demand whenever a texture is set as a color rendertarget, and a null depth-stencil is specified.
 
-- On Direct3D9 setting the first color rendertarget resets the viewport dimensions. On OpenGL there is no such mechanism. However, as sometimes (for example in OpenGL shadow rendering) only a depth-stencil texture will be used for rendering, in OpenGL mode Graphics instead resets the viewport when the depth-stencil is set. The following sequence will produce reliable results on both APIs: first set the rendertarget(s), then the depth-stencil surface, and finally the viewport, if you need it to be less than the whole rendertarget.
-
 - On OpenGL modifying a texture will cause it to be momentarily set on the first texture unit. If another texture was set there, the assignment will be lost. Graphics performs a check to not assign textures redundantly, so it is safe and recommended to always set all needed textures before rendering.
 
 - Modifying an index buffer on OpenGL will similarly cause the existing index buffer assignment to be lost. Therefore, always set the vertex and index buffers before rendering.

+ 1 - 7
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -1269,6 +1269,7 @@ void Graphics::ResetRenderTargets()
     for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
         SetRenderTarget(i, (RenderSurface*)0);
     SetDepthStencil((RenderSurface*)0);
+    SetViewport(IntRect(0, 0, width_, height_));
 }
 
 void Graphics::ResetRenderTarget(unsigned index)
@@ -1319,13 +1320,6 @@ void Graphics::SetRenderTarget(unsigned index, RenderSurface* renderTarget)
                 SetTexture(i, textures_[i]->GetBackupTexture());
         }
     }
-    
-    if (!index)
-    {
-        // Reset viewport and scissor test
-        IntVector2 rtSize = GetRenderTargetDimensions();
-        SetViewport(IntRect(0, 0, rtSize.x_, rtSize.y_));
-    }
 }
 
 void Graphics::SetRenderTarget(unsigned index, Texture2D* texture)

+ 1 - 1
Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -133,7 +133,7 @@ public:
     void SetDefaultTextureFilterMode(TextureFilterMode mode);
     /// %Set texture anisotropy.
     void SetTextureAnisotropy(unsigned level);
-    /// Reset all rendertargets and depth-stencil surface (render to back buffer.)
+    /// Reset all rendertargets, depth-stencil surface and viewport.
     void ResetRenderTargets();
     /// Reset specific rendertarget.
     void ResetRenderTarget(unsigned index);

+ 1 - 4
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -1163,6 +1163,7 @@ void Graphics::ResetRenderTargets()
     for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
         SetRenderTarget(i, (RenderSurface*)0);
     SetDepthStencil((RenderSurface*)0);
+    SetViewport(0, 0, width_, height_);
 }
 
 void Graphics::ResetRenderTarget(unsigned index)
@@ -1353,10 +1354,6 @@ void Graphics::SetDepthStencil(RenderSurface* depthStencil)
             impl_->fboBound_ = false;
         }
     }
-    
-    // Reset viewport to default when the depth-stencil changes
-    IntVector2 viewSize = GetRenderTargetDimensions();
-    SetViewport(IntRect(0, 0, viewSize.x_, viewSize.y_));
 }
 
 void Graphics::SetDepthStencil(Texture2D* texture)

+ 1 - 1
Engine/Graphics/OpenGL/OGLGraphics.h

@@ -156,7 +156,7 @@ public:
     void SetTextureAnisotropy(unsigned level);
     /// Dirty texture parameters of all textures (when global settings change.)
     void SetTextureParametersDirty();
-    /// Reset all rendertargets and depth-stencil surface (render to back buffer.)
+    /// Reset all rendertargets, depth-stencil surface and viewport.
     void ResetRenderTargets();
     /// Reset specific rendertarget.
     void ResetRenderTarget(unsigned index);

+ 1 - 0
Engine/Graphics/View.cpp

@@ -2498,6 +2498,7 @@ void View::RenderShadowMap(const LightBatchQueue& queue)
     graphics_->SetStencilTest(false);
     graphics_->SetRenderTarget(0, shadowMap->GetRenderSurface()->GetLinkedRenderTarget());
     graphics_->SetDepthStencil(shadowMap);
+    graphics_->SetViewport(IntRect(0, 0, shadowMap->GetWidth(), shadowMap->GetHeight()));
     graphics_->Clear(CLEAR_DEPTH);
     
     // Set shadow depth bias