| 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 "command_buffer/service/cross/gl/sampler_gl.h" | 36 #include "command_buffer/service/cross/gl/sampler_gl.h" | 
| 37 | 37 | 
| 38 namespace o3d { | 38 namespace o3d { | 
| 39 namespace command_buffer { | 39 namespace command_buffer { | 
| 40 | 40 | 
| 41 namespace { | 41 namespace { | 
| 42 | 42 | 
| 43 // Gets the GL enum corresponding to an addressing mode. | 43 // Gets the GL enum corresponding to an addressing mode. | 
| 44 GLenum GLAddressMode(sampler::AddressingMode o3d_mode) { | 44 GLenum GLAddressMode(sampler::AddressingMode o3d_mode) { | 
| 45   switch (o3d_mode) { | 45   switch (o3d_mode) { | 
| 46     case sampler::WRAP: | 46     case sampler::kWrap: | 
| 47       return GL_REPEAT; | 47       return GL_REPEAT; | 
| 48     case sampler::MIRROR_REPEAT: | 48     case sampler::kMirrorRepeat: | 
| 49       return GL_MIRRORED_REPEAT; | 49       return GL_MIRRORED_REPEAT; | 
| 50     case sampler::CLAMP_TO_EDGE: | 50     case sampler::kClampToEdge: | 
| 51       return GL_CLAMP_TO_EDGE; | 51       return GL_CLAMP_TO_EDGE; | 
| 52     case sampler::CLAMP_TO_BORDER: | 52     case sampler::kClampToBorder: | 
| 53       return GL_CLAMP_TO_BORDER; | 53       return GL_CLAMP_TO_BORDER; | 
| 54     default: | 54     default: | 
| 55       DLOG(FATAL) << "Not Reached"; | 55       DLOG(FATAL) << "Not Reached"; | 
| 56       return GL_REPEAT; | 56       return GL_REPEAT; | 
| 57   } | 57   } | 
| 58 } | 58 } | 
| 59 | 59 | 
| 60 // Gets the GL enum for the minification filter based on the command buffer min | 60 // Gets the GL enum for the minification filter based on the command buffer min | 
| 61 // and mip filtering modes. | 61 // and mip filtering modes. | 
| 62 GLenum GLMinFilter(sampler::FilteringMode min_filter, | 62 GLenum GLMinFilter(sampler::FilteringMode min_filter, | 
| 63                    sampler::FilteringMode mip_filter) { | 63                    sampler::FilteringMode mip_filter) { | 
| 64   switch (min_filter) { | 64   switch (min_filter) { | 
| 65     case sampler::POINT: | 65     case sampler::kPoint: | 
| 66       if (mip_filter == sampler::NONE) | 66       if (mip_filter == sampler::kNone) | 
| 67         return GL_NEAREST; | 67         return GL_NEAREST; | 
| 68       else if (mip_filter == sampler::POINT) | 68       else if (mip_filter == sampler::kPoint) | 
| 69         return GL_NEAREST_MIPMAP_NEAREST; | 69         return GL_NEAREST_MIPMAP_NEAREST; | 
| 70       else if (mip_filter == sampler::LINEAR) | 70       else if (mip_filter == sampler::kLinear) | 
| 71         return GL_NEAREST_MIPMAP_LINEAR; | 71         return GL_NEAREST_MIPMAP_LINEAR; | 
| 72     case sampler::LINEAR: | 72     case sampler::kLinear: | 
| 73       if (mip_filter == sampler::NONE) | 73       if (mip_filter == sampler::kNone) | 
| 74         return GL_LINEAR; | 74         return GL_LINEAR; | 
| 75       else if (mip_filter == sampler::POINT) | 75       else if (mip_filter == sampler::kPoint) | 
| 76         return GL_LINEAR_MIPMAP_NEAREST; | 76         return GL_LINEAR_MIPMAP_NEAREST; | 
| 77       else if (mip_filter == sampler::LINEAR) | 77       else if (mip_filter == sampler::kLinear) | 
| 78         return GL_LINEAR_MIPMAP_LINEAR; | 78         return GL_LINEAR_MIPMAP_LINEAR; | 
| 79     default: | 79     default: | 
| 80       DLOG(FATAL) << "Not Reached"; | 80       DLOG(FATAL) << "Not Reached"; | 
| 81       return GL_LINEAR_MIPMAP_NEAREST; | 81       return GL_LINEAR_MIPMAP_NEAREST; | 
| 82   } | 82   } | 
| 83 } | 83 } | 
| 84 | 84 | 
| 85 // Gets the GL enum for the magnification filter based on the command buffer mag | 85 // Gets the GL enum for the magnification filter based on the command buffer mag | 
| 86 // filtering mode. | 86 // filtering mode. | 
| 87 GLenum GLMagFilter(sampler::FilteringMode mag_filter) { | 87 GLenum GLMagFilter(sampler::FilteringMode mag_filter) { | 
| 88   switch (mag_filter) { | 88   switch (mag_filter) { | 
| 89     case sampler::POINT: | 89     case sampler::kPoint: | 
| 90       return GL_NEAREST; | 90       return GL_NEAREST; | 
| 91     case sampler::LINEAR: | 91     case sampler::kLinear: | 
| 92       return GL_LINEAR; | 92       return GL_LINEAR; | 
| 93     default: | 93     default: | 
| 94       DLOG(FATAL) << "Not Reached"; | 94       DLOG(FATAL) << "Not Reached"; | 
| 95       return GL_LINEAR; | 95       return GL_LINEAR; | 
| 96   } | 96   } | 
| 97 } | 97 } | 
| 98 | 98 | 
| 99 // Gets the GL enum representing the GL target based on the texture type. | 99 // Gets the GL enum representing the GL target based on the texture type. | 
| 100 GLenum GLTextureTarget(texture::Type type) { | 100 GLenum GLTextureTarget(texture::Type type) { | 
| 101   switch (type) { | 101   switch (type) { | 
| 102     case texture::TEXTURE_2D: | 102     case texture::kTexture2d: | 
| 103       return GL_TEXTURE_2D; | 103       return GL_TEXTURE_2D; | 
| 104     case texture::TEXTURE_3D: | 104     case texture::kTexture3d: | 
| 105       return GL_TEXTURE_3D; | 105       return GL_TEXTURE_3D; | 
| 106     case texture::TEXTURE_CUBE: | 106     case texture::kTextureCube: | 
| 107       return GL_TEXTURE_CUBE_MAP; | 107       return GL_TEXTURE_CUBE_MAP; | 
| 108     default: | 108     default: | 
| 109       DLOG(FATAL) << "Not Reached"; | 109       DLOG(FATAL) << "Not Reached"; | 
| 110       return GL_TEXTURE_2D; | 110       return GL_TEXTURE_2D; | 
| 111   } | 111   } | 
| 112 } | 112 } | 
| 113 | 113 | 
| 114 }  // anonymous namespace | 114 }  // anonymous namespace | 
| 115 | 115 | 
| 116 SamplerGL::SamplerGL() | 116 SamplerGL::SamplerGL() | 
| 117     : texture_id_(kInvalidResource), | 117     : texture_id_(kInvalidResource), | 
| 118       gl_texture_(0) { | 118       gl_texture_(0) { | 
| 119   SetStates(sampler::CLAMP_TO_EDGE, | 119   SetStates(sampler::kClampToEdge, | 
| 120             sampler::CLAMP_TO_EDGE, | 120             sampler::kClampToEdge, | 
| 121             sampler::CLAMP_TO_EDGE, | 121             sampler::kClampToEdge, | 
| 122             sampler::LINEAR, | 122             sampler::kLinear, | 
| 123             sampler::LINEAR, | 123             sampler::kLinear, | 
| 124             sampler::POINT, | 124             sampler::kPoint, | 
| 125             1); | 125             1); | 
| 126   RGBA black = {0, 0, 0, 1}; | 126   RGBA black = {0, 0, 0, 1}; | 
| 127   SetBorderColor(black); | 127   SetBorderColor(black); | 
| 128 } | 128 } | 
| 129 | 129 | 
| 130 bool SamplerGL::ApplyStates(GAPIGL *gapi) { | 130 bool SamplerGL::ApplyStates(GAPIGL *gapi) { | 
| 131   DCHECK(gapi); | 131   DCHECK(gapi); | 
| 132   TextureGL *texture = gapi->GetTexture(texture_id_); | 132   TextureGL *texture = gapi->GetTexture(texture_id_); | 
| 133   if (!texture) { | 133   if (!texture) { | 
| 134     gl_texture_ = 0; | 134     gl_texture_ = 0; | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 148 } | 148 } | 
| 149 | 149 | 
| 150 void SamplerGL::SetStates(sampler::AddressingMode addressing_u, | 150 void SamplerGL::SetStates(sampler::AddressingMode addressing_u, | 
| 151                           sampler::AddressingMode addressing_v, | 151                           sampler::AddressingMode addressing_v, | 
| 152                           sampler::AddressingMode addressing_w, | 152                           sampler::AddressingMode addressing_w, | 
| 153                           sampler::FilteringMode mag_filter, | 153                           sampler::FilteringMode mag_filter, | 
| 154                           sampler::FilteringMode min_filter, | 154                           sampler::FilteringMode min_filter, | 
| 155                           sampler::FilteringMode mip_filter, | 155                           sampler::FilteringMode mip_filter, | 
| 156                           unsigned int max_anisotropy) { | 156                           unsigned int max_anisotropy) { | 
| 157   // These are validated in GAPIDecoder.cc | 157   // These are validated in GAPIDecoder.cc | 
| 158   DCHECK_NE(mag_filter, sampler::NONE); | 158   DCHECK_NE(mag_filter, sampler::kNone); | 
| 159   DCHECK_NE(min_filter, sampler::NONE); | 159   DCHECK_NE(min_filter, sampler::kNone); | 
| 160   DCHECK_GT(max_anisotropy, 0); | 160   DCHECK_GT(max_anisotropy, 0); | 
| 161   gl_wrap_s_ = GLAddressMode(addressing_u); | 161   gl_wrap_s_ = GLAddressMode(addressing_u); | 
| 162   gl_wrap_t_ = GLAddressMode(addressing_v); | 162   gl_wrap_t_ = GLAddressMode(addressing_v); | 
| 163   gl_wrap_r_ = GLAddressMode(addressing_w); | 163   gl_wrap_r_ = GLAddressMode(addressing_w); | 
| 164   gl_mag_filter_ = GLMagFilter(mag_filter); | 164   gl_mag_filter_ = GLMagFilter(mag_filter); | 
| 165   gl_min_filter_ = GLMinFilter(min_filter, mip_filter); | 165   gl_min_filter_ = GLMinFilter(min_filter, mip_filter); | 
| 166   gl_max_anisotropy_ = max_anisotropy; | 166   gl_max_anisotropy_ = max_anisotropy; | 
| 167 } | 167 } | 
| 168 | 168 | 
| 169 void SamplerGL::SetBorderColor(const RGBA &color) { | 169 void SamplerGL::SetBorderColor(const RGBA &color) { | 
| 170   gl_border_color_[0] = color.red; | 170   gl_border_color_[0] = color.red; | 
| 171   gl_border_color_[1] = color.green; | 171   gl_border_color_[1] = color.green; | 
| 172   gl_border_color_[2] = color.blue; | 172   gl_border_color_[2] = color.blue; | 
| 173   gl_border_color_[3] = color.alpha; | 173   gl_border_color_[3] = color.alpha; | 
| 174 } | 174 } | 
| 175 | 175 | 
| 176 BufferSyncInterface::ParseError GAPIGL::CreateSampler( | 176 BufferSyncInterface::ParseError GAPIGL::CreateSampler( | 
| 177     ResourceID id) { | 177     ResourceId id) { | 
| 178   // Dirty effect, because this sampler id may be used. | 178   // Dirty effect, because this sampler id may be used. | 
| 179   DirtyEffect(); | 179   DirtyEffect(); | 
| 180   samplers_.Assign(id, new SamplerGL()); | 180   samplers_.Assign(id, new SamplerGL()); | 
| 181   return BufferSyncInterface::kParseNoError; | 181   return BufferSyncInterface::kParseNoError; | 
| 182 } | 182 } | 
| 183 | 183 | 
| 184 // Destroys the Sampler resource. | 184 // Destroys the Sampler resource. | 
| 185 BufferSyncInterface::ParseError GAPIGL::DestroySampler(ResourceID id) { | 185 BufferSyncInterface::ParseError GAPIGL::DestroySampler(ResourceId id) { | 
| 186   // Dirty effect, because this sampler id may be used. | 186   // Dirty effect, because this sampler id may be used. | 
| 187   DirtyEffect(); | 187   DirtyEffect(); | 
| 188   return samplers_.Destroy(id) ? | 188   return samplers_.Destroy(id) ? | 
| 189       BufferSyncInterface::kParseNoError : | 189       BufferSyncInterface::kParseNoError : | 
| 190       BufferSyncInterface::kParseInvalidArguments; | 190       BufferSyncInterface::kParseInvalidArguments; | 
| 191 } | 191 } | 
| 192 | 192 | 
| 193 BufferSyncInterface::ParseError GAPIGL::SetSamplerStates( | 193 BufferSyncInterface::ParseError GAPIGL::SetSamplerStates( | 
| 194     ResourceID id, | 194     ResourceId id, | 
| 195     sampler::AddressingMode addressing_u, | 195     sampler::AddressingMode addressing_u, | 
| 196     sampler::AddressingMode addressing_v, | 196     sampler::AddressingMode addressing_v, | 
| 197     sampler::AddressingMode addressing_w, | 197     sampler::AddressingMode addressing_w, | 
| 198     sampler::FilteringMode mag_filter, | 198     sampler::FilteringMode mag_filter, | 
| 199     sampler::FilteringMode min_filter, | 199     sampler::FilteringMode min_filter, | 
| 200     sampler::FilteringMode mip_filter, | 200     sampler::FilteringMode mip_filter, | 
| 201     unsigned int max_anisotropy) { | 201     unsigned int max_anisotropy) { | 
| 202   SamplerGL *sampler = samplers_.Get(id); | 202   SamplerGL *sampler = samplers_.Get(id); | 
| 203   if (!sampler) | 203   if (!sampler) | 
| 204     return BufferSyncInterface::kParseInvalidArguments; | 204     return BufferSyncInterface::kParseInvalidArguments; | 
| 205   // Dirty effect, because this sampler id may be used. | 205   // Dirty effect, because this sampler id may be used. | 
| 206   DirtyEffect(); | 206   DirtyEffect(); | 
| 207   sampler->SetStates(addressing_u, addressing_v, addressing_w, | 207   sampler->SetStates(addressing_u, addressing_v, addressing_w, | 
| 208                      mag_filter, min_filter, mip_filter, max_anisotropy); | 208                      mag_filter, min_filter, mip_filter, max_anisotropy); | 
| 209   return BufferSyncInterface::kParseNoError; | 209   return BufferSyncInterface::kParseNoError; | 
| 210 } | 210 } | 
| 211 | 211 | 
| 212 BufferSyncInterface::ParseError GAPIGL::SetSamplerBorderColor( | 212 BufferSyncInterface::ParseError GAPIGL::SetSamplerBorderColor( | 
| 213     ResourceID id, | 213     ResourceId id, | 
| 214     const RGBA &color) { | 214     const RGBA &color) { | 
| 215   SamplerGL *sampler = samplers_.Get(id); | 215   SamplerGL *sampler = samplers_.Get(id); | 
| 216   if (!sampler) | 216   if (!sampler) | 
| 217     return BufferSyncInterface::kParseInvalidArguments; | 217     return BufferSyncInterface::kParseInvalidArguments; | 
| 218   // Dirty effect, because this sampler id may be used. | 218   // Dirty effect, because this sampler id may be used. | 
| 219   DirtyEffect(); | 219   DirtyEffect(); | 
| 220   sampler->SetBorderColor(color); | 220   sampler->SetBorderColor(color); | 
| 221   return BufferSyncInterface::kParseNoError; | 221   return BufferSyncInterface::kParseNoError; | 
| 222 } | 222 } | 
| 223 | 223 | 
| 224 BufferSyncInterface::ParseError GAPIGL::SetSamplerTexture( | 224 BufferSyncInterface::ParseError GAPIGL::SetSamplerTexture( | 
| 225     ResourceID id, | 225     ResourceId id, | 
| 226     ResourceID texture_id) { | 226     ResourceId texture_id) { | 
| 227   SamplerGL *sampler = samplers_.Get(id); | 227   SamplerGL *sampler = samplers_.Get(id); | 
| 228   if (!sampler) | 228   if (!sampler) | 
| 229     return BufferSyncInterface::kParseInvalidArguments; | 229     return BufferSyncInterface::kParseInvalidArguments; | 
| 230   // Dirty effect, because this sampler id may be used. | 230   // Dirty effect, because this sampler id may be used. | 
| 231   DirtyEffect(); | 231   DirtyEffect(); | 
| 232   sampler->SetTexture(texture_id); | 232   sampler->SetTexture(texture_id); | 
| 233   return BufferSyncInterface::kParseNoError; | 233   return BufferSyncInterface::kParseNoError; | 
| 234 } | 234 } | 
| 235 | 235 | 
| 236 | 236 | 
| 237 }  // namespace command_buffer | 237 }  // namespace command_buffer | 
| 238 }  // namespace o3d | 238 }  // namespace o3d | 
| OLD | NEW | 
|---|