From f7d704fcf9d58f5bf107bda4cb89142028d00f28 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 29 Jun 2008 22:08:23 +0000 Subject: svn merge -r15360:HEAD https://svn.blender.org/svnroot/bf-blender/trunk/blender/ --- .../gameengine/Rasterizer/RAS_2DFilterManager.cpp | 101 +++++++++++++++++---- source/gameengine/Rasterizer/RAS_2DFilterManager.h | 10 +- source/gameengine/Rasterizer/RAS_IRenderTools.h | 2 +- .../RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp | 3 + .../RAS_VAOpenGLRasterizer.cpp | 5 +- 5 files changed, 96 insertions(+), 25 deletions(-) (limited to 'source/gameengine/Rasterizer') diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index e9ab4ccca8d..23153fcd86c 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -54,7 +54,7 @@ RAS_2DFilterManager::RAS_2DFilterManager(): -texname(-1), texturewidth(-1), textureheight(-1), +texturewidth(-1), textureheight(-1), canvaswidth(-1), canvasheight(-1), numberoffilters(0) { @@ -72,8 +72,9 @@ numberoffilters(0) { m_filters[passindex] = 0; m_enabled[passindex] = 0; + texflag[passindex] = 0; } - + texname[0] = texname[1] = texname[2] = -1; } RAS_2DFilterManager::~RAS_2DFilterManager() @@ -150,30 +151,54 @@ unsigned int RAS_2DFilterManager::CreateShaderProgram(int filtermode) return 0; } -void RAS_2DFilterManager::StartShaderProgram(unsigned int shaderprogram) +void RAS_2DFilterManager::StartShaderProgram(int passindex) { GLint uniformLoc; - glUseProgramObjectARB(shaderprogram); - uniformLoc = glGetUniformLocationARB(shaderprogram, "bgl_RenderedTexture"); + glUseProgramObjectARB(m_filters[passindex]); + uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_RenderedTexture"); glActiveTextureARB(GL_TEXTURE0); - //glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texname); + glBindTexture(GL_TEXTURE_2D, texname[0]); if (uniformLoc != -1) { glUniform1iARB(uniformLoc, 0); } - uniformLoc = glGetUniformLocationARB(shaderprogram, "bgl_TextureCoordinateOffset"); + + /* send depth texture to glsl program if it needs */ + if(texflag[passindex] & 0x1){ + uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_DepthTexture"); + glActiveTextureARB(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, texname[1]); + + if (uniformLoc != -1) + { + glUniform1iARB(uniformLoc, 1); + } + } + + /* send luminance texture to glsl program if it needs */ + if(texflag[passindex] & 0x1){ + uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_LuminanceTexture"); + glActiveTextureARB(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, texname[2]); + + if (uniformLoc != -1) + { + glUniform1iARB(uniformLoc, 2); + } + } + + uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_TextureCoordinateOffset"); if (uniformLoc != -1) { glUniform2fvARB(uniformLoc, 9, textureoffsets); } - uniformLoc = glGetUniformLocationARB(shaderprogram, "bgl_RenderedTextureWidth"); + uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_RenderedTextureWidth"); if (uniformLoc != -1) { glUniform1fARB(uniformLoc,texturewidth); } - uniformLoc = glGetUniformLocationARB(shaderprogram, "bgl_RenderedTextureHeight"); + uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_RenderedTextureHeight"); if (uniformLoc != -1) { glUniform1fARB(uniformLoc,textureheight); @@ -187,14 +212,33 @@ void RAS_2DFilterManager::EndShaderProgram() void RAS_2DFilterManager::SetupTexture() { - if(texname!=-1) + if(texname[0]!=-1 || texname[1]!=-1) { - glDeleteTextures(1,(const GLuint *)&texname); + glDeleteTextures(2, (GLuint*)texname); } - glGenTextures(1, (GLuint *)&texname); - glBindTexture(GL_TEXTURE_2D, texname); + glGenTextures(3, (GLuint*)texname); + + glBindTexture(GL_TEXTURE_2D, texname[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texturewidth, textureheight, 0, GL_RGB, - GL_UNSIGNED_BYTE, 0); + GL_UNSIGNED_BYTE, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + glBindTexture(GL_TEXTURE_2D, texname[1]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, texturewidth,textureheight, 0, GL_DEPTH_COMPONENT, + GL_FLOAT,NULL); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, + GL_NONE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + glBindTexture(GL_TEXTURE_2D, texname[2]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16, texturewidth, textureheight, 0, GL_LUMINANCE, + GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); @@ -246,12 +290,27 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) int passindex; bool first = true; + for(passindex =0; passindex