void RenderState::StateBlock::setState(const char* name, const char* value) { GP_ASSERT(name); if (strcmp(name, "blend") == 0) { setBlend(parseBoolean(value)); } else if (strcmp(name, "blendSrc") == 0 || strcmp(name, "srcBlend") == 0 ) // Leaving srcBlend for backward compat. { setBlendSrc(parseBlend(value)); } else if (strcmp(name, "blendDst") == 0 || strcmp(name, "dstBlend") == 0) // // Leaving dstBlend for backward compat. { setBlendDst(parseBlend(value)); } else if (strcmp(name, "cullFace") == 0) { setCullFace(parseBoolean(value)); } else if (strcmp(name, "depthTest") == 0) { setDepthTest(parseBoolean(value)); } else if (strcmp(name, "depthWrite") == 0) { setDepthWrite(parseBoolean(value)); } else { GP_ERROR("Unsupported render state string '%s'.", name); } }
void Sprite3DMirrorTest::addNewSpriteWithCoords(Vec2 p) { std::string fileName = "Sprite3DTest/orc.c3b"; auto sprite = Sprite3D::create(fileName); sprite->setScale(5); sprite->setRotation3D(Vec3(0,180,0)); addChild(sprite); sprite->setPosition( Vec2( p.x - 80, p.y) ); //test attach auto sp = Sprite3D::create("Sprite3DTest/axe.c3b"); sprite->getAttachNode("Bip001 R Hand")->addChild(sp); auto animation = Animation3D::create(fileName); if (animation) { auto animate = Animate3D::create(animation); sprite->runAction(RepeatForever::create(animate)); } _sprite = sprite; _hasWeapon = true; //create mirror Sprite3D sprite = Sprite3D::create(fileName); sprite->setScale(5); sprite->setScaleX(-5); sprite->setCullFace(GL_FRONT); sprite->setRotation3D(Vec3(0,180,0)); addChild(sprite); sprite->setPosition( Vec2( p.x + 80, p.y) ); //test attach sp = Sprite3D::create("Sprite3DTest/axe.c3b"); sprite->getAttachNode("Bip001 R Hand")->addChild(sp); animation = Animation3D::create(fileName); if (animation) { auto animate = Animate3D::create(animation); sprite->runAction(RepeatForever::create(animate)); } _mirrorSprite = sprite; }
void State::setEnableFeature(GLenum feature, bool enabled) { switch (feature) { case GL_CULL_FACE: setCullFace(enabled); break; case GL_POLYGON_OFFSET_FILL: setPolygonOffsetFill(enabled); break; case GL_SAMPLE_ALPHA_TO_COVERAGE: setSampleAlphaToCoverage(enabled); break; case GL_SAMPLE_COVERAGE: setSampleCoverage(enabled); break; case GL_SCISSOR_TEST: setScissorTest(enabled); break; case GL_STENCIL_TEST: setStencilTest(enabled); break; case GL_DEPTH_TEST: setDepthTest(enabled); break; case GL_BLEND: setBlend(enabled); break; case GL_DITHER: setDither(enabled); break; case GL_PRIMITIVE_RESTART_FIXED_INDEX: UNIMPLEMENTED(); break; case GL_RASTERIZER_DISCARD: setRasterizerDiscard(enabled); break; default: UNREACHABLE(); } }
void GraphicsManager::setupScene() { if (!_screen) throw Common::Exception("No screen initialized"); glClearColor(0, 0, 0, 0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glViewport(0, 0, _width, _height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glAlphaFunc(GL_GREATER, 0.1f); glEnable(GL_ALPHA_TEST); setCullFace(_cullFaceEnabled, _cullFaceMode); switch (_projectType) { case kProjectTypePerspective: perspective(_viewAngle, ((float) _width) / ((float) _height), _clipNear, _clipFar); break; case kProjectTypeOrthogonal: ortho(0.0f, _width, 0.0f, _height, _clipNear, _clipFar); break; default: assert(false); break; } }
void StateManagerGL::syncState(const gl::State &state, const gl::State::DirtyBits &dirtyBits) { // TODO(jmadill): Investigate only syncing vertex state for active attributes for (auto dirtyBit : angle::IterateBitSet(dirtyBits | mLocalDirtyBits)) { switch (dirtyBit) { case gl::State::DIRTY_BIT_SCISSOR_TEST_ENABLED: setScissorTestEnabled(state.isScissorTestEnabled()); break; case gl::State::DIRTY_BIT_SCISSOR: setScissor(state.getScissor()); break; case gl::State::DIRTY_BIT_VIEWPORT: setViewport(state.getViewport()); break; case gl::State::DIRTY_BIT_DEPTH_RANGE: setDepthRange(state.getNearPlane(), state.getFarPlane()); break; case gl::State::DIRTY_BIT_BLEND_ENABLED: setBlendEnabled(state.isBlendEnabled()); break; case gl::State::DIRTY_BIT_BLEND_COLOR: setBlendColor(state.getBlendColor()); break; case gl::State::DIRTY_BIT_BLEND_FUNCS: { const auto &blendState = state.getBlendState(); setBlendFuncs(blendState.sourceBlendRGB, blendState.destBlendRGB, blendState.sourceBlendAlpha, blendState.destBlendAlpha); break; } case gl::State::DIRTY_BIT_BLEND_EQUATIONS: { const auto &blendState = state.getBlendState(); setBlendEquations(blendState.blendEquationRGB, blendState.blendEquationAlpha); break; } case gl::State::DIRTY_BIT_COLOR_MASK: { const auto &blendState = state.getBlendState(); setColorMask(blendState.colorMaskRed, blendState.colorMaskGreen, blendState.colorMaskBlue, blendState.colorMaskAlpha); break; } case gl::State::DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED: setSampleAlphaToCoverageEnabled(state.isSampleAlphaToCoverageEnabled()); break; case gl::State::DIRTY_BIT_SAMPLE_COVERAGE_ENABLED: setSampleCoverageEnabled(state.isSampleCoverageEnabled()); break; case gl::State::DIRTY_BIT_SAMPLE_COVERAGE: setSampleCoverage(state.getSampleCoverageValue(), state.getSampleCoverageInvert()); break; case gl::State::DIRTY_BIT_DEPTH_TEST_ENABLED: setDepthTestEnabled(state.isDepthTestEnabled()); break; case gl::State::DIRTY_BIT_DEPTH_FUNC: setDepthFunc(state.getDepthStencilState().depthFunc); break; case gl::State::DIRTY_BIT_DEPTH_MASK: setDepthMask(state.getDepthStencilState().depthMask); break; case gl::State::DIRTY_BIT_STENCIL_TEST_ENABLED: setStencilTestEnabled(state.isStencilTestEnabled()); break; case gl::State::DIRTY_BIT_STENCIL_FUNCS_FRONT: { const auto &depthStencilState = state.getDepthStencilState(); setStencilFrontFuncs(depthStencilState.stencilFunc, state.getStencilRef(), depthStencilState.stencilMask); break; } case gl::State::DIRTY_BIT_STENCIL_FUNCS_BACK: { const auto &depthStencilState = state.getDepthStencilState(); setStencilBackFuncs(depthStencilState.stencilBackFunc, state.getStencilBackRef(), depthStencilState.stencilBackMask); break; } case gl::State::DIRTY_BIT_STENCIL_OPS_FRONT: { const auto &depthStencilState = state.getDepthStencilState(); setStencilFrontOps(depthStencilState.stencilFail, depthStencilState.stencilPassDepthFail, depthStencilState.stencilPassDepthPass); break; } case gl::State::DIRTY_BIT_STENCIL_OPS_BACK: { const auto &depthStencilState = state.getDepthStencilState(); setStencilBackOps(depthStencilState.stencilBackFail, depthStencilState.stencilBackPassDepthFail, depthStencilState.stencilBackPassDepthPass); break; } case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT: setStencilFrontWritemask(state.getDepthStencilState().stencilWritemask); break; case gl::State::DIRTY_BIT_STENCIL_WRITEMASK_BACK: setStencilBackWritemask(state.getDepthStencilState().stencilBackWritemask); break; case gl::State::DIRTY_BIT_CULL_FACE_ENABLED: setCullFaceEnabled(state.isCullFaceEnabled()); break; case gl::State::DIRTY_BIT_CULL_FACE: setCullFace(state.getRasterizerState().cullMode); break; case gl::State::DIRTY_BIT_FRONT_FACE: setFrontFace(state.getRasterizerState().frontFace); break; case gl::State::DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED: setPolygonOffsetFillEnabled(state.isPolygonOffsetFillEnabled()); break; case gl::State::DIRTY_BIT_POLYGON_OFFSET: { const auto &rasterizerState = state.getRasterizerState(); setPolygonOffset(rasterizerState.polygonOffsetFactor, rasterizerState.polygonOffsetUnits); break; } case gl::State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED: setRasterizerDiscardEnabled(state.isRasterizerDiscardEnabled()); break; case gl::State::DIRTY_BIT_LINE_WIDTH: setLineWidth(state.getLineWidth()); break; case gl::State::DIRTY_BIT_PRIMITIVE_RESTART_ENABLED: setPrimitiveRestartEnabled(state.isPrimitiveRestartEnabled()); break; case gl::State::DIRTY_BIT_CLEAR_COLOR: setClearColor(state.getColorClearValue()); break; case gl::State::DIRTY_BIT_CLEAR_DEPTH: setClearDepth(state.getDepthClearValue()); break; case gl::State::DIRTY_BIT_CLEAR_STENCIL: setClearStencil(state.getStencilClearValue()); break; case gl::State::DIRTY_BIT_UNPACK_ALIGNMENT: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_ROW_LENGTH: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_SKIP_IMAGES: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_SKIP_ROWS: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_UNPACK_SKIP_PIXELS: // TODO(jmadill): split this setPixelUnpackState(state.getUnpackState()); break; case gl::State::DIRTY_BIT_PACK_ALIGNMENT: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_PACK_ROW_LENGTH: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_PACK_SKIP_ROWS: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_PACK_SKIP_PIXELS: // TODO(jmadill): split this setPixelPackState(state.getPackState()); break; case gl::State::DIRTY_BIT_DITHER_ENABLED: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_GENERATE_MIPMAP_HINT: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_SHADER_DERIVATIVE_HINT: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_READ_FRAMEBUFFER_OBJECT: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_OBJECT: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_RENDERBUFFER_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_VERTEX_ARRAY_OBJECT: state.getVertexArray()->syncImplState(); break; case gl::State::DIRTY_BIT_PROGRAM_BINDING: // TODO(jmadill): implement this break; case gl::State::DIRTY_BIT_PROGRAM_OBJECT: // TODO(jmadill): implement this break; default: { ASSERT(dirtyBit >= gl::State::DIRTY_BIT_CURRENT_VALUE_0 && dirtyBit < gl::State::DIRTY_BIT_CURRENT_VALUE_MAX); size_t attribIndex = static_cast<size_t>(dirtyBit) - gl::State::DIRTY_BIT_CURRENT_VALUE_0; setAttributeCurrentData(attribIndex, state.getVertexAttribCurrentValue( static_cast<unsigned int>(attribIndex))); break; } } mLocalDirtyBits.reset(); } }
void RenderState::StateBlock::setState(const std::string& name, const std::string& value) { if (name.compare("blend") == 0) { setBlend(parseBoolean(value)); } else if (name.compare("blendSrc") == 0) { setBlendSrc(parseBlend(value)); } else if (name.compare("blendDst") == 0) { setBlendDst(parseBlend(value)); } else if (name.compare("cullFace") == 0) { setCullFace(parseBoolean(value)); } else if (name.compare("cullFaceSide") == 0) { setCullFaceSide(parseCullFaceSide(value)); } else if (name.compare("frontFace") == 0) { setFrontFace(parseFrontFace(value)); } else if (name.compare("depthTest") == 0) { setDepthTest(parseBoolean(value)); } else if (name.compare("depthWrite") == 0) { setDepthWrite(parseBoolean(value)); } else if (name.compare("depthFunc") == 0) { setDepthFunction(parseDepthFunc(value)); } else if (name.compare("stencilTest") == 0) { setStencilTest(parseBoolean(value)); } else if (name.compare("stencilWrite") == 0) { setStencilWrite(parseUInt(value)); } else if (name.compare("stencilFunc") == 0) { setStencilFunction(parseStencilFunc(value), _stencilFunctionRef, _stencilFunctionMask); } else if (name.compare("stencilFuncRef") == 0) { setStencilFunction(_stencilFunction, parseInt(value), _stencilFunctionMask); } else if (name.compare("stencilFuncMask") == 0) { setStencilFunction(_stencilFunction, _stencilFunctionRef, parseUInt(value)); } else if (name.compare("stencilOpSfail") == 0) { setStencilOperation(parseStencilOp(value), _stencilOpDpfail, _stencilOpDppass); } else if (name.compare("stencilOpDpfail") == 0) { setStencilOperation(_stencilOpSfail, parseStencilOp(value), _stencilOpDppass); } else if (name.compare("stencilOpDppass") == 0) { setStencilOperation(_stencilOpSfail, _stencilOpDpfail, parseStencilOp(value)); } else { CCLOG("Unsupported render state string '%s'.", name.c_str()); } }