From 555f5110fba6040226b587de1bcbd4c785b8c60b Mon Sep 17 00:00:00 2001 From: OV2 Date: Tue, 26 Mar 2013 16:09:01 +0100 Subject: [PATCH] win32: add float_framebuffer to cg shaders --- win32/CCGShader.cpp | 3 +++ win32/CCGShader.h | 1 + win32/CD3DCG.cpp | 8 +++++--- win32/CD3DCG.h | 3 ++- win32/CGLCG.cpp | 4 +++- win32/CGLCG.h | 1 + 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/win32/CCGShader.cpp b/win32/CCGShader.cpp index e0fe089b..cc1a8f4b 100644 --- a/win32/CCGShader.cpp +++ b/win32/CCGShader.cpp @@ -278,6 +278,9 @@ bool CCGShader::LoadShader(const char *path) sprintf(keyName,"::frame_count_mod%u",i); pass.frameCounterMod = conf.GetInt(keyName,0); + sprintf(keyName,"::float_framebuffer%u",i); + pass.floatFbo = conf.GetBool(keyName); + shaderPasses.push_back(pass); } diff --git a/win32/CCGShader.h b/win32/CCGShader.h index 527cafe2..a0d49dea 100644 --- a/win32/CCGShader.h +++ b/win32/CCGShader.h @@ -200,6 +200,7 @@ public: cgScaleParams scaleParams; bool linearFilter; bool filterSet; + bool floatFbo; unsigned frameCounterMod; char cgShaderFile[PATH_MAX]; } shaderPass; diff --git a/win32/CD3DCG.cpp b/win32/CD3DCG.cpp index 925157de..d0f5128f 100644 --- a/win32/CD3DCG.cpp +++ b/win32/CD3DCG.cpp @@ -334,6 +334,8 @@ bool CD3DCG::LoadShader(const TCHAR *shaderFile) pass.frameCounterMod = it->frameCounterMod; + pass.useFloatTex = it->floatFbo; + // paths in the meta file can be relative _tfullpath(tempPath,_tFromChar(it->cgShaderFile),MAX_PATH); char *fileContents = ReadShaderFileContents(tempPath); @@ -415,7 +417,7 @@ bool CD3DCG::LoadShader(const TCHAR *shaderFile) } void CD3DCG::ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, D3DXVECTOR2 &texSize, - D3DXVECTOR2 wantedSize,bool renderTarget) + D3DXVECTOR2 wantedSize,bool renderTarget,bool useFloat) { HRESULT hr; @@ -427,7 +429,7 @@ void CD3DCG::ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, D3DXVECTOR2 &texSize, wantedSize.x, wantedSize.y, 1, // 1 level, no mipmaps renderTarget?D3DUSAGE_RENDERTARGET:0, - renderTarget?D3DFMT_X8R8G8B8:D3DFMT_R5G6B5, + renderTarget?(useFloat?D3DFMT_A32B32G32R32F:D3DFMT_X8R8G8B8):D3DFMT_R5G6B5, renderTarget?D3DPOOL_DEFAULT:D3DPOOL_MANAGED, // render targets cannot be managed &tex, NULL ); @@ -536,7 +538,7 @@ void CD3DCG::Render(LPDIRECT3DTEXTURE9 &origTex, D3DXVECTOR2 textureSize, /* make sure the render target exists and has an appropriate size, then set as current render target with last pass as source */ - ensureTextureSize(shaderPasses[i].tex,shaderPasses[i].textureSize,D3DXVECTOR2(texSize,texSize),true); + ensureTextureSize(shaderPasses[i].tex,shaderPasses[i].textureSize,D3DXVECTOR2(texSize,texSize),true,shaderPasses[i].useFloatTex); shaderPasses[i].tex->GetSurfaceLevel(0,&pRenderSurface); pDevice->SetTexture(0, shaderPasses[i-1].tex); pDevice->SetRenderTarget(0,pRenderSurface); diff --git a/win32/CD3DCG.h b/win32/CD3DCG.h index 12d1f19a..ff3d7fab 100644 --- a/win32/CD3DCG.h +++ b/win32/CD3DCG.h @@ -197,6 +197,7 @@ private: typedef struct _shaderPass { cgScaleParams scaleParams; bool linearFilter; + bool useFloatTex; unsigned int frameCounterMod; CGprogram cgVertexProgram, cgFragmentProgram; LPDIRECT3DTEXTURE9 tex; @@ -241,7 +242,7 @@ private: void setVertexStream(IDirect3DVertexBuffer9 *vertexBuffer,D3DXVECTOR2 inputSize,D3DXVECTOR2 textureSize,D3DXVECTOR2 outputSize); void setViewport(DWORD x, DWORD y, DWORD width, DWORD height); void setShaderVars(int pass); - void ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, D3DXVECTOR2 &texSize, D3DXVECTOR2 wantedSize,bool renderTarget); + void ensureTextureSize(LPDIRECT3DTEXTURE9 &tex, D3DXVECTOR2 &texSize, D3DXVECTOR2 wantedSize,bool renderTarget, bool useFloat = false); void fillParameterMap(std::vector &map, CGparameter param); void setupVertexDeclaration(shaderPass &pass); void calculateMatrix(); diff --git a/win32/CGLCG.cpp b/win32/CGLCG.cpp index e7767419..2babd61e 100644 --- a/win32/CGLCG.cpp +++ b/win32/CGLCG.cpp @@ -346,6 +346,8 @@ bool CGLCG::LoadShader(const TCHAR *shaderFile) pass.frameCounterMod = it->frameCounterMod; + pass.floatFbo = it->floatFbo; + // paths in the meta file can be relative _tfullpath(tempPath,_tFromChar(it->cgShaderFile),MAX_PATH); char *fileContents = ReadShaderFileContents(tempPath); @@ -533,7 +535,7 @@ void CGLCG::Render(GLuint &origTex, xySize textureSize, xySize inputSize, xySize /* set size of output texture */ glBindTexture(GL_TEXTURE_2D,shaderPasses[i].tex); - glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,(unsigned int)shaderPasses[i].textureSize.x, + glTexImage2D(GL_TEXTURE_2D,0,(shaderPasses[i].floatFbo?GL_RGBA32F:GL_RGBA),(unsigned int)shaderPasses[i].textureSize.x, (unsigned int)shaderPasses[i].textureSize.y,0,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,NULL); /* viewport determines the area we render into the output texture diff --git a/win32/CGLCG.h b/win32/CGLCG.h index 8064dd9b..1c586936 100644 --- a/win32/CGLCG.h +++ b/win32/CGLCG.h @@ -213,6 +213,7 @@ private: cgScaleParams scaleParams; bool linearFilter; unsigned frameCounterMod; + bool floatFbo; CGprogram cgVertexProgram, cgFragmentProgram; GLuint tex; GLuint fbo;