diff options
Diffstat (limited to 'source/gameengine/Rasterizer')
15 files changed, 1041 insertions, 20 deletions
diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp new file mode 100644 index 00000000000..7b895258c1e --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -0,0 +1,340 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#define STRINGIFY(A) #A + +#include "RAS_OpenGLFilters/RAS_Blur2DFilter.h" +#include "RAS_OpenGLFilters/RAS_Sharpen2DFilter.h" +#include "RAS_OpenGLFilters/RAS_Dilation2DFilter.h" +#include "RAS_OpenGLFilters/RAS_Erosion2DFilter.h" +#include "RAS_OpenGLFilters/RAS_Laplacian2DFilter.h" +#include "RAS_OpenGLFilters/RAS_Sobel2DFilter.h" +#include "RAS_OpenGLFilters/RAS_Prewitt2DFilter.h" +#include "RAS_OpenGLFilters/RAS_GrayScale2DFilter.h" +#include "RAS_OpenGLFilters/RAS_Sepia2DFilter.h" +#include "RAS_OpenGLFilters/RAS_Invert2DFilter.h" + +#include "STR_String.h" +#include "RAS_ICanvas.h" +#include "RAS_2DFilterManager.h" +#include <iostream> + +#ifdef WIN32 +// OpenGL gl.h needs 'windows.h' on windows platforms +#include <windows.h> +#endif //WIN32 +#ifdef __APPLE__ +#define GL_GLEXT_LEGACY 1 +#include <OpenGL/gl.h> +#else +#include <GL/gl.h> +#endif + +#include "RAS_OpenGLRasterizer/RAS_GLExtensionManager.h" + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + + +RAS_2DFilterManager::RAS_2DFilterManager(): +texturewidth(-1), textureheight(-1), +canvaswidth(-1), canvasheight(-1), +numberoffilters(0),texname(-1) +{ + isshadersupported = bgl::QueryVersion(2,0); + if(!isshadersupported) + { + std::cout<<"shaders not supported!" << std::endl; + return; + } + + int passindex; + for(passindex =0; passindex<MAX_RENDER_PASS; passindex++) + { + m_filters[passindex] = 0; + m_enabled[passindex] = 0; + } + +} + +RAS_2DFilterManager::~RAS_2DFilterManager() +{ +} + +unsigned int RAS_2DFilterManager::CreateShaderProgram(char* shadersource) +{ + GLuint program; + GLuint fShader = bgl::blCreateShaderObjectARB(GL_FRAGMENT_SHADER); + GLint success; + + bgl::blShaderSourceARB(fShader, 1, (const char**)&shadersource, NULL); + + bgl::blCompileShaderARB(fShader); + + bgl::blGetObjectParameterivARB(fShader, GL_COMPILE_STATUS, &success); + if(!success) + { + /*Shader Comile Error*/ + std::cout << "2dFilters - Shader compile error" << std::endl; + return 0; + } + + program = bgl::blCreateProgramObjectARB(); + bgl::blAttachObjectARB(program, fShader); + + bgl::blLinkProgramARB(program); + bgl::blGetObjectParameterivARB(program, GL_LINK_STATUS, &success); + if (!success) + { + /*Program Link Error*/ + std::cout << "2dFilters - Shader program link error" << std::endl; + return 0; + } + + bgl::blValidateProgramARB(program); + bgl::blGetObjectParameterivARB(program, GL_VALIDATE_STATUS, &success); + if (!success) + { + /*Program Validation Error*/ + std::cout << "2dFilters - Shader program validation error" << std::endl; + return 0; + } + return program; +} + +unsigned int RAS_2DFilterManager::CreateShaderProgram(int filtermode) +{ + switch(filtermode) + { + case RAS_2DFILTER_BLUR: + return CreateShaderProgram(BlurFragmentShader); + case RAS_2DFILTER_SHARPEN: + return CreateShaderProgram(SharpenFragmentShader); + case RAS_2DFILTER_DILATION: + return CreateShaderProgram(DilationFragmentShader); + case RAS_2DFILTER_EROSION: + return CreateShaderProgram(ErosionFragmentShader); + case RAS_2DFILTER_LAPLACIAN: + return CreateShaderProgram(LaplacionFragmentShader); + case RAS_2DFILTER_SOBEL: + return CreateShaderProgram(SobelFragmentShader); + case RAS_2DFILTER_PREWITT: + return CreateShaderProgram(PrewittFragmentShader); + case RAS_2DFILTER_GRAYSCALE: + return CreateShaderProgram(GrayScaleFragmentShader); + case RAS_2DFILTER_SEPIA: + return CreateShaderProgram(SepiaFragmentShader); + case RAS_2DFILTER_INVERT: + return CreateShaderProgram(InvertFragmentShader); + } + return 0; +} + +void RAS_2DFilterManager::StartShaderProgram(unsigned int shaderprogram) +{ + GLint uniformLoc; + bgl::blUseProgramObjectARB(shaderprogram); + uniformLoc = bgl::blGetUniformLocationARB(shaderprogram, "bgl_RenderedTexture"); + if (uniformLoc != -1) + { + bgl::blUniform1iARB(uniformLoc, 0); + } + uniformLoc = bgl::blGetUniformLocationARB(shaderprogram, "bgl_TextureCoordinateOffset"); + if (uniformLoc != -1) + { + bgl::blUniform2fvARB(uniformLoc, 9, textureoffsets); + } + uniformLoc = bgl::blGetUniformLocationARB(shaderprogram, "bgl_RenderedTextureWidth"); + if (uniformLoc != -1) + { + bgl::blUniform1fARB(uniformLoc,texturewidth); + } + uniformLoc = bgl::blGetUniformLocationARB(shaderprogram, "bgl_RenderedTextureHeight"); + if (uniformLoc != -1) + { + bgl::blUniform1fARB(uniformLoc,textureheight); + } + +} + +void RAS_2DFilterManager::EndShaderProgram() +{ + bgl::blUseProgramObjectARB(0); +} + +void RAS_2DFilterManager::SetupTexture() +{ + if(texname!=-1) + { + glDeleteTextures(1,&texname); + } + glGenTextures(1, &texname); + glBindTexture(GL_TEXTURE_2D, texname); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texturewidth, textureheight, 0, GL_RGB, + 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); +} + +void RAS_2DFilterManager::UpdateOffsetMatrix(int width, int height) +{ + canvaswidth = texturewidth = width; + canvasheight = textureheight = height; + + GLint i,j; + i = 0; + while ((1 << i) <= texturewidth) + i++; + texturewidth = (1 << (i)); + + // Now for height + i = 0; + while ((1 << i) <= textureheight) + i++; + textureheight = (1 << (i)); + + GLfloat xInc = 1.0f / (GLfloat)texturewidth; + GLfloat yInc = 1.0f / (GLfloat)textureheight; + + for (i = 0; i < 3; i++) + { + for (j = 0; j < 3; j++) + { + textureoffsets[(((i*3)+j)*2)+0] = (-1.0f * xInc) + ((GLfloat)i * xInc); + textureoffsets[(((i*3)+j)*2)+1] = (-1.0f * yInc) + ((GLfloat)j * yInc); + } + } + + SetupTexture(); +} + +void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) +{ + if(!isshadersupported) + return; + + if(canvaswidth != canvas->GetWidth() || canvasheight != canvas->GetHeight()) + { + UpdateOffsetMatrix(canvas->GetWidth(), canvas->GetHeight()); + } + GLuint viewport[4]={0}; + + int passindex; + bool first = true; + for(passindex =0; passindex<MAX_RENDER_PASS; passindex++) + { + if(m_filters[passindex] && m_enabled[passindex]) + { + if(first) + { + glGetIntegerv(GL_VIEWPORT,(int*)viewport); + glViewport(0, 0, texturewidth, textureheight); + + glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + first = false; + } + + StartShaderProgram(m_filters[passindex]); + + glBindTexture(GL_TEXTURE_2D, texname); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, texturewidth, textureheight, 0); + + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_QUADS); + glColor4f(1.f, 1.f, 1.f, 1.f); + glTexCoord2f(1.0, 1.0); glVertex2f(1,1); + glTexCoord2f(0.0, 1.0); glVertex2f(-1,1); + glTexCoord2f(0.0, 0.0); glVertex2f(-1,-1); + glTexCoord2f(1.0, 0.0); glVertex2f(1,-1); + glEnd(); + } + } + + if(!first) + { + glEnable(GL_DEPTH_TEST); + glViewport(viewport[0],viewport[1],viewport[2],viewport[3]); + EndShaderProgram(); + } +} + +void RAS_2DFilterManager::EnableFilter(RAS_2DFILTER_MODE mode, int pass, STR_String& text) +{ + if(!isshadersupported) + return; + if(pass<0 || pass>=MAX_RENDER_PASS) + return; + + if(mode == RAS_2DFILTER_DISABLED) + { + m_enabled[pass] = 0; + return; + } + + if(mode == RAS_2DFILTER_ENABLED) + { + m_enabled[pass] = 1; + return; + } + + if(mode == RAS_2DFILTER_NOFILTER) + { + if(m_filters[pass]) + bgl::blDeleteObjectARB(m_filters[pass]); + m_enabled[pass] = 0; + m_filters[pass] = 0; + return; + } + + if(mode == RAS_2DFILTER_CUSTOMFILTER) + { + if(m_filters[pass]) + bgl::blDeleteObjectARB(m_filters[pass]); + m_filters[pass] = CreateShaderProgram(text.Ptr()); + m_enabled[pass] = 1; + return; + } + + if(mode>=RAS_2DFILTER_MOTIONBLUR && mode<=RAS_2DFILTER_INVERT) + { + if(m_filters[pass]) + bgl::blDeleteObjectARB(m_filters[pass]); + m_filters[pass] = CreateShaderProgram(mode); + m_enabled[pass] = 1; + } +} diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.h b/source/gameengine/Rasterizer/RAS_2DFilterManager.h new file mode 100644 index 00000000000..227d2a26d41 --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.h @@ -0,0 +1,91 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_I2DFILTER +#define __RAS_I2DFILTER + + + +#define MAX_RENDER_PASS 100 + +class RAS_2DFilterManager +{ +private: + unsigned int CreateShaderProgram(char* shadersource); + unsigned int CreateShaderProgram(int filtermode); + void StartShaderProgram(unsigned int shaderprogram); + void EndShaderProgram(); + + float textureoffsets[18]; + float view[4]; + unsigned int texname; + int texturewidth; + int textureheight; + int canvaswidth; + int canvasheight; + int numberoffilters; + + bool isshadersupported; +public: + enum RAS_2DFILTER_MODE { + RAS_2DFILTER_ENABLED = -2, + RAS_2DFILTER_DISABLED = -1, + RAS_2DFILTER_NOFILTER = 0, + RAS_2DFILTER_MOTIONBLUR, + RAS_2DFILTER_BLUR, + RAS_2DFILTER_SHARPEN, + RAS_2DFILTER_DILATION, + RAS_2DFILTER_EROSION, + RAS_2DFILTER_LAPLACIAN, + RAS_2DFILTER_SOBEL, + RAS_2DFILTER_PREWITT, + RAS_2DFILTER_GRAYSCALE, + RAS_2DFILTER_SEPIA, + RAS_2DFILTER_INVERT, + RAS_2DFILTER_CUSTOMFILTER, + RAS_2DFILTER_NUMBER_OF_FILTERS + }; + + unsigned int m_filters[MAX_RENDER_PASS]; + short m_enabled[MAX_RENDER_PASS]; + + RAS_2DFilterManager(); + + ~RAS_2DFilterManager(); + + void SetupTexture(); + + void UpdateOffsetMatrix(int width, int height); + + void RenderFilters(RAS_ICanvas* canvas); + + void EnableFilter(RAS_2DFILTER_MODE mode, int pass, STR_String& text); +}; +#endif diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h index 114783b9a47..771c34a595f 100644 --- a/source/gameengine/Rasterizer/RAS_IRenderTools.h +++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h @@ -34,6 +34,7 @@ #include "MT_Transform.h" #include "RAS_IRasterizer.h" +#include "RAS_2DFilterManager.h" #include <vector> #include <algorithm> @@ -41,6 +42,7 @@ class RAS_IPolyMaterial; struct RAS_LightObject; + class RAS_IRenderTools { @@ -52,7 +54,8 @@ protected: bool m_modified; std::vector<struct RAS_LightObject*> m_lights; - + + RAS_2DFilterManager m_filtermanager; public: enum RAS_TEXT_RENDER_MODE { @@ -61,7 +64,7 @@ public: RAS_TEXT_PADDED, RAS_TEXT_MAX }; - + RAS_IRenderTools( ) : m_clientobject(NULL), @@ -178,6 +181,14 @@ public: void MotionBlur(RAS_IRasterizer* rasterizer)=0; + virtual + void + Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)=0; + + virtual + void + Render2DFilters(RAS_ICanvas* canvas)=0; + virtual class RAS_IPolyMaterial* CreateBlenderPolyMaterial( @@ -200,3 +211,4 @@ public: #endif //__RAS_IRENDERTOOLS + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h new file mode 100644 index 00000000000..ac4c2456573 --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h @@ -0,0 +1,54 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_BLUR2DFILTER +#define __RAS_BLUR2DFILTER + +char * BlurFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; +uniform vec2 bgl_TextureCoordinateOffset[9]; + +void main(void) +{ + vec4 sample[9]; + + for (int i = 0; i < 9; i++) + { + sample[i] = texture2D(bgl_RenderedTexture, + gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]); + } + + gl_FragColor = (sample[0] + (2.0*sample[1]) + sample[2] + + (2.0*sample[3]) + sample[4] + (2.0*sample[5]) + + sample[6] + (2.0*sample[7]) + sample[8]) / 13.0; +} +); +#endif + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h new file mode 100644 index 00000000000..44f67af3d75 --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h @@ -0,0 +1,54 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_DILATION2DFILTER +#define __RAS_DILATION2DFILTER + +char * DilationFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; +uniform vec2 bgl_TextureCoordinateOffset[9]; + +void main(void) +{ + vec4 sample[9]; + vec4 maxValue = vec4(0.0); + + for (int i = 0; i < 9; i++) + { + sample[i] = texture2D(bgl_RenderedTexture, + gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]); + maxValue = max(sample[i], maxValue); + } + + gl_FragColor = maxValue; +} +); +#endif + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h new file mode 100644 index 00000000000..80b6f184c36 --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h @@ -0,0 +1,53 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_EROSION2DFILTER +#define __RAS_EROSION2DFILTER + +char * ErosionFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; +uniform vec2 bgl_TextureCoordinateOffset[9]; + +void main(void) +{ + vec4 sample[9]; + vec4 minValue = vec4(1.0); + + for (int i = 0; i < 9; i++) + { + sample[i] = texture2D(bgl_RenderedTexture, + gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]); + minValue = min(sample[i], minValue); + } + + gl_FragColor = minValue; +} +); +#endif diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h new file mode 100644 index 00000000000..29cc91814ce --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h @@ -0,0 +1,44 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_GRAYSCALE2DFILTER +#define __RAS_GRAYSCALE2DFILTER + +char * GrayScaleFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; + +void main(void) +{ + vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st); + float gray = dot(texcolor.rgb, vec3(0.299, 0.587, 0.114)); + gl_FragColor = vec4(gray, gray, gray, texcolor.a); +} +); +#endif diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h new file mode 100644 index 00000000000..a3482f9647f --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h @@ -0,0 +1,44 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_INVERT2DFILTER +#define __RAS_INVERT2DFILTER + +char * InvertFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; + +void main(void) +{ + vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st); + gl_FragColor.rgb = 1.0 - texcolor.rgb; + gl_FragColor.a = texcolor.a; +} +); +#endif diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h new file mode 100644 index 00000000000..636ecdb68aa --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h @@ -0,0 +1,56 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_LAPLACION2DFILTER +#define __RAS_LAPLACION2DFILTER + +char * LaplacionFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; +uniform vec2 bgl_TextureCoordinateOffset[9]; + +void main(void) +{ + vec4 sample[9]; + + for (int i = 0; i < 9; i++) + { + sample[i] = texture2D(bgl_RenderedTexture, + gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]); + } + + gl_FragColor = (sample[4] * 8.0) - + (sample[0] + sample[1] + sample[2] + + sample[3] + sample[5] + + sample[6] + sample[7] + sample[8]); + gl_FragColor = vec4(gl_FragColor.rgb, 1.0); +} +); +#endif + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h new file mode 100644 index 00000000000..8046aacfbb1 --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h @@ -0,0 +1,61 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_PREWITT2DFILTER +#define __RAS_PREWITT2DFILTER + +char * PrewittFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; +uniform vec2 bgl_TextureCoordinateOffset[9]; + +void main(void) +{ + vec4 sample[9]; + + for (int i = 0; i < 9; i++) + { + sample[i] = texture2D(bgl_RenderedTexture, + gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]); + } + + vec4 horizEdge = sample[2] + sample[5] + sample[8] - + (sample[0] + sample[3] + sample[6]); + + vec4 vertEdge = sample[0] + sample[1] + sample[2] - + (sample[6] + sample[7] + sample[8]); + + gl_FragColor.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) + + (vertEdge.rgb * vertEdge.rgb)); + gl_FragColor.a = 1.0; +} + +); +#endif + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h new file mode 100644 index 00000000000..b56911a48b4 --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h @@ -0,0 +1,44 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_SEPIA2DFILTER +#define __RAS_SEPIA2DFILTER + +char * SepiaFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; + +void main(void) +{ + vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st); + float gray = dot(texcolor.rgb, vec3(0.299, 0.587, 0.114)); + gl_FragColor = vec4(gray * vec3(1.2, 1.0, 0.8), texcolor.a); +} +); +#endif diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h new file mode 100644 index 00000000000..e5f942a535c --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h @@ -0,0 +1,55 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_SHARPEN2DFILTER +#define __RAS_SHARPEN2DFILTER + +char * SharpenFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; +uniform vec2 bgl_TextureCoordinateOffset[9]; + +void main(void) +{ + vec4 sample[9]; + + for (int i = 0; i < 9; i++) + { + sample[i] = texture2D(bgl_RenderedTexture, + gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]); + } + + gl_FragColor = (sample[4] * 9.0) - + (sample[0] + sample[1] + sample[2] + + sample[3] + sample[5] + + sample[6] + sample[7] + sample[8]); +} +); +#endif + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h new file mode 100644 index 00000000000..545e76601e8 --- /dev/null +++ b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h @@ -0,0 +1,60 @@ +/** + * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. The Blender + * Foundation also sells licenses for use in proprietary software under + * the Blender License. See http://www.blender.org/BL/ for information + * about this. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL/BL DUAL LICENSE BLOCK ***** + */ + +#ifndef __RAS_SOBEL2DFILTER +#define __RAS_SOBEL2DFILTER + +char * SobelFragmentShader=STRINGIFY( +uniform sampler2D bgl_RenderedTexture; +uniform vec2 bgl_TextureCoordinateOffset[9]; + +void main(void) +{ + vec4 sample[9]; + + for (int i = 0; i < 9; i++) + { + sample[i] = texture2D(bgl_RenderedTexture, + gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]); + } + + vec4 horizEdge = sample[2] + (2.0*sample[5]) + sample[8] - + (sample[0] + (2.0*sample[3]) + sample[6]); + + vec4 vertEdge = sample[0] + (2.0*sample[1]) + sample[2] - + (sample[6] + (2.0*sample[7]) + sample[8]); + + gl_FragColor.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) + + (vertEdge.rgb * vertEdge.rgb)); + gl_FragColor.a = 1.0; +} +); +#endif + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp index ed4cfb2ae42..7baa6c49656 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp @@ -96,8 +96,9 @@ bool RAS_ListSlot::End() -RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas) -: RAS_OpenGLRasterizer(canvas) +RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas, bool useVertexArrays, bool lock) +: RAS_VAOpenGLRasterizer(canvas, lock), + mUseVertexArrays(useVertexArrays) { // -- } @@ -159,13 +160,22 @@ void RAS_ListRasterizer::IndexPrimitives( if(localSlot->End()) return; } - - RAS_OpenGLRasterizer::IndexPrimitives( - vertexarrays, indexarrays, - mode, polymat, - rendertools, useObjectColor, - rgbacolor,slot - ); + + if (mUseVertexArrays) { + RAS_VAOpenGLRasterizer::IndexPrimitives( + vertexarrays, indexarrays, + mode, polymat, + rendertools, useObjectColor, + rgbacolor,slot + ); + } else { + RAS_OpenGLRasterizer::IndexPrimitives( + vertexarrays, indexarrays, + mode, polymat, + rendertools, useObjectColor, + rgbacolor,slot + ); + } if(!useObjectColor) { localSlot->EndList(); @@ -195,16 +205,53 @@ void RAS_ListRasterizer::IndexPrimitivesMulti( return; } - RAS_OpenGLRasterizer::IndexPrimitivesMulti( - vertexarrays, indexarrays, - mode, polymat, - rendertools, useObjectColor, - rgbacolor,slot - ); + if (mUseVertexArrays) { + RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( + vertexarrays, indexarrays, + mode, polymat, + rendertools, useObjectColor, + rgbacolor,slot + ); + } else { + RAS_OpenGLRasterizer::IndexPrimitivesMulti( + vertexarrays, indexarrays, + mode, polymat, + rendertools, useObjectColor, + rgbacolor,slot + ); + } + if(!useObjectColor) { localSlot->EndList(); *slot = localSlot; } } +bool RAS_ListRasterizer::Init(void) +{ + if (mUseVertexArrays) { + return RAS_VAOpenGLRasterizer::Init(); + } else { + return RAS_OpenGLRasterizer::Init(); + } +} + +void RAS_ListRasterizer::SetDrawingMode(int drawingmode) +{ + if (mUseVertexArrays) { + RAS_VAOpenGLRasterizer::SetDrawingMode(drawingmode); + } else { + RAS_OpenGLRasterizer::SetDrawingMode(drawingmode); + } +} + +void RAS_ListRasterizer::Exit() +{ + if (mUseVertexArrays) { + RAS_VAOpenGLRasterizer::Exit(); + } else { + RAS_OpenGLRasterizer::Exit(); + } +} + // eof diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h index 82840cd1399..f25f621f70c 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h @@ -2,7 +2,7 @@ #define __RAS_LISTRASTERIZER_H__ #include "RAS_MaterialBucket.h" -#include "RAS_OpenGLRasterizer.h" +#include "RAS_VAOpenGLRasterizer.h" #include <vector> class RAS_ListSlot : public KX_ListSlot @@ -33,15 +33,16 @@ enum RAS_ListSlotFlags { typedef std::map<const vecVertexArray, RAS_ListSlot*> RAS_Lists; -class RAS_ListRasterizer : public RAS_OpenGLRasterizer +class RAS_ListRasterizer : public RAS_VAOpenGLRasterizer { + bool mUseVertexArrays; RAS_Lists mLists; RAS_ListSlot* FindOrAdd(const vecVertexArray& vertexarrays, KX_ListSlot** slot); void ReleaseAlloc(); public: - RAS_ListRasterizer(RAS_ICanvas* canvas); + RAS_ListRasterizer(RAS_ICanvas* canvas, bool useVertexArrays=false, bool lock=false); virtual ~RAS_ListRasterizer(); virtual void IndexPrimitives( @@ -66,6 +67,11 @@ public: class KX_ListSlot** slot ); + virtual bool Init(); + virtual void Exit(); + + virtual void SetDrawingMode(int drawingmode); + virtual bool QueryLists(){return true;} }; |