| 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 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 // case the creation fails. | 713 // case the creation fails. |
| 714 effects_.Destroy(id); | 714 effects_.Destroy(id); |
| 715 // Data is vp_main \0 fp_main \0 effect_text. | 715 // Data is vp_main \0 fp_main \0 effect_text. |
| 716 String vertex_program_entry; | 716 String vertex_program_entry; |
| 717 String fragment_program_entry; | 717 String fragment_program_entry; |
| 718 String effect_code; | 718 String effect_code; |
| 719 if (!ParseEffectData(size, data, | 719 if (!ParseEffectData(size, data, |
| 720 &vertex_program_entry, | 720 &vertex_program_entry, |
| 721 &fragment_program_entry, | 721 &fragment_program_entry, |
| 722 &effect_code)) { | 722 &effect_code)) { |
| 723 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 723 return BufferSyncInterface::kParseInvalidArguments; |
| 724 } | 724 } |
| 725 EffectGL * effect = EffectGL::Create(this, effect_code, | 725 EffectGL * effect = EffectGL::Create(this, effect_code, |
| 726 vertex_program_entry, | 726 vertex_program_entry, |
| 727 fragment_program_entry); | 727 fragment_program_entry); |
| 728 if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 728 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 729 effects_.Assign(id, effect); | 729 effects_.Assign(id, effect); |
| 730 return BufferSyncInterface::PARSE_NO_ERROR; | 730 return BufferSyncInterface::kParseNoError; |
| 731 } | 731 } |
| 732 | 732 |
| 733 BufferSyncInterface::ParseError GAPIGL::DestroyEffect(ResourceID id) { | 733 BufferSyncInterface::ParseError GAPIGL::DestroyEffect(ResourceID id) { |
| 734 if (id == current_effect_id_) DirtyEffect(); | 734 if (id == current_effect_id_) DirtyEffect(); |
| 735 return effects_.Destroy(id) ? | 735 return effects_.Destroy(id) ? |
| 736 BufferSyncInterface::PARSE_NO_ERROR : | 736 BufferSyncInterface::kParseNoError : |
| 737 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 737 BufferSyncInterface::kParseInvalidArguments; |
| 738 } | 738 } |
| 739 | 739 |
| 740 BufferSyncInterface::ParseError GAPIGL::SetEffect(ResourceID id) { | 740 BufferSyncInterface::ParseError GAPIGL::SetEffect(ResourceID id) { |
| 741 DirtyEffect(); | 741 DirtyEffect(); |
| 742 current_effect_id_ = id; | 742 current_effect_id_ = id; |
| 743 return BufferSyncInterface::PARSE_NO_ERROR; | 743 return BufferSyncInterface::kParseNoError; |
| 744 } | 744 } |
| 745 | 745 |
| 746 BufferSyncInterface::ParseError GAPIGL::GetParamCount(ResourceID id, | 746 BufferSyncInterface::ParseError GAPIGL::GetParamCount(ResourceID id, |
| 747 unsigned int size, | 747 unsigned int size, |
| 748 void *data) { | 748 void *data) { |
| 749 EffectGL *effect = effects_.Get(id); | 749 EffectGL *effect = effects_.Get(id); |
| 750 if (!effect || size < sizeof(Uint32)) // NOLINT | 750 if (!effect || size < sizeof(Uint32)) // NOLINT |
| 751 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 751 return BufferSyncInterface::kParseInvalidArguments; |
| 752 *static_cast<Uint32 *>(data) = effect->GetParamCount(); | 752 *static_cast<Uint32 *>(data) = effect->GetParamCount(); |
| 753 return BufferSyncInterface::PARSE_NO_ERROR; | 753 return BufferSyncInterface::kParseNoError; |
| 754 } | 754 } |
| 755 | 755 |
| 756 BufferSyncInterface::ParseError GAPIGL::CreateParam(ResourceID param_id, | 756 BufferSyncInterface::ParseError GAPIGL::CreateParam(ResourceID param_id, |
| 757 ResourceID effect_id, | 757 ResourceID effect_id, |
| 758 unsigned int index) { | 758 unsigned int index) { |
| 759 EffectGL *effect = effects_.Get(effect_id); | 759 EffectGL *effect = effects_.Get(effect_id); |
| 760 if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 760 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 761 EffectParamGL *param = effect->CreateParam(index); | 761 EffectParamGL *param = effect->CreateParam(index); |
| 762 if (!param) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 762 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 763 effect_params_.Assign(param_id, param); | 763 effect_params_.Assign(param_id, param); |
| 764 return BufferSyncInterface::PARSE_NO_ERROR; | 764 return BufferSyncInterface::kParseNoError; |
| 765 } | 765 } |
| 766 | 766 |
| 767 BufferSyncInterface::ParseError GAPIGL::CreateParamByName(ResourceID param_id, | 767 BufferSyncInterface::ParseError GAPIGL::CreateParamByName(ResourceID param_id, |
| 768 ResourceID effect_id, | 768 ResourceID effect_id, |
| 769 unsigned int size, | 769 unsigned int size, |
| 770 const void *name) { | 770 const void *name) { |
| 771 EffectGL *effect = effects_.Get(effect_id); | 771 EffectGL *effect = effects_.Get(effect_id); |
| 772 if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 772 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 773 std::string string_name(static_cast<const char *>(name), size); | 773 std::string string_name(static_cast<const char *>(name), size); |
| 774 EffectParamGL *param = effect->CreateParamByName(string_name.c_str()); | 774 EffectParamGL *param = effect->CreateParamByName(string_name.c_str()); |
| 775 if (!param) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 775 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 776 effect_params_.Assign(param_id, param); | 776 effect_params_.Assign(param_id, param); |
| 777 return BufferSyncInterface::PARSE_NO_ERROR; | 777 return BufferSyncInterface::kParseNoError; |
| 778 } | 778 } |
| 779 | 779 |
| 780 BufferSyncInterface::ParseError GAPIGL::DestroyParam(ResourceID id) { | 780 BufferSyncInterface::ParseError GAPIGL::DestroyParam(ResourceID id) { |
| 781 return effect_params_.Destroy(id) ? | 781 return effect_params_.Destroy(id) ? |
| 782 BufferSyncInterface::PARSE_NO_ERROR : | 782 BufferSyncInterface::kParseNoError : |
| 783 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 783 BufferSyncInterface::kParseInvalidArguments; |
| 784 } | 784 } |
| 785 | 785 |
| 786 BufferSyncInterface::ParseError GAPIGL::SetParamData(ResourceID id, | 786 BufferSyncInterface::ParseError GAPIGL::SetParamData(ResourceID id, |
| 787 unsigned int size, | 787 unsigned int size, |
| 788 const void *data) { | 788 const void *data) { |
| 789 EffectParamGL *param = effect_params_.Get(id); | 789 EffectParamGL *param = effect_params_.Get(id); |
| 790 if (!param) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 790 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 791 return param->SetData(this, size, data) ? | 791 return param->SetData(this, size, data) ? |
| 792 BufferSyncInterface::PARSE_NO_ERROR : | 792 BufferSyncInterface::kParseNoError : |
| 793 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 793 BufferSyncInterface::kParseInvalidArguments; |
| 794 } | 794 } |
| 795 | 795 |
| 796 BufferSyncInterface::ParseError GAPIGL::GetParamDesc(ResourceID id, | 796 BufferSyncInterface::ParseError GAPIGL::GetParamDesc(ResourceID id, |
| 797 unsigned int size, | 797 unsigned int size, |
| 798 void *data) { | 798 void *data) { |
| 799 EffectParamGL *param = effect_params_.Get(id); | 799 EffectParamGL *param = effect_params_.Get(id); |
| 800 if (!param) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 800 if (!param) return BufferSyncInterface::kParseInvalidArguments; |
| 801 return param->GetDesc(size, data) ? | 801 return param->GetDesc(size, data) ? |
| 802 BufferSyncInterface::PARSE_NO_ERROR : | 802 BufferSyncInterface::kParseNoError : |
| 803 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 803 BufferSyncInterface::kParseInvalidArguments; |
| 804 } | 804 } |
| 805 | 805 |
| 806 BufferSyncInterface::ParseError GAPIGL::GetStreamCount( | 806 BufferSyncInterface::ParseError GAPIGL::GetStreamCount( |
| 807 ResourceID id, | 807 ResourceID id, |
| 808 unsigned int size, | 808 unsigned int size, |
| 809 void *data) { | 809 void *data) { |
| 810 EffectGL *effect = effects_.Get(id); | 810 EffectGL *effect = effects_.Get(id); |
| 811 if (!effect || size < sizeof(Uint32)) // NOLINT | 811 if (!effect || size < sizeof(Uint32)) // NOLINT |
| 812 return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 812 return BufferSyncInterface::kParseInvalidArguments; |
| 813 *static_cast<Uint32 *>(data) = effect->GetStreamCount(); | 813 *static_cast<Uint32 *>(data) = effect->GetStreamCount(); |
| 814 return BufferSyncInterface::PARSE_NO_ERROR; | 814 return BufferSyncInterface::kParseNoError; |
| 815 } | 815 } |
| 816 | 816 |
| 817 BufferSyncInterface::ParseError GAPIGL::GetStreamDesc(ResourceID id, | 817 BufferSyncInterface::ParseError GAPIGL::GetStreamDesc(ResourceID id, |
| 818 unsigned int index, | 818 unsigned int index, |
| 819 unsigned int size, | 819 unsigned int size, |
| 820 void *data) { | 820 void *data) { |
| 821 EffectGL *effect = effects_.Get(id); | 821 EffectGL *effect = effects_.Get(id); |
| 822 if (!effect) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 822 if (!effect) return BufferSyncInterface::kParseInvalidArguments; |
| 823 return effect->GetStreamDesc(index, size, data) ? | 823 return effect->GetStreamDesc(index, size, data) ? |
| 824 BufferSyncInterface::PARSE_NO_ERROR : | 824 BufferSyncInterface::kParseNoError : |
| 825 BufferSyncInterface::PARSE_INVALID_ARGUMENTS; | 825 BufferSyncInterface::kParseInvalidArguments; |
| 826 } | 826 } |
| 827 | 827 |
| 828 // If the current effect is valid, call End on it, and tag for revalidation. | 828 // If the current effect is valid, call End on it, and tag for revalidation. |
| 829 void GAPIGL::DirtyEffect() { | 829 void GAPIGL::DirtyEffect() { |
| 830 if (validate_effect_) return; | 830 if (validate_effect_) return; |
| 831 DCHECK(current_effect_); | 831 DCHECK(current_effect_); |
| 832 current_effect_->End(this); | 832 current_effect_->End(this); |
| 833 current_effect_ = NULL; | 833 current_effect_ = NULL; |
| 834 validate_effect_ = true; | 834 validate_effect_ = true; |
| 835 } | 835 } |
| 836 | 836 |
| 837 // Gets the current effect, and calls Begin on it (if successful). | 837 // Gets the current effect, and calls Begin on it (if successful). |
| 838 // Should only be called if the current effect is not valid. | 838 // Should only be called if the current effect is not valid. |
| 839 bool GAPIGL::ValidateEffect() { | 839 bool GAPIGL::ValidateEffect() { |
| 840 DCHECK(validate_effect_); | 840 DCHECK(validate_effect_); |
| 841 DCHECK(!current_effect_); | 841 DCHECK(!current_effect_); |
| 842 current_effect_ = effects_.Get(current_effect_id_); | 842 current_effect_ = effects_.Get(current_effect_id_); |
| 843 if (!current_effect_) return false; | 843 if (!current_effect_) return false; |
| 844 validate_effect_ = false; | 844 validate_effect_ = false; |
| 845 return current_effect_->Begin(this); | 845 return current_effect_->Begin(this); |
| 846 } | 846 } |
| 847 | 847 |
| 848 } // namespace command_buffer | 848 } // namespace command_buffer |
| 849 } // namespace o3d | 849 } // namespace o3d |
| OLD | NEW |