00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "TactileSensorShader.hpp"
00021
00022 namespace Graphics
00023 {
00024 namespace Sensing
00025 {
00026
00027 TactileSensorShader::~TactileSensorShader()
00028 {
00029 clearVariables();
00030 }
00031
00032 void TactileSensorShader::clearVariables()
00033 {
00034 std::list<ShaderVariable*>::iterator i;
00035 for ( i=vars.begin(); i!=vars.end(); i++ )
00036 {
00037 if (*i) delete *i;
00038 }
00039 vars.clear();
00040 }
00041
00042 void TactileSensorShader :: execute( GLuint input, GLuint output )
00043 {
00044 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,output);
00045 showTex(input);
00046 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
00047 }
00048
00049 void TactileSensorShader :: showTex( GLuint input )
00050 {
00051
00052 glMatrixMode(GL_MODELVIEW);
00053 glPushMatrix();
00054 glLoadIdentity();
00055
00056 glMatrixMode(GL_PROJECTION);
00057 glPushMatrix();
00058 glLoadIdentity();
00059 glOrtho(-1,1,-1,1,-1,1);
00060
00061 glMatrixMode(GL_MODELVIEW);
00062
00063 glActiveTexture(GL_TEXTURE0);
00064
00065 glEnable(GL_TEXTURE_2D);
00066
00067 glBindTexture(GL_TEXTURE_2D, input );
00068
00069
00070
00071
00072
00073
00074 applyShaders();
00075
00076
00077
00078
00079
00080 glColor3f(1,1,1);
00081 glBegin(GL_QUADS);
00082
00083 glTexCoord2f(0.0,0.0);
00084 glVertex2f(-1.0,-1.0);
00085
00086 glTexCoord2f(1.0,0.0);
00087 glVertex2f(1.0,-1.0);
00088
00089 glTexCoord2f(1.0,1.0);
00090 glVertex2f(1.0,1.0);
00091
00092 glTexCoord2f(0.0,1.0);
00093 glVertex2f(-1.0,1.0);
00094
00095 glEnd();
00096
00097
00098 stopShaders();
00099
00100 glActiveTexture(GL_TEXTURE0);
00101
00102 glMatrixMode(GL_PROJECTION);
00103 glPopMatrix();
00104 glMatrixMode(GL_MODELVIEW);
00105 glPopMatrix();
00106 }
00107
00108 void TactileSensorShader :: applyShaders()
00109 {
00110 launchShaders();
00111 associateVariables();
00112 }
00113
00114 void TactileSensorShaderWTex :: applyShaders()
00115 {
00116 launchShaders();
00117 associateVariables();
00118 bindAuxInput();
00119 }
00120
00121 void TactileSensorShader :: associateVariables()
00122 {
00123 std::list<ShaderVariable*>::iterator i;
00124 for ( i=vars.begin(); i!=vars.end(); i++ )
00125 {
00126 (*i)->updateVal();
00127 }
00128 }
00129
00130 void TactileSensorShaderWTex :: bindAuxInput()
00131 {
00132 glActiveTexture( GL_TEXTURE0 + activeTex );
00133 glBindTexture( GL_TEXTURE_2D, auxTex );
00134 glActiveTexture( GL_TEXTURE0 );
00135 }
00136
00137 }
00138 }
00139