| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // anonymous namespace | 82 } // anonymous namespace |
| 83 | 83 |
| 84 SamplerCB::SamplerCB(ServiceLocator* service_locator, RendererCB* renderer) | 84 SamplerCB::SamplerCB(ServiceLocator* service_locator, RendererCB* renderer) |
| 85 : Sampler(service_locator), | 85 : Sampler(service_locator), |
| 86 renderer_(renderer) { | 86 renderer_(renderer) { |
| 87 DCHECK(renderer_); | 87 DCHECK(renderer_); |
| 88 resource_id_ = renderer_->sampler_ids().AllocateID(); | 88 resource_id_ = renderer_->sampler_ids().AllocateID(); |
| 89 CommandBufferEntry args[1]; | 89 renderer_->helper()->CreateSampler(resource_id_); |
| 90 args[0].value_uint32 = resource_id_; | |
| 91 renderer_->helper()->AddCommand(command_buffer::CREATE_SAMPLER, 1, args); | |
| 92 } | 90 } |
| 93 | 91 |
| 94 SamplerCB::~SamplerCB() { | 92 SamplerCB::~SamplerCB() { |
| 95 CommandBufferEntry args[1]; | 93 renderer_->helper()->DestroySampler(resource_id_); |
| 96 args[0].value_uint32 = resource_id_; | |
| 97 renderer_->helper()->AddCommand(command_buffer::DESTROY_SAMPLER, 1, args); | |
| 98 renderer_->sampler_ids().FreeID(resource_id_); | 94 renderer_->sampler_ids().FreeID(resource_id_); |
| 99 } | 95 } |
| 100 | 96 |
| 101 void SamplerCB::SetTextureAndStates() { | 97 void SamplerCB::SetTextureAndStates() { |
| 102 CommandBufferHelper *helper = renderer_->helper(); | 98 CommandBufferHelper *helper = renderer_->helper(); |
| 103 sampler::AddressingMode address_mode_u_cb = AddressModeToCB(address_mode_u()); | 99 sampler::AddressingMode address_mode_u_cb = AddressModeToCB(address_mode_u()); |
| 104 sampler::AddressingMode address_mode_v_cb = AddressModeToCB(address_mode_v()); | 100 sampler::AddressingMode address_mode_v_cb = AddressModeToCB(address_mode_v()); |
| 101 sampler::AddressingMode address_mode_w_cb = AddressModeToCB(address_mode_w()); |
| 105 sampler::FilteringMode mag_filter_cb = FilterTypeToCB(mag_filter()); | 102 sampler::FilteringMode mag_filter_cb = FilterTypeToCB(mag_filter()); |
| 106 sampler::FilteringMode min_filter_cb = FilterTypeToCB(min_filter()); | 103 sampler::FilteringMode min_filter_cb = FilterTypeToCB(min_filter()); |
| 107 sampler::FilteringMode mip_filter_cb = FilterTypeToCB(mip_filter()); | 104 sampler::FilteringMode mip_filter_cb = FilterTypeToCB(mip_filter()); |
| 108 if (mag_filter_cb == sampler::NONE) mag_filter_cb = sampler::POINT; | 105 if (mag_filter_cb == sampler::NONE) mag_filter_cb = sampler::POINT; |
| 109 if (min_filter_cb == sampler::NONE) min_filter_cb = sampler::POINT; | 106 if (min_filter_cb == sampler::NONE) min_filter_cb = sampler::POINT; |
| 110 int max_max_anisotropy = set_sampler_states::MaxAnisotropy::kMask; | 107 int max_max_anisotropy = set_sampler_states::MaxAnisotropy::kMask; |
| 111 unsigned int max_anisotropy_cb = | 108 unsigned int max_anisotropy_cb = |
| 112 std::max(1, std::min(max_max_anisotropy, max_anisotropy())); | 109 std::max(1, std::min(max_max_anisotropy, max_anisotropy())); |
| 113 if (min_filter() != Sampler::ANISOTROPIC) { | 110 if (min_filter() != Sampler::ANISOTROPIC) { |
| 114 max_anisotropy_cb = 1; | 111 max_anisotropy_cb = 1; |
| 115 } | 112 } |
| 116 CommandBufferEntry args[5]; | 113 helper->SetSamplerStates( |
| 117 args[0].value_uint32 = resource_id_; | 114 resource_id_, |
| 118 args[1].value_uint32 = | 115 address_mode_u_cb, |
| 119 set_sampler_states::AddressingU::MakeValue(address_mode_u_cb) | | 116 address_mode_v_cb, |
| 120 set_sampler_states::AddressingV::MakeValue(address_mode_v_cb) | | 117 address_mode_w_cb, |
| 121 set_sampler_states::AddressingW::MakeValue(sampler::WRAP) | | 118 mag_filter_cb, |
| 122 set_sampler_states::MagFilter::MakeValue(mag_filter_cb) | | 119 min_filter_cb, |
| 123 set_sampler_states::MinFilter::MakeValue(min_filter_cb) | | 120 mip_filter_cb, |
| 124 set_sampler_states::MipFilter::MakeValue(mip_filter_cb) | | 121 max_anisotropy_cb); |
| 125 set_sampler_states::MaxAnisotropy::MakeValue(max_anisotropy_cb); | |
| 126 helper->AddCommand(command_buffer::SET_SAMPLER_STATES, 2, args); | |
| 127 | 122 |
| 128 Float4 color = border_color(); | 123 Float4 color = border_color(); |
| 129 args[1].value_float = color[0]; | 124 helper->SetSamplerBorderColor(resource_id_, |
| 130 args[2].value_float = color[1]; | 125 color[0], color[1], color[2], color[3]); |
| 131 args[3].value_float = color[2]; | |
| 132 args[4].value_float = color[3]; | |
| 133 helper->AddCommand(command_buffer::SET_SAMPLER_BORDER_COLOR, 5, args); | |
| 134 | 126 |
| 135 Texture *texture_object = texture(); | 127 Texture *texture_object = texture(); |
| 136 if (!texture_object) { | 128 if (!texture_object) { |
| 137 texture_object = renderer_->error_texture(); | 129 texture_object = renderer_->error_texture(); |
| 138 if (!texture_object) { | 130 if (!texture_object) { |
| 139 O3D_ERROR(service_locator()) | 131 O3D_ERROR(service_locator()) |
| 140 << "Missing texture for sampler " << name(); | 132 << "Missing texture for sampler " << name(); |
| 141 texture_object = renderer_->fallback_error_texture(); | 133 texture_object = renderer_->fallback_error_texture(); |
| 142 } | 134 } |
| 143 } | 135 } |
| 144 | 136 |
| 145 if (texture_object) { | 137 if (texture_object) { |
| 146 args[1].value_uint32 = | 138 helper->SetSamplerTexture( |
| 147 reinterpret_cast<ResourceID>(texture_object->GetTextureHandle()); | 139 resource_id_, |
| 148 helper->AddCommand(command_buffer::SET_SAMPLER_TEXTURE, 2, args); | 140 reinterpret_cast<uint32>(texture_object->GetTextureHandle())); |
| 149 } | 141 } |
| 150 } | 142 } |
| 151 | 143 |
| 152 } // namespace o3d | 144 } // namespace o3d |
| OLD | NEW |