Blender  V2.59
RAS_2DFilterManager.h
Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00032 #ifndef __RAS_I2DFILTER
00033 #define __RAS_I2DFILTER
00034 
00035 #include "RAS_ICanvas.h"
00036 #define MAX_RENDER_PASS 100
00037 
00038 #ifdef WITH_CXX_GUARDEDALLOC
00039 #include "MEM_guardedalloc.h"
00040 #endif
00041 
00042 class RAS_2DFilterManager
00043 {
00044 private:
00045         unsigned int    CreateShaderProgram(const char* shadersource);
00046         unsigned int    CreateShaderProgram(int filtermode);
00047         void            AnalyseShader(int passindex, vector<STR_String>& propNames);
00048         void                    StartShaderProgram(int passindex);
00049         void                    EndShaderProgram();
00050         void                    PrintShaderErrors(unsigned int shader, const char *task, const char *code);
00051 
00052         void SetupTextures(bool depth, bool luminance);
00053         void FreeTextures();
00054 
00055         void UpdateOffsetMatrix(RAS_ICanvas* canvas);
00056         void UpdateCanvasTextureCoord(unsigned int * viewport);
00057  
00058         float                   canvascoord[4];
00059         float                   textureoffsets[18];
00060         float                   view[4];
00061         /* texname[0] contains render to texture, texname[1] contains depth texture,  texname[2] contains luminance texture*/
00062         unsigned int    texname[3]; 
00063         int                             texturewidth;
00064         int                             textureheight;
00065         int                             canvaswidth;
00066         int                             canvasheight;
00067         int                             numberoffilters;
00068         /* bit 0: enable/disable depth texture
00069          * bit 1: enable/disable luminance texture*/
00070         short                   texflag[MAX_RENDER_PASS];
00071 
00072         bool                    isshadersupported;
00073         bool                    errorprinted;
00074         bool                    need_tex_update;
00075 
00076         unsigned int    m_filters[MAX_RENDER_PASS];
00077         short           m_enabled[MAX_RENDER_PASS];
00078 
00079         // stores object properties to send to shaders in each pass
00080         vector<STR_String>      m_properties[MAX_RENDER_PASS];
00081         void* m_gameObjects[MAX_RENDER_PASS];
00082 public:
00083         enum RAS_2DFILTER_MODE {
00084                 RAS_2DFILTER_ENABLED = -2,
00085                 RAS_2DFILTER_DISABLED = -1,
00086                 RAS_2DFILTER_NOFILTER = 0,
00087                 RAS_2DFILTER_MOTIONBLUR,
00088                 RAS_2DFILTER_BLUR,
00089                 RAS_2DFILTER_SHARPEN,
00090                 RAS_2DFILTER_DILATION,
00091                 RAS_2DFILTER_EROSION,
00092                 RAS_2DFILTER_LAPLACIAN,
00093                 RAS_2DFILTER_SOBEL,
00094                 RAS_2DFILTER_PREWITT,
00095                 RAS_2DFILTER_GRAYSCALE,
00096                 RAS_2DFILTER_SEPIA,
00097                 RAS_2DFILTER_INVERT,
00098                 RAS_2DFILTER_CUSTOMFILTER,
00099                 RAS_2DFILTER_NUMBER_OF_FILTERS
00100         };
00101 
00102         RAS_2DFilterManager();
00103 
00104         ~RAS_2DFilterManager();
00105 
00106         void RenderFilters(RAS_ICanvas* canvas);
00107 
00108         void EnableFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFILTER_MODE mode, int pass, STR_String& text);
00109         
00110         
00111 #ifdef WITH_CXX_GUARDEDALLOC
00112 public:
00113         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_2DFilterManager"); }
00114         void operator delete( void *mem ) { MEM_freeN(mem); }
00115 #endif
00116 };
00117 #endif