Browse Source

Implemented OpenGL multisampled backbuffer resolve.
Fixed OpenGL greyscale shader.

Lasse Öörni 14 years ago
parent
commit
f437a1ec04

+ 3 - 2
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -1,6 +1,6 @@
 //
 //
 // Urho3D Engine
 // Urho3D Engine
-// Copyright (c) 2008-2011 Lasse Öörni
+// Copyright (c) 2008-2011 Lasse Öörni
 //
 //
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to deal
 // of this software and associated documentation files (the "Software"), to deal
@@ -616,7 +616,8 @@ void Graphics::Clear(unsigned flags, const Color& color, float depth, unsigned s
 
 
 bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
 bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
 {
 {
-    if (!destination || destination->GetUsage() != TEXTURE_RENDERTARGET)
+    if (!destination || !destination->GetRenderSurface() || destination->GetWidth() != width_ ||
+        destination->GetHeight() != height_)
         return false;
         return false;
     
     
     IntRect vpCopy = viewport;
     IntRect vpCopy = viewport;

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

@@ -342,6 +342,7 @@ bool Graphics::TakeScreenShot(Image& destImage)
     PROFILE(TakeScreenShot);
     PROFILE(TakeScreenShot);
     
     
     ResetRenderTargets();
     ResetRenderTargets();
+    
     destImage.SetSize(width_, height_, 3);
     destImage.SetSize(width_, height_, 3);
     glReadPixels(0, 0, width_, height_, GL_RGB, GL_UNSIGNED_BYTE, destImage.GetData());
     glReadPixels(0, 0, width_, height_, GL_RGB, GL_UNSIGNED_BYTE, destImage.GetData());
     
     
@@ -439,7 +440,30 @@ void Graphics::Clear(unsigned flags, const Color& color, float depth, unsigned s
 
 
 bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
 bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
 {
 {
-    /// \todo Implement
+    if (!destination || !destination->GetRenderSurface() || destination->GetWidth() != width_ ||
+        destination->GetHeight() != height_)
+        return false;
+    
+    IntRect vpCopy = viewport;
+    if (vpCopy.right_ <= vpCopy.left_)
+        vpCopy.right_ = vpCopy.left_ + 1;
+    if (vpCopy.bottom_ <= vpCopy.top_)
+        vpCopy.bottom_ = vpCopy.top_ + 1;
+    vpCopy.left_ = Clamp(vpCopy.left_, 0, width_);
+    vpCopy.top_ = Clamp(vpCopy.top_, 0, height_);
+    vpCopy.right_ = Clamp(vpCopy.right_, 0, width_);
+    vpCopy.bottom_ = Clamp(vpCopy.bottom_, 0, height_);
+    
+    // Make sure the FBO is not in use
+    ResetRenderTargets();
+    
+    // Use Direct3D convention with the vertical coordinates ie. 0 is top
+    SetTextureForUpdate(destination);
+    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, vpCopy.left_, height_ - vpCopy.bottom_, vpCopy.left_, height_ - vpCopy.bottom_,
+        vpCopy.right_ - vpCopy.left_, vpCopy.bottom_ - vpCopy.top_);
+    SetTexture(0, 0);
+    
+    return true;
 }
 }
 
 
 void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount)
 void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount)

+ 3 - 1
Engine/Graphics/OpenGL/OGLTexture2D.cpp

@@ -159,7 +159,7 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
         dynamic_ = true;
         dynamic_ = true;
     else
     else
         dynamic_ = false;
         dynamic_ = false;
-
+    
     width_ = width;
     width_ = width;
     height_ = height;
     height_ = height;
     format_ = format;
     format_ = format;
@@ -204,6 +204,8 @@ bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, con
     }
     }
     
     
     bool wholeLevel = x == 0 && y == 0 && width == levelWidth && height == levelHeight;
     bool wholeLevel = x == 0 && y == 0 && width == levelWidth && height == levelHeight;
+    // Use Direct3D convention with the vertical coordinates ie. 0 is top
+    y = levelHeight - (y + height);
     
     
     graphics_->SetTextureForUpdate(this);
     graphics_->SetTextureForUpdate(this);
     
     

+ 2 - 0
Engine/Graphics/OpenGL/OGLTextureCube.cpp

@@ -211,6 +211,8 @@ bool TextureCube::SetData(CubeMapFace face, unsigned level, int x, int y, int wi
     }
     }
     
     
     bool wholeLevel = x == 0 && y == 0 && width == levelWidth && height == levelHeight;
     bool wholeLevel = x == 0 && y == 0 && width == levelWidth && height == levelHeight;
+    // Use Direct3D convention with the vertical coordinates ie. 0 is top
+    y = levelHeight - (y + height);
     
     
     graphics_->SetTextureForUpdate(this);
     graphics_->SetTextureForUpdate(this);
     
     

+ 0 - 2
Engine/Graphics/Renderer.cpp

@@ -628,8 +628,6 @@ void Renderer::Render()
         graphics_->SetScissorTest(false);
         graphics_->SetScissorTest(false);
         graphics_->SetStencilTest(false);
         graphics_->SetStencilTest(false);
         graphics_->ResetRenderTargets();
         graphics_->ResetRenderTargets();
-        graphics_->ResetDepthStencil();
-        graphics_->SetViewport(IntRect(0, 0, graphics_->GetWidth(), graphics_->GetHeight()));
         graphics_->Clear(CLEAR_COLOR | CLEAR_DEPTH | CLEAR_STENCIL);
         graphics_->Clear(CLEAR_COLOR | CLEAR_DEPTH | CLEAR_STENCIL);
         
         
         numPrimitives_ = 0;
         numPrimitives_ = 0;

+ 1 - 1
Engine/Graphics/View.cpp

@@ -297,7 +297,7 @@ void View::Render()
     graphics_->SetTexture(TU_INDIRECTION, renderer_->GetIndirectionCubeMap());
     graphics_->SetTexture(TU_INDIRECTION, renderer_->GetIndirectionCubeMap());
     
     
     // Set "view texture" to prevent destination texture sampling in case we do not render to the destination directly
     // Set "view texture" to prevent destination texture sampling in case we do not render to the destination directly
-    // ie. when using light pre-pass and/or doing edge filtering
+    // ie. when using light pre-pass and/or doing post-processing
     if (renderTarget_)
     if (renderTarget_)
         graphics_->SetViewTexture(renderTarget_->GetParentTexture());
         graphics_->SetViewTexture(renderTarget_->GetParentTexture());
     
     

+ 1 - 1
Engine/Graphics/View.h

@@ -127,7 +127,7 @@ private:
     void RenderBatchesLightPrepass();
     void RenderBatchesLightPrepass();
     /// Allocate needed screen buffers for post-processing and/or framebuffer blitting.
     /// Allocate needed screen buffers for post-processing and/or framebuffer blitting.
     void AllocateScreenBuffers();
     void AllocateScreenBuffers();
-    /// Blit the framebuffer to destination. Used in OpenGL light pre-pass mode and when applying edge filter.
+    /// Blit the framebuffer to destination. Used in OpenGL light pre-pass mode.
     void BlitFramebuffer();
     void BlitFramebuffer();
     /// Run post-processing effects.
     /// Run post-processing effects.
     void RunPostProcesses();
     void RunPostProcesses();

+ 0 - 2
Engine/UI/UI.cpp

@@ -270,8 +270,6 @@ void UI::Render()
     graphics_->SetFillMode(FILL_SOLID);
     graphics_->SetFillMode(FILL_SOLID);
     graphics_->SetStencilTest(false);
     graphics_->SetStencilTest(false);
     graphics_->ResetRenderTargets();
     graphics_->ResetRenderTargets();
-    graphics_->ResetDepthStencil();
-    graphics_->SetViewport(IntRect(0, 0, graphics_->GetWidth(), graphics_->GetHeight()));
     
     
     ShaderVariation* ps = 0;
     ShaderVariation* ps = 0;
     ShaderVariation* vs = 0;
     ShaderVariation* vs = 0;

+ 2 - 2
SourceAssets/GLSLShaders/GreyScale.frag

@@ -6,7 +6,7 @@ varying vec2 vScreenPos;
 
 
 void main()
 void main()
 {
 {
-    vec3 input = texture2D(sDiffMap, vScreenPos).rgb;
-    float intensity = GetIntensity(input);
+    vec3 rgb = texture2D(sDiffMap, vScreenPos).rgb;
+    float intensity = GetIntensity(rgb);
     gl_FragColor = vec4(intensity, intensity, intensity, 1.0);
     gl_FragColor = vec4(intensity, intensity, intensity, 1.0);
 }
 }

+ 2 - 2
SourceAssets/HLSLShaders/GreyScale.hlsl

@@ -17,7 +17,7 @@ void VS(float4 iPos : POSITION,
 void PS(float2 iScreenPos : TEXCOORD0,
 void PS(float2 iScreenPos : TEXCOORD0,
     out float4 oColor : COLOR0)
     out float4 oColor : COLOR0)
 {
 {
-    float3 input = Sample(sDiffMap, iScreenPos).rgb;
-    float intensity = GetIntensity(input);
+    float3 rgb = Sample(sDiffMap, iScreenPos).rgb;
+    float intensity = GetIntensity(rgb);
     oColor = float4(intensity, intensity, intensity, 1.0);
     oColor = float4(intensity, intensity, intensity, 1.0);
 }
 }