| 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 14 matching lines...) Expand all Loading... |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 // This file implements the render state-related GAPI functions on GL. | 33 // This file implements the render state-related GAPI functions on GL. |
| 34 | 34 |
| 35 #include "command_buffer/common/cross/cmd_buffer_format.h" | 35 #include "command_buffer/common/cross/o3d_cmd_format.h" |
| 36 #include "command_buffer/service/cross/gl/gapi_gl.h" | 36 #include "command_buffer/service/cross/gl/gapi_gl.h" |
| 37 | 37 |
| 38 namespace o3d { | 38 namespace o3d { |
| 39 namespace command_buffer { | 39 namespace command_buffer { |
| 40 namespace o3d { |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 GLenum kGLPolygonModes[] = { | 44 GLenum kGLPolygonModes[] = { |
| 44 GL_POINT, | 45 GL_POINT, |
| 45 GL_LINE, | 46 GL_LINE, |
| 46 GL_FILL, | 47 GL_FILL, |
| 47 }; | 48 }; |
| 48 COMPILE_ASSERT(command_buffer::kNumPolygonMode == arraysize(kGLPolygonModes), | 49 COMPILE_ASSERT(o3d::kNumPolygonMode == arraysize(kGLPolygonModes), |
| 49 kGLPolygonModes_does_not_match_command_buffer_PolygonMode); | 50 kGLPolygonModes_does_not_match_command_buffer_PolygonMode); |
| 50 | 51 |
| 51 GLenum kGLComparison[] = { | 52 GLenum kGLComparison[] = { |
| 52 GL_NEVER, | 53 GL_NEVER, |
| 53 GL_LESS, | 54 GL_LESS, |
| 54 GL_EQUAL, | 55 GL_EQUAL, |
| 55 GL_LEQUAL, | 56 GL_LEQUAL, |
| 56 GL_GREATER, | 57 GL_GREATER, |
| 57 GL_NOTEQUAL, | 58 GL_NOTEQUAL, |
| 58 GL_GEQUAL, | 59 GL_GEQUAL, |
| 59 GL_ALWAYS, | 60 GL_ALWAYS, |
| 60 }; | 61 }; |
| 61 COMPILE_ASSERT(command_buffer::kNumComparison == arraysize(kGLComparison), | 62 COMPILE_ASSERT(o3d::kNumComparison == arraysize(kGLComparison), |
| 62 kGLComparison_does_not_match_command_buffer_Comparison); | 63 kGLComparison_does_not_match_command_buffer_Comparison); |
| 63 | 64 |
| 64 GLenum kGLBlendFunc[] = { | 65 GLenum kGLBlendFunc[] = { |
| 65 GL_ZERO, | 66 GL_ZERO, |
| 66 GL_ONE, | 67 GL_ONE, |
| 67 GL_SRC_COLOR, | 68 GL_SRC_COLOR, |
| 68 GL_ONE_MINUS_SRC_COLOR, | 69 GL_ONE_MINUS_SRC_COLOR, |
| 69 GL_SRC_ALPHA, | 70 GL_SRC_ALPHA, |
| 70 GL_ONE_MINUS_SRC_ALPHA, | 71 GL_ONE_MINUS_SRC_ALPHA, |
| 71 GL_DST_ALPHA, | 72 GL_DST_ALPHA, |
| 72 GL_ONE_MINUS_DST_ALPHA, | 73 GL_ONE_MINUS_DST_ALPHA, |
| 73 GL_DST_COLOR, | 74 GL_DST_COLOR, |
| 74 GL_ONE_MINUS_DST_COLOR, | 75 GL_ONE_MINUS_DST_COLOR, |
| 75 GL_SRC_ALPHA_SATURATE, | 76 GL_SRC_ALPHA_SATURATE, |
| 76 GL_CONSTANT_COLOR, | 77 GL_CONSTANT_COLOR, |
| 77 GL_ONE_MINUS_CONSTANT_COLOR, | 78 GL_ONE_MINUS_CONSTANT_COLOR, |
| 78 }; | 79 }; |
| 79 COMPILE_ASSERT(command_buffer::kNumBlendFunc == arraysize(kGLBlendFunc), | 80 COMPILE_ASSERT(o3d::kNumBlendFunc == arraysize(kGLBlendFunc), |
| 80 kGLBlendFunc_does_not_match_command_buffer_BlendFunc); | 81 kGLBlendFunc_does_not_match_command_buffer_BlendFunc); |
| 81 | 82 |
| 82 GLenum kGLBlendEq[] = { | 83 GLenum kGLBlendEq[] = { |
| 83 GL_FUNC_ADD, | 84 GL_FUNC_ADD, |
| 84 GL_FUNC_SUBTRACT, | 85 GL_FUNC_SUBTRACT, |
| 85 GL_FUNC_REVERSE_SUBTRACT, | 86 GL_FUNC_REVERSE_SUBTRACT, |
| 86 GL_MIN, | 87 GL_MIN, |
| 87 GL_MAX, | 88 GL_MAX, |
| 88 }; | 89 }; |
| 89 COMPILE_ASSERT(command_buffer::kNumBlendEq == arraysize(kGLBlendEq), | 90 COMPILE_ASSERT(o3d::kNumBlendEq == arraysize(kGLBlendEq), |
| 90 kGLBlendEq_does_not_match_command_buffer_BlendEq); | 91 kGLBlendEq_does_not_match_command_buffer_BlendEq); |
| 91 | 92 |
| 92 GLenum kGLStencilOp[] = { | 93 GLenum kGLStencilOp[] = { |
| 93 GL_KEEP, | 94 GL_KEEP, |
| 94 GL_ZERO, | 95 GL_ZERO, |
| 95 GL_REPLACE, | 96 GL_REPLACE, |
| 96 GL_INCR, | 97 GL_INCR, |
| 97 GL_DECR, | 98 GL_DECR, |
| 98 GL_INVERT, | 99 GL_INVERT, |
| 99 GL_INCR_WRAP, | 100 GL_INCR_WRAP, |
| 100 GL_DECR_WRAP, | 101 GL_DECR_WRAP, |
| 101 }; | 102 }; |
| 102 COMPILE_ASSERT(command_buffer::kNumStencilOp == arraysize(kGLStencilOp), | 103 COMPILE_ASSERT(o3d::kNumStencilOp == arraysize(kGLStencilOp), |
| 103 kGLStencilOp_does_not_match_command_buffer_StencilOp); | 104 kGLStencilOp_does_not_match_command_buffer_StencilOp); |
| 104 | 105 |
| 105 // Check that the definition of the counter-clockwise func/ops match the | 106 // Check that the definition of the counter-clockwise func/ops match the |
| 106 // clockwise ones, just shifted by 16 bits, so that we can use | 107 // clockwise ones, just shifted by 16 bits, so that we can use |
| 107 // DecodeStencilFuncOps on both of them. | 108 // DecodeStencilFuncOps on both of them. |
| 108 #define CHECK_CCW_MATCHES_CW(FIELD) \ | 109 #define CHECK_CCW_MATCHES_CW(FIELD) \ |
| 109 COMPILE_ASSERT(cmd::SetStencilTest::CW ## FIELD::kLength == \ | 110 COMPILE_ASSERT(o3d::SetStencilTest::CW ## FIELD::kLength == \ |
| 110 cmd::SetStencilTest::CCW ## FIELD::kLength, \ | 111 o3d::SetStencilTest::CCW ## FIELD::kLength, \ |
| 111 CCW ## FIELD ## _length_does_not_match_ ## CW ## FIELD); \ | 112 CCW ## FIELD ## _length_does_not_match_ ## CW ## FIELD); \ |
| 112 COMPILE_ASSERT(cmd::SetStencilTest::CW ## FIELD::kShift + 16 == \ | 113 COMPILE_ASSERT(o3d::SetStencilTest::CW ## FIELD::kShift + 16 == \ |
| 113 cmd::SetStencilTest::CCW ## FIELD::kShift, \ | 114 o3d::SetStencilTest::CCW ## FIELD::kShift, \ |
| 114 CCW ## FIELD ## _shift_does_not_match_ ## CW ## FIELD) | 115 CCW ## FIELD ## _shift_does_not_match_ ## CW ## FIELD) |
| 115 | 116 |
| 116 CHECK_CCW_MATCHES_CW(Func); | 117 CHECK_CCW_MATCHES_CW(Func); |
| 117 CHECK_CCW_MATCHES_CW(PassOp); | 118 CHECK_CCW_MATCHES_CW(PassOp); |
| 118 CHECK_CCW_MATCHES_CW(FailOp); | 119 CHECK_CCW_MATCHES_CW(FailOp); |
| 119 CHECK_CCW_MATCHES_CW(ZFailOp); | 120 CHECK_CCW_MATCHES_CW(ZFailOp); |
| 120 | 121 |
| 121 #undef CHECK_CCW_MATCHES_CW | 122 #undef CHECK_CCW_MATCHES_CW |
| 122 | 123 |
| 123 // Decodes stencil test function and operations from the bitfield. | 124 // Decodes stencil test function and operations from the bitfield. |
| 124 void DecodeStencilFuncOps(Uint32 params, | 125 void DecodeStencilFuncOps(Uint32 params, |
| 125 GLenum *func, | 126 GLenum *func, |
| 126 GLenum *pass, | 127 GLenum *pass, |
| 127 GLenum *fail, | 128 GLenum *fail, |
| 128 GLenum *zfail) { | 129 GLenum *zfail) { |
| 129 // Sanity check. The value has already been tested in | 130 // Sanity check. The value has already been tested in |
| 130 // GAPIDecoder::DecodeSetStencilTest in gapi_decoder.cc. | 131 // GAPIDecoder::DecodeSetStencilTest in gapi_decoder.cc. |
| 131 DCHECK_EQ(cmd::SetStencilTest::Unused1::Get(params), 0); | 132 DCHECK_EQ(o3d::SetStencilTest::Unused1::Get(params), 0); |
| 132 // Check that the bitmask get cannot generate values outside of the allowed | 133 // Check that the bitmask get cannot generate values outside of the allowed |
| 133 // range. | 134 // range. |
| 134 COMPILE_ASSERT(cmd::SetStencilTest::CWFunc::kMask < | 135 COMPILE_ASSERT(o3d::SetStencilTest::CWFunc::kMask < |
| 135 command_buffer::kNumComparison, | 136 o3d::kNumComparison, |
| 136 set_stencil_test_CWFunc_may_produce_invalid_values); | 137 set_stencil_test_CWFunc_may_produce_invalid_values); |
| 137 *func = kGLComparison[cmd::SetStencilTest::CWFunc::Get(params)]; | 138 *func = kGLComparison[o3d::SetStencilTest::CWFunc::Get(params)]; |
| 138 | 139 |
| 139 COMPILE_ASSERT(cmd::SetStencilTest::CWPassOp::kMask < | 140 COMPILE_ASSERT(o3d::SetStencilTest::CWPassOp::kMask < |
| 140 command_buffer::kNumStencilOp, | 141 o3d::kNumStencilOp, |
| 141 set_stencil_test_CWPassOp_may_produce_invalid_values); | 142 set_stencil_test_CWPassOp_may_produce_invalid_values); |
| 142 *pass = kGLStencilOp[cmd::SetStencilTest::CWPassOp::Get(params)]; | 143 *pass = kGLStencilOp[o3d::SetStencilTest::CWPassOp::Get(params)]; |
| 143 | 144 |
| 144 COMPILE_ASSERT(cmd::SetStencilTest::CWFailOp::kMask < | 145 COMPILE_ASSERT(o3d::SetStencilTest::CWFailOp::kMask < |
| 145 command_buffer::kNumStencilOp, | 146 o3d::kNumStencilOp, |
| 146 set_stencil_test_CWFailOp_may_produce_invalid_values); | 147 set_stencil_test_CWFailOp_may_produce_invalid_values); |
| 147 *fail = kGLStencilOp[cmd::SetStencilTest::CWFailOp::Get(params)]; | 148 *fail = kGLStencilOp[o3d::SetStencilTest::CWFailOp::Get(params)]; |
| 148 | 149 |
| 149 COMPILE_ASSERT(cmd::SetStencilTest::CWZFailOp::kMask < | 150 COMPILE_ASSERT(o3d::SetStencilTest::CWZFailOp::kMask < |
| 150 command_buffer::kNumStencilOp, | 151 o3d::kNumStencilOp, |
| 151 set_stencil_test_CWZFailOp_may_produce_invalid_values); | 152 set_stencil_test_CWZFailOp_may_produce_invalid_values); |
| 152 *zfail = kGLStencilOp[cmd::SetStencilTest::CWZFailOp::Get(params)]; | 153 *zfail = kGLStencilOp[o3d::SetStencilTest::CWZFailOp::Get(params)]; |
| 153 } | 154 } |
| 154 | 155 |
| 155 } // anonymous namespace | 156 } // anonymous namespace |
| 156 | 157 |
| 157 void GAPIGL::SetViewport(unsigned int x, | 158 void GAPIGL::SetViewport(unsigned int x, |
| 158 unsigned int y, | 159 unsigned int y, |
| 159 unsigned int width, | 160 unsigned int width, |
| 160 unsigned int height, | 161 unsigned int height, |
| 161 float z_min, | 162 float z_min, |
| 162 float z_max) { | 163 float z_max) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE); | 201 glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE); |
| 201 glDisable(GL_POINT_SPRITE); | 202 glDisable(GL_POINT_SPRITE); |
| 202 } | 203 } |
| 203 glPointSize(point_size); | 204 glPointSize(point_size); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void GAPIGL::SetPolygonOffset(float slope_factor, float units) { | 207 void GAPIGL::SetPolygonOffset(float slope_factor, float units) { |
| 207 glPolygonOffset(slope_factor, units); | 208 glPolygonOffset(slope_factor, units); |
| 208 } | 209 } |
| 209 | 210 |
| 210 void GAPIGL::SetPolygonRaster(PolygonMode fill_mode, | 211 void GAPIGL::SetPolygonRaster(o3d::PolygonMode fill_mode, |
| 211 FaceCullMode cull_mode) { | 212 o3d::FaceCullMode cull_mode) { |
| 212 DCHECK_LT(fill_mode, kNumPolygonMode); | 213 DCHECK_LT(fill_mode, kNumPolygonMode); |
| 213 glPolygonMode(GL_FRONT_AND_BACK, kGLPolygonModes[fill_mode]); | 214 glPolygonMode(GL_FRONT_AND_BACK, kGLPolygonModes[fill_mode]); |
| 214 DCHECK_LT(cull_mode, kNumFaceCullMode); | 215 DCHECK_LT(cull_mode, kNumFaceCullMode); |
| 215 switch (cull_mode) { | 216 switch (cull_mode) { |
| 216 case kCullCW: | 217 case kCullCW: |
| 217 glEnable(GL_CULL_FACE); | 218 glEnable(GL_CULL_FACE); |
| 218 glCullFace(GL_BACK); | 219 glCullFace(GL_BACK); |
| 219 break; | 220 break; |
| 220 case kCullCCW: | 221 case kCullCCW: |
| 221 glEnable(GL_CULL_FACE); | 222 glEnable(GL_CULL_FACE); |
| 222 glCullFace(GL_FRONT); | 223 glCullFace(GL_FRONT); |
| 223 break; | 224 break; |
| 224 default: | 225 default: |
| 225 glDisable(GL_CULL_FACE); | 226 glDisable(GL_CULL_FACE); |
| 226 break; | 227 break; |
| 227 } | 228 } |
| 228 } | 229 } |
| 229 | 230 |
| 230 void GAPIGL::SetAlphaTest(bool enable, | 231 void GAPIGL::SetAlphaTest(bool enable, |
| 231 float reference, | 232 float reference, |
| 232 Comparison comp) { | 233 o3d::Comparison comp) { |
| 233 DCHECK_LT(comp, kNumComparison); | 234 DCHECK_LT(comp, kNumComparison); |
| 234 if (enable) { | 235 if (enable) { |
| 235 glEnable(GL_ALPHA_TEST); | 236 glEnable(GL_ALPHA_TEST); |
| 236 glAlphaFunc(kGLComparison[comp], reference); | 237 glAlphaFunc(kGLComparison[comp], reference); |
| 237 } else { | 238 } else { |
| 238 glDisable(GL_ALPHA_TEST); | 239 glDisable(GL_ALPHA_TEST); |
| 239 } | 240 } |
| 240 } | 241 } |
| 241 | 242 |
| 242 void GAPIGL::SetDepthTest(bool enable, | 243 void GAPIGL::SetDepthTest(bool enable, |
| 243 bool write_enable, | 244 bool write_enable, |
| 244 Comparison comp) { | 245 o3d::Comparison comp) { |
| 245 DCHECK_LT(comp, kNumComparison); | 246 DCHECK_LT(comp, kNumComparison); |
| 246 if (enable) { | 247 if (enable) { |
| 247 glEnable(GL_DEPTH_TEST); | 248 glEnable(GL_DEPTH_TEST); |
| 248 glDepthFunc(kGLComparison[comp]); | 249 glDepthFunc(kGLComparison[comp]); |
| 249 } else { | 250 } else { |
| 250 glDisable(GL_DEPTH_TEST); | 251 glDisable(GL_DEPTH_TEST); |
| 251 } | 252 } |
| 252 glDepthMask(write_enable); | 253 glDepthMask(write_enable); |
| 253 } | 254 } |
| 254 | 255 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 335 } |
| 335 } else { | 336 } else { |
| 336 glDisable(GL_BLEND); | 337 glDisable(GL_BLEND); |
| 337 } | 338 } |
| 338 } | 339 } |
| 339 | 340 |
| 340 void GAPIGL::SetBlendingColor(const RGBA &color) { | 341 void GAPIGL::SetBlendingColor(const RGBA &color) { |
| 341 glBlendColor(color.red, color.green, color.blue, color.alpha); | 342 glBlendColor(color.red, color.green, color.blue, color.alpha); |
| 342 } | 343 } |
| 343 | 344 |
| 345 } // namespace o3d |
| 344 } // namespace command_buffer | 346 } // namespace command_buffer |
| 345 } // namespace o3d | 347 } // namespace o3d |
| OLD | NEW |