| 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 27 matching lines...) Expand all Loading... |
| 38 namespace o3d { | 38 namespace o3d { |
| 39 namespace command_buffer { | 39 namespace command_buffer { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 GLenum kGLPolygonModes[] = { | 43 GLenum kGLPolygonModes[] = { |
| 44 GL_POINT, | 44 GL_POINT, |
| 45 GL_LINE, | 45 GL_LINE, |
| 46 GL_FILL, | 46 GL_FILL, |
| 47 }; | 47 }; |
| 48 COMPILE_ASSERT(GAPIInterface::NUM_POLYGON_MODE == arraysize(kGLPolygonModes), | 48 COMPILE_ASSERT(command_buffer::kNumPolygonMode == arraysize(kGLPolygonModes), |
| 49 kGLPolygonModes_does_not_match_GAPIInterface_PolygonMode); | 49 kGLPolygonModes_does_not_match_command_buffer_PolygonMode); |
| 50 | 50 |
| 51 GLenum kGLComparison[] = { | 51 GLenum kGLComparison[] = { |
| 52 GL_NEVER, | 52 GL_NEVER, |
| 53 GL_LESS, | 53 GL_LESS, |
| 54 GL_EQUAL, | 54 GL_EQUAL, |
| 55 GL_LEQUAL, | 55 GL_LEQUAL, |
| 56 GL_GREATER, | 56 GL_GREATER, |
| 57 GL_NOTEQUAL, | 57 GL_NOTEQUAL, |
| 58 GL_GEQUAL, | 58 GL_GEQUAL, |
| 59 GL_ALWAYS, | 59 GL_ALWAYS, |
| 60 }; | 60 }; |
| 61 COMPILE_ASSERT(GAPIInterface::NUM_COMPARISON == arraysize(kGLComparison), | 61 COMPILE_ASSERT(command_buffer::kNumComparison == arraysize(kGLComparison), |
| 62 kGLComparison_does_not_match_GAPIInterface_Comparison); | 62 kGLComparison_does_not_match_command_buffer_Comparison); |
| 63 | 63 |
| 64 GLenum kGLBlendFunc[] = { | 64 GLenum kGLBlendFunc[] = { |
| 65 GL_ZERO, | 65 GL_ZERO, |
| 66 GL_ONE, | 66 GL_ONE, |
| 67 GL_SRC_COLOR, | 67 GL_SRC_COLOR, |
| 68 GL_ONE_MINUS_SRC_COLOR, | 68 GL_ONE_MINUS_SRC_COLOR, |
| 69 GL_SRC_ALPHA, | 69 GL_SRC_ALPHA, |
| 70 GL_ONE_MINUS_SRC_ALPHA, | 70 GL_ONE_MINUS_SRC_ALPHA, |
| 71 GL_DST_ALPHA, | 71 GL_DST_ALPHA, |
| 72 GL_ONE_MINUS_DST_ALPHA, | 72 GL_ONE_MINUS_DST_ALPHA, |
| 73 GL_DST_COLOR, | 73 GL_DST_COLOR, |
| 74 GL_ONE_MINUS_DST_COLOR, | 74 GL_ONE_MINUS_DST_COLOR, |
| 75 GL_SRC_ALPHA_SATURATE, | 75 GL_SRC_ALPHA_SATURATE, |
| 76 GL_CONSTANT_COLOR, | 76 GL_CONSTANT_COLOR, |
| 77 GL_ONE_MINUS_CONSTANT_COLOR, | 77 GL_ONE_MINUS_CONSTANT_COLOR, |
| 78 }; | 78 }; |
| 79 COMPILE_ASSERT(GAPIInterface::NUM_BLEND_FUNC == arraysize(kGLBlendFunc), | 79 COMPILE_ASSERT(command_buffer::kNumBlendFunc == arraysize(kGLBlendFunc), |
| 80 kGLBlendFunc_does_not_match_GAPIInterface_BlendFunc); | 80 kGLBlendFunc_does_not_match_command_buffer_BlendFunc); |
| 81 | 81 |
| 82 GLenum kGLBlendEq[] = { | 82 GLenum kGLBlendEq[] = { |
| 83 GL_FUNC_ADD, | 83 GL_FUNC_ADD, |
| 84 GL_FUNC_SUBTRACT, | 84 GL_FUNC_SUBTRACT, |
| 85 GL_FUNC_REVERSE_SUBTRACT, | 85 GL_FUNC_REVERSE_SUBTRACT, |
| 86 GL_MIN, | 86 GL_MIN, |
| 87 GL_MAX, | 87 GL_MAX, |
| 88 }; | 88 }; |
| 89 COMPILE_ASSERT(GAPIInterface::NUM_BLEND_EQ == arraysize(kGLBlendEq), | 89 COMPILE_ASSERT(command_buffer::kNumBlendEq == arraysize(kGLBlendEq), |
| 90 kGLBlendEq_does_not_match_GAPIInterface_BlendEq); | 90 kGLBlendEq_does_not_match_command_buffer_BlendEq); |
| 91 | 91 |
| 92 GLenum kGLStencilOp[] = { | 92 GLenum kGLStencilOp[] = { |
| 93 GL_KEEP, | 93 GL_KEEP, |
| 94 GL_ZERO, | 94 GL_ZERO, |
| 95 GL_REPLACE, | 95 GL_REPLACE, |
| 96 GL_INCR, | 96 GL_INCR, |
| 97 GL_DECR, | 97 GL_DECR, |
| 98 GL_INVERT, | 98 GL_INVERT, |
| 99 GL_INCR_WRAP, | 99 GL_INCR_WRAP, |
| 100 GL_DECR_WRAP, | 100 GL_DECR_WRAP, |
| 101 }; | 101 }; |
| 102 COMPILE_ASSERT(GAPIInterface::NUM_STENCIL_OP == arraysize(kGLStencilOp), | 102 COMPILE_ASSERT(command_buffer::kNumStencilOp == arraysize(kGLStencilOp), |
| 103 kGLStencilOp_does_not_match_GAPIInterface_StencilOp); | 103 kGLStencilOp_does_not_match_command_buffer_StencilOp); |
| 104 | 104 |
| 105 // Check that the definition of the counter-clockwise func/ops match the | 105 // 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 | 106 // clockwise ones, just shifted by 16 bits, so that we can use |
| 107 // DecodeStencilFuncOps on both of them. | 107 // DecodeStencilFuncOps on both of them. |
| 108 #define CHECK_CCW_MATCHES_CW(FIELD) \ | 108 #define CHECK_CCW_MATCHES_CW(FIELD) \ |
| 109 COMPILE_ASSERT(set_stencil_test::CW ## FIELD::kLength == \ | 109 COMPILE_ASSERT(cmd::SetStencilTest::CW ## FIELD::kLength == \ |
| 110 set_stencil_test::CCW ## FIELD::kLength, \ | 110 cmd::SetStencilTest::CCW ## FIELD::kLength, \ |
| 111 CCW ## FIELD ## _length_does_not_match_ ## CW ## FIELD); \ | 111 CCW ## FIELD ## _length_does_not_match_ ## CW ## FIELD); \ |
| 112 COMPILE_ASSERT(set_stencil_test::CW ## FIELD::kShift + 16 == \ | 112 COMPILE_ASSERT(cmd::SetStencilTest::CW ## FIELD::kShift + 16 == \ |
| 113 set_stencil_test::CCW ## FIELD::kShift, \ | 113 cmd::SetStencilTest::CCW ## FIELD::kShift, \ |
| 114 CCW ## FIELD ## _shift_does_not_match_ ## CW ## FIELD) | 114 CCW ## FIELD ## _shift_does_not_match_ ## CW ## FIELD) |
| 115 | 115 |
| 116 CHECK_CCW_MATCHES_CW(Func); | 116 CHECK_CCW_MATCHES_CW(Func); |
| 117 CHECK_CCW_MATCHES_CW(PassOp); | 117 CHECK_CCW_MATCHES_CW(PassOp); |
| 118 CHECK_CCW_MATCHES_CW(FailOp); | 118 CHECK_CCW_MATCHES_CW(FailOp); |
| 119 CHECK_CCW_MATCHES_CW(ZFailOp); | 119 CHECK_CCW_MATCHES_CW(ZFailOp); |
| 120 | 120 |
| 121 #undef CHECK_CCW_MATCHES_CW | 121 #undef CHECK_CCW_MATCHES_CW |
| 122 | 122 |
| 123 // Decodes stencil test function and operations from the bitfield. | 123 // Decodes stencil test function and operations from the bitfield. |
| 124 void DecodeStencilFuncOps(Uint32 params, | 124 void DecodeStencilFuncOps(Uint32 params, |
| 125 GLenum *func, | 125 GLenum *func, |
| 126 GLenum *pass, | 126 GLenum *pass, |
| 127 GLenum *fail, | 127 GLenum *fail, |
| 128 GLenum *zfail) { | 128 GLenum *zfail) { |
| 129 namespace cmd = set_stencil_test; | |
| 130 // Sanity check. The value has already been tested in | 129 // Sanity check. The value has already been tested in |
| 131 // GAPIDecoder::DecodeSetStencilTest in gapi_decoder.cc. | 130 // GAPIDecoder::DecodeSetStencilTest in gapi_decoder.cc. |
| 132 DCHECK_EQ(cmd::Unused1::Get(params), 0); | 131 DCHECK_EQ(cmd::SetStencilTest::Unused1::Get(params), 0); |
| 133 // Check that the bitmask get cannot generate values outside of the allowed | 132 // Check that the bitmask get cannot generate values outside of the allowed |
| 134 // range. | 133 // range. |
| 135 COMPILE_ASSERT(cmd::CWFunc::kMask < GAPIInterface::NUM_COMPARISON, | 134 COMPILE_ASSERT(cmd::SetStencilTest::CWFunc::kMask < |
| 135 command_buffer::kNumComparison, |
| 136 set_stencil_test_CWFunc_may_produce_invalid_values); | 136 set_stencil_test_CWFunc_may_produce_invalid_values); |
| 137 *func = kGLComparison[cmd::CWFunc::Get(params)]; | 137 *func = kGLComparison[cmd::SetStencilTest::CWFunc::Get(params)]; |
| 138 | 138 |
| 139 COMPILE_ASSERT(cmd::CWPassOp::kMask < GAPIInterface::NUM_STENCIL_OP, | 139 COMPILE_ASSERT(cmd::SetStencilTest::CWPassOp::kMask < |
| 140 command_buffer::kNumStencilOp, |
| 140 set_stencil_test_CWPassOp_may_produce_invalid_values); | 141 set_stencil_test_CWPassOp_may_produce_invalid_values); |
| 141 *pass = kGLStencilOp[cmd::CWPassOp::Get(params)]; | 142 *pass = kGLStencilOp[cmd::SetStencilTest::CWPassOp::Get(params)]; |
| 142 | 143 |
| 143 COMPILE_ASSERT(cmd::CWFailOp::kMask < GAPIInterface::NUM_STENCIL_OP, | 144 COMPILE_ASSERT(cmd::SetStencilTest::CWFailOp::kMask < |
| 145 command_buffer::kNumStencilOp, |
| 144 set_stencil_test_CWFailOp_may_produce_invalid_values); | 146 set_stencil_test_CWFailOp_may_produce_invalid_values); |
| 145 *fail = kGLStencilOp[cmd::CWFailOp::Get(params)]; | 147 *fail = kGLStencilOp[cmd::SetStencilTest::CWFailOp::Get(params)]; |
| 146 | 148 |
| 147 COMPILE_ASSERT(cmd::CWZFailOp::kMask < GAPIInterface::NUM_STENCIL_OP, | 149 COMPILE_ASSERT(cmd::SetStencilTest::CWZFailOp::kMask < |
| 150 command_buffer::kNumStencilOp, |
| 148 set_stencil_test_CWZFailOp_may_produce_invalid_values); | 151 set_stencil_test_CWZFailOp_may_produce_invalid_values); |
| 149 *zfail = kGLStencilOp[cmd::CWZFailOp::Get(params)]; | 152 *zfail = kGLStencilOp[cmd::SetStencilTest::CWZFailOp::Get(params)]; |
| 150 } | 153 } |
| 151 | 154 |
| 152 } // anonymous namespace | 155 } // anonymous namespace |
| 153 | 156 |
| 154 void GAPIGL::SetViewport(unsigned int x, | 157 void GAPIGL::SetViewport(unsigned int x, |
| 155 unsigned int y, | 158 unsigned int y, |
| 156 unsigned int width, | 159 unsigned int width, |
| 157 unsigned int height, | 160 unsigned int height, |
| 158 float z_min, | 161 float z_min, |
| 159 float z_max) { | 162 float z_max) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 202 } |
| 200 glPointSize(point_size); | 203 glPointSize(point_size); |
| 201 } | 204 } |
| 202 | 205 |
| 203 void GAPIGL::SetPolygonOffset(float slope_factor, float units) { | 206 void GAPIGL::SetPolygonOffset(float slope_factor, float units) { |
| 204 glPolygonOffset(slope_factor, units); | 207 glPolygonOffset(slope_factor, units); |
| 205 } | 208 } |
| 206 | 209 |
| 207 void GAPIGL::SetPolygonRaster(PolygonMode fill_mode, | 210 void GAPIGL::SetPolygonRaster(PolygonMode fill_mode, |
| 208 FaceCullMode cull_mode) { | 211 FaceCullMode cull_mode) { |
| 209 DCHECK_LT(fill_mode, NUM_POLYGON_MODE); | 212 DCHECK_LT(fill_mode, kNumPolygonMode); |
| 210 glPolygonMode(GL_FRONT_AND_BACK, kGLPolygonModes[fill_mode]); | 213 glPolygonMode(GL_FRONT_AND_BACK, kGLPolygonModes[fill_mode]); |
| 211 DCHECK_LT(cull_mode, NUM_FACE_CULL_MODE); | 214 DCHECK_LT(cull_mode, kNumFaceCullMode); |
| 212 switch (cull_mode) { | 215 switch (cull_mode) { |
| 213 case CULL_CW: | 216 case kCullCW: |
| 214 glEnable(GL_CULL_FACE); | 217 glEnable(GL_CULL_FACE); |
| 215 glCullFace(GL_BACK); | 218 glCullFace(GL_BACK); |
| 216 break; | 219 break; |
| 217 case CULL_CCW: | 220 case kCullCCW: |
| 218 glEnable(GL_CULL_FACE); | 221 glEnable(GL_CULL_FACE); |
| 219 glCullFace(GL_FRONT); | 222 glCullFace(GL_FRONT); |
| 220 break; | 223 break; |
| 221 default: | 224 default: |
| 222 glDisable(GL_CULL_FACE); | 225 glDisable(GL_CULL_FACE); |
| 223 break; | 226 break; |
| 224 } | 227 } |
| 225 } | 228 } |
| 226 | 229 |
| 227 void GAPIGL::SetAlphaTest(bool enable, | 230 void GAPIGL::SetAlphaTest(bool enable, |
| 228 float reference, | 231 float reference, |
| 229 Comparison comp) { | 232 Comparison comp) { |
| 230 DCHECK_LT(comp, NUM_COMPARISON); | 233 DCHECK_LT(comp, kNumComparison); |
| 231 if (enable) { | 234 if (enable) { |
| 232 glEnable(GL_ALPHA_TEST); | 235 glEnable(GL_ALPHA_TEST); |
| 233 glAlphaFunc(kGLComparison[comp], reference); | 236 glAlphaFunc(kGLComparison[comp], reference); |
| 234 } else { | 237 } else { |
| 235 glDisable(GL_ALPHA_TEST); | 238 glDisable(GL_ALPHA_TEST); |
| 236 } | 239 } |
| 237 } | 240 } |
| 238 | 241 |
| 239 void GAPIGL::SetDepthTest(bool enable, | 242 void GAPIGL::SetDepthTest(bool enable, |
| 240 bool write_enable, | 243 bool write_enable, |
| 241 Comparison comp) { | 244 Comparison comp) { |
| 242 DCHECK_LT(comp, NUM_COMPARISON); | 245 DCHECK_LT(comp, kNumComparison); |
| 243 if (enable) { | 246 if (enable) { |
| 244 glEnable(GL_DEPTH_TEST); | 247 glEnable(GL_DEPTH_TEST); |
| 245 glDepthFunc(kGLComparison[comp]); | 248 glDepthFunc(kGLComparison[comp]); |
| 246 } else { | 249 } else { |
| 247 glDisable(GL_DEPTH_TEST); | 250 glDisable(GL_DEPTH_TEST); |
| 248 } | 251 } |
| 249 glDepthMask(write_enable); | 252 glDepthMask(write_enable); |
| 250 } | 253 } |
| 251 | 254 |
| 252 void GAPIGL::SetStencilTest(bool enable, | 255 void GAPIGL::SetStencilTest(bool enable, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 303 } |
| 301 | 304 |
| 302 void GAPIGL::SetBlending(bool enable, | 305 void GAPIGL::SetBlending(bool enable, |
| 303 bool separate_alpha, | 306 bool separate_alpha, |
| 304 BlendEq color_eq, | 307 BlendEq color_eq, |
| 305 BlendFunc color_src_func, | 308 BlendFunc color_src_func, |
| 306 BlendFunc color_dst_func, | 309 BlendFunc color_dst_func, |
| 307 BlendEq alpha_eq, | 310 BlendEq alpha_eq, |
| 308 BlendFunc alpha_src_func, | 311 BlendFunc alpha_src_func, |
| 309 BlendFunc alpha_dst_func) { | 312 BlendFunc alpha_dst_func) { |
| 310 DCHECK_LT(color_eq, NUM_BLEND_EQ); | 313 DCHECK_LT(color_eq, kNumBlendEq); |
| 311 DCHECK_LT(color_src_func, NUM_BLEND_FUNC); | 314 DCHECK_LT(color_src_func, kNumBlendFunc); |
| 312 DCHECK_LT(color_dst_func, NUM_BLEND_FUNC); | 315 DCHECK_LT(color_dst_func, kNumBlendFunc); |
| 313 DCHECK_LT(alpha_eq, NUM_BLEND_EQ); | 316 DCHECK_LT(alpha_eq, kNumBlendEq); |
| 314 DCHECK_LT(alpha_src_func, NUM_BLEND_FUNC); | 317 DCHECK_LT(alpha_src_func, kNumBlendFunc); |
| 315 DCHECK_LT(alpha_dst_func, NUM_BLEND_FUNC); | 318 DCHECK_LT(alpha_dst_func, kNumBlendFunc); |
| 316 if (enable) { | 319 if (enable) { |
| 317 glEnable(GL_BLEND); | 320 glEnable(GL_BLEND); |
| 318 GLenum gl_color_eq = kGLBlendEq[color_eq]; | 321 GLenum gl_color_eq = kGLBlendEq[color_eq]; |
| 319 GLenum gl_color_src_func = kGLBlendFunc[color_src_func]; | 322 GLenum gl_color_src_func = kGLBlendFunc[color_src_func]; |
| 320 GLenum gl_color_dst_func = kGLBlendFunc[color_dst_func]; | 323 GLenum gl_color_dst_func = kGLBlendFunc[color_dst_func]; |
| 321 if (separate_alpha) { | 324 if (separate_alpha) { |
| 322 GLenum gl_alpha_eq = kGLBlendEq[alpha_eq]; | 325 GLenum gl_alpha_eq = kGLBlendEq[alpha_eq]; |
| 323 GLenum gl_alpha_src_func = kGLBlendFunc[alpha_src_func]; | 326 GLenum gl_alpha_src_func = kGLBlendFunc[alpha_src_func]; |
| 324 GLenum gl_alpha_dst_func = kGLBlendFunc[alpha_dst_func]; | 327 GLenum gl_alpha_dst_func = kGLBlendFunc[alpha_dst_func]; |
| 325 glBlendFuncSeparate(gl_color_src_func, gl_color_dst_func, | 328 glBlendFuncSeparate(gl_color_src_func, gl_color_dst_func, |
| 326 gl_alpha_src_func, gl_alpha_dst_func); | 329 gl_alpha_src_func, gl_alpha_dst_func); |
| 327 glBlendEquationSeparate(gl_color_eq, gl_alpha_eq); | 330 glBlendEquationSeparate(gl_color_eq, gl_alpha_eq); |
| 328 } else { | 331 } else { |
| 329 glBlendFunc(gl_color_src_func, gl_color_dst_func); | 332 glBlendFunc(gl_color_src_func, gl_color_dst_func); |
| 330 glBlendEquation(gl_color_eq); | 333 glBlendEquation(gl_color_eq); |
| 331 } | 334 } |
| 332 } else { | 335 } else { |
| 333 glDisable(GL_BLEND); | 336 glDisable(GL_BLEND); |
| 334 } | 337 } |
| 335 } | 338 } |
| 336 | 339 |
| 337 void GAPIGL::SetBlendingColor(const RGBA &color) { | 340 void GAPIGL::SetBlendingColor(const RGBA &color) { |
| 338 glBlendColor(color.red, color.green, color.blue, color.alpha); | 341 glBlendColor(color.red, color.green, color.blue, color.alpha); |
| 339 } | 342 } |
| 340 | 343 |
| 341 } // namespace command_buffer | 344 } // namespace command_buffer |
| 342 } // namespace o3d | 345 } // namespace o3d |
| OLD | NEW |