diff options
author | Brad Davis <[email protected]> | 2014-09-04 14:32:18 -0700 |
---|---|---|
committer | Brad Davis <[email protected]> | 2014-09-04 14:32:18 -0700 |
commit | 32dc394487af8e4fb1b43fb852f1d5448eaf7f31 (patch) | |
tree | be53f49e96e8e2bba1dada04197cf508b60b4eaf /Samples/CommonSrc | |
parent | 85d370840fa4d49a63331a203460fe763288d417 (diff) |
Updating to windows 0.4.2
Diffstat (limited to 'Samples/CommonSrc')
-rw-r--r-- | Samples/CommonSrc/Render/Render_D3D1X_Device.cpp | 98 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_D3D1X_Device.h | 1 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_Device.h | 1 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_GL_Device.cpp | 193 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_GL_Device.h | 48 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_GL_Win32_Device.cpp | 2 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_LoadTextureDDS.cpp | 4 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_XmlSceneLoader.cpp | 4 | ||||
-rw-r--r-- | Samples/CommonSrc/Render/Render_XmlSceneLoader.h | 4 |
9 files changed, 247 insertions, 108 deletions
diff --git a/Samples/CommonSrc/Render/Render_D3D1X_Device.cpp b/Samples/CommonSrc/Render/Render_D3D1X_Device.cpp index 3f645ab..a904ee5 100644 --- a/Samples/CommonSrc/Render/Render_D3D1X_Device.cpp +++ b/Samples/CommonSrc/Render/Render_D3D1X_Device.cpp @@ -152,17 +152,12 @@ static const char* MultiTexturePixelShaderSrc = "float4 color1;\n" "float4 color2;\n" " color1 = Texture[0].Sample(Linear, ov.TexCoord);\n" - // go to linear space colors (assume gamma 2.0 for speed) - " color1.rgb *= color1.rgb;\n" " color2 = Texture[1].Sample(Linear, ov.TexCoord1);\n" - // go to linear space colors (assume gamma 2.0 for speed) - " color2.rgb *= color2.rgb;\n" - " color2.rgb = color2.rgb * lerp(1.2, 1.9, saturate(length(color2.rgb)));\n" + " color2.rgb = color2.rgb * lerp(1.9, 1.2, saturate(length(color2.rgb)));\n" " color2 = color1 * color2;\n" " if (color2.a <= 0.4)\n" " discard;\n" - // go to back to gamma space space colors (assume gamma 2.0 for speed) - " return float4(sqrt(color2.rgb) / color2.a, 1);\n" + " return float4(color2.rgb / color2.a, 1);\n" "}\n"; #define LIGHTING_COMMON \ @@ -668,31 +663,37 @@ static const char* PostProcessHeightmapTimewarpPixelShaderSrc = //---------------------------------------------------------------------------- -static const char* VShaderSrcs[VShader_Count] = +struct ShaderSource { - DirectVertexShaderSrc, - StdVertexShaderSrc, - PostProcessVertexShaderSrc, - PostProcessMeshVertexShaderSrc, - PostProcessMeshTimewarpVertexShaderSrc, - PostProcessMeshPositionalTimewarpVertexShaderSrc, - PostProcessHeightmapTimewarpVertexShaderSrc + const char* ShaderModel; + const char* SourceStr; }; -static const char* FShaderSrcs[FShader_Count] = -{ - SolidPixelShaderSrc, - GouraudPixelShaderSrc, - TexturePixelShaderSrc, - AlphaTexturePixelShaderSrc, - AlphaBlendedTexturePixelShaderSrc, - PostProcessPixelShaderWithChromAbSrc, - LitSolidPixelShaderSrc, - LitTexturePixelShaderSrc, - MultiTexturePixelShaderSrc, - PostProcessMeshPixelShaderSrc, - PostProcessMeshTimewarpPixelShaderSrc, - PostProcessMeshPositionalTimewarpPixelShaderSrc, - PostProcessHeightmapTimewarpPixelShaderSrc + +static ShaderSource VShaderSrcs[VShader_Count] = +{ + {"vs_4_0", DirectVertexShaderSrc}, + {"vs_4_0", StdVertexShaderSrc}, + {"vs_4_0", PostProcessVertexShaderSrc}, + {"vs_4_0", PostProcessMeshVertexShaderSrc}, + {"vs_4_0", PostProcessMeshTimewarpVertexShaderSrc}, + {"vs_4_1", PostProcessMeshPositionalTimewarpVertexShaderSrc}, + {"vs_4_1", PostProcessHeightmapTimewarpVertexShaderSrc}, +}; +static ShaderSource FShaderSrcs[FShader_Count] = +{ + {"ps_4_0", SolidPixelShaderSrc}, + {"ps_4_0", GouraudPixelShaderSrc}, + {"ps_4_0", TexturePixelShaderSrc}, + {"ps_4_0", AlphaTexturePixelShaderSrc}, + {"ps_4_0", AlphaBlendedTexturePixelShaderSrc}, + {"ps_4_0", PostProcessPixelShaderWithChromAbSrc}, + {"ps_4_0", LitSolidPixelShaderSrc}, + {"ps_4_0", LitTexturePixelShaderSrc}, + {"ps_4_0", MultiTexturePixelShaderSrc}, + {"ps_4_0", PostProcessMeshPixelShaderSrc}, + {"ps_4_0", PostProcessMeshTimewarpPixelShaderSrc}, + {"ps_4_0", PostProcessMeshPositionalTimewarpPixelShaderSrc}, + {"ps_4_0", PostProcessHeightmapTimewarpPixelShaderSrc}, }; #ifdef OVR_BUILD_DEBUG @@ -706,7 +707,7 @@ static void ReportCOMError(HRESULT hr, const char* file, int line) if (sizeof(TCHAR) == sizeof(char)) { - LogError("[D3D] Error in %s on line %d : %s", file, line, errMsg); + LogError("{ERR-017w} [D3D] Error in %s on line %d : %s", file, line, errMsg); } else { @@ -719,7 +720,7 @@ static void ReportCOMError(HRESULT hr, const char* file, int line) len = count; } data[len] = '\0'; - LogError("[D3D] Error in %s on line %d : %s", file, line, data); + LogError("{ERR-018w} [D3D] Error in %s on line %d : %s", file, line, data); delete[] data; } @@ -825,7 +826,7 @@ RenderDevice::RenderDevice(const RendererParams& p, HWND window) if (FAILED(hr)) { OVR_LOG_COM_ERROR(hr); - LogError("[D3D1X] Unable to create device: %x", hr); + LogError("{ERR-019w} [D3D1X] Unable to create device: %x", hr); OVR_ASSERT(false); return; } @@ -843,12 +844,14 @@ RenderDevice::RenderDevice(const RendererParams& p, HWND window) MaxTextureSet[i] = 0; } - ID3D10Blob* vsData = CompileShader("vs_4_1", DirectVertexShaderSrc); + ID3D10Blob* vsData = CompileShader(VShaderSrcs[0].ShaderModel, VShaderSrcs[0].SourceStr); + VertexShaders[VShader_MV] = *new VertexShader(this, vsData); for(int i = 1; i < VShader_Count; i++) { - OVR_ASSERT ( VShaderSrcs[i] != NULL ); // You forgot a shader! - ID3D10Blob *pShader = CompileShader("vs_4_1", VShaderSrcs[i]); + OVR_ASSERT ( VShaderSrcs[i].SourceStr != NULL ); // You forgot a shader! + ID3D10Blob *pShader = CompileShader(VShaderSrcs[i].ShaderModel, VShaderSrcs[i].SourceStr); + VertexShaders[i] = NULL; if ( pShader != NULL ) { @@ -858,8 +861,9 @@ RenderDevice::RenderDevice(const RendererParams& p, HWND window) for(int i = 0; i < FShader_Count; i++) { - OVR_ASSERT ( FShaderSrcs[i] != NULL ); // You forgot a shader! - ID3D10Blob *pShader = CompileShader("ps_4_1", FShaderSrcs[i]); + OVR_ASSERT ( FShaderSrcs[i].SourceStr != NULL ); // You forgot a shader! + ID3D10Blob *pShader = CompileShader(FShaderSrcs[i].ShaderModel, FShaderSrcs[i].SourceStr); + PixelShaders[i] = NULL; if ( pShader != NULL ) { @@ -2083,20 +2087,12 @@ Texture* RenderDevice::CreateTexture(int format, int width, int height, const vo unsigned effectiveMipCount = mipcount; unsigned textureSize = 0; -#ifdef OVR_DEFINE_NEW -#undef new -#endif - D3D1x_(SUBRESOURCE_DATA)* subresData = (D3D1x_(SUBRESOURCE_DATA)*) OVR_ALLOC(sizeof(D3D1x_(SUBRESOURCE_DATA)) * mipcount); GenerateSubresourceData(width, height, convertedFormat, imageDimUpperLimit, data, subresData, largestMipWidth, largestMipHeight, textureSize, effectiveMipCount); TotalTextureMemoryUsage += textureSize; -#ifdef OVR_DEFINE_NEW -#define new OVR_DEFINE_NEW -#endif - if (!Device || !subresData) { return NULL; @@ -2520,6 +2516,9 @@ size_t RenderDevice::QueryGPUMemorySize() { OVR_LOG_COM_ERROR(hr); } + + pDXGIAdapter->Release(); + pDXGIDevice->Release(); return adapterDesc.DedicatedVideoMemory; } @@ -2550,9 +2549,14 @@ void RenderDevice::Present ( bool withVsync ) } } +void RenderDevice::Flush() +{ + Context->Flush(); +} + void RenderDevice::WaitUntilGpuIdle() { -#if 1 +#if 0 // If enabling this option and using an NVIDIA GPU, // then make sure your "max pre-rendered frames" is set to 1 under the NVIDIA GPU settings. diff --git a/Samples/CommonSrc/Render/Render_D3D1X_Device.h b/Samples/CommonSrc/Render/Render_D3D1X_Device.h index 4207d8a..cac104e 100644 --- a/Samples/CommonSrc/Render/Render_D3D1X_Device.h +++ b/Samples/CommonSrc/Render/Render_D3D1X_Device.h @@ -313,6 +313,7 @@ public: virtual void Present ( bool withVsync ); virtual void WaitUntilGpuIdle(); + virtual void Flush(); virtual bool SetFullscreen(DisplayMode fullscreen); virtual size_t QueryGPUMemorySize(); diff --git a/Samples/CommonSrc/Render/Render_Device.h b/Samples/CommonSrc/Render/Render_Device.h index d7e4917..1da49fe 100644 --- a/Samples/CommonSrc/Render/Render_Device.h +++ b/Samples/CommonSrc/Render/Render_Device.h @@ -877,6 +877,7 @@ public: virtual void Present ( bool withVsync ) = 0; // Waits for rendering to complete; important for reducing latency. virtual void WaitUntilGpuIdle() { } + virtual void Flush() = 0; // Resources virtual Buffer* CreateBuffer() { return NULL; } diff --git a/Samples/CommonSrc/Render/Render_GL_Device.cpp b/Samples/CommonSrc/Render/Render_GL_Device.cpp index f6e13ef..54a2b9b 100644 --- a/Samples/CommonSrc/Render/Render_GL_Device.cpp +++ b/Samples/CommonSrc/Render/Render_GL_Device.cpp @@ -26,7 +26,8 @@ limitations under the License. #include "OVR_CAPI_GL.h" namespace OVR { namespace Render { namespace GL { - + + #if !defined(OVR_OS_MAC) // GL Hooks for PC. @@ -716,47 +717,10 @@ static const char* FShaderSrcs[FShader_Count] = RenderDevice::RenderDevice(const RendererParams&) { - int GlMajorVersion = 0; - int GlMinorVersion = 0; - bool isES = false; - - const char* glVersionString = (const char*)glGetString(GL_VERSION); + GetGLVersionAndExtensions(GLVersionInfo); -#ifdef OVR_CC_MSVC - // Hack: This is using sscanf_s on MSVC to kill the security warning. - // Normally the two functions are not interchangeable because the string format - // is different for %s types, however we only use %d so it's fine. -#define _OVR_SSCANF sscanf_s -#else -#define _OVR_SSCANF sscanf -#endif + OVR_ASSERT(GLVersionInfo.MajorVersion >= 2); - isES = strstr( glVersionString, "OpenGL ES-CM" ) != NULL; - if( isES ) - { - _OVR_SSCANF(glVersionString, "OpenGL ES-CM %d.%d", &GlMajorVersion, &GlMinorVersion); - } - else - { - isES = strstr( glVersionString, "OpenGL ES " ) != NULL; - if ( isES ) - { - _OVR_SSCANF(glVersionString, "OpenGL ES %d.%d", &GlMajorVersion, &GlMinorVersion); - } - else - { - _OVR_SSCANF(glVersionString, "%d.%d", &GlMajorVersion, &GlMinorVersion); - } - } - -#undef _OVR_SSCANF - - OVR_ASSERT( isES == false ); - OVR_ASSERT(GlMajorVersion >= 2); - - const char* extensions = (const char*)glGetString(GL_EXTENSIONS); - SupportsVao = (GlMajorVersion >= 3) || (strstr("GL_ARB_vertex_array_object", extensions) != NULL); - for (int i = 0; i < VShader_Count; i++) { OVR_ASSERT ( VShaderSrcs[i] != NULL ); // You forgot a shader! @@ -776,8 +740,10 @@ RenderDevice::RenderDevice(const RendererParams&) glGenFramebuffers(1, &CurrentFbo); - if (SupportsVao) + if (GLVersionInfo.SupportsVAO) + { glGenVertexArrays(1, &Vao); + } } RenderDevice::~RenderDevice() @@ -794,14 +760,20 @@ void RenderDevice::Shutdown() glDeleteFramebuffers(1, &CurrentFbo); - if (SupportsVao) + if (GLVersionInfo.SupportsVAO) + { glDeleteVertexArrays(1, &Vao); + } for (int i = 0; i < VShader_Count; ++i) + { VertexShaders[i].Clear(); + } for (int i = 0; i < FShader_Count; ++i) + { FragShaders[i].Clear(); + } DefaultFill.Clear(); DepthBuffers.Clear(); @@ -865,6 +837,11 @@ void RenderDevice::SetViewport(const Recti& vp) glViewport(vp.x, wh - vp.y - vp.h, vp.w, vp.h); } +void RenderDevice::Flush() +{ + glFlush(); +} + void RenderDevice::WaitUntilGpuIdle() { glFlush(); @@ -943,8 +920,10 @@ Fill* RenderDevice::CreateSimpleFill(int flags) void RenderDevice::Render(const Matrix4f& matrix, Model* model) { - if (SupportsVao) + if (GLVersionInfo.SupportsVAO) + { glBindVertexArray(Vao); + } // Store data in buffers if not already if (!model->VertexBuffer) @@ -953,6 +932,7 @@ void RenderDevice::Render(const Matrix4f& matrix, Model* model) vb->Data(Buffer_Vertex | Buffer_ReadOnly, &model->Vertices[0], model->Vertices.GetSize() * sizeof(Vertex)); model->VertexBuffer = vb; } + if (!model->IndexBuffer) { Ptr<Render::Buffer> ib = *CreateBuffer(); @@ -1454,4 +1434,129 @@ RBuffer::~RBuffer() glDeleteRenderbuffers(1, &BufId); } -}}} + +//// GLVersion + +static void ParseGLVersion(GLVersionAndExtensions& versionInfo) +{ + const char* version = (const char*)glGetString(GL_VERSION); + int fields = 0, major = 0, minor = 0; + bool isGLES = false; + + OVR_ASSERT(version); + if (version) + { + OVR_DEBUG_LOG(("GL_VERSION: %s", (const char*)version)); + +#ifdef OVR_CC_MSVC + // Hack: This is using sscanf_s on MSVC to kill the security warning. + // Normally the two functions are not interchangeable because the string format + // is different for %s types, however we only use %d so it's fine. +#define TEMP_OVR_SSCANF sscanf_s +#else +#define TEMP_OVR_SSCANF sscanf +#endif + + // Skip all leading non-digits before reading %d. + // Example GL_VERSION strings: + // "1.5 ATI-1.4.18" + // "OpenGL ES-CM 3.2" + fields = TEMP_OVR_SSCANF(version, isdigit(*version) ? "%d.%d" : "%*[^0-9]%d.%d", &major, &minor); + isGLES = (strstr(version, "OpenGL ES") != NULL); + +#undef TEMP_OVR_SSCANF + } + else + { + LogText("Warning: GL_VERSION was NULL\n"); + } + + // If two fields were not found, + if (fields != 2) + { + static_assert(sizeof(major) == sizeof(GLint), "type mis-match"); + + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + } + + // Write version data + versionInfo.MajorVersion = major; + versionInfo.MinorVersion = minor; + versionInfo.IsGLES = isGLES; +} + +static bool HasGLExtension(const char* extensions, const char* searchKey) +{ + const int searchKeyLen = (int)strlen(searchKey); + const char* p = extensions; + + for (;;) + { + p = strstr(p, searchKey); + + // If not found, + if (p == NULL) + { + break; + } + + // Only match full string + if ((p == extensions || p[-1] == ' ') && + (p[searchKeyLen] == '\0' || p[searchKeyLen] == ' ')) + { + return true; + } + + // Skip ahead + p += searchKeyLen; + } + + return false; +} + +static void ParseGLExtensions(GLVersionAndExtensions& versionInfo) +{ + const char* extensions = (const char*)glGetString(GL_EXTENSIONS); + + OVR_ASSERT(extensions); + if (!extensions) + { + extensions = ""; // Note: glGetString() can return null + LogText("Warning: GL_EXTENSIONS was NULL\n"); + } + else + { + // Cannot print this to debug log: It's too long! + //OVR_DEBUG_LOG(("GL_EXTENSIONS: %s", (const char*)extensions)); + } + + versionInfo.Extensions = extensions; + + if (versionInfo.MajorVersion >= 3) + { + versionInfo.SupportsVAO = true; + } + else + { + versionInfo.SupportsVAO = + HasGLExtension(extensions, "GL_ARB_vertex_array_object") || + HasGLExtension(extensions, "GL_APPLE_vertex_array_object"); + } + + versionInfo.SupportsDrawBuffers = HasGLExtension(extensions, "GL_EXT_draw_buffers2"); + + // Add more extension checks here... +} + +void GetGLVersionAndExtensions(GLVersionAndExtensions& versionInfo) +{ + ParseGLVersion(versionInfo); + + // GL Version must be parsed before parsing extensions: + + ParseGLExtensions(versionInfo); +} + + +}}} // namespace OVR::Render::GL diff --git a/Samples/CommonSrc/Render/Render_GL_Device.h b/Samples/CommonSrc/Render/Render_GL_Device.h index 9b8ccef..0e24517 100644 --- a/Samples/CommonSrc/Render/Render_GL_Device.h +++ b/Samples/CommonSrc/Render/Render_GL_Device.h @@ -43,9 +43,9 @@ limitations under the License. #include <GL/glx.h> #endif - namespace OVR { namespace Render { namespace GL { - + + #if !defined(OVR_OS_MAC) // GL extension Hooks for PC. @@ -114,6 +114,44 @@ extern void InitGLExtensions(); #endif + + +//// GLVersion + +/* + FIXME: CODE DUPLICATION WARNING + + Right now we have this same code in CommonSrc and in CAPI::GL. + At some point we need to consolidate these, in Kernel or Util. + Be sure to update both locations for now! +*/ + +struct GLVersionAndExtensions +{ + // Version information + int MajorVersion; // Best guess at major version + int MinorVersion; // Best guess at minor version + bool IsGLES; // Open GL ES? + + // Extension information + bool SupportsVAO; // Supports Vertex Array Objects? + bool SupportsDrawBuffers; // Supports Draw Buffers? + const char* Extensions; // Other extensions string (will not be null) + + GLVersionAndExtensions() + { + IsGLES = false; + MajorVersion = 0; + MinorVersion = 0; + SupportsDrawBuffers = false; + SupportsVAO = false; + Extensions = ""; + } +}; + +void GetGLVersionAndExtensions(GLVersionAndExtensions& versionInfo); + + class RenderDevice; class Buffer : public Render::Buffer @@ -243,10 +281,10 @@ protected: Ptr<Texture> CurRenderTarget; Array<Ptr<Texture> > DepthBuffers; GLuint CurrentFbo; + GLVersionAndExtensions GLVersionInfo; const LightingParams* Lighting; - bool SupportsVao; - + public: RenderDevice(const RendererParams& p); virtual ~RenderDevice(); @@ -258,6 +296,7 @@ public: virtual void SetViewport(const Recti& vp); virtual void WaitUntilGpuIdle(); + virtual void Flush(); virtual void Clear(float r = 0, float g = 0, float b = 0, float a = 1, float depth = 1, bool clearColor = true, bool clearDepth = true); @@ -292,6 +331,7 @@ public: void SetTexture(Render::ShaderStage, int slot, const Texture* t); }; + }}} #endif diff --git a/Samples/CommonSrc/Render/Render_GL_Win32_Device.cpp b/Samples/CommonSrc/Render/Render_GL_Win32_Device.cpp index 8b4ac73..b2e2e10 100644 --- a/Samples/CommonSrc/Render/Render_GL_Win32_Device.cpp +++ b/Samples/CommonSrc/Render/Render_GL_Win32_Device.cpp @@ -31,7 +31,7 @@ namespace OVR { namespace Render { namespace GL { namespace Win32 { typedef HRESULT (WINAPI *PFNDWMENABLECOMPOSITIONPROC) (UINT); #pragma warning(disable : 4995) -PFNDWMENABLECOMPOSITIONPROC DwmEnableComposition; +PFNDWMENABLECOMPOSITIONPROC DwmEnableComposition = NULL; // ***** GL::Win32::RenderDevice diff --git a/Samples/CommonSrc/Render/Render_LoadTextureDDS.cpp b/Samples/CommonSrc/Render/Render_LoadTextureDDS.cpp index 3da1441..08dda43 100644 --- a/Samples/CommonSrc/Render/Render_LoadTextureDDS.cpp +++ b/Samples/CommonSrc/Render/Render_LoadTextureDDS.cpp @@ -22,10 +22,6 @@ limitations under the License. ************************************************************************************/ #include "Render_Device.h" -#ifdef OVR_DEFINE_NEW -#undef new -#endif - namespace OVR { namespace Render { static const size_t OVR_DDS_PF_FOURCC = 0x4; diff --git a/Samples/CommonSrc/Render/Render_XmlSceneLoader.cpp b/Samples/CommonSrc/Render/Render_XmlSceneLoader.cpp index 3d035e2..0eea8eb 100644 --- a/Samples/CommonSrc/Render/Render_XmlSceneLoader.cpp +++ b/Samples/CommonSrc/Render/Render_XmlSceneLoader.cpp @@ -24,10 +24,6 @@ limitations under the License. #include "Render_XmlSceneLoader.h" #include <Kernel/OVR_Log.h> -#ifdef OVR_DEFINE_NEW -#undef new -#endif - namespace OVR { namespace Render { XmlHandler::XmlHandler() : pXmlDocument(NULL) diff --git a/Samples/CommonSrc/Render/Render_XmlSceneLoader.h b/Samples/CommonSrc/Render/Render_XmlSceneLoader.h index 7dff174..22c9ccd 100644 --- a/Samples/CommonSrc/Render/Render_XmlSceneLoader.h +++ b/Samples/CommonSrc/Render/Render_XmlSceneLoader.h @@ -29,10 +29,6 @@ limitations under the License. using namespace OVR; using namespace OVR::Render; -#ifdef OVR_DEFINE_NEW -#undef new -#endif - #include "../../../3rdParty/TinyXml/tinyxml2.h" namespace OVR { namespace Render { |