~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/gameengine/Rasterizer/RAS_2DFilterManager.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
 
1
/*
2
2
 * ***** BEGIN GPL LICENSE BLOCK *****
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License
6
6
 * as published by the Free Software Foundation; either version 2
7
 
 * of the License, or (at your option) any later version. The Blender
8
 
 * Foundation also sells licenses for use in proprietary software under
9
 
 * the Blender License.  See http://www.blender.org/BL/ for information
10
 
 * about this.
 
7
 * of the License, or (at your option) any later version.
11
8
 *
12
9
 * This program is distributed in the hope that it will be useful,
13
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
15
 * along with this program; if not, write to the Free Software Foundation,
19
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
17
 *
21
 
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
22
 
 * All rights reserved.
23
 
 *
24
 
 * The Original Code is: all of this file.
25
 
 *
26
18
 * Contributor(s): none yet.
27
19
 *
28
20
 * ***** END GPL LICENSE BLOCK *****
29
21
 */
 
22
 
 
23
/** \file gameengine/Rasterizer/RAS_2DFilterManager.cpp
 
24
 *  \ingroup bgerast
 
25
 */
 
26
 
30
27
 
31
28
#define STRINGIFY(A)  #A
32
29
 
61
58
        isshadersupported = GLEW_ARB_shader_objects &&
62
59
                GLEW_ARB_fragment_shader && GLEW_ARB_multitexture;
63
60
 
64
 
        /* used to return before 2.49 but need to initialize values so dont */
65
 
        if(!isshadersupported)
 
61
        /* used to return before 2.49 but need to initialize values so don't */
 
62
        if (!isshadersupported)
66
63
                std::cout<<"shaders not supported!" << std::endl;
67
64
 
68
65
        int passindex;
69
 
        for(passindex =0; passindex<MAX_RENDER_PASS; passindex++)
 
66
        for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
70
67
        {
71
68
                m_filters[passindex] = 0;
72
69
                m_enabled[passindex] = 0;
89
86
        const char *c, *pos, *end;
90
87
        int line = 1;
91
88
 
92
 
        if(errorprinted)
 
89
        if (errorprinted)
93
90
                return;
94
91
        
95
92
        errorprinted= true;
106
103
                c = pos+1;
107
104
                line++;
108
105
        }
109
 
        printf("%s", c);
110
106
 
111
 
        printf("%s\n", log);
 
107
        puts(c);
 
108
        puts(log);
 
109
        puts("\n");
112
110
}
113
111
 
114
112
unsigned int RAS_2DFilterManager::CreateShaderProgram(const char* shadersource)
123
121
 
124
122
 
125
123
        glGetObjectParameterivARB(fShader, GL_COMPILE_STATUS, &success);
126
 
        if(!success)
 
124
        if (!success)
127
125
        {
128
126
                /*Shader Comile Error*/
129
127
                PrintShaderErrors(fShader, "compile", shadersource);
185
183
void RAS_2DFilterManager::AnalyseShader(int passindex, vector<STR_String>& propNames)
186
184
{
187
185
        texflag[passindex] = 0;
188
 
        if(glGetUniformLocationARB(m_filters[passindex], "bgl_DepthTexture") != -1)
 
186
        if (glGetUniformLocationARB(m_filters[passindex], "bgl_DepthTexture") != -1)
189
187
        {
190
 
                if(GLEW_ARB_depth_texture)
 
188
                if (GLEW_ARB_depth_texture)
191
189
                        texflag[passindex] |= 0x1;
192
190
        }
193
 
        if(glGetUniformLocationARB(m_filters[passindex], "bgl_LuminanceTexture") != -1)
 
191
        if (glGetUniformLocationARB(m_filters[passindex], "bgl_LuminanceTexture") != -1)
194
192
        {
195
193
                texflag[passindex] |= 0x2;
196
194
        }
197
195
 
198
 
        if(m_gameObjects[passindex])
 
196
        if (m_gameObjects[passindex])
199
197
        {
200
198
                int objProperties = propNames.size();
201
199
                int i;
202
 
                for(i=0; i<objProperties; i++)
203
 
                        if(glGetUniformLocationARB(m_filters[passindex], propNames[i]) != -1)
 
200
                for (i=0; i<objProperties; i++)
 
201
                        if (glGetUniformLocationARB(m_filters[passindex], propNames[i]) != -1)
204
202
                                m_properties[passindex].push_back(propNames[i]);
205
203
        }
206
204
}
219
217
        }
220
218
 
221
219
        /* send depth texture to glsl program if it needs */
222
 
        if(texflag[passindex] & 0x1){
 
220
        if (texflag[passindex] & 0x1) {
223
221
                uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_DepthTexture");
224
222
                glActiveTextureARB(GL_TEXTURE1);
225
223
                glBindTexture(GL_TEXTURE_2D, texname[1]);
231
229
        }
232
230
 
233
231
        /* send luminance texture to glsl program if it needs */
234
 
        if(texflag[passindex] & 0x2){
 
232
        if (texflag[passindex] & 0x2) {
235
233
                uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_LuminanceTexture");
236
234
                glActiveTextureARB(GL_TEXTURE2);
237
235
                glBindTexture(GL_TEXTURE_2D, texname[2]);
259
257
        }
260
258
 
261
259
        int i, objProperties = m_properties[passindex].size();
262
 
        for(i=0; i<objProperties; i++)
 
260
        for (i=0; i<objProperties; i++)
263
261
        {
264
262
                uniformLoc = glGetUniformLocationARB(m_filters[passindex], m_properties[passindex][i]);
265
 
                if(uniformLoc != -1)
 
263
                if (uniformLoc != -1)
266
264
                {
267
265
                        float value = ((CValue*)m_gameObjects[passindex])->GetPropertyNumber(m_properties[passindex][i], 0.0);
268
266
                        glUniform1fARB(uniformLoc,value);
277
275
 
278
276
void RAS_2DFilterManager::FreeTextures()
279
277
{
280
 
        if(texname[0]!=(unsigned int)-1)
 
278
        if (texname[0]!=(unsigned int)-1)
281
279
                glDeleteTextures(1, (GLuint*)&texname[0]);
282
 
        if(texname[1]!=(unsigned int)-1)
 
280
        if (texname[1]!=(unsigned int)-1)
283
281
                glDeleteTextures(1, (GLuint*)&texname[1]);
284
 
        if(texname[2]!=(unsigned int)-1)
 
282
        if (texname[2]!=(unsigned int)-1)
285
283
                glDeleteTextures(1, (GLuint*)&texname[2]);
286
284
}
287
285
 
298
296
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
299
297
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
300
298
 
301
 
        if(depth){
 
299
        if (depth) {
302
300
                glGenTextures(1, (GLuint*)&texname[1]);
303
301
                glBindTexture(GL_TEXTURE_2D, texname[1]);
304
 
                glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, texturewidth,textureheight, 
305
 
                        0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE,NULL);
 
302
                glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, texturewidth,textureheight,
 
303
                             0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE,NULL);
306
304
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
307
305
                                GL_NONE);
308
306
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
311
309
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
312
310
        }
313
311
 
314
 
        if(luminance){
 
312
        if (luminance) {
315
313
                glGenTextures(1, (GLuint*)&texname[2]);
316
314
                glBindTexture(GL_TEXTURE_2D, texname[2]);
317
315
                glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16, texturewidth, textureheight,
359
357
void RAS_2DFilterManager::UpdateCanvasTextureCoord(unsigned int * viewport)
360
358
{
361
359
        /*
362
 
        This function update canvascoord[].
363
 
        These parameters are used to create texcoord[1]
364
 
        That way we can access the texcoord relative to the canvas:
365
 
        (0.0,0.0) bottom left, (1.0,1.0) top right, (0.5,0.5) center
366
 
        */
 
360
         * This function update canvascoord[].
 
361
         * These parameters are used to create texcoord[1]
 
362
         * That way we can access the texcoord relative to the canvas:
 
363
         * (0.0,0.0) bottom left, (1.0,1.0) top right, (0.5,0.5) center
 
364
         */
367
365
        canvascoord[0] = (GLfloat) viewport[0] / viewport[2];
368
366
        canvascoord[0] *= -1;
369
367
        canvascoord[1] = (GLfloat) (texturewidth - viewport[0]) / viewport[2];
381
379
 
382
380
        int passindex;
383
381
 
384
 
        if(!isshadersupported)
 
382
        if (!isshadersupported)
385
383
                return;
386
384
 
387
 
        for(passindex =0; passindex<MAX_RENDER_PASS; passindex++)
 
385
        for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
388
386
        {
389
 
                if(m_filters[passindex] && m_enabled[passindex]){
 
387
                if (m_filters[passindex] && m_enabled[passindex]) {
390
388
                        num_filters ++;
391
 
                        if(texflag[passindex] & 0x1)
 
389
                        if (texflag[passindex] & 0x1)
392
390
                                need_depth = true;
393
 
                        if(texflag[passindex] & 0x2)
 
391
                        if (texflag[passindex] & 0x2)
394
392
                                need_luminance = true;
395
 
                        if(need_depth && need_luminance)
 
393
                        if (need_depth && need_luminance)
396
394
                                break;
397
395
                }
398
396
        }
399
397
 
400
 
        if(num_filters <= 0)
 
398
        if (num_filters <= 0)
401
399
                return;
402
400
 
403
401
        GLuint  viewport[4]={0};
404
402
        glGetIntegerv(GL_VIEWPORT,(GLint *)viewport);
405
403
 
406
 
        if(canvaswidth != canvas->GetWidth() || canvasheight != canvas->GetHeight())
 
404
        if (canvaswidth != canvas->GetWidth() || canvasheight != canvas->GetHeight())
407
405
        {
408
406
                UpdateOffsetMatrix(canvas);
409
407
                UpdateCanvasTextureCoord((unsigned int*)viewport);
410
408
                need_tex_update = true;
411
409
        }
412
410
        
413
 
        if(need_tex_update)
 
411
        if (need_tex_update)
414
412
        {
415
413
                SetupTextures(need_depth, need_luminance);
416
414
                need_tex_update = false;
417
415
        }
418
416
 
419
 
        if(need_depth){
 
417
        if (need_depth) {
420
418
                glActiveTextureARB(GL_TEXTURE1);
421
419
                glBindTexture(GL_TEXTURE_2D, texname[1]);
422
420
                glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, 0, 0, texturewidth,textureheight, 0);
423
421
        }
424
422
        
425
 
        if(need_luminance){
 
423
        if (need_luminance) {
426
424
                glActiveTextureARB(GL_TEXTURE2);
427
425
                glBindTexture(GL_TEXTURE_2D, texname[2]);
428
426
                glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, 0, 0, texturewidth,textureheight, 0);
429
427
        }
430
428
 
 
429
        // reverting to texunit 0, without this we get bug [#28462]
 
430
        glActiveTextureARB(GL_TEXTURE0);
 
431
 
431
432
        glViewport(0,0, texturewidth, textureheight);
432
433
 
433
434
        glDisable(GL_DEPTH_TEST);
 
435
        // in case the previous material was wire
 
436
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
437
        // if the last rendered face had alpha add it would messes with the color of the plane we apply 2DFilter to
 
438
        glDisable(GL_BLEND); 
434
439
        glPushMatrix();         //GL_MODELVIEW
435
440
        glLoadIdentity();       // GL_MODELVIEW
436
441
        glMatrixMode(GL_TEXTURE);
439
444
        glPushMatrix();
440
445
        glLoadIdentity();
441
446
 
442
 
        for(passindex =0; passindex<MAX_RENDER_PASS; passindex++)
 
447
        for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
443
448
        {
444
 
                if(m_filters[passindex] && m_enabled[passindex])
 
449
                if (m_filters[passindex] && m_enabled[passindex])
445
450
                {
446
451
                        StartShaderProgram(passindex);
447
452
 
470
475
 
471
476
void RAS_2DFilterManager::EnableFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFILTER_MODE mode, int pass, STR_String& text)
472
477
{
473
 
        if(!isshadersupported)
 
478
        if (!isshadersupported)
474
479
                return;
475
 
        if(pass<0 || pass>=MAX_RENDER_PASS)
 
480
        if (pass<0 || pass>=MAX_RENDER_PASS)
476
481
                return;
477
482
        need_tex_update = true;
478
 
        if(mode == RAS_2DFILTER_DISABLED)
 
483
        if (mode == RAS_2DFILTER_DISABLED)
479
484
        {
480
485
                m_enabled[pass] = 0;
481
486
                return;
482
487
        }
483
488
 
484
 
        if(mode == RAS_2DFILTER_ENABLED)
 
489
        if (mode == RAS_2DFILTER_ENABLED)
485
490
        {
486
491
                m_enabled[pass] = 1;
487
492
                return;
488
493
        }
489
494
 
490
 
        if(mode == RAS_2DFILTER_NOFILTER)
 
495
        if (mode == RAS_2DFILTER_NOFILTER)
491
496
        {
492
 
                if(m_filters[pass])
 
497
                if (m_filters[pass])
493
498
                        glDeleteObjectARB(m_filters[pass]);
494
499
                m_enabled[pass] = 0;
495
500
                m_filters[pass] = 0;
499
504
                return;
500
505
        }
501
506
        
502
 
        if(mode == RAS_2DFILTER_CUSTOMFILTER)
 
507
        if (mode == RAS_2DFILTER_CUSTOMFILTER)
503
508
        {
504
 
                if(m_filters[pass])
 
509
                if (m_filters[pass])
505
510
                        glDeleteObjectARB(m_filters[pass]);
506
511
                m_filters[pass] = CreateShaderProgram(text.Ptr());
507
512
                m_gameObjects[pass] = gameObj;
510
515
                return;
511
516
        }
512
517
 
513
 
        if(mode>=RAS_2DFILTER_MOTIONBLUR && mode<=RAS_2DFILTER_INVERT)
514
 
        {
515
 
                if(m_filters[pass])
516
 
                        glDeleteObjectARB(m_filters[pass]);
517
 
                m_filters[pass] = CreateShaderProgram(mode);
518
 
                m_enabled[pass] = 1;
519
 
        }
 
518
        // We've checked all other cases, which means we must be dealing with a builtin filter
 
519
        if (m_filters[pass])
 
520
                glDeleteObjectARB(m_filters[pass]);
 
521
        m_filters[pass] = CreateShaderProgram(mode);
 
522
        m_gameObjects[pass] = NULL;
 
523
        AnalyseShader(pass, propNames);
 
524
        m_enabled[pass] = 1;
520
525
}