Changeset 1221
- Timestamp:
- Apr 12, 2012, 7:38:54 PM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gpu/shader.cpp
r1215 r1221 322 322 { 323 323 #if defined USE_D3D9 || defined _XBOX 324 SetUniform(uni, v); 324 if (uni.flags & 1) 325 g_d3ddevice->SetPixelShaderConstantI((UINT)uni.frag, &v[0], 1); 326 if (uni.flags & 2) 327 g_d3ddevice->SetVertexShaderConstantI((UINT)uni.vert, &v[0], 1); 325 328 #elif !defined __CELLOS_LV2__ 326 329 glUniform4i(uni.frag, v.x, v.y, v.z, v.w); … … 374 377 void Shader::SetUniform(ShaderUniform const &uni, vec4 const &v) 375 378 { 376 /* FIXME: use the array versions of these functions */377 379 #if defined USE_D3D9 || defined _XBOX 378 380 if (uni.flags & 1) … … 383 385 glUniform4f(uni.frag, v.x, v.y, v.z, v.w); 384 386 #else 387 /* FIXME: use the array versions of these functions */ 385 388 if (uni.frag) 386 389 cgGLSetParameter4f((CGparameter)uni.frag, v.x, v.y, v.z, v.w); -
trunk/src/scene.cpp
r1215 r1221 19 19 # define WIN32_LEAN_AND_MEAN 20 20 # include <windows.h> 21 # if defined USE_D3D9 22 # define FAR 23 # define NEAR 24 # include <d3d9.h> 25 # endif 21 26 #endif 22 27 23 28 #include "core.h" 24 29 #include "lolgl.h" 30 31 #if defined USE_D3D9 32 extern IDirect3DDevice9 *g_d3ddevice; 33 #elif defined _XBOX 34 extern D3DDevice *g_d3ddevice; 35 #endif 25 36 26 37 namespace lol … … 61 72 float angle; 62 73 63 #if defined USE_D3D9 || defined _XBOX 64 # if defined __GNUC__ 65 # warning Scene not implemented 66 # else 67 # define STR0(x) #x 68 # define STR(x) STR0(x) 69 # pragma message(__FILE__ "(" STR(__LINE__) "): warning: Scene not implemented") 70 # undef STR 71 # undef STR0 72 # endif 73 #else 74 #if defined HAVE_GL_2X && !defined __APPLE__ 74 #if defined USE_D3D9 75 IDirect3DVertexDeclaration9 *m_vdecl; 76 IDirect3DVertexBuffer9 **bufs; 77 #elif defined _XBOX 78 D3DVertexDeclaration *m_vdecl; 79 D3DVertexBuffer **bufs; 80 #else 81 # if defined HAVE_GL_2X && !defined __APPLE__ 75 82 GLuint vao; 76 # endif83 # endif 77 84 GLuint *bufs; 85 #endif 78 86 int nbufs; 79 #endif80 87 81 88 static Scene *scene; … … 95 102 data->angle = angle; 96 103 97 #if defined USE_D3D9 || defined _XBOX98 /* TODO */99 #else100 104 data->bufs = 0; 101 105 data->nbufs = 0; 102 106 107 #if defined _XBOX || defined USE_D3D9 108 D3DVERTEXELEMENT9 const elements[] = 109 { 110 { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, 111 { 1, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, 112 D3DDECL_END() 113 }; 114 g_d3ddevice->CreateVertexDeclaration(elements, &data->m_vdecl); 115 #else 103 116 # if defined HAVE_GL_2X && !defined __APPLE__ 104 117 glGenVertexArrays(1, &data->vao); … … 110 123 { 111 124 #if defined USE_D3D9 || defined _XBOX 112 /* TODO */125 /* FIXME: TODO */ 113 126 #else 114 127 /* FIXME: this must be done while the GL context is still active. … … 141 154 void Scene::AddTile(TileSet *tileset, int id, vec3 pos, int o, vec2 scale) 142 155 { 143 #if !defined USE_D3D9 && !defined _XBOX144 156 if ((data->ntiles % 1024) == 0) 145 157 data->tiles = (Tile *)realloc(data->tiles, … … 153 165 data->tiles[data->ntiles].scale = scale; 154 166 data->ntiles++; 155 #endif156 167 } 157 168 158 169 void Scene::Render() // XXX: rename to Blit() 159 170 { 160 #if !defined USE_D3D9 && !defined _XBOX /* No WPOS on Xbox, what about Win32? */161 171 if (!stdshader) 162 172 { 163 #if !defined _XBOX && !defined __CELLOS_LV2__ 173 #if !defined _XBOX && !defined __CELLOS_LV2__ && !defined USE_D3D9 164 174 stdshader = Shader::Create( 165 175 #if !defined HAVE_GLES_2X … … 258 268 259 269 "void main(float2 in_TexCoord : TEXCOORD0," 270 #if 0 260 271 " float4 in_FragCoord : WPOS," 272 #endif 261 273 " uniform sampler2D tex," 262 274 " out float4 out_FragColor : COLOR)" … … 298 310 " out_FragColor = col;" 299 311 "}"); 300 #endif301 312 } 302 313 … … 326 337 327 338 ShaderUniform uni_mat, uni_tex; 339 #if defined USE_D3D9 || defined _XBOX 340 /* Nothing? */ 341 #else 328 342 int attr_pos, attr_tex; 329 343 #if !defined __CELLOS_LV2__ 330 344 attr_pos = stdshader->GetAttribLocation("in_Position"); 331 345 attr_tex = stdshader->GetAttribLocation("in_TexCoord"); 346 #endif 332 347 #endif 333 348 … … 341 356 stdshader->SetUniform(uni_mat, data->model_matrix); 342 357 358 #if defined USE_D3D9 || defined _XBOX 359 //g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); 360 g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); 361 g_d3ddevice->SetVertexDeclaration(data->m_vdecl); 362 #else 343 363 uni_tex = stdshader->GetUniformLocation("in_Texture"); 344 364 stdshader->SetUniform(uni_tex, 0); 345 365 346 #if defined USE_D3D9 || defined _XBOX347 /* TODO */348 #else349 366 #if !defined HAVE_GLES_2X 350 367 glEnable(GL_TEXTURE_2D); … … 362 379 for (int buf = 0, i = 0, n; i < data->ntiles; i = n, buf += 2) 363 380 { 364 #if defined USE_D3D9 || defined _XBOX365 /* TODO */366 #else367 381 /* Generate new vertex / texture coord buffers if necessary */ 368 382 if (buf + 2 > data->nbufs) 369 383 { 384 #if defined USE_D3D9 385 data->bufs = (IDirect3DVertexBuffer9 **)realloc(data->bufs, (buf + 2) * sizeof(IDirect3DVertexBuffer9 *)); 386 #elif defined _XBOX 387 data->bufs = (D3DVertexBuffer **)realloc(data->bufs, (buf + 2) * sizeof(D3DVertexBuffer *)); 388 #else 370 389 data->bufs = (uint32_t *)realloc(data->bufs, (buf + 2) * sizeof(uint32_t)); 371 390 glGenBuffers(buf + 2 - data->nbufs, data->bufs + data->nbufs); 391 #endif 372 392 data->nbufs = buf + 2; 393 } 394 #if defined USE_D3D9 || defined _XBOX 395 else 396 { 397 data->bufs[buf]->Release(); 398 data->bufs[buf + 1]->Release(); 373 399 } 374 400 #endif … … 380 406 381 407 /* Create a vertex array object */ 382 float *vertex = (float *)malloc(6 * 3 * (n - i) * sizeof(float)); 383 float *texture = (float *)malloc(6 * 2 * (n - i) * sizeof(float)); 408 float *vertex, *texture; 409 #if defined USE_D3D9 || defined _XBOX 410 if (FAILED(g_d3ddevice->CreateVertexBuffer(6 * 3 * (n - i) * sizeof(float), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &data->bufs[buf], NULL))) 411 exit(0); 412 if (FAILED(data->bufs[buf]->Lock(0, 0, (void **)&vertex, 0))) 413 exit(0); 414 if (FAILED(g_d3ddevice->CreateVertexBuffer(6 * 2 * (n - i) * sizeof(float), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &data->bufs[buf + 1], NULL))) 415 exit(0); 416 if (FAILED(data->bufs[buf + 1]->Lock(0, 0, (void **)&texture, 0))) 417 exit(0); 418 #else 419 vertex = (float *)malloc(6 * 3 * (n - i) * sizeof(float)); 420 texture = (float *)malloc(6 * 2 * (n - i) * sizeof(float)); 421 #endif 384 422 385 423 for (int j = i; j < n; j++) … … 391 429 } 392 430 431 #if defined USE_D3D9 || defined _XBOX 432 data->bufs[buf]->Unlock(); 433 data->bufs[buf + 1]->Unlock(); 434 #endif 435 393 436 stdshader->Bind(); 394 437 … … 397 440 398 441 /* Bind vertex, color and texture coordinate buffers */ 399 #if defined HAVE_GL_2X && !defined __APPLE__ 442 #if defined USE_D3D9 || defined _XBOX 443 g_d3ddevice->SetStreamSource(0, data->bufs[data->nbufs - 2], 0, 6 * 3 * (n - i) * sizeof(float)); 444 g_d3ddevice->SetStreamSource(1, data->bufs[data->nbufs - 1], 0, 6 * 2 * (n - i) * sizeof(float)); 445 g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, (n - i) * 6); 446 #else 447 # if defined HAVE_GL_2X && !defined __APPLE__ 400 448 glBindVertexArray(data->vao); 401 #endif 402 #if defined USE_D3D9 || defined _XBOX 403 /* TODO */ 404 #else 405 #if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. 449 # endif 450 # if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. 406 451 glEnableVertexAttribArray(attr_pos); 407 452 glEnableVertexAttribArray(attr_tex); … … 416 461 texture, GL_STATIC_DRAW); 417 462 glVertexAttribPointer(attr_tex, 2, GL_FLOAT, GL_FALSE, 0, 0); 418 # else463 # else 419 464 glEnableClientState(GL_VERTEX_ARRAY); 420 465 glEnableClientState(GL_TEXTURE_COORD_ARRAY); … … 422 467 glVertexPointer(3, GL_FLOAT, 0, vertex); 423 468 glTexCoordPointer(2, GL_FLOAT, 0, texture); 424 # endif469 # endif 425 470 426 471 /* Draw arrays */ 427 472 glDrawArrays(GL_TRIANGLES, 0, (n - i) * 6); 428 473 429 # if defined HAVE_GL_2X && !defined __APPLE__474 # if defined HAVE_GL_2X && !defined __APPLE__ 430 475 glBindVertexArray(0); 431 # endif432 # if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc.476 # endif 477 # if !defined __CELLOS_LV2__ // Use cgGLEnableClientState etc. 433 478 glDisableVertexAttribArray(attr_pos); 434 479 glDisableVertexAttribArray(attr_tex); 435 # else480 # else 436 481 glDisableClientState(GL_VERTEX_ARRAY); 437 482 glDisableClientState(GL_TEXTURE_COORD_ARRAY); 438 #endif 439 #endif 483 # endif 440 484 441 485 free(vertex); 442 486 free(texture); 487 #endif 443 488 } 444 489 -
trunk/src/tileset.cpp
r1208 r1221 21 21 # define WIN32_LEAN_AND_MEAN 22 22 # include <windows.h> 23 # if defined USE_D3D9 24 # define FAR 25 # define NEAR 26 # include <d3d9.h> 27 # endif 23 28 #endif 24 29 … … 27 32 28 33 using namespace std; 34 35 #if defined USE_D3D9 36 extern IDirect3DDevice9 *g_d3ddevice; 37 #elif defined _XBOX 38 extern D3DDevice *g_d3ddevice; 39 #endif 29 40 30 41 namespace lol … … 47 58 48 59 Image *img; 49 #if defined USE_D3D9 || defined _XBOX 50 # define STR0(x) #x 51 # define STR(x) STR0(x) 52 # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet not implemented") 53 # undef STR 54 # undef STR0 55 #else 56 GLuint texture; 60 #if defined USE_D3D9 61 IDirect3DTexture9 *m_tex; 62 #elif defined _XBOX 63 D3DTexture *m_tex; 64 #else 65 GLuint m_tex; 57 66 #endif 58 67 }; … … 70 79 71 80 data->tiles = NULL; 72 #if defined USE_D3D9 || defined _XBOX 73 # define STR0(x) #x 74 # define STR(x) STR0(x) 75 # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented") 76 # undef STR 77 # undef STR0 78 #else 79 data->texture = 0; 80 #endif 81 data->m_tex = 0; 81 82 data->img = new Image(path); 82 83 data->isize = data->img->GetSize(); … … 119 120 if (data->img) 120 121 delete data->img; 121 #if defined USE_D3D9 || defined _XBOX122 # define STR0(x) #x123 # define STR(x) STR0(x)124 # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented")125 # undef STR126 # undef STR0127 #else128 122 else 129 glDeleteTextures(1, &data->texture); 123 #if defined USE_D3D9 || defined _XBOX 124 /* FIXME: is it really the correct call? */ 125 data->m_tex->Release(); 126 #else 127 glDeleteTextures(1, &data->m_tex); 130 128 #endif 131 129 } … … 133 131 { 134 132 #if defined USE_D3D9 || defined _XBOX 135 # define STR0(x) #x 136 # define STR(x) STR0(x) 137 # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TickDraw() not implemented") 138 # undef STR 139 # undef STR0 133 D3DFORMAT format; 140 134 #else 141 135 GLuint format; 136 #endif 142 137 int planes; 143 138 … … 145 140 { 146 141 case Image::FORMAT_RGB: 142 #if defined USE_D3D9 143 format = D3DFMT_R8G8B8; 144 #elif defined _XBOX 145 format = D3DFMT_LIN_R8G8B8; /* FIXME */ 146 #else 147 147 format = GL_RGB; 148 #endif 148 149 planes = 3; 149 150 break; 150 151 case Image::FORMAT_RGBA: 151 152 default: 153 #if defined USE_D3D9 154 format = D3DFMT_A8R8G8B8; 155 #elif defined _XBOX 156 format = D3DFMT_LIN_A8R8G8B8; 157 #else 152 158 format = GL_RGBA; 159 #endif 153 160 planes = 4; 154 161 break; … … 169 176 } 170 177 171 glGenTextures(1, &data->texture); 178 #if defined USE_D3D9 || defined _XBOX 179 D3DLOCKED_RECT rect; 180 # if defined USE_D3D9 181 g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_DYNAMIC, format, 182 D3DPOOL_SYSTEMMEM, &data->m_tex, NULL); 183 data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE); 184 # elif defined _XBOX 185 /* By default the X360 will swizzle the texture. Ask for linear. */ 186 g_d3ddevice->CreateTexture(w, h, 1, D3DUSAGE_WRITEONLY, format, 187 D3DPOOL_DEFAULT, &data->m_tex, NULL); 188 data->m_tex->LockRect(0, &rect, NULL, D3DLOCK_NOOVERWRITE); 189 # endif 190 for (int j = 0; j < h; j++) 191 memcpy((uint8_t *)rect.pBits + j * rect.Pitch, pixels + w * j * 4, w * 4); 192 data->m_tex->UnlockRect(0); 193 #else 194 glGenTextures(1, &data->m_tex); 172 195 glEnable(GL_TEXTURE_2D); 173 glBindTexture(GL_TEXTURE_2D, data-> texture);196 glBindTexture(GL_TEXTURE_2D, data->m_tex); 174 197 175 198 glTexImage2D(GL_TEXTURE_2D, 0, format, w, h, 0, … … 178 201 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 179 202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 203 #endif 180 204 181 205 if (pixels != data->img->GetData()) 182 206 free(pixels); 183 #endif184 207 delete data->img; 185 208 data->img = NULL; … … 204 227 void TileSet::Bind() 205 228 { 206 #if defined USE_D3D9 || defined _XBOX 207 # define STR0(x) #x 208 # define STR(x) STR0(x) 209 # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::Bind() not implemented") 210 # undef STR 211 # undef STR0 212 #else 213 if (!data->img && data->texture) 214 { 229 if (!data->img && data->m_tex) 230 { 231 #if defined USE_D3D9 || defined _XBOX 232 g_d3ddevice->SetTexture(0, data->m_tex); 233 #else 215 234 glActiveTexture(GL_TEXTURE0); 216 glBindTexture(GL_TEXTURE_2D, data-> texture);217 } 218 #endif 235 glBindTexture(GL_TEXTURE_2D, data->m_tex); 236 #endif 237 } 219 238 } 220 239 … … 229 248 int dz = o ? data->size.y * scale.y : 0; 230 249 231 #if defined USE_D3D9 || defined _XBOX 232 # define STR0(x) #x 233 # define STR(x) STR0(x) 234 # pragma message(__FILE__ "(" STR(__LINE__) "): warning: TileSet::TileSet() not implemented") 235 # undef STR 236 # undef STR0 237 #else 238 if (!data->img && data->texture) 250 if (!data->img && data->m_tex) 239 251 { 240 252 float tmp[10]; … … 281 293 memset(texture, 0, 2 * sizeof(float)); 282 294 } 283 #endif284 295 } 285 296
Note: See TracChangeset
for help on using the changeset viewer.