diff options
author | Hamed Zaghaghi <hamed.zaghaghi@gmail.com> | 2008-02-04 05:33:27 +0300 |
---|---|---|
committer | Hamed Zaghaghi <hamed.zaghaghi@gmail.com> | 2008-02-04 05:33:27 +0300 |
commit | 47b53510a56e80a6d82589334437ffbc706b5b67 (patch) | |
tree | ff48818dab8312318fa61c6130c62960ee6b9c78 /source/gameengine | |
parent | 2da3bd32dd34e44a326a30c43b33e75dc65ce95a (diff) | |
parent | bf4d79c47b9865a75ab0d6bb5649a8edce53a57d (diff) |
merging game_engine branch changes into trunk, 2d-filters and opengl speedup
Diffstat (limited to 'source/gameengine')
28 files changed, 1345 insertions, 28 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 0c42a35c808..e89c78614cc 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -176,9 +176,13 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, bool lock_arrays = (displaylists && useVertexArrays); - if(displaylists && !useVertexArrays) - rasterizer = new RAS_ListRasterizer(canvas); - else if (useVertexArrays && bgl::QueryVersion(1, 1)) + if(displaylists){ + if (useVertexArrays) { + rasterizer = new RAS_ListRasterizer(canvas, true, lock_arrays); + } else { + rasterizer = new RAS_ListRasterizer(canvas); + } + } else if (useVertexArrays && bgl::QueryVersion(1, 1)) rasterizer = new RAS_VAOpenGLRasterizer(canvas, lock_arrays); else rasterizer = new RAS_OpenGLRasterizer(canvas); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp index 463f06869d6..7e32ade37f2 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -475,4 +475,14 @@ void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer) } } +void KX_BlenderRenderTools::Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text) +{ + m_filtermanager.EnableFilter(filtermode, pass, text); +} + +void KX_BlenderRenderTools::Render2DFilters(RAS_ICanvas* canvas) +{ + m_filtermanager.RenderFilters(canvas); +} + unsigned int KX_BlenderRenderTools::m_numgllights; diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h index a79302a283e..3c2d4ac8e35 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h @@ -55,6 +55,7 @@ class KX_BlenderRenderTools : public RAS_IRenderTools bool m_lastlighting; static unsigned int m_numgllights; + public: KX_BlenderRenderTools(); @@ -102,8 +103,14 @@ public: bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data); virtual void MotionBlur(RAS_IRasterizer* rasterizer); + + virtual void Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text); + + virtual void Render2DFilters(RAS_ICanvas* canvas); + }; #endif //__KX_BLENDERRENDERTOOLS + diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index a6baa04b045..89a07abe21d 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -37,6 +37,8 @@ #define BLENDER_HACK_DTIME 0.02 +#include "MEM_guardedalloc.h" + #include "KX_BlenderSceneConverter.h" #include "KX_ConvertActuators.h" @@ -45,6 +47,7 @@ #include "SCA_PropertyActuator.h" #include "SCA_LogicManager.h" #include "SCA_RandomActuator.h" +#include "SCA_2DFilterActuator.h" // Ketsji specific logicbricks @@ -69,7 +72,7 @@ #include "KX_GameObject.h" /* This little block needed for linking to Blender... */ - +#include "BKE_text.h" #include "BLI_blenlib.h" #include "KX_NetworkMessageActuator.h" @@ -836,7 +839,84 @@ void BL_ConvertActuators(char* maggiename, baseact = tmp_vis_act; } break; + + case ACT_2DFILTER: + { + bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data; + SCA_2DFilterActuator *tmp = NULL; + RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode; + switch(_2dfilter->type) + { + case ACT_2DFILTER_MOTIONBLUR: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR; + break; + case ACT_2DFILTER_BLUR: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR; + break; + case ACT_2DFILTER_SHARPEN: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN; + break; + case ACT_2DFILTER_DILATION: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION; + break; + case ACT_2DFILTER_EROSION: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION; + break; + case ACT_2DFILTER_LAPLACIAN: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN; + break; + case ACT_2DFILTER_SOBEL: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL; + break; + case ACT_2DFILTER_PREWITT: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT; + break; + case ACT_2DFILTER_GRAYSCALE: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE; + break; + case ACT_2DFILTER_SEPIA: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA; + break; + case ACT_2DFILTER_INVERT: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT; + break; + case ACT_2DFILTER_CUSTOMFILTER: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER; + break; + case ACT_2DFILTER_NOFILTER: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER; + break; + case ACT_2DFILTER_DISABLED: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED; + break; + case ACT_2DFILTER_ENABLED: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED; + break; + default: + filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER; + break; + } + + tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag, + _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),rendertools); + + if (_2dfilter->text) + { + char *buf; + // this is some blender specific code + buf = txt_to_buf(_2dfilter->text); + if (buf) + { + tmp->SetShaderText(STR_String(buf)); + MEM_freeN(buf); + } + } + + baseact = tmp; + + } + break; default: ; /* generate some error */ } @@ -860,3 +940,4 @@ void BL_ConvertActuators(char* maggiename, } } + diff --git a/source/gameengine/GameLogic/CMakeLists.txt b/source/gameengine/GameLogic/CMakeLists.txt index 127edfc151d..4f40fa22b9e 100644 --- a/source/gameengine/GameLogic/CMakeLists.txt +++ b/source/gameengine/GameLogic/CMakeLists.txt @@ -35,6 +35,7 @@ SET(INC ../../../intern/string ../../../source/gameengine/Expressions ../../../intern/moto/include + ../../../source/gameengine/Rasterizer ${PYTHON_INC} ${SDL_INC} ) diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp new file mode 100644 index 00000000000..9627ad92c4c --- /dev/null +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp @@ -0,0 +1,118 @@ +#include "SCA_IActuator.h" + +#include "SCA_2DFilterActuator.h" + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <iostream> + + +SCA_2DFilterActuator::~SCA_2DFilterActuator() +{ +} + +SCA_2DFilterActuator::SCA_2DFilterActuator( + SCA_IObject *gameobj, + RAS_2DFilterManager::RAS_2DFILTER_MODE type, + short flag, + float float_arg, + int int_arg, + RAS_IRasterizer* rasterizer, + RAS_IRenderTools* rendertools, + PyTypeObject* T) + : SCA_IActuator(gameobj, T), + m_type(type), + m_flag(flag), + m_int_arg(int_arg), + m_float_arg(float_arg), + m_rasterizer(rasterizer), + m_rendertools(rendertools) +{ +} + +void SCA_2DFilterActuator::SetShaderText(STR_String& text) +{ + m_shaderText = text; +} + + + +CValue* SCA_2DFilterActuator::GetReplica() +{ + SCA_2DFilterActuator* replica = new SCA_2DFilterActuator(*this); + replica->ProcessReplica(); + CValue::AddDataToReplica(replica); + + return replica; +} + + +bool SCA_2DFilterActuator::Update() +{ + bool result = false; + + bool bNegativeEvent = IsNegativeEvent(); + RemoveAllEvents(); + + + if (bNegativeEvent) + return false; // do nothing on negative events + + if( m_type == RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR ) + { + if(!m_flag) + { + m_rasterizer->EnableMotionBlur(m_float_arg); + } + else + { + m_rasterizer->DisableMotionBlur(); + } + } + else if(m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS) + { + m_rendertools->Update2DFilter(m_type, m_int_arg, m_shaderText); + } + return true; +} + + +PyTypeObject SCA_2DFilterActuator::Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, + "SCA_2DFilterActuator", + sizeof(SCA_2DFilterActuator), + 0, + PyDestructor, + 0, + __getattr, + __setattr, + 0, + __repr, + 0, + 0, + 0, + 0, + 0 +}; + + +PyParentObject SCA_2DFilterActuator::Parents[] = { + &SCA_2DFilterActuator::Type, + &SCA_IActuator::Type, + &SCA_ILogicBrick::Type, + &CValue::Type, + NULL +}; + + +PyMethodDef SCA_2DFilterActuator::Methods[] = { + /* add python functions to deal with m_msg... */ + {NULL,NULL} +}; + + +PyObject* SCA_2DFilterActuator::_getattr(const STR_String& attr) { + _getattr_up(SCA_IActuator); +} diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h new file mode 100644 index 00000000000..76df95ac399 --- /dev/null +++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.h @@ -0,0 +1,44 @@ +#ifndef __SCA_2DFILETRACTUATOR_H__ +#define __SCA_2DFILETRACTUATOR_H__ + +#include "RAS_IRasterizer.h" +#include "RAS_IRenderTools.h" +#include "SCA_IActuator.h" + + +class SCA_2DFilterActuator : public SCA_IActuator +{ + Py_Header; + +private: + + RAS_2DFilterManager::RAS_2DFILTER_MODE m_type; + short m_flag; + float m_float_arg; + int m_int_arg; + STR_String m_shaderText; + RAS_IRasterizer* m_rasterizer; + RAS_IRenderTools* m_rendertools; + +public: + + SCA_2DFilterActuator( + class SCA_IObject* gameobj, + RAS_2DFilterManager::RAS_2DFILTER_MODE type, + short flag, + float float_arg, + int int_arg, + RAS_IRasterizer* rasterizer, + RAS_IRenderTools* rendertools, + PyTypeObject* T=&Type + ); + + void SetShaderText(STR_String& text); + virtual ~SCA_2DFilterActuator(); + virtual bool Update(); + + virtual CValue* GetReplica(); + virtual PyObject* _getattr(const STR_String& attr); + +}; +#endif diff --git a/source/gameengine/GameLogic/SConscript b/source/gameengine/GameLogic/SConscript index 7a2c3d91e72..1ca884f6dec 100644 --- a/source/gameengine/GameLogic/SConscript +++ b/source/gameengine/GameLogic/SConscript @@ -5,6 +5,7 @@ sources = env.Glob('*.cpp') + env.Glob('Joystick/*.cpp') incs = '. #/source/kernel/gen_system #/intern/string' incs += ' #/source/gameengine/Expressions #/intern/moto/include' +incs += ' #/source/gameengine/Rasterizer' incs += ' ' + env['BF_PYTHON_INC'] incs += ' ' + env['BF_SDL_INC'] diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp index cc5c392d51a..388882e67e4 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp @@ -593,4 +593,14 @@ void GPC_RenderTools::MotionBlur(RAS_IRasterizer* rasterizer) } } +void GPC_RenderTools::Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text) +{ + m_filtermanager.EnableFilter(filtermode, pass, text); +} + +void GPC_RenderTools::Render2DFilters(RAS_ICanvas* canvas) +{ + m_filtermanager.RenderFilters( canvas); +} + unsigned int GPC_RenderTools::m_numgllights; diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.h b/source/gameengine/GamePlayer/common/GPC_RenderTools.h index e1f2a869c22..d90f0e5da45 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.h +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.h @@ -151,6 +151,11 @@ public: bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data); virtual void MotionBlur(RAS_IRasterizer* rasterizer); + + virtual void Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text); + + virtual void Render2DFilters(RAS_ICanvas* canvas); + protected: /** * Copied from KX_BlenderGL.cpp in KX_blenderhook @@ -176,3 +181,4 @@ protected: #endif // __GPC_RENDERTOOLS_H + diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index 4f6c78a0fd8..5ef20514390 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -537,7 +537,11 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode) goto initFailed; if(useLists) - m_rasterizer = new RAS_ListRasterizer(m_canvas); + if (useVertexArrays) { + m_rasterizer = new RAS_ListRasterizer(m_canvas, true); + } else { + m_rasterizer = new RAS_ListRasterizer(m_canvas); + } else if (useVertexArrays && bgl::QueryVersion(1, 1)) m_rasterizer = new RAS_VAOpenGLRasterizer(m_canvas); else diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index f8826245aab..e0a826b8d5d 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -966,13 +966,18 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam) scene->CalculateVisibleMeshes(m_rasterizer,cam); scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools); + + PostRenderFrame(); +} +void KX_KetsjiEngine::PostRenderFrame() +{ + m_rendertools->PushMatrix(); + m_rendertools->Render2DFilters(m_canvas); m_rendertools->MotionBlur(m_rasterizer); - + m_rendertools->PopMatrix(); } - - void KX_KetsjiEngine::StopEngine() { if (m_bInitialized) @@ -1467,3 +1472,4 @@ void KX_KetsjiEngine::GetOverrideFrameColor(float& r, float& g, float& b) const } + diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index 16b53b6b688..fcb4d0a0790 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -179,6 +179,7 @@ private: void SetupRenderFrame(KX_Scene *scene, KX_Camera* cam); void RenderFrame(KX_Scene* scene, KX_Camera* cam); + void PostRenderFrame(); void RenderDebugProperties(); void SetBackGround(KX_WorldInfo* worldinfo); void SetWorldSettings(KX_WorldInfo* worldinfo); @@ -201,6 +202,8 @@ public: void SetSceneConverter(KX_ISceneConverter* sceneconverter); void SetGame2IpoMode(bool game2ipo,int startFrame); + RAS_IRasterizer* GetRasterizer(){return m_rasterizer;}; + ///returns true if an update happened to indicate -> Render bool NextFrame(); void Render(); @@ -342,3 +345,4 @@ protected: #endif //__KX_KETSJI_ENGINE + 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;} }; |