optionally use guarded alloc for tiles compositor, also replace allocation functions...
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 /** \file RAS_2DFilterManager.h
29  *  \ingroup bgerast
30  */
31
32 #ifndef __RAS_2DFILTERMANAGER_H__
33 #define __RAS_2DFILTERMANAGER_H__
34
35 #include "RAS_ICanvas.h"
36 #define MAX_RENDER_PASS 100
37
38 #ifdef WITH_CXX_GUARDEDALLOC
39 #include "MEM_guardedalloc.h"
40 #endif
41
42 class RAS_2DFilterManager
43 {
44 private:
45         unsigned int    CreateShaderProgram(const char* shadersource);
46         unsigned int    CreateShaderProgram(int filtermode);
47         void            AnalyseShader(int passindex, std::vector<STR_String>& propNames);
48         void                    StartShaderProgram(int passindex);
49         void                    EndShaderProgram();
50         void                    PrintShaderErrors(unsigned int shader, const char *task, const char *code);
51
52         void SetupTextures(bool depth, bool luminance);
53         void FreeTextures();
54
55         void UpdateOffsetMatrix(RAS_ICanvas* canvas);
56         void UpdateCanvasTextureCoord(unsigned int * viewport);
57  
58         float                   canvascoord[4];
59         float                   textureoffsets[18];
60         /* float                        view[4]; */ /* UNUSED */
61         /* texname[0] contains render to texture, texname[1] contains depth texture,  texname[2] contains luminance texture*/
62         unsigned int    texname[3]; 
63         int                             texturewidth;
64         int                             textureheight;
65         int                             canvaswidth;
66         int                             canvasheight;
67         /* int                          numberoffilters; */ /* UNUSED */
68         /* bit 0: enable/disable depth texture
69          * bit 1: enable/disable luminance texture*/
70         short                   texflag[MAX_RENDER_PASS];
71
72         bool                    isshadersupported;
73         bool                    errorprinted;
74         bool                    need_tex_update;
75
76         unsigned int    m_filters[MAX_RENDER_PASS];
77         short           m_enabled[MAX_RENDER_PASS];
78
79         // stores object properties to send to shaders in each pass
80         std::vector<STR_String> m_properties[MAX_RENDER_PASS];
81         void* m_gameObjects[MAX_RENDER_PASS];
82 public:
83         enum RAS_2DFILTER_MODE {
84                 RAS_2DFILTER_ENABLED = -2,
85                 RAS_2DFILTER_DISABLED = -1,
86                 RAS_2DFILTER_NOFILTER = 0,
87                 RAS_2DFILTER_MOTIONBLUR,
88                 RAS_2DFILTER_BLUR,
89                 RAS_2DFILTER_SHARPEN,
90                 RAS_2DFILTER_DILATION,
91                 RAS_2DFILTER_EROSION,
92                 RAS_2DFILTER_LAPLACIAN,
93                 RAS_2DFILTER_SOBEL,
94                 RAS_2DFILTER_PREWITT,
95                 RAS_2DFILTER_GRAYSCALE,
96                 RAS_2DFILTER_SEPIA,
97                 RAS_2DFILTER_INVERT,
98                 RAS_2DFILTER_CUSTOMFILTER,
99                 RAS_2DFILTER_NUMBER_OF_FILTERS
100         };
101
102         RAS_2DFilterManager();
103
104         ~RAS_2DFilterManager();
105
106         void RenderFilters(RAS_ICanvas* canvas);
107
108         void EnableFilter(std::vector<STR_String>& propNames, void* gameObj, RAS_2DFILTER_MODE mode, int pass, STR_String& text);
109
110
111 #ifdef WITH_CXX_GUARDEDALLOC
112         MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_2DFilterManager")
113 #endif
114 };
115 #endif