17973Patch by dfelinto, and also fixed a bug in 2d-filters
[blender.git] / source / gameengine / Rasterizer / RAS_2DFilterManager.h
1 /**
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #ifndef __RAS_I2DFILTER
29 #define __RAS_I2DFILTER
30
31 #define MAX_RENDER_PASS 100
32
33 class RAS_2DFilterManager
34 {
35 private:
36         unsigned int    CreateShaderProgram(const char* shadersource);
37         unsigned int    CreateShaderProgram(int filtermode);
38         void            AnalyseShader(int passindex, vector<STR_String>& propNames);
39         void                    StartShaderProgram(int passindex);
40         void                    EndShaderProgram();
41         void                    PrintShaderErrors(unsigned int shader, const char *task, const char *code);
42
43         void SetupTextures(bool depth, bool luminance);
44         void FreeTextures();
45
46         void UpdateOffsetMatrix(RAS_ICanvas* canvas);
47         void UpdateCanvasTextureCoord(unsigned int * viewport);
48  
49         float                   canvascoord[4];
50         float                   textureoffsets[18];
51         float                   view[4];
52         /* texname[0] contains render to texture, texname[1] contains depth texture,  texname[2] contains luminance texture*/
53         unsigned int    texname[3]; 
54         int                             texturewidth;
55         int                             textureheight;
56         int                             canvaswidth;
57         int                             canvasheight;
58         int                             numberoffilters;
59         /* bit 0: enable/disable depth texture
60          * bit 1: enable/disable luminance texture*/
61         short                   texflag[MAX_RENDER_PASS];
62
63         bool                    isshadersupported;
64         bool                    errorprinted;
65         bool                    need_tex_update;
66
67         unsigned int    m_filters[MAX_RENDER_PASS];
68         short           m_enabled[MAX_RENDER_PASS];
69
70         // stores object properties to send to shaders in each pass
71         vector<STR_String>      m_properties[MAX_RENDER_PASS];
72         void* m_gameObjects[MAX_RENDER_PASS];
73 public:
74         enum RAS_2DFILTER_MODE {
75                 RAS_2DFILTER_ENABLED = -2,
76                 RAS_2DFILTER_DISABLED = -1,
77                 RAS_2DFILTER_NOFILTER = 0,
78                 RAS_2DFILTER_MOTIONBLUR,
79                 RAS_2DFILTER_BLUR,
80                 RAS_2DFILTER_SHARPEN,
81                 RAS_2DFILTER_DILATION,
82                 RAS_2DFILTER_EROSION,
83                 RAS_2DFILTER_LAPLACIAN,
84                 RAS_2DFILTER_SOBEL,
85                 RAS_2DFILTER_PREWITT,
86                 RAS_2DFILTER_GRAYSCALE,
87                 RAS_2DFILTER_SEPIA,
88                 RAS_2DFILTER_INVERT,
89                 RAS_2DFILTER_CUSTOMFILTER,
90                 RAS_2DFILTER_NUMBER_OF_FILTERS
91         };
92
93         RAS_2DFilterManager();
94
95         ~RAS_2DFilterManager();
96
97         void RenderFilters(RAS_ICanvas* canvas);
98
99         void EnableFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFILTER_MODE mode, int pass, STR_String& text);
100 };
101 #endif