| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // Gets the GL internal format, format and type corresponding to a command | 43 // Gets the GL internal format, format and type corresponding to a command |
| 44 // buffer texture format. | 44 // buffer texture format. |
| 45 bool GetGLFormatType(texture::Format format, | 45 bool GetGLFormatType(texture::Format format, |
| 46 GLenum *internal_format, | 46 GLenum *internal_format, |
| 47 GLenum *gl_format, | 47 GLenum *gl_format, |
| 48 GLenum *gl_type) { | 48 GLenum *gl_type) { |
| 49 switch (format) { | 49 switch (format) { |
| 50 case texture::XRGB8: | 50 case texture::kXRGB8: |
| 51 *internal_format = GL_RGB; | 51 *internal_format = GL_RGB; |
| 52 *gl_format = GL_BGRA; | 52 *gl_format = GL_BGRA; |
| 53 *gl_type = GL_UNSIGNED_BYTE; | 53 *gl_type = GL_UNSIGNED_BYTE; |
| 54 return true; | 54 return true; |
| 55 case texture::ARGB8: | 55 case texture::kARGB8: |
| 56 *internal_format = GL_RGBA; | 56 *internal_format = GL_RGBA; |
| 57 *gl_format = GL_BGRA; | 57 *gl_format = GL_BGRA; |
| 58 *gl_type = GL_UNSIGNED_BYTE; | 58 *gl_type = GL_UNSIGNED_BYTE; |
| 59 return true; | 59 return true; |
| 60 case texture::ABGR16F: | 60 case texture::kABGR16F: |
| 61 *internal_format = GL_RGBA16F_ARB; | 61 *internal_format = GL_RGBA16F_ARB; |
| 62 *gl_format = GL_RGBA; | 62 *gl_format = GL_RGBA; |
| 63 *gl_type = GL_HALF_FLOAT_ARB; | 63 *gl_type = GL_HALF_FLOAT_ARB; |
| 64 return true; | 64 return true; |
| 65 case texture::DXT1: | 65 case texture::kDXT1: |
| 66 *internal_format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; | 66 *internal_format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; |
| 67 *gl_format = 0; | 67 *gl_format = 0; |
| 68 *gl_type = 0; | 68 *gl_type = 0; |
| 69 return true; | 69 return true; |
| 70 default: | 70 default: |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Helper class used to prepare image data to match the layout that | 75 // Helper class used to prepare image data to match the layout that |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 buffer.get()); | 513 buffer.get()); |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 mip_side = std::max(1U, mip_side >> 1); | 516 mip_side = std::max(1U, mip_side >> 1); |
| 517 } | 517 } |
| 518 return new TextureCubeGL( | 518 return new TextureCubeGL( |
| 519 levels, format, enable_render_surfaces, flags, side, gl_texture); | 519 levels, format, enable_render_surfaces, flags, side, gl_texture); |
| 520 } | 520 } |
| 521 | 521 |
| 522 // Check that GL_TEXTURE_CUBE_MAP_POSITIVE_X + face yields the correct GLenum. | 522 // Check that GL_TEXTURE_CUBE_MAP_POSITIVE_X + face yields the correct GLenum. |
| 523 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::FACE_POSITIVE_X == | 523 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFacePositiveX == |
| 524 GL_TEXTURE_CUBE_MAP_POSITIVE_X, POSITIVE_X_ENUMS_DO_NOT_MATCH); | 524 GL_TEXTURE_CUBE_MAP_POSITIVE_X, POSITIVE_X_ENUMS_DO_NOT_MATCH); |
| 525 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::FACE_NEGATIVE_X == | 525 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFaceNegativeX == |
| 526 GL_TEXTURE_CUBE_MAP_NEGATIVE_X, NEGATIVE_X_ENUMS_DO_NOT_MATCH); | 526 GL_TEXTURE_CUBE_MAP_NEGATIVE_X, NEGATIVE_X_ENUMS_DO_NOT_MATCH); |
| 527 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::FACE_POSITIVE_Y == | 527 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFacePositiveY == |
| 528 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, POSITIVE_Y_ENUMS_DO_NOT_MATCH); | 528 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, POSITIVE_Y_ENUMS_DO_NOT_MATCH); |
| 529 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::FACE_NEGATIVE_Y == | 529 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFaceNegativeY == |
| 530 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, NEGATIVE_Y_ENUMS_DO_NOT_MATCH); | 530 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, NEGATIVE_Y_ENUMS_DO_NOT_MATCH); |
| 531 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::FACE_POSITIVE_Z == | 531 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFacePositiveZ == |
| 532 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, POSITIVE_Z_ENUMS_DO_NOT_MATCH); | 532 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, POSITIVE_Z_ENUMS_DO_NOT_MATCH); |
| 533 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::FACE_NEGATIVE_Z == | 533 COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFaceNegativeZ == |
| 534 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, NEGATIVE_Z_ENUMS_DO_NOT_MATCH); | 534 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, NEGATIVE_Z_ENUMS_DO_NOT_MATCH); |
| 535 | 535 |
| 536 bool TextureCubeGL::SetData(const Volume& volume, | 536 bool TextureCubeGL::SetData(const Volume& volume, |
| 537 unsigned int level, | 537 unsigned int level, |
| 538 texture::Face face, | 538 texture::Face face, |
| 539 unsigned int row_pitch, | 539 unsigned int row_pitch, |
| 540 unsigned int slice_pitch, | 540 unsigned int slice_pitch, |
| 541 unsigned int size, | 541 unsigned int size, |
| 542 const void *data) { | 542 const void *data) { |
| 543 if (level >= levels()) | 543 if (level >= levels()) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 return false; | 620 return false; |
| 621 } | 621 } |
| 622 | 622 |
| 623 return true; | 623 return true; |
| 624 } | 624 } |
| 625 | 625 |
| 626 | 626 |
| 627 // GAPIGL functions. | 627 // GAPIGL functions. |
| 628 | 628 |
| 629 // Destroys a texture resource. | 629 // Destroys a texture resource. |
| 630 BufferSyncInterface::ParseError GAPIGL::DestroyTexture(ResourceID id) { | 630 BufferSyncInterface::ParseError GAPIGL::DestroyTexture(ResourceId id) { |
| 631 // Dirty effect, because this texture id may be used. | 631 // Dirty effect, because this texture id may be used. |
| 632 DirtyEffect(); | 632 DirtyEffect(); |
| 633 return textures_.Destroy(id) ? | 633 return textures_.Destroy(id) ? |
| 634 BufferSyncInterface::kParseNoError : | 634 BufferSyncInterface::kParseNoError : |
| 635 BufferSyncInterface::kParseInvalidArguments; | 635 BufferSyncInterface::kParseInvalidArguments; |
| 636 } | 636 } |
| 637 | 637 |
| 638 // Creates a 2D texture resource. | 638 // Creates a 2D texture resource. |
| 639 BufferSyncInterface::ParseError GAPIGL::CreateTexture2D( | 639 BufferSyncInterface::ParseError GAPIGL::CreateTexture2D( |
| 640 ResourceID id, | 640 ResourceId id, |
| 641 unsigned int width, | 641 unsigned int width, |
| 642 unsigned int height, | 642 unsigned int height, |
| 643 unsigned int levels, | 643 unsigned int levels, |
| 644 texture::Format format, | 644 texture::Format format, |
| 645 unsigned int flags, | 645 unsigned int flags, |
| 646 bool enable_render_surfaces) { | 646 bool enable_render_surfaces) { |
| 647 Texture2DGL *texture = Texture2DGL::Create( | 647 Texture2DGL *texture = Texture2DGL::Create( |
| 648 width, height, levels, format, flags, enable_render_surfaces); | 648 width, height, levels, format, flags, enable_render_surfaces); |
| 649 if (!texture) return BufferSyncInterface::kParseInvalidArguments; | 649 if (!texture) return BufferSyncInterface::kParseInvalidArguments; |
| 650 // Dirty effect, because this texture id may be used. | 650 // Dirty effect, because this texture id may be used. |
| 651 DirtyEffect(); | 651 DirtyEffect(); |
| 652 textures_.Assign(id, texture); | 652 textures_.Assign(id, texture); |
| 653 return BufferSyncInterface::kParseNoError; | 653 return BufferSyncInterface::kParseNoError; |
| 654 } | 654 } |
| 655 | 655 |
| 656 // Creates a 3D texture resource. | 656 // Creates a 3D texture resource. |
| 657 BufferSyncInterface::ParseError GAPIGL::CreateTexture3D( | 657 BufferSyncInterface::ParseError GAPIGL::CreateTexture3D( |
| 658 ResourceID id, | 658 ResourceId id, |
| 659 unsigned int width, | 659 unsigned int width, |
| 660 unsigned int height, | 660 unsigned int height, |
| 661 unsigned int depth, | 661 unsigned int depth, |
| 662 unsigned int levels, | 662 unsigned int levels, |
| 663 texture::Format format, | 663 texture::Format format, |
| 664 unsigned int flags, | 664 unsigned int flags, |
| 665 bool enable_render_surfaces) { | 665 bool enable_render_surfaces) { |
| 666 Texture3DGL *texture = Texture3DGL::Create( | 666 Texture3DGL *texture = Texture3DGL::Create( |
| 667 width, height, depth, levels, format, flags, enable_render_surfaces); | 667 width, height, depth, levels, format, flags, enable_render_surfaces); |
| 668 if (!texture) return BufferSyncInterface::kParseInvalidArguments; | 668 if (!texture) return BufferSyncInterface::kParseInvalidArguments; |
| 669 // Dirty effect, because this texture id may be used. | 669 // Dirty effect, because this texture id may be used. |
| 670 DirtyEffect(); | 670 DirtyEffect(); |
| 671 textures_.Assign(id, texture); | 671 textures_.Assign(id, texture); |
| 672 return BufferSyncInterface::kParseNoError; | 672 return BufferSyncInterface::kParseNoError; |
| 673 } | 673 } |
| 674 | 674 |
| 675 // Creates a cube map texture resource. | 675 // Creates a cube map texture resource. |
| 676 BufferSyncInterface::ParseError GAPIGL::CreateTextureCube( | 676 BufferSyncInterface::ParseError GAPIGL::CreateTextureCube( |
| 677 ResourceID id, | 677 ResourceId id, |
| 678 unsigned int side, | 678 unsigned int side, |
| 679 unsigned int levels, | 679 unsigned int levels, |
| 680 texture::Format format, | 680 texture::Format format, |
| 681 unsigned int flags, | 681 unsigned int flags, |
| 682 bool enable_render_surfaces) { | 682 bool enable_render_surfaces) { |
| 683 TextureCubeGL *texture = TextureCubeGL::Create( | 683 TextureCubeGL *texture = TextureCubeGL::Create( |
| 684 side, levels, format, flags, enable_render_surfaces); | 684 side, levels, format, flags, enable_render_surfaces); |
| 685 if (!texture) return BufferSyncInterface::kParseInvalidArguments; | 685 if (!texture) return BufferSyncInterface::kParseInvalidArguments; |
| 686 // Dirty effect, because this texture id may be used. | 686 // Dirty effect, because this texture id may be used. |
| 687 DirtyEffect(); | 687 DirtyEffect(); |
| 688 textures_.Assign(id, texture); | 688 textures_.Assign(id, texture); |
| 689 return BufferSyncInterface::kParseNoError; | 689 return BufferSyncInterface::kParseNoError; |
| 690 } | 690 } |
| 691 | 691 |
| 692 // Copies the data into a texture resource. | 692 // Copies the data into a texture resource. |
| 693 BufferSyncInterface::ParseError GAPIGL::SetTextureData( | 693 BufferSyncInterface::ParseError GAPIGL::SetTextureData( |
| 694 ResourceID id, | 694 ResourceId id, |
| 695 unsigned int x, | 695 unsigned int x, |
| 696 unsigned int y, | 696 unsigned int y, |
| 697 unsigned int z, | 697 unsigned int z, |
| 698 unsigned int width, | 698 unsigned int width, |
| 699 unsigned int height, | 699 unsigned int height, |
| 700 unsigned int depth, | 700 unsigned int depth, |
| 701 unsigned int level, | 701 unsigned int level, |
| 702 texture::Face face, | 702 texture::Face face, |
| 703 unsigned int row_pitch, | 703 unsigned int row_pitch, |
| 704 unsigned int slice_pitch, | 704 unsigned int slice_pitch, |
| 705 unsigned int size, | 705 unsigned int size, |
| 706 const void *data) { | 706 const void *data) { |
| 707 TextureGL *texture = textures_.Get(id); | 707 TextureGL *texture = textures_.Get(id); |
| 708 if (!texture) | 708 if (!texture) |
| 709 return BufferSyncInterface::kParseInvalidArguments; | 709 return BufferSyncInterface::kParseInvalidArguments; |
| 710 Volume volume = {x, y, z, width, height, depth}; | 710 Volume volume = {x, y, z, width, height, depth}; |
| 711 // Dirty effect: SetData may need to call glBindTexture which will mess up the | 711 // Dirty effect: SetData may need to call glBindTexture which will mess up the |
| 712 // sampler parameters. | 712 // sampler parameters. |
| 713 DirtyEffect(); | 713 DirtyEffect(); |
| 714 return texture->SetData(volume, level, face, row_pitch, slice_pitch, | 714 return texture->SetData(volume, level, face, row_pitch, slice_pitch, |
| 715 size, data) ? | 715 size, data) ? |
| 716 BufferSyncInterface::kParseNoError : | 716 BufferSyncInterface::kParseNoError : |
| 717 BufferSyncInterface::kParseInvalidArguments; | 717 BufferSyncInterface::kParseInvalidArguments; |
| 718 } | 718 } |
| 719 | 719 |
| 720 // Copies the data from a texture resource. | 720 // Copies the data from a texture resource. |
| 721 BufferSyncInterface::ParseError GAPIGL::GetTextureData( | 721 BufferSyncInterface::ParseError GAPIGL::GetTextureData( |
| 722 ResourceID id, | 722 ResourceId id, |
| 723 unsigned int x, | 723 unsigned int x, |
| 724 unsigned int y, | 724 unsigned int y, |
| 725 unsigned int z, | 725 unsigned int z, |
| 726 unsigned int width, | 726 unsigned int width, |
| 727 unsigned int height, | 727 unsigned int height, |
| 728 unsigned int depth, | 728 unsigned int depth, |
| 729 unsigned int level, | 729 unsigned int level, |
| 730 texture::Face face, | 730 texture::Face face, |
| 731 unsigned int row_pitch, | 731 unsigned int row_pitch, |
| 732 unsigned int slice_pitch, | 732 unsigned int slice_pitch, |
| 733 unsigned int size, | 733 unsigned int size, |
| 734 void *data) { | 734 void *data) { |
| 735 TextureGL *texture = textures_.Get(id); | 735 TextureGL *texture = textures_.Get(id); |
| 736 if (!texture) | 736 if (!texture) |
| 737 return BufferSyncInterface::kParseInvalidArguments; | 737 return BufferSyncInterface::kParseInvalidArguments; |
| 738 Volume volume = {x, y, z, width, height, depth}; | 738 Volume volume = {x, y, z, width, height, depth}; |
| 739 // Dirty effect: GetData may need to call glBindTexture which will mess up the | 739 // Dirty effect: GetData may need to call glBindTexture which will mess up the |
| 740 // sampler parameters. | 740 // sampler parameters. |
| 741 DirtyEffect(); | 741 DirtyEffect(); |
| 742 return texture->GetData(volume, level, face, row_pitch, slice_pitch, | 742 return texture->GetData(volume, level, face, row_pitch, slice_pitch, |
| 743 size, data) ? | 743 size, data) ? |
| 744 BufferSyncInterface::kParseNoError : | 744 BufferSyncInterface::kParseNoError : |
| 745 BufferSyncInterface::kParseInvalidArguments; | 745 BufferSyncInterface::kParseInvalidArguments; |
| 746 } | 746 } |
| 747 | 747 |
| 748 } // namespace command_buffer | 748 } // namespace command_buffer |
| 749 } // namespace o3d | 749 } // namespace o3d |
| OLD | NEW |