improvement of 2d-filter custom shader,
[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 SCA_2DFilterActuator::~SCA_2DFilterActuator()
11 {
12 }
13
14 SCA_2DFilterActuator::SCA_2DFilterActuator(
15         SCA_IObject *gameobj, 
16         RAS_2DFilterManager::RAS_2DFILTER_MODE type,
17                 short flag,
18                 float float_arg,
19                 int int_arg,
20                 RAS_IRasterizer* rasterizer,
21                 RAS_IRenderTools* rendertools,
22         PyTypeObject* T)
23     : SCA_IActuator(gameobj, T),
24      m_type(type),
25          m_flag(flag),
26          m_int_arg(int_arg),
27          m_float_arg(float_arg),
28          m_rasterizer(rasterizer),
29          m_rendertools(rendertools)
30 {
31         m_gameObj = NULL;
32         if(gameobj){
33                 m_propNames = gameobj->GetPropertyNames();
34                 m_gameObj = gameobj;
35         }
36 }
37
38 void SCA_2DFilterActuator::SetShaderText(STR_String text)
39 {
40         m_shaderText = text;
41 }
42
43
44
45 CValue* SCA_2DFilterActuator::GetReplica()
46 {
47     SCA_2DFilterActuator* replica = new SCA_2DFilterActuator(*this);
48     replica->ProcessReplica();
49     CValue::AddDataToReplica(replica);
50
51     return replica;
52 }
53
54
55 bool SCA_2DFilterActuator::Update()
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_propNames, m_gameObj, m_type, m_int_arg, m_shaderText);
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 }