Browse Source

Check that render targets are supported before allowing auxiliary views.

Lasse Öörni 14 years ago
parent
commit
1c5e878832

BIN
Bin/Data/Textures/HealthBarInside.png


+ 1 - 0
Engine/Engine/GraphicsAPI.cpp

@@ -721,6 +721,7 @@ static void RegisterGraphics(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Graphics", "bool get_deviceLost() const", asMETHOD(Graphics, IsDeviceLost), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_deviceLost() const", asMETHOD(Graphics, IsDeviceLost), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "uint get_numPrimitives() const", asMETHOD(Graphics, GetNumPrimitives), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "uint get_numPrimitives() const", asMETHOD(Graphics, GetNumPrimitives), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "uint get_numBatches() const", asMETHOD(Graphics, GetNumBatches), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "uint get_numBatches() const", asMETHOD(Graphics, GetNumBatches), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Graphics", "bool get_renderTargetSupport() const", asMETHOD(Graphics, GetRenderTargetSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_deferredSupport() const", asMETHOD(Graphics, GetDeferredSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_deferredSupport() const", asMETHOD(Graphics, GetDeferredSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_sm3Support() const", asMETHOD(Graphics, GetSM3Support), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_sm3Support() const", asMETHOD(Graphics, GetSM3Support), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_hardwareShadowSupport() const", asMETHOD(Graphics, GetHardwareShadowSupport), asCALL_THISCALL);
     engine->RegisterObjectMethod("Graphics", "bool get_hardwareShadowSupport() const", asMETHOD(Graphics, GetHardwareShadowSupport), asCALL_THISCALL);

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

@@ -166,6 +166,7 @@ Graphics::Graphics(Context* context) :
     flushGPU_(true),
     flushGPU_(true),
     deviceLost_(false),
     deviceLost_(false),
     queryIssued_(false),
     queryIssued_(false),
+    renderTargetSupport_(true),
     deferredSupport_(false),
     deferredSupport_(false),
     hardwareShadowSupport_(false),
     hardwareShadowSupport_(false),
     hiresShadowSupport_(false),
     hiresShadowSupport_(false),

+ 4 - 0
Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -233,6 +233,8 @@ public:
     unsigned GetShadowMapFormat() const { return shadowMapFormat_; }
     unsigned GetShadowMapFormat() const { return shadowMapFormat_; }
     /// Return 24-bit shadow map depth texture format, or 0 if not supported
     /// Return 24-bit shadow map depth texture format, or 0 if not supported
     unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
     unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
+    /// Return whether texture render targets are supported
+    bool GetRenderTargetSupport() const { return renderTargetSupport_; }
     /// Return whether deferred rendering is supported
     /// Return whether deferred rendering is supported
     bool GetDeferredSupport() const { return deferredSupport_; }
     bool GetDeferredSupport() const { return deferredSupport_; }
     /// Return whether Shader Model 3 is supported
     /// Return whether Shader Model 3 is supported
@@ -400,6 +402,8 @@ private:
     bool deviceLost_;
     bool deviceLost_;
     /// Query issued (used to flush the GPU command queue) flag
     /// Query issued (used to flush the GPU command queue) flag
     bool queryIssued_;
     bool queryIssued_;
+    /// Texture render target support flag
+    bool renderTargetSupport_;
     /// Deferred rendering support flag
     /// Deferred rendering support flag
     bool deferredSupport_;
     bool deferredSupport_;
     /// Hardware shadow map depth compare support flag
     /// Hardware shadow map depth compare support flag

+ 1 - 1
Engine/Graphics/GPUObject.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLGPUObject.h"
 #include "OpenGL/OGLGPUObject.h"
 #else
 #else
 #include "Direct3D9/D3D9GPUObject.h"
 #include "Direct3D9/D3D9GPUObject.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/Graphics.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLGraphics.h"
 #include "OpenGL/OGLGraphics.h"
 #else
 #else
 #include "Direct3D9/D3D9Graphics.h"
 #include "Direct3D9/D3D9Graphics.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/GraphicsImpl.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLGraphicsImpl.h"
 #include "OpenGL/OGLGraphicsImpl.h"
 #else
 #else
 #include "Direct3D9/D3D9GraphicsImpl.h"
 #include "Direct3D9/D3D9GraphicsImpl.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/IndexBuffer.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLIndexBuffer.h"
 #include "OpenGL/OGLIndexBuffer.h"
 #else
 #else
 #include "Direct3D9/D3D9IndexBuffer.h"
 #include "Direct3D9/D3D9IndexBuffer.h"
-#endif
+#endif

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

@@ -127,6 +127,7 @@ Graphics::Graphics(Context* context_) :
     flushGPU_(true),
     flushGPU_(true),
     fullscreenModeSet_(false),
     fullscreenModeSet_(false),
     inModeChange_(false),
     inModeChange_(false),
+    renderTargetSupport_(false),
     deferredSupport_(false),
     deferredSupport_(false),
     numPrimitives_(0),
     numPrimitives_(0),
     numBatches_(0),
     numBatches_(0),
@@ -236,14 +237,15 @@ bool Graphics::SetMode(RenderMode mode, int width, int height, bool fullscreen,
             return false;
             return false;
         }
         }
         
         
-        // Create the FBO if supported
+        // Create the FBO if fully supported
         if ((_GLEE_EXT_framebuffer_object) && (_GLEE_EXT_packed_depth_stencil))
         if ((_GLEE_EXT_framebuffer_object) && (_GLEE_EXT_packed_depth_stencil))
         {
         {
             glGenFramebuffersEXT(1, &impl_->fbo_);
             glGenFramebuffersEXT(1, &impl_->fbo_);
             
             
-            // If both FBO and packed depth stencil is supported, shadows and deferred rendering can be supported
+            // Shadows, render targets and deferred rendering all depend on FBO & packed depth stencil
             shadowMapFormat_ = GL_DEPTH_COMPONENT16;
             shadowMapFormat_ = GL_DEPTH_COMPONENT16;
             hiresShadowMapFormat_ = GL_DEPTH_COMPONENT24;
             hiresShadowMapFormat_ = GL_DEPTH_COMPONENT24;
+            renderTargetSupport_ = true;
             deferredSupport_ = true;
             deferredSupport_ = true;
         }
         }
         
         
@@ -1950,11 +1952,6 @@ unsigned Graphics::GetWindowHandle() const
     return (unsigned)impl_->window_;
     return (unsigned)impl_->window_;
 }
 }
 
 
-bool Graphics::GetRenderTextureSupport() const
-{
-    return impl_->fbo_ != 0;
-}
-
 bool Graphics::OpenWindow(int width, int height)
 bool Graphics::OpenWindow(int width, int height)
 {
 {
     WNDCLASS wc;
     WNDCLASS wc;

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

@@ -240,7 +240,7 @@ public:
     /// Return 24-bit shadow map depth texture format, or 0 if not supported
     /// Return 24-bit shadow map depth texture format, or 0 if not supported
     unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
     unsigned GetHiresShadowMapFormat() const { return hiresShadowMapFormat_; }
     /// Return whether texture render targets are supported
     /// Return whether texture render targets are supported
-    bool GetRenderTextureSupport() const;
+    bool GetRenderTargetSupport() const { return renderTargetSupport_; }
     /// Return whether deferred rendering is supported
     /// Return whether deferred rendering is supported
     bool GetDeferredSupport() const { return deferredSupport_; }
     bool GetDeferredSupport() const { return deferredSupport_; }
     /// Return whether Shader Model 3 is supported. Always false on OpenGL
     /// Return whether Shader Model 3 is supported. Always false on OpenGL
@@ -408,6 +408,8 @@ private:
     bool fullscreenModeSet_;
     bool fullscreenModeSet_;
     /// In screen mode change -flag
     /// In screen mode change -flag
     bool inModeChange_;
     bool inModeChange_;
+    /// Texture render target support flag
+    bool renderTargetSupport_;
     /// Deferred rendering support flag
     /// Deferred rendering support flag
     bool deferredSupport_;
     bool deferredSupport_;
     /// Number of primitives this frame
     /// Number of primitives this frame

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

@@ -113,7 +113,7 @@ bool Texture2D::SetSize(int width, int height, unsigned format, TextureUsage usa
     
     
     if (usage >= TEXTURE_RENDERTARGET)
     if (usage >= TEXTURE_RENDERTARGET)
     {
     {
-        if (!graphics_->GetRenderTextureSupport())
+        if (!graphics_->GetRenderTargetSupport())
             return false;
             return false;
         
         
         renderSurface_ = new RenderSurface(this, GL_TEXTURE_2D);
         renderSurface_ = new RenderSurface(this, GL_TEXTURE_2D);

+ 4 - 1
Engine/Graphics/Renderer.cpp

@@ -722,9 +722,12 @@ void Renderer::ResetViews()
 
 
 bool Renderer::AddView(RenderSurface* renderTarget, const Viewport& viewport)
 bool Renderer::AddView(RenderSurface* renderTarget, const Viewport& viewport)
 {
 {
-    // If using a render target texture, make sure it will not be rendered to multiple times
+    // If using a render target texture, make sure it is supported, and will not be rendered to multiple times
     if (renderTarget)
     if (renderTarget)
     {
     {
+        if (!graphics_->GetRenderTargetSupport())
+            return false;
+        
         for (unsigned i = 0; i < numViews_; ++i)
         for (unsigned i = 0; i < numViews_; ++i)
         {
         {
             if (views_[i]->GetRenderTarget() == renderTarget)
             if (views_[i]->GetRenderTarget() == renderTarget)

+ 1 - 1
Engine/Graphics/Shader.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLShader.h"
 #include "OpenGL/OGLShader.h"
 #else
 #else
 #include "Direct3D9/D3D9Shader.h"
 #include "Direct3D9/D3D9Shader.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/ShaderProgram.h

@@ -25,4 +25,4 @@
 
 
 #ifdef USE_OPENGL
 #ifdef USE_OPENGL
 #include "OpenGL/OGLShaderProgram.h"
 #include "OpenGL/OGLShaderProgram.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/ShaderVariation.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLShaderVariation.h"
 #include "OpenGL/OGLShaderVariation.h"
 #else
 #else
 #include "Direct3D9/D3D9ShaderVariation.h"
 #include "Direct3D9/D3D9ShaderVariation.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/Texture.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLTexture.h"
 #include "OpenGL/OGLTexture.h"
 #else
 #else
 #include "Direct3D9/D3D9Texture.h"
 #include "Direct3D9/D3D9Texture.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/Texture2D.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLTexture2D.h"
 #include "OpenGL/OGLTexture2D.h"
 #else
 #else
 #include "Direct3D9/D3D9Texture2D.h"
 #include "Direct3D9/D3D9Texture2D.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/TextureCube.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLTextureCube.h"
 #include "OpenGL/OGLTextureCube.h"
 #else
 #else
 #include "Direct3D9/D3D9TextureCube.h"
 #include "Direct3D9/D3D9TextureCube.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/VertexBuffer.h

@@ -27,4 +27,4 @@
 #include "OpenGL/OGLVertexBuffer.h"
 #include "OpenGL/OGLVertexBuffer.h"
 #else
 #else
 #include "Direct3D9/D3D9VertexBuffer.h"
 #include "Direct3D9/D3D9VertexBuffer.h"
-#endif
+#endif

+ 1 - 1
Engine/Graphics/VertexDeclaration.h

@@ -25,4 +25,4 @@
 
 
 #ifndef USE_OPENGL
 #ifndef USE_OPENGL
 #include "Direct3D9/D3D9VertexDeclaration.h"
 #include "Direct3D9/D3D9VertexDeclaration.h"
-#endif
+#endif

+ 2 - 2
SourceAssets/GLSLShaders/Ambient.frag

@@ -19,6 +19,6 @@ void main()
 
 
     // Store coarse linear depth to alpha channel for deferred antialiasing
     // Store coarse linear depth to alpha channel for deferred antialiasing
     gl_FragColor = vec4(ambientColor + GetFogFactor(linearDepth) * cFogColor, linearDepth);
     gl_FragColor = vec4(ambientColor + GetFogFactor(linearDepth) * cFogColor, linearDepth);
-    // Copy the actual hardware depth value to the destination depth buffer
-    gl_FragDepth = depth;
+    // Copy the actual hardware depth value with slight bias to the destination depth buffer
+    gl_FragDepth = min(depth + 0.0000001;
 }
 }