Changeset 784 for trunk/src/video.cpp
 Timestamp:
 Jun 22, 2011, 12:36:47 AM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/video.cpp
r780 r784 28 28 { 29 29 30 class VideoData 31 { 32 friend class Video; 33 34 private: 35 static mat4 proj_matrix, view_matrix; 30 36 #if defined ANDROID_NDK 31 vec2i saved_viewport;37 static vec2i saved_viewport; 32 38 #endif 39 }; 33 40 34 Shader *stdshader;35 mat4 proj_matrix, view_matrix, model_matrix;41 mat4 VideoData::proj_matrix; 42 mat4 VideoData::view_matrix; 36 43 37 #define OLD 38 39 static char const *vertexshader = 40 "#version 130\n" 41 "\n" 42 #if defined HAVE_GLES_2X 43 "attribute vec3 in_Position;\n" 44 "attribute vec2 in_TexCoord;\n" 45 "varying vec2 pass_TexCoord;\n" 46 #else 47 "in vec3 in_Position;\n" 48 "in vec2 in_TexCoord;\n" 44 #if defined ANDROID_NDK 45 vec2i VideoData::saved_viewport = 0; 49 46 #endif 50 "uniform mat4 proj_matrix;\n"51 "uniform mat4 view_matrix;\n"52 "uniform mat4 model_matrix;\n"53 "\n"54 "void main()\n"55 "{\n"56 " gl_Position = proj_matrix * view_matrix * model_matrix"57 " * vec4(in_Position, 1.0);\n"58 #if defined HAVE_GLES_2X59 " pass_TexCoord = in_TexCoord;\n"60 #else61 " gl_TexCoord[0] = vec4(in_TexCoord, 0.0, 0.0);\n"62 #endif63 "}\n";64 65 static char const *fragmentshader =66 "#version 130\n"67 "\n"68 "uniform sampler2D in_Texture;\n"69 #if defined HAVE_GLES_2X70 "varying vec2 pass_TexCoord;\n"71 #endif72 "\n"73 "void main()\n"74 "{\n"75 #if defined HAVE_GLES_2X76 " vec4 col = texture2D(in_Texture, pass_TexCoord);\n"77 //" vec4 col = vec4(0.5, 1.0, 0.0, 0.5);\n"78 //" vec4 col = vec4(pass_TexCoord * 4.0, 0.0, 0.25);\n"79 #else80 " vec4 col = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n"81 #endif82 #if 083 " float mul = 2.0;\n"84 #if 085 " vec2 d1 = mod(vec2(gl_FragCoord), vec2(2.0, 2.0));\n"86 " float t1 = mod(3.0 * d1.x + 2.0 * d1.y, 4.0);\n"87 " float dx2 = mod(floor(gl_FragCoord.x * 0.5), 2.0);\n"88 " float dy2 = mod(floor(gl_FragCoord.y * 0.5), 2.0);\n"89 " float t2 = mod(3.0 * dx2 + 2.0 * dy2, 4.0);\n"90 " float dx3 = mod(floor(gl_FragCoord.x * 0.25), 2.0);\n"91 " float dy3 = mod(floor(gl_FragCoord.y * 0.25), 2.0);\n"92 " float t3 = mod(3.0 * dx3 + 2.0 * dy3, 4.0);\n"93 " float t1 = (1.0 + 16.0 * t1 + 4.0 * t2 + t3) / 65.0;\n"94 " float t2 = t1;\n"95 " float t3 = t1;\n"96 #else97 " float rand = sin(gl_FragCoord.x * 1.23456) * 123.456\n"98 " + cos(gl_FragCoord.y * 2.34567) * 789.012;\n"99 " float t1 = mod(sin(rand) * 17.13043, 1.0);\n"100 " float t2 = mod(sin(rand) * 27.13043, 1.0);\n"101 " float t3 = mod(sin(rand) * 37.13043, 1.0);\n"102 #endif103 " float fracx = fract(col.x * mul);\n"104 " float fracy = fract(col.y * mul);\n"105 " float fracz = fract(col.z * mul);\n"106 " fracx = fracx > t1 ? 1.0 : 0.0;\n"107 " fracy = fracy > t2 ? 1.0 : 0.0;\n"108 " fracz = fracz > t3 ? 1.0 : 0.0;\n"109 " col.x = (floor(col.x * mul) + fracx) / mul;\n"110 " col.y = (floor(col.y * mul) + fracy) / mul;\n"111 " col.z = (floor(col.z * mul) + fracz) / mul;\n"112 #endif113 " gl_FragColor = col;\n"114 "}\n";115 47 116 48 /* … … 124 56 125 57 #if defined ANDROID_NDK 126 saved_viewport = vec2i(size.x, size.y);58 VideoData::saved_viewport = size; 127 59 #endif 128 60 … … 134 66 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 135 67 #endif 136 137 stdshader = Shader::Create(vertexshader, fragmentshader);138 68 } 139 69 … … 142 72 #undef near /* Fuck Microsoft */ 143 73 #undef far /* Fuck Microsoft again */ 144 mat4 proj;145 146 74 vec2 size = GetSize(); 147 75 float near = size.x  size.y; … … 156 84 { 157 85 /* The easy way: purely orthogonal projection. */ 158 proj_matrix = mat4::ortho(0, size.x, 0, size.y, near, far);86 VideoData::proj_matrix = mat4::ortho(0, size.x, 0, size.y, near, far); 159 87 } 160 88 else … … 176 104 } 177 105 178 proj_matrix = mat4::frustum(near * t1, near * t1, 179 near * t2, near * t2, near, far) 180 * mat4::translate(0.5f * size.x, 0.5f * size.y, dist); 106 mat4 proj = mat4::frustum(near * t1, near * t1, 107 near * t2, near * t2, near, far); 108 mat4 trans = mat4::translate(0.5f * size.x, 0.5f * size.y, dist); 109 VideoData::proj_matrix = proj * trans; 181 110 } 182 111 183 view_matrix = mat4(1.0f); 184 185 stdshader>Bind(); /* Required on GLES 2.x? */ 186 #if !defined __CELLOS_LV2__ // Use cgGetNamedParameter etc. 187 GLuint uni; 188 uni = stdshader>GetUniformLocation("proj_matrix"); 189 glUniformMatrix4fv(uni, 1, GL_FALSE, &proj_matrix[0][0]); 190 uni = stdshader>GetUniformLocation("view_matrix"); 191 glUniformMatrix4fv(uni, 1, GL_FALSE, &view_matrix[0][0]); 192 #endif 112 VideoData::view_matrix = mat4(1.0f); 193 113 } 194 114 … … 212 132 void Video::Destroy() 213 133 { 214 Shader::Destroy(stdshader);134 ; 215 135 } 216 136 … … 250 170 { 251 171 #if defined ANDROID_NDK 252 return saved_viewport;172 return VideoData::saved_viewport; 253 173 #elif defined __CELLOS_LV2__ 254 174 // FIXME: use psglCreateDeviceAuto && psglGetDeviceDimensions … … 261 181 } 262 182 183 mat4 const & Video::GetProjMatrix() 184 { 185 return VideoData::proj_matrix; 186 } 187 188 mat4 const & Video::GetViewMatrix() 189 { 190 return VideoData::view_matrix; 191 } 192 263 193 } /* namespace lol */ 264 194
Note: See TracChangeset
for help on using the changeset viewer.