BGE 2d-filter, custom shaders now can have depth texture and luminance texture
[blender.git] / source / gameengine / GameLogic / SCA_2DFilterActuator.cpp
1 #include "SCA_IActuator.h"
2
3 #include "SCA_2DFilterActuator.h"
4
5 #ifdef HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8 #include <iostream>
9
10
11 SCA_2DFilterActuator::~SCA_2DFilterActuator()
12 {
13 }
14
15 SCA_2DFilterActuator::SCA_2DFilterActuator(
16         SCA_IObject *gameobj, 
17         RAS_2DFilterManager::RAS_2DFILTER_MODE type,
18                 short flag,
19                 float float_arg,
20                 int int_arg,
21                 short texture_flag,
22                 RAS_IRasterizer* rasterizer,
23                 RAS_IRenderTools* rendertools,
24         PyTypeObject* T)
25     : SCA_IActuator(gameobj, T),
26      m_type(type),
27          m_flag(flag),
28          m_int_arg(int_arg),
29          m_texture_flag(texture_flag),
30          m_float_arg(float_arg),
31          m_rasterizer(rasterizer),
32          m_rendertools(rendertools)
33 {
34 }
35
36 void SCA_2DFilterActuator::SetShaderText(STR_String text)
37 {
38         m_shaderText = text;
39 }
40
41
42
43 CValue* SCA_2DFilterActuator::GetReplica()
44 {
45     SCA_2DFilterActuator* replica = new SCA_2DFilterActuator(*this);
46     replica->ProcessReplica();
47     CValue::AddDataToReplica(replica);
48
49     return replica;
50 }
51
52
53 bool SCA_2DFilterActuator::Update()
54 {
55         bool result = false;
56
57         bool bNegativeEvent = IsNegativeEvent();
58         RemoveAllEvents();
59
60
61         if (bNegativeEvent)
62                 return false; // do nothing on negative events
63
64         if( m_type == RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR )
65         {
66                 if(!m_flag)
67                 {
68                         m_rasterizer->EnableMotionBlur(m_float_arg);
69                 }
70                 else
71                 {
72                         m_rasterizer->DisableMotionBlur();
73                 }
74         }
75         else if(m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS)
76         {
77                 m_rendertools->Update2DFilter(m_type, m_int_arg, m_shaderText, m_texture_flag);
78         }
79     return true;
80 }
81
82
83 PyTypeObject SCA_2DFilterActuator::Type = {
84         PyObject_HEAD_INIT(&PyType_Type)
85         0,
86         "SCA_2DFilterActuator",
87         sizeof(SCA_2DFilterActuator),
88         0,
89         PyDestructor,
90         0,
91         __getattr,
92         __setattr,
93         0, 
94          __repr,
95         0,
96         0,
97         0,
98         0,
99         0
100 };
101
102
103 PyParentObject SCA_2DFilterActuator::Parents[] = {
104         &SCA_2DFilterActuator::Type,
105         &SCA_IActuator::Type,
106         &SCA_ILogicBrick::Type,
107         &CValue::Type,
108         NULL
109 };
110
111
112 PyMethodDef SCA_2DFilterActuator::Methods[] = {
113     /* add python functions to deal with m_msg... */
114     {NULL,NULL}
115 };
116
117
118 PyObject* SCA_2DFilterActuator::_getattr(const STR_String& attr) {
119     _getattr_up(SCA_IActuator);
120 }