Exemplo n.º 1
0
void OpenGLRenderer::setDrawState(const glm::mat4& model, DrawBuffer* draw,
                                  const Renderer::DrawParameters& p) {
    useDrawBuffer(draw);

    for (GLuint u = 0; u < p.textures.size(); ++u) {
        useTexture(u, p.textures[u]);
    }

    setBlend(p.blendMode);
    setDepthWrite(p.depthWrite);
    setDepthMode(p.depthMode);

    ObjectUniformData objectData{model,
                             glm::vec4(p.colour.r / 255.f, p.colour.g / 255.f,
                                       p.colour.b / 255.f, p.colour.a / 255.f),
                             1.f, 1.f, p.visibility};
    uploadUBO(UBOObject, objectData);

    drawCounter++;
#ifdef RW_GRAPHICS_STATS
    if (currentDebugDepth > 0) {
        profileInfo[currentDebugDepth - 1].draws++;
        profileInfo[currentDebugDepth - 1].primitives += p.count;
    }
#endif
}
Exemplo n.º 2
0
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);
    }
}
Exemplo n.º 3
0
void OpenGLRenderer::clear(const glm::vec4& colour, bool clearColour,
                           bool clearDepth) {
    auto flags = 0;
    if (clearColour) {
        flags |= GL_COLOR_BUFFER_BIT;
        glClearColor(colour.r, colour.g, colour.b, colour.a);
    }
    bool depthWriteWasEnabled = depthWriteEnabled;
    if (clearDepth) {
        flags |= GL_DEPTH_BUFFER_BIT;
        setDepthWrite(true);
    }

    glClear(flags);

    if (depthWriteWasEnabled != depthWriteEnabled) {
        setDepthWrite(depthWriteWasEnabled);
    }
}
Exemplo n.º 4
0
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());
    }
}
Exemplo n.º 5
0
	Renderable::Renderable(const variant& node)
		: order_(0),
		  position_(0.0f),
		  rotation_(1.0f, 0.0f, 0.0f, 0.0f),
		  scale_(1.0f),
		  shader_(ShaderProgram::getSystemDefault()),
		  enabled_(true),
		  ignore_global_model_(false),
		  derived_position_(0.0f),
		  derived_rotation_(),
		  derived_scale_(1.0f)
	{
		if(!node.is_map()) {
			return;
		}

		if(node.has_key("ignore_global_model")) {
			ignore_global_model_ = node["ignore_global_model"].as_bool(false);
		}
		if(node.has_key("order")) {
			order_ = node["order"].as_int32();
		}
		// XXX set other stuff here, tbd
		if(node.has_key("blend")) {
			setBlendMode(KRE::BlendMode(node["blend"]));
		}
		if(node.has_key("blend_equation")) {
			setBlendEquation(KRE::BlendEquation(node["blend_equation"]));
		} else if(node.has_key("blend_eq")) {
			setBlendEquation(KRE::BlendEquation(node["blend_eq"]));
		}
		if(node.has_key("rotation")) {
			const variant& rot = node["rotation"];
			if(rot.is_numeric()) {
				// Assume it's a simple rotation around z-axis
				setRotation(rot.as_float(), glm::vec3(0.f,0.f,1.f));
			} else if(rot.is_list()) {
				// Either a single rotation formatted as [angle,[x,y,z]] or a list of three euler angles
				if(rot.num_elements() == 2) {
					ASSERT_LOG(rot[1].is_list() && rot[1].num_elements() == 3,
						"Format for a single rotation is [angle, [x,y,z]]");
					setRotation(rot[0].as_float(), variant_to_vec3(rot[1]));
				} else if(rot.num_elements() == 3) {
					setRotation(rot[0].as_float(), glm::vec3(1.,0.,0.));
					setRotation(rot[1].as_float(), glm::vec3(0.,1.,0.));
					setRotation(rot[2].as_float(), glm::vec3(0.,0.,1.));
				} else {
					ASSERT_LOG(false, "Need a list of three (x/y/z rotations) or 2 elements (angle, [axis])");
				}
			}
		}
		if(node.has_key("translation") || node.has_key("position")) {
			const variant& pos = node.has_key("translation") ? node["translation"] : node["position"];
			ASSERT_LOG(pos.is_list() && (pos.num_elements() == 2 || pos.num_elements() == 3),
				"'translation'/'position' attribute should have 2 [x,y] or 3 [x,y,z] elements.");
			if(pos.num_elements() == 3) {
				setPosition(variant_to_vec3(pos));
			} else {
				setPosition(pos[0].as_float(), pos[1].as_float());
			}
		}
		if(node.has_key("scale")) {
			const variant& sc = node["scale"];
			if(sc.is_numeric()) {
				const float scale = sc.as_float();
				setScale(scale, scale, scale);
			} else if(sc.is_list()) {
				float xs = 1.0f;
				float ys = 1.0f;
				float zs = 1.0f;
				if(sc.num_elements() == 1) {
					xs = sc[0].as_float();
				} else if(sc.num_elements() == 2) {
					xs = sc[0].as_float();
					ys = sc[1].as_float();
				} else if(sc.num_elements() == 3) {
					xs = sc[0].as_float();
					ys = sc[1].as_float();
					zs = sc[2].as_float();
				}
				setScale(xs, ys, zs);
			} else {
				ASSERT_LOG(false, "Scale should be a number of a list of up to three elements.");
			}
		}
		if(node.has_key("color")) {
			setColor(KRE::Color(node["color"]));
		}
		if(node.has_key("texture")) {
			texture_ = Texture::createTexture(node["texture"]);
		} else if(node.has_key("image")) {
			texture_ = Texture::createTexture(node["image"]);			
		}
		if(node.has_key("depth_check")) {
			setDepthEnable(node["depth_check"].as_bool());
		}
		if(node.has_key("depth_write")) {
			setDepthWrite(node["depth_write"].as_bool());
		}
		// XXX add depth function.
		if(node.has_key("use_lighting")) {
			enableLighting(node["use_lighting"].as_bool());
		}
	}