Changeset 1213
- Timestamp:
- Apr 10, 2012, 8:39:16 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/tutorial/tut03.cpp
r1178 r1213 23 23 using namespace lol; 24 24 25 #if defined _WIN32 && defined USE_D3D9 26 # define FAR 27 # define NEAR 28 # include <d3d9.h> 29 #endif 30 25 31 #if USE_SDL && defined __APPLE__ 26 32 # include <SDL_main.h> … … 32 38 #endif 33 39 34 #ifdef __CELLOS_LV2__ 40 #if defined USE_D3D9 41 extern IDirect3DDevice9 *g_d3ddevice; 42 #elif defined _XBOX 43 extern D3DDevice *g_d3ddevice; 44 #elif __CELLOS_LV2__ 35 45 static GLint const INTERNAL_FORMAT = GL_ARGB_SCE; 36 46 static GLenum const TEXTURE_FORMAT = GL_BGRA; … … 444 454 if (!m_ready) 445 455 { 456 #if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 446 457 /* Create a texture of half the width and twice the height 447 458 * so that we can upload four different subimages each frame. */ … … 451 462 m_size.x / 2, m_size.y * 2, 0, 452 463 TEXTURE_FORMAT, TEXTURE_TYPE, m_pixels); 453 # if defined __CELLOS_LV2__464 # if defined __CELLOS_LV2__ 454 465 /* We need this hint because by default the storage type is 455 466 * GL_TEXTURE_SWIZZLED_GPU_SCE. */ 456 467 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ALLOCATION_HINT_SCE, 457 468 GL_TEXTURE_TILED_GPU_SCE); 458 # endif469 # endif 459 470 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 460 471 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 472 #else 473 g_d3ddevice->CreateTexture(m_size.x / 2, m_size.y * 2, 1, 474 D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, 475 D3DPOOL_SYSTEMMEM, &m_tex, NULL); 476 #endif 461 477 462 478 m_shader = Shader::Create( 463 #if !defined __CELLOS_LV2__ 464 # if !defined HAVE_GLES_2X479 #if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 480 # if !defined HAVE_GLES_2X 465 481 "#version 120\n" 466 # else482 # else 467 483 "precision highp float;" 468 # endif484 # endif 469 485 "" 470 486 "uniform mat4 u_ZoomSettings;" … … 511 527 "}", 512 528 513 # if !defined HAVE_GLES_2X529 # if !defined HAVE_GLES_2X 514 530 "#version 120\n" 515 # else531 # else 516 532 "precision highp float;" 517 # endif533 # endif 518 534 "" 519 535 "uniform vec4 u_TexelSize;" … … 540 556 " ry = ry * 0.25 + vec4(0.0, 0.25, 0.5, 0.75);" 541 557 "" 542 # if 1558 # if 1 543 559 "\n#if 0\n" /* XXX: disabled until we can autodetect i915 */ 544 560 /* t1.x <-- dd.x > dd.y */ … … 577 593 /* Nearest neighbour */ 578 594 " gl_FragColor = texture2D(u_Texture, ret.xy);" 579 # else595 # else 580 596 /* Alternate version: some kind of linear interpolation */ 581 597 " vec4 p0 = texture2D(u_Texture, vec2(rx.x, ry.x));" … … 585 601 " gl_FragColor = 1.0 / (dd.x + dd.y + dd.z + dd.w)" 586 602 " * (dd.x * p0 + dd.y * p1 + dd.z * p2 + dd.w * p3);" 587 # endif603 # endif 588 604 "}" 589 605 #else … … 648 664 #endif 649 665 ); 666 #if !defined _XBOX && !defined USE_D3D9 650 667 m_vertexattrib = m_shader->GetAttribLocation("a_Vertex"); 651 668 m_texattrib = m_shader->GetAttribLocation("a_TexCoord"); 669 #endif 652 670 m_texeluni = m_shader->GetUniformLocation("u_TexelSize"); 653 671 #if defined __CELLOS_LV2__ … … 658 676 m_ready = true; 659 677 660 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ 678 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined _XBOX && !defined USE_D3D9 661 679 /* Method 1: store vertex buffer on the GPU memory */ 662 680 glGenBuffers(1, &m_vbo); … … 668 686 glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, 669 687 GL_STATIC_DRAW); 670 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ 688 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ && !defined _XBOX && !defined USE_D3D9 671 689 /* Method 2: upload vertex information at each frame */ 690 #elif defined _XBOX || defined USE_D3D9 691 D3DVERTEXELEMENT9 const elements[] = 692 { 693 { 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, 694 { 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, 695 D3DDECL_END() 696 }; 697 g_d3ddevice->CreateVertexDeclaration(elements, &m_vdecl); 698 699 if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(vertices), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_vbo, NULL))) 700 exit(0); 701 702 vec2 *tmp1; 703 if (FAILED(m_vbo->Lock(0, 0, (void **)&tmp1, 0))) 704 exit(0); 705 memcpy(tmp1, vertices, sizeof(vertices)); 706 m_vbo->Unlock(); 707 708 if (FAILED(g_d3ddevice->CreateVertexBuffer(sizeof(texcoords), D3DUSAGE_WRITEONLY, NULL, D3DPOOL_MANAGED, &m_tbo, NULL))) 709 exit(0); 710 711 vec2 *tmp2; 712 if (FAILED(m_tbo->Lock(0, 0, (void **)&tmp2, 0))) 713 exit(0); 714 memcpy(tmp2, texcoords, sizeof(texcoords)); 715 m_tbo->Unlock(); 672 716 #else 673 717 #endif … … 676 720 } 677 721 678 #if !defined HAVE_GLES_2X 722 #if defined _XBOX || defined USE_D3D9 723 724 #else 725 # if !defined HAVE_GLES_2X 679 726 glEnable(GL_TEXTURE_2D); 680 # endif727 # endif 681 728 glBindTexture(GL_TEXTURE_2D, m_texid); 729 #endif 682 730 683 731 if (m_dirty[m_frame]) … … 688 736 m_dirty[m_frame]--; 689 737 690 #ifdef __CELLOS_LV2__ 738 #if defined _XBOX || defined USE_D3D9 739 D3DLOCKED_RECT rect; 740 m_tex->LockRect(0, &rect, NULL, 741 D3DLOCK_DISCARD | D3DLOCK_NOOVERWRITE); 742 for (int j = 0; j < m_size.y * 2; j++) 743 { 744 u8vec4 *line = (u8vec4 *)rect.pBits + j * rect.Pitch / 4; 745 for (int i = 0; i < m_size.x / 2; j++) 746 line[i] = m_pixels[m_size.x / 2 * j + i]; 747 } 748 m_tex->UnlockRect(0); 749 #elif defined __CELLOS_LV2__ 691 750 /* glTexSubImage2D is extremely slow on the PS3, to the point 692 751 * that uploading the whole texture is 40 times faster. */ … … 709 768 m_shader->SetUniform(m_screenuni, m_screen_settings); 710 769 m_shader->SetUniform(m_zoomuni, m_zoom_settings); 711 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ 770 #if defined _XBOX || defined USE_D3D9 771 g_d3ddevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); 772 g_d3ddevice->SetVertexDeclaration(m_vdecl); 773 g_d3ddevice->SetStreamSource(0, m_vbo, 0, sizeof(*vertices)); 774 g_d3ddevice->SetStreamSource(1, m_tbo, 0, sizeof(*texcoords)); 775 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ 712 776 glBindBuffer(GL_ARRAY_BUFFER, m_vbo); 713 777 glEnableVertexAttribArray(m_vertexattrib); … … 728 792 #endif 729 793 794 #if defined _XBOX || defined USE_D3D9 795 g_d3ddevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 6); 796 #else 730 797 glDrawArrays(GL_TRIANGLES, 0, 6); 731 732 #if !defined __CELLOS_LV2__ && !defined __ANDROID__ 798 #endif 799 800 #if defined _XBOX || defined USE_D3D9 801 802 #elif !defined __CELLOS_LV2__ && !defined __ANDROID__ 733 803 glDisableVertexAttribArray(m_vertexattrib); 734 804 glDisableVertexAttribArray(m_texattrib); … … 755 825 u8vec4 *m_pixels, *m_tmppixels, *m_palette; 756 826 Shader *m_shader; 827 #if defined USE_D3D9 828 IDirect3DTexture9 *m_tex; 829 IDirect3DVertexDeclaration9 *m_vdecl; 830 IDirect3DVertexBuffer9 *m_vbo, *m_tbo; 831 #elif defined _XBOX 832 D3DTexture *m_tex; 833 D3DVertexDeclaration *m_vdecl; 834 D3DVertexBuffer *m_vbo, *m_tbo; 835 #else 757 836 GLuint m_texid; 758 # if !defined __CELLOS_LV2__ && !defined __ANDROID__837 # if !defined __CELLOS_LV2__ && !defined __ANDROID__ 759 838 GLuint m_vbo, m_tbo; 760 839 GLuint m_tco; 840 # endif 761 841 #endif 762 842 int m_vertexattrib, m_texattrib, m_texeluni, m_screenuni, m_zoomuni;
Note: See TracChangeset
for help on using the changeset viewer.