Changeset 1987
- Timestamp:
- Oct 8, 2012, 1:09:29 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Makefile.am
r1938 r1987 51 51 gpu/vertexbuffer.cpp gpu/vertexbuffer.h \ 52 52 gpu/framebuffer.cpp gpu/framebuffer.h \ 53 gpu/texture.cpp gpu/texture.h \ 53 54 \ 54 55 gpu/defaultmaterial.lolfx \ -
trunk/src/core.h
r1927 r1987 116 116 #include "gpu/lolfx.h" 117 117 #include "gpu/shader.h" 118 #include "gpu/texture.h" 118 119 #include "gpu/indexbuffer.h" 119 120 #include "gpu/vertexbuffer.h" -
trunk/src/lolcore.vcxproj
r1927 r1987 255 255 <ClCompile Include="gpu\lolfx.cpp" /> 256 256 <ClCompile Include="gpu\shader.cpp" /> 257 <ClCompile Include="gpu\texture.cpp" /> 257 258 <ClCompile Include="gpu\vertexbuffer.cpp" /> 258 259 <ClCompile Include="gradient.cpp" /> … … 568 569 <ClInclude Include="gpu\lolfx.h" /> 569 570 <ClInclude Include="gpu\shader.h" /> 571 <ClInclude Include="gpu\texture.h" /> 570 572 <ClInclude Include="gpu\vertexbuffer.h" /> 571 573 <ClInclude Include="gradient.h" /> -
trunk/src/lolcore.vcxproj.filters
r1927 r1987 98 98 <Filter>src\gpu</Filter> 99 99 </ClCompile> 100 <ClCompile Include="gpu\texture.cpp"> 101 <Filter>src\gpu</Filter> 102 </ClCompile> 100 103 <ClCompile Include="gpu\vertexbuffer.cpp"> 101 104 <Filter>src\gpu</Filter> … … 668 671 </ClInclude> 669 672 <ClInclude Include="gpu\shader.h"> 673 <Filter>src\gpu</Filter> 674 </ClInclude> 675 <ClInclude Include="gpu\texture.h"> 670 676 <Filter>src\gpu</Filter> 671 677 </ClInclude> -
trunk/tutorial/11_fractal.cpp
r1963 r1987 16 16 17 17 #include "core.h" 18 #include "lolgl.h"19 18 #include "loldebug.h" 20 19 21 20 using namespace lol; 22 21 23 #if defined _WIN3224 # include <direct.h>25 # if defined USE_D3D926 # define FAR27 # define NEAR28 # include <d3d9.h>29 # endif30 #endif31 32 22 extern char const *lolfx_11_fractal; 33 34 #if defined USE_D3D935 extern IDirect3DDevice9 *g_d3ddevice;36 #elif defined _XBOX37 extern D3DDevice *g_d3ddevice;38 #elif __CELLOS_LV2__39 static GLint const INTERNAL_FORMAT = GL_ARGB_SCE;40 static GLenum const TEXTURE_FORMAT = GL_BGRA;41 static GLenum const TEXTURE_TYPE = GL_UNSIGNED_INT_8_8_8_8_REV;42 #elif defined __native_client__ || defined HAVE_GLES_2X43 static GLint const INTERNAL_FORMAT = GL_RGBA;44 static GLenum const TEXTURE_FORMAT = GL_RGBA;45 static GLenum const TEXTURE_TYPE = GL_UNSIGNED_BYTE;46 #else47 /* Seems efficient for little endian textures */48 static GLint const INTERNAL_FORMAT = GL_RGBA;49 static GLenum const TEXTURE_FORMAT = GL_BGRA;50 static GLenum const TEXTURE_TYPE = GL_UNSIGNED_INT_8_8_8_8_REV;51 #endif52 23 53 24 class Fractal : public WorldEntity … … 468 439 if (!m_ready) 469 440 { 470 #if !defined _XBOX && !defined USE_D3D9471 441 /* Create a texture of half the width and twice the height 472 442 * so that we can upload four different subimages each frame. */ 473 glGenTextures(1, &m_texid); 474 glBindTexture(GL_TEXTURE_2D, m_texid); 475 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 476 m_size.x / 2, m_size.y * 2, 0, 477 TEXTURE_FORMAT, TEXTURE_TYPE, &m_pixels[0]); 478 # if defined __CELLOS_LV2__ 479 /* We need this hint because by default the storage type is 480 * GL_TEXTURE_SWIZZLED_GPU_SCE. */ 481 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ALLOCATION_HINT_SCE, 482 GL_TEXTURE_TILED_GPU_SCE); 483 # endif 484 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 485 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 486 #elif defined _XBOX 487 /* By default the X360 will swizzle the texture. Ask for linear. */ 488 g_d3ddevice->CreateTexture(m_size.x / 2, m_size.y * 2, 1, 489 D3DUSAGE_WRITEONLY, D3DFMT_LIN_A8R8G8B8, 490 D3DPOOL_DEFAULT, &m_tex, NULL); 491 #else 492 g_d3ddevice->CreateTexture(m_size.x / 2, m_size.y * 2, 1, 493 D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, 494 D3DPOOL_SYSTEMMEM, &m_tex, NULL); 495 #endif 443 m_texture = new Texture(ivec2(m_size.x / 2, m_size.y * 2)); 444 445 /* Ensure the texture data is complete at least once, otherwise 446 * uploading subimages will not work. */ 447 m_texture->SetData(&m_pixels[0]); 496 448 497 449 m_shader = Shader::Create(lolfx_11_fractal); … … 521 473 } 522 474 523 #if defined _XBOX || defined USE_D3D9 524 525 #else 526 # if !defined HAVE_GLES_2X 527 glEnable(GL_TEXTURE_2D); 528 # endif 529 glBindTexture(GL_TEXTURE_2D, m_texid); 530 #endif 475 m_texture->Bind(); 531 476 532 477 if (m_dirty[m_frame]) … … 537 482 m_dirty[m_frame]--; 538 483 539 #if defined _XBOX || defined USE_D3D9 540 D3DLOCKED_RECT rect; 541 # if defined _XBOX 542 m_tex->LockRect(0, &rect, NULL, D3DLOCK_NOOVERWRITE); 543 # else 544 m_tex->LockRect(0, &rect, NULL, 545 D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE); 546 # endif 547 for (int j = 0; j < m_size.y * 2; j++) 548 { 549 u8vec4 *line = (u8vec4 *)rect.pBits + j * rect.Pitch / 4; 550 for (int i = 0; i < m_size.x / 2; i++) 551 line[i] = m_pixels[m_size.x / 2 * j + i]; 552 } 553 m_tex->UnlockRect(0); 554 #elif defined __CELLOS_LV2__ 484 #if defined __CELLOS_LV2__ 555 485 /* glTexSubImage2D is extremely slow on the PS3, to the point 556 486 * that uploading the whole texture is 40 times faster. */ 557 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 558 m_size.x / 2, m_size.y * 2, 0, 559 TEXTURE_FORMAT, TEXTURE_TYPE, &m_pixels[0]); 487 m_texture->SetData(&m_pixels[0]); 560 488 #else 561 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, m_frame * m_size.y / 2, 562 m_size.x / 2, m_size.y / 2, 563 TEXTURE_FORMAT, TEXTURE_TYPE, 564 &m_pixels[m_size.x * m_size.y / 4 * m_frame]); 489 m_texture->SetSubData(ivec2(0, m_frame * m_size.y / 2), 490 m_size / 2, 491 &m_pixels[m_size.x * m_size.y / 4 * m_frame]); 565 492 #endif 566 493 } … … 573 500 m_vdecl->SetStream(m_vbo, m_vertexattrib); 574 501 m_vdecl->SetStream(m_tbo, m_texattrib); 575 #if defined _XBOX || defined USE_D3D9 576 g_d3ddevice->SetTexture(0, m_tex); 577 g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); 578 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ 579 #else 580 #endif 502 m_texture->Bind(); 581 503 m_vdecl->DrawElements(MeshPrimitive::Triangles, 0, 6); 582 504 m_vdecl->Unbind(); … … 600 522 VertexDeclaration *m_vdecl; 601 523 VertexBuffer *m_vbo, *m_tbo; 602 #if defined USE_D3D9 603 IDirect3DTexture9 *m_tex; 604 #elif defined _XBOX 605 D3DTexture *m_tex; 606 #else 607 GLuint m_texid; 608 #endif 524 Texture *m_texture; 525 609 526 int m_frame, m_slices, m_dirty[4]; 610 527 bool m_ready, m_drag;
Note: See TracChangeset
for help on using the changeset viewer.