Changeset 784
Legend:
 Unmodified
 Added
 Removed

trunk/src/scene.cpp
r758 r784 33 33 }; 34 34 35 extern Shader *stdshader; 36 extern mat4 model_matrix; 35 static Shader *stdshader = NULL; 37 36 38 37 /* … … 52 51 return t2>prio  t1>prio; 53 52 } 53 54 mat4 model_matrix; 54 55 55 56 Tile *tiles; … … 130 131 void Scene::Render() // XXX: rename to Blit() 131 132 { 133 if (!stdshader) 134 { 135 stdshader = Shader::Create( 136 "#version 130\n" 137 "\n" 138 #if defined HAVE_GLES_2X 139 "attribute vec3 in_Position;\n" 140 "attribute vec2 in_TexCoord;\n" 141 "varying vec2 pass_TexCoord;\n" 142 #else 143 "in vec3 in_Position;\n" 144 "in vec2 in_TexCoord;\n" 145 #endif 146 "uniform mat4 proj_matrix;\n" 147 "uniform mat4 view_matrix;\n" 148 "uniform mat4 model_matrix;\n" 149 "\n" 150 "void main()\n" 151 "{\n" 152 " gl_Position = proj_matrix * view_matrix * model_matrix" 153 " * vec4(in_Position, 1.0);\n" 154 #if defined HAVE_GLES_2X 155 " pass_TexCoord = in_TexCoord;\n" 156 #else 157 " gl_TexCoord[0] = vec4(in_TexCoord, 0.0, 0.0);\n" 158 #endif 159 "}\n", 160 161 "#version 130\n" 162 "\n" 163 "uniform sampler2D in_Texture;\n" 164 #if defined HAVE_GLES_2X 165 "varying vec2 pass_TexCoord;\n" 166 #endif 167 "\n" 168 "void main()\n" 169 "{\n" 170 #if defined HAVE_GLES_2X 171 " vec4 col = texture2D(in_Texture, pass_TexCoord);\n" 172 //" vec4 col = vec4(0.5, 1.0, 0.0, 0.5);\n" 173 //" vec4 col = vec4(pass_TexCoord * 4.0, 0.0, 0.25);\n" 174 #else 175 " vec4 col = texture2D(in_Texture, vec2(gl_TexCoord[0]));\n" 176 #endif 177 #if 0 178 " float mul = 2.0;\n" 179 #if 0 180 " vec2 d1 = mod(vec2(gl_FragCoord), vec2(2.0, 2.0));\n" 181 " float t1 = mod(3.0 * d1.x + 2.0 * d1.y, 4.0);\n" 182 " float dx2 = mod(floor(gl_FragCoord.x * 0.5), 2.0);\n" 183 " float dy2 = mod(floor(gl_FragCoord.y * 0.5), 2.0);\n" 184 " float t2 = mod(3.0 * dx2 + 2.0 * dy2, 4.0);\n" 185 " float dx3 = mod(floor(gl_FragCoord.x * 0.25), 2.0);\n" 186 " float dy3 = mod(floor(gl_FragCoord.y * 0.25), 2.0);\n" 187 " float t3 = mod(3.0 * dx3 + 2.0 * dy3, 4.0);\n" 188 " float t1 = (1.0 + 16.0 * t1 + 4.0 * t2 + t3) / 65.0;\n" 189 " float t2 = t1;\n" 190 " float t3 = t1;\n" 191 #else 192 " float rand = sin(gl_FragCoord.x * 1.23456) * 123.456\n" 193 " + cos(gl_FragCoord.y * 2.34567) * 789.012;\n" 194 " float t1 = mod(sin(rand) * 17.13043, 1.0);\n" 195 " float t2 = mod(sin(rand) * 27.13043, 1.0);\n" 196 " float t3 = mod(sin(rand) * 37.13043, 1.0);\n" 197 #endif 198 " float fracx = fract(col.x * mul);\n" 199 " float fracy = fract(col.y * mul);\n" 200 " float fracz = fract(col.z * mul);\n" 201 " fracx = fracx > t1 ? 1.0 : 0.0;\n" 202 " fracy = fracy > t2 ? 1.0 : 0.0;\n" 203 " fracz = fracz > t3 ? 1.0 : 0.0;\n" 204 " col.x = (floor(col.x * mul) + fracx) / mul;\n" 205 " col.y = (floor(col.y * mul) + fracy) / mul;\n" 206 " col.z = (floor(col.z * mul) + fracz) / mul;\n" 207 #endif 208 " gl_FragColor = col;\n" 209 "}\n"); 210 } 211 132 212 #if 0 133 213 // Randomise, then sort. … … 143 223 144 224 // XXX: debug stuff 145 model_matrix = mat4::translate(320.0f, 240.0f, 0.0f);146 model_matrix *= mat4::rotate(data>angle, 1.0f, 0.0f, 0.0f);225 data>model_matrix = mat4::translate(320.0f, 240.0f, 0.0f); 226 data>model_matrix *= mat4::rotate(data>angle, 1.0f, 0.0f, 0.0f); 147 227 #if 0 148 228 static float f = 0.0f; 149 229 f += 0.01f; 150 model_matrix *= mat4::rotate(0.1f * sinf(f), 1.0f, 0.0f, 0.0f);151 model_matrix *= mat4::rotate(0.3f * cosf(f), 0.0f, 0.0f, 1.0f);152 #endif 153 model_matrix *= mat4::translate(320.0f, 240.0f, 0.0f);230 data>model_matrix *= mat4::rotate(0.1f * sinf(f), 1.0f, 0.0f, 0.0f); 231 data>model_matrix *= mat4::rotate(0.3f * cosf(f), 0.0f, 0.0f, 1.0f); 232 #endif 233 data>model_matrix *= mat4::translate(320.0f, 240.0f, 0.0f); 154 234 // XXX: end of debug stuff 155 235 … … 160 240 #if !defined __CELLOS_LV2__ // Use cgGetNamedParameter etc. 161 241 stdshader>Bind(); 242 243 uni_mat = stdshader>GetUniformLocation("proj_matrix"); 244 glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &Video::GetProjMatrix()[0][0]); 245 uni_mat = stdshader>GetUniformLocation("view_matrix"); 246 glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &Video::GetViewMatrix()[0][0]); 162 247 uni_mat = stdshader>GetUniformLocation("model_matrix"); 163 glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &model_matrix[0][0]); 248 glUniformMatrix4fv(uni_mat, 1, GL_FALSE, &data>model_matrix[0][0]); 249 164 250 uni_tex = stdshader>GetUniformLocation("in_Texture"); 165 251 glUniform1i(uni_tex, 0); 
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 
trunk/src/video.h
r755 r784 33 33 static void Capture(uint32_t *buffer); 34 34 static vec2i GetSize(); 35 static mat4 const & GetProjMatrix(); 36 static mat4 const & GetViewMatrix(); 35 37 }; 36 38
Note: See TracChangeset
for help on using the changeset viewer.