| 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 25 matching lines...) Expand all Loading... |
| 36 #include "core/cross/error.h" | 36 #include "core/cross/error.h" |
| 37 #include "core/cross/command_buffer/sampler_cb.h" | 37 #include "core/cross/command_buffer/sampler_cb.h" |
| 38 #include "core/cross/command_buffer/renderer_cb.h" | 38 #include "core/cross/command_buffer/renderer_cb.h" |
| 39 #include "command_buffer/common/cross/cmd_buffer_format.h" | 39 #include "command_buffer/common/cross/cmd_buffer_format.h" |
| 40 #include "command_buffer/client/cross/cmd_buffer_helper.h" | 40 #include "command_buffer/client/cross/cmd_buffer_helper.h" |
| 41 | 41 |
| 42 namespace o3d { | 42 namespace o3d { |
| 43 | 43 |
| 44 using command_buffer::CommandBufferEntry; | 44 using command_buffer::CommandBufferEntry; |
| 45 using command_buffer::CommandBufferHelper; | 45 using command_buffer::CommandBufferHelper; |
| 46 using command_buffer::ResourceID; | 46 using command_buffer::ResourceId; |
| 47 namespace set_sampler_states = command_buffer::set_sampler_states; | |
| 48 namespace sampler = command_buffer::sampler; | 47 namespace sampler = command_buffer::sampler; |
| 49 | 48 |
| 50 namespace { | 49 namespace { |
| 51 | 50 |
| 52 sampler::AddressingMode AddressModeToCB(Sampler::AddressMode o3d_mode) { | 51 sampler::AddressingMode AddressModeToCB(Sampler::AddressMode o3d_mode) { |
| 53 switch (o3d_mode) { | 52 switch (o3d_mode) { |
| 54 case Sampler::WRAP: | 53 case Sampler::WRAP: |
| 55 return sampler::WRAP; | 54 return sampler::kWrap; |
| 56 case Sampler::MIRROR: | 55 case Sampler::MIRROR: |
| 57 return sampler::MIRROR_REPEAT; | 56 return sampler::kMirrorRepeat; |
| 58 case Sampler::CLAMP: | 57 case Sampler::CLAMP: |
| 59 return sampler::CLAMP_TO_EDGE; | 58 return sampler::kClampToEdge; |
| 60 case Sampler::BORDER: | 59 case Sampler::BORDER: |
| 61 return sampler::CLAMP_TO_BORDER; | 60 return sampler::kClampToBorder; |
| 62 default: | 61 default: |
| 63 DLOG(ERROR) << "Unknown Address mode " << static_cast<int>(o3d_mode); | 62 DLOG(ERROR) << "Unknown Address mode " << static_cast<int>(o3d_mode); |
| 64 return sampler::WRAP; | 63 return sampler::kWrap; |
| 65 } | 64 } |
| 66 } | 65 } |
| 67 | 66 |
| 68 sampler::FilteringMode FilterTypeToCB(Sampler::FilterType o3d_mode) { | 67 sampler::FilteringMode FilterTypeToCB(Sampler::FilterType o3d_mode) { |
| 69 switch (o3d_mode) { | 68 switch (o3d_mode) { |
| 70 case Sampler::NONE: | 69 case Sampler::NONE: |
| 71 return sampler::NONE; | 70 return sampler::kNone; |
| 72 case Sampler::POINT: | 71 case Sampler::POINT: |
| 73 return sampler::POINT; | 72 return sampler::kPoint; |
| 74 case Sampler::LINEAR: | 73 case Sampler::LINEAR: |
| 75 case Sampler::ANISOTROPIC: | 74 case Sampler::ANISOTROPIC: |
| 76 return sampler::LINEAR; | 75 return sampler::kLinear; |
| 77 default: | 76 default: |
| 78 return sampler::NONE; | 77 return sampler::kNone; |
| 79 } | 78 } |
| 80 } | 79 } |
| 81 | 80 |
| 82 } // anonymous namespace | 81 } // anonymous namespace |
| 83 | 82 |
| 84 SamplerCB::SamplerCB(ServiceLocator* service_locator, RendererCB* renderer) | 83 SamplerCB::SamplerCB(ServiceLocator* service_locator, RendererCB* renderer) |
| 85 : Sampler(service_locator), | 84 : Sampler(service_locator), |
| 86 renderer_(renderer) { | 85 renderer_(renderer) { |
| 87 DCHECK(renderer_); | 86 DCHECK(renderer_); |
| 88 resource_id_ = renderer_->sampler_ids().AllocateID(); | 87 resource_id_ = renderer_->sampler_ids().AllocateID(); |
| 89 renderer_->helper()->CreateSampler(resource_id_); | 88 renderer_->helper()->CreateSampler(resource_id_); |
| 90 } | 89 } |
| 91 | 90 |
| 92 SamplerCB::~SamplerCB() { | 91 SamplerCB::~SamplerCB() { |
| 93 renderer_->helper()->DestroySampler(resource_id_); | 92 renderer_->helper()->DestroySampler(resource_id_); |
| 94 renderer_->sampler_ids().FreeID(resource_id_); | 93 renderer_->sampler_ids().FreeID(resource_id_); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void SamplerCB::SetTextureAndStates() { | 96 void SamplerCB::SetTextureAndStates() { |
| 98 CommandBufferHelper *helper = renderer_->helper(); | 97 CommandBufferHelper *helper = renderer_->helper(); |
| 99 sampler::AddressingMode address_mode_u_cb = AddressModeToCB(address_mode_u()); | 98 sampler::AddressingMode address_mode_u_cb = AddressModeToCB(address_mode_u()); |
| 100 sampler::AddressingMode address_mode_v_cb = AddressModeToCB(address_mode_v()); | 99 sampler::AddressingMode address_mode_v_cb = AddressModeToCB(address_mode_v()); |
| 101 sampler::AddressingMode address_mode_w_cb = AddressModeToCB(address_mode_w()); | 100 sampler::AddressingMode address_mode_w_cb = AddressModeToCB(address_mode_w()); |
| 102 sampler::FilteringMode mag_filter_cb = FilterTypeToCB(mag_filter()); | 101 sampler::FilteringMode mag_filter_cb = FilterTypeToCB(mag_filter()); |
| 103 sampler::FilteringMode min_filter_cb = FilterTypeToCB(min_filter()); | 102 sampler::FilteringMode min_filter_cb = FilterTypeToCB(min_filter()); |
| 104 sampler::FilteringMode mip_filter_cb = FilterTypeToCB(mip_filter()); | 103 sampler::FilteringMode mip_filter_cb = FilterTypeToCB(mip_filter()); |
| 105 if (mag_filter_cb == sampler::NONE) mag_filter_cb = sampler::POINT; | 104 if (mag_filter_cb == sampler::kNone) mag_filter_cb = sampler::kPoint; |
| 106 if (min_filter_cb == sampler::NONE) min_filter_cb = sampler::POINT; | 105 if (min_filter_cb == sampler::kNone) min_filter_cb = sampler::kPoint; |
| 107 int max_max_anisotropy = set_sampler_states::MaxAnisotropy::kMask; | 106 int max_max_anisotropy = |
| 107 command_buffer::cmd::SetSamplerStates::MaxAnisotropy::kMask; |
| 108 unsigned int max_anisotropy_cb = | 108 unsigned int max_anisotropy_cb = |
| 109 std::max(1, std::min(max_max_anisotropy, max_anisotropy())); | 109 std::max(1, std::min(max_max_anisotropy, max_anisotropy())); |
| 110 if (min_filter() != Sampler::ANISOTROPIC) { | 110 if (min_filter() != Sampler::ANISOTROPIC) { |
| 111 max_anisotropy_cb = 1; | 111 max_anisotropy_cb = 1; |
| 112 } | 112 } |
| 113 helper->SetSamplerStates( | 113 helper->SetSamplerStates( |
| 114 resource_id_, | 114 resource_id_, |
| 115 address_mode_u_cb, | 115 address_mode_u_cb, |
| 116 address_mode_v_cb, | 116 address_mode_v_cb, |
| 117 address_mode_w_cb, | 117 address_mode_w_cb, |
| 118 mag_filter_cb, | 118 mag_filter_cb, |
| 119 min_filter_cb, | 119 min_filter_cb, |
| 120 mip_filter_cb, | 120 mip_filter_cb, |
| 121 max_anisotropy_cb); | 121 max_anisotropy_cb); |
| 122 | 122 |
| 123 Float4 color = border_color(); | 123 Float4 color = border_color(); |
| 124 helper->SetSamplerBorderColor(resource_id_, | 124 helper->SetSamplerBorderColor(resource_id_, |
| 125 color[0], color[1], color[2], color[3]); | 125 color[0], color[1], color[2], color[3]); |
| 126 | 126 |
| 127 Texture *texture_object = texture(); | 127 Texture *texture_object = texture(); |
| 128 if (!texture_object) { | 128 if (!texture_object) { |
| 129 texture_object = renderer_->error_texture(); | 129 texture_object = renderer_->error_texture(); |
| 130 if (!texture_object) { | 130 if (!texture_object) { |
| 131 O3D_ERROR(service_locator()) | 131 O3D_ERROR(service_locator()) |
| 132 << "Missing texture for sampler " << name(); | 132 << "Missing texture for sampler " << name(); |
| 133 texture_object = renderer_->fallback_error_texture(); | 133 texture_object = renderer_->fallback_error_texture(); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 if (texture_object) { | 137 if (texture_object) { |
| 138 helper->SetSamplerTexture( | 138 helper->SetSamplerTexture( |
| 139 resource_id_, | 139 resource_id_, |
| 140 reinterpret_cast<uint32>(texture_object->GetTextureHandle())); | 140 reinterpret_cast<uint32>(texture_object->GetTextureHandle())); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 } // namespace o3d | 144 } // namespace o3d |
| OLD | NEW |