| 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 26 matching lines...) Expand all Loading... |
| 37 #include "command_buffer/service/win/d3d9/texture_d3d9.h" | 37 #include "command_buffer/service/win/d3d9/texture_d3d9.h" |
| 38 | 38 |
| 39 namespace o3d { | 39 namespace o3d { |
| 40 namespace command_buffer { | 40 namespace command_buffer { |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // Converts an addressing mode to corresponding D3D values. | 44 // Converts an addressing mode to corresponding D3D values. |
| 45 D3DTEXTUREADDRESS AddressModeToD3D(sampler::AddressingMode mode) { | 45 D3DTEXTUREADDRESS AddressModeToD3D(sampler::AddressingMode mode) { |
| 46 switch (mode) { | 46 switch (mode) { |
| 47 case sampler::WRAP: | 47 case sampler::kWrap: |
| 48 return D3DTADDRESS_WRAP; | 48 return D3DTADDRESS_WRAP; |
| 49 case sampler::MIRROR_REPEAT: | 49 case sampler::kMirrorRepeat: |
| 50 return D3DTADDRESS_MIRROR; | 50 return D3DTADDRESS_MIRROR; |
| 51 case sampler::CLAMP_TO_EDGE: | 51 case sampler::kClampToEdge: |
| 52 return D3DTADDRESS_CLAMP; | 52 return D3DTADDRESS_CLAMP; |
| 53 case sampler::CLAMP_TO_BORDER: | 53 case sampler::kClampToBorder: |
| 54 return D3DTADDRESS_BORDER; | 54 return D3DTADDRESS_BORDER; |
| 55 } | 55 } |
| 56 DLOG(FATAL) << "Not reached"; | 56 DLOG(FATAL) << "Not reached"; |
| 57 return D3DTADDRESS_WRAP; | 57 return D3DTADDRESS_WRAP; |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Converts a filtering mode to corresponding D3D values. | 60 // Converts a filtering mode to corresponding D3D values. |
| 61 D3DTEXTUREFILTERTYPE FilteringModeToD3D(sampler::FilteringMode mode) { | 61 D3DTEXTUREFILTERTYPE FilteringModeToD3D(sampler::FilteringMode mode) { |
| 62 switch (mode) { | 62 switch (mode) { |
| 63 case sampler::NONE: | 63 case sampler::kNone: |
| 64 return D3DTEXF_NONE; | 64 return D3DTEXF_NONE; |
| 65 case sampler::POINT: | 65 case sampler::kPoint: |
| 66 return D3DTEXF_POINT; | 66 return D3DTEXF_POINT; |
| 67 case sampler::LINEAR: | 67 case sampler::kLinear: |
| 68 return D3DTEXF_LINEAR; | 68 return D3DTEXF_LINEAR; |
| 69 } | 69 } |
| 70 DLOG(FATAL) << "Not reached"; | 70 DLOG(FATAL) << "Not reached"; |
| 71 return D3DTEXF_POINT; | 71 return D3DTEXF_POINT; |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // anonymous namespace | 74 } // anonymous namespace |
| 75 | 75 |
| 76 SamplerD3D9::SamplerD3D9() | 76 SamplerD3D9::SamplerD3D9() |
| 77 : texture_id_(kInvalidResource) { | 77 : texture_id_(kInvalidResource) { |
| 78 SetStates(sampler::CLAMP_TO_EDGE, | 78 SetStates(sampler::kClampToEdge, |
| 79 sampler::CLAMP_TO_EDGE, | 79 sampler::kClampToEdge, |
| 80 sampler::CLAMP_TO_EDGE, | 80 sampler::kClampToEdge, |
| 81 sampler::LINEAR, | 81 sampler::kLinear, |
| 82 sampler::LINEAR, | 82 sampler::kLinear, |
| 83 sampler::POINT, | 83 sampler::kPoint, |
| 84 1); | 84 1); |
| 85 RGBA black = {0, 0, 0, 1}; | 85 RGBA black = {0, 0, 0, 1}; |
| 86 SetBorderColor(black); | 86 SetBorderColor(black); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool SamplerD3D9::ApplyStates(GAPID3D9 *gapi, unsigned int unit) const { | 89 bool SamplerD3D9::ApplyStates(GAPID3D9 *gapi, unsigned int unit) const { |
| 90 DCHECK(gapi); | 90 DCHECK(gapi); |
| 91 TextureD3D9 *texture = gapi->GetTexture(texture_id_); | 91 TextureD3D9 *texture = gapi->GetTexture(texture_id_); |
| 92 if (!texture) { | 92 if (!texture) { |
| 93 return false; | 93 return false; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 void SamplerD3D9::SetStates(sampler::AddressingMode addressing_u, | 109 void SamplerD3D9::SetStates(sampler::AddressingMode addressing_u, |
| 110 sampler::AddressingMode addressing_v, | 110 sampler::AddressingMode addressing_v, |
| 111 sampler::AddressingMode addressing_w, | 111 sampler::AddressingMode addressing_w, |
| 112 sampler::FilteringMode mag_filter, | 112 sampler::FilteringMode mag_filter, |
| 113 sampler::FilteringMode min_filter, | 113 sampler::FilteringMode min_filter, |
| 114 sampler::FilteringMode mip_filter, | 114 sampler::FilteringMode mip_filter, |
| 115 unsigned int max_anisotropy) { | 115 unsigned int max_anisotropy) { |
| 116 // These are validated in GAPIDecoder.cc | 116 // These are validated in GAPIDecoder.cc |
| 117 DCHECK_NE(mag_filter, sampler::NONE); | 117 DCHECK_NE(mag_filter, sampler::kNone); |
| 118 DCHECK_NE(min_filter, sampler::NONE); | 118 DCHECK_NE(min_filter, sampler::kNone); |
| 119 DCHECK_GT(max_anisotropy, 0U); | 119 DCHECK_GT(max_anisotropy, 0U); |
| 120 d3d_address_u_ = AddressModeToD3D(addressing_u); | 120 d3d_address_u_ = AddressModeToD3D(addressing_u); |
| 121 d3d_address_v_ = AddressModeToD3D(addressing_v); | 121 d3d_address_v_ = AddressModeToD3D(addressing_v); |
| 122 d3d_address_w_ = AddressModeToD3D(addressing_w); | 122 d3d_address_w_ = AddressModeToD3D(addressing_w); |
| 123 d3d_mag_filter_ = FilteringModeToD3D(mag_filter); | 123 d3d_mag_filter_ = FilteringModeToD3D(mag_filter); |
| 124 d3d_min_filter_ = FilteringModeToD3D(min_filter); | 124 d3d_min_filter_ = FilteringModeToD3D(min_filter); |
| 125 d3d_mip_filter_ = FilteringModeToD3D(mip_filter); | 125 d3d_mip_filter_ = FilteringModeToD3D(mip_filter); |
| 126 if (max_anisotropy > 1) { | 126 if (max_anisotropy > 1) { |
| 127 d3d_mag_filter_ = D3DTEXF_ANISOTROPIC; | 127 d3d_mag_filter_ = D3DTEXF_ANISOTROPIC; |
| 128 d3d_min_filter_ = D3DTEXF_ANISOTROPIC; | 128 d3d_min_filter_ = D3DTEXF_ANISOTROPIC; |
| 129 } | 129 } |
| 130 d3d_max_anisotropy_ = max_anisotropy; | 130 d3d_max_anisotropy_ = max_anisotropy; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void SamplerD3D9::SetBorderColor(const RGBA &color) { | 133 void SamplerD3D9::SetBorderColor(const RGBA &color) { |
| 134 d3d_border_color_ = RGBAToD3DCOLOR(color); | 134 d3d_border_color_ = RGBAToD3DCOLOR(color); |
| 135 } | 135 } |
| 136 | 136 |
| 137 BufferSyncInterface::ParseError GAPID3D9::CreateSampler( | 137 BufferSyncInterface::ParseError GAPID3D9::CreateSampler( |
| 138 ResourceID id) { | 138 ResourceId id) { |
| 139 // Dirty effect, because this sampler id may be used | 139 // Dirty effect, because this sampler id may be used |
| 140 DirtyEffect(); | 140 DirtyEffect(); |
| 141 samplers_.Assign(id, new SamplerD3D9()); | 141 samplers_.Assign(id, new SamplerD3D9()); |
| 142 return BufferSyncInterface::kParseNoError; | 142 return BufferSyncInterface::kParseNoError; |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Destroys the Sampler resource. | 145 // Destroys the Sampler resource. |
| 146 BufferSyncInterface::ParseError GAPID3D9::DestroySampler(ResourceID id) { | 146 BufferSyncInterface::ParseError GAPID3D9::DestroySampler(ResourceId id) { |
| 147 // Dirty effect, because this sampler id may be used | 147 // Dirty effect, because this sampler id may be used |
| 148 DirtyEffect(); | 148 DirtyEffect(); |
| 149 return samplers_.Destroy(id) ? | 149 return samplers_.Destroy(id) ? |
| 150 BufferSyncInterface::kParseNoError : | 150 BufferSyncInterface::kParseNoError : |
| 151 BufferSyncInterface::kParseInvalidArguments; | 151 BufferSyncInterface::kParseInvalidArguments; |
| 152 } | 152 } |
| 153 | 153 |
| 154 BufferSyncInterface::ParseError GAPID3D9::SetSamplerStates( | 154 BufferSyncInterface::ParseError GAPID3D9::SetSamplerStates( |
| 155 ResourceID id, | 155 ResourceId id, |
| 156 sampler::AddressingMode addressing_u, | 156 sampler::AddressingMode addressing_u, |
| 157 sampler::AddressingMode addressing_v, | 157 sampler::AddressingMode addressing_v, |
| 158 sampler::AddressingMode addressing_w, | 158 sampler::AddressingMode addressing_w, |
| 159 sampler::FilteringMode mag_filter, | 159 sampler::FilteringMode mag_filter, |
| 160 sampler::FilteringMode min_filter, | 160 sampler::FilteringMode min_filter, |
| 161 sampler::FilteringMode mip_filter, | 161 sampler::FilteringMode mip_filter, |
| 162 unsigned int max_anisotropy) { | 162 unsigned int max_anisotropy) { |
| 163 SamplerD3D9 *sampler = samplers_.Get(id); | 163 SamplerD3D9 *sampler = samplers_.Get(id); |
| 164 if (!sampler) | 164 if (!sampler) |
| 165 return BufferSyncInterface::kParseInvalidArguments; | 165 return BufferSyncInterface::kParseInvalidArguments; |
| 166 // Dirty effect, because this sampler id may be used | 166 // Dirty effect, because this sampler id may be used |
| 167 DirtyEffect(); | 167 DirtyEffect(); |
| 168 sampler->SetStates(addressing_u, addressing_v, addressing_w, | 168 sampler->SetStates(addressing_u, addressing_v, addressing_w, |
| 169 mag_filter, min_filter, mip_filter, max_anisotropy); | 169 mag_filter, min_filter, mip_filter, max_anisotropy); |
| 170 return BufferSyncInterface::kParseNoError; | 170 return BufferSyncInterface::kParseNoError; |
| 171 } | 171 } |
| 172 | 172 |
| 173 BufferSyncInterface::ParseError GAPID3D9::SetSamplerBorderColor( | 173 BufferSyncInterface::ParseError GAPID3D9::SetSamplerBorderColor( |
| 174 ResourceID id, | 174 ResourceId id, |
| 175 const RGBA &color) { | 175 const RGBA &color) { |
| 176 SamplerD3D9 *sampler = samplers_.Get(id); | 176 SamplerD3D9 *sampler = samplers_.Get(id); |
| 177 if (!sampler) | 177 if (!sampler) |
| 178 return BufferSyncInterface::kParseInvalidArguments; | 178 return BufferSyncInterface::kParseInvalidArguments; |
| 179 // Dirty effect, because this sampler id may be used | 179 // Dirty effect, because this sampler id may be used |
| 180 DirtyEffect(); | 180 DirtyEffect(); |
| 181 sampler->SetBorderColor(color); | 181 sampler->SetBorderColor(color); |
| 182 return BufferSyncInterface::kParseNoError; | 182 return BufferSyncInterface::kParseNoError; |
| 183 } | 183 } |
| 184 | 184 |
| 185 BufferSyncInterface::ParseError GAPID3D9::SetSamplerTexture( | 185 BufferSyncInterface::ParseError GAPID3D9::SetSamplerTexture( |
| 186 ResourceID id, | 186 ResourceId id, |
| 187 ResourceID texture_id) { | 187 ResourceId texture_id) { |
| 188 SamplerD3D9 *sampler = samplers_.Get(id); | 188 SamplerD3D9 *sampler = samplers_.Get(id); |
| 189 if (!sampler) | 189 if (!sampler) |
| 190 return BufferSyncInterface::kParseInvalidArguments; | 190 return BufferSyncInterface::kParseInvalidArguments; |
| 191 // Dirty effect, because this sampler id may be used | 191 // Dirty effect, because this sampler id may be used |
| 192 DirtyEffect(); | 192 DirtyEffect(); |
| 193 sampler->SetTexture(texture_id); | 193 sampler->SetTexture(texture_id); |
| 194 return BufferSyncInterface::kParseNoError; | 194 return BufferSyncInterface::kParseNoError; |
| 195 } | 195 } |
| 196 | 196 |
| 197 | 197 |
| 198 } // namespace command_buffer | 198 } // namespace command_buffer |
| 199 } // namespace o3d | 199 } // namespace o3d |
| OLD | NEW |