int lua_RenderStateStateBlock_setBlend(lua_State* state)
{
    // Get the number of parameters.
    int paramCount = lua_gettop(state);

    // Attempt to match the parameters to a valid binding.
    switch (paramCount)
    {
        case 2:
        {
            if ((lua_type(state, 1) == LUA_TUSERDATA) &&
                lua_type(state, 2) == LUA_TBOOLEAN)
            {
                // Get parameter 1 off the stack.
                bool param1 = ScriptUtil::luaCheckBool(state, 2);

                RenderState::StateBlock* instance = getInstance(state);
                instance->setBlend(param1);
                
                return 0;
            }

            lua_pushstring(state, "lua_RenderStateStateBlock_setBlend - Failed to match the given parameters to a valid function signature.");
            lua_error(state);
            break;
        }
        default:
        {
            lua_pushstring(state, "Invalid number of parameters (expected 2).");
            lua_error(state);
            break;
        }
    }
    return 0;
}
Beispiel #2
0
void Form::setNode(Node* node)
{
    // If the user wants a custom node then we need to create a 3D quad
    if (node && node != _node)
    {
        // Set this Form up to be 3D by initializing a quad.
        float x2 = _bounds.width;
        float y2 = _bounds.height;
        float vertices[] =
        {
            0, y2, 0,   0, _v1,
            0, 0, 0,    0, 0,
            x2, y2, 0,  _u2, _v1,
            x2, 0, 0,   _u2, 0
        };
        VertexFormat::Element elements[] =
        {
            VertexFormat::Element(VertexFormat::POSITION, 3),
            VertexFormat::Element(VertexFormat::TEXCOORD0, 2)
        };
        Mesh* mesh = Mesh::createMesh(VertexFormat(elements, 2), 4, false);
        GP_ASSERT(mesh);
        mesh->setPrimitiveType(Mesh::TRIANGLE_STRIP);
        mesh->setVertexData(vertices, 0, 4);

        _nodeQuad = Model::create(mesh);
        SAFE_RELEASE(mesh);
        GP_ASSERT(_nodeQuad);

        // Create the effect and material
        Effect* effect = createEffect();
        GP_ASSERT(effect);
        _nodeMaterial = Material::create(effect);

        GP_ASSERT(_nodeMaterial);
        _nodeQuad->setMaterial(_nodeMaterial);
        _nodeMaterial->release();
        node->setModel(_nodeQuad);
        _nodeQuad->release();

        // Bind the WorldViewProjection matrix.
        _nodeMaterial->setParameterAutoBinding("u_worldViewProjectionMatrix", RenderState::WORLD_VIEW_PROJECTION_MATRIX);

        // Bind the texture from the framebuffer and set the texture to clamp
        Texture::Sampler* sampler = Texture::Sampler::create(_frameBuffer->getRenderTarget()->getTexture());
        GP_ASSERT(sampler);
        sampler->setWrapMode(Texture::CLAMP, Texture::CLAMP);
        _nodeMaterial->getParameter("u_texture")->setValue(sampler);
        sampler->release();

        RenderState::StateBlock* rsBlock = _nodeMaterial->getStateBlock();
        rsBlock->setDepthWrite(true);
        rsBlock->setBlend(true);
        rsBlock->setBlendSrc(RenderState::BLEND_SRC_ALPHA);
        rsBlock->setBlendDst(RenderState::BLEND_ONE_MINUS_SRC_ALPHA);
    }
    _node = node;
}
Beispiel #3
0
Material *gamehsp::makeMaterialTex2D( char *fname, int matopt )
{
	bool mipmap;
	mipmap = (matopt & GPOBJ_MATOPT_NOMIPMAP ) == 0;

    Texture* texture = Texture::create(fname);
	if ( texture == NULL ) {
        Alertf("Texture not found.(%s)",fname);
		return NULL;
	}
	_tex_width = texture->getWidth();
	_tex_height = texture->getHeight();

    // Search for the first sampler uniform in the effect.
    Uniform* samplerUniform = NULL;
    for (unsigned int i = 0, count = _spriteEffect->getUniformCount(); i < count; ++i)
    {
        Uniform* uniform = _spriteEffect->getUniform(i);
        if (uniform && uniform->getType() == GL_SAMPLER_2D)
        {
            samplerUniform = uniform;
            break;
        }
    }
    if (!samplerUniform)
    {
        GP_ERROR("No uniform of type GL_SAMPLER_2D found in sprite effect.");
        return NULL;
    }

	RenderState::StateBlock *state;

	// Wrap the effect in a material
    Material* mesh_material = Material::create(_spriteEffect); // +ref effect

    // Bind the texture to the material as a sampler
    Texture::Sampler* sampler = Texture::Sampler::create(texture); // +ref texture
    mesh_material->getParameter(samplerUniform->getName())->setValue(sampler);

	/*
	Material* mesh_material = Material::create( SPRITE_VSH, SPRITE_FSH, NULL );
	if ( mesh_material == NULL ) {
        GP_ERROR("2D initalize failed.");
		return NULL;
	}
	mesh_material->getParameter("u_diffuseTexture")->setValue( fname, mipmap );
	*/

	mesh_material->getParameter("u_projectionMatrix")->setValue(_projectionMatrix2D);

	state = mesh_material->getStateBlock();

	state->setCullFace(false);
	state->setDepthTest(false);
	state->setDepthWrite(false);
	state->setBlend(true);
	state->setBlendSrc(RenderState::BLEND_SRC_ALPHA);
	state->setBlendDst(RenderState::BLEND_ONE_MINUS_SRC_ALPHA);

	SAFE_RELEASE( texture );
	return mesh_material;
}
Beispiel #4
0
void gamehsp::setMaterialDefaultBinding( Material* material, int icolor, int matopt )
{
	// These parameters are normally set in a .material file but this example sets them programmatically.
    // Bind the uniform "u_worldViewProjectionMatrix" to use the WORLD_VIEW_PROJECTION_MATRIX from the scene's active camera and the node that the model belongs to.

//	material->getParameter("u_worldViewProjectionMatrix")->setValue( _camera->getWorldViewProjectionMatrix() );
//	material->getParameter("u_inverseTransposeWorldViewMatrix")->setValue( _camera->getInverseTransposeWorldViewMatrix() );
//	material->getParameter("u_cameraPosition")->setValue( _camera->getTranslation() );

//	material->getParameter("u_worldViewProjectionMatrix")->bindValue( _camera, &Node::getWorldViewProjectionMatrix );
//	material->getParameter("u_inverseTransposeWorldViewMatrix")->bindValue( _camera, &Node::getInverseTransposeWorldViewMatrix );
//	material->getParameter("u_cameraPosition")->bindValue( _camera, &Node::getTranslation );

	if ( hasParameter( material, "u_cameraPosition" ) )
		material->setParameterAutoBinding("u_cameraPosition", "CAMERA_WORLD_POSITION");
	if ( hasParameter( material, "u_worldViewProjectionMatrix" ) )
		material->setParameterAutoBinding("u_worldViewProjectionMatrix", "WORLD_VIEW_PROJECTION_MATRIX");
	if ( hasParameter( material, "u_inverseTransposeWorldViewMatrix" ) )
		material->setParameterAutoBinding("u_inverseTransposeWorldViewMatrix", "INVERSE_TRANSPOSE_WORLD_VIEW_MATRIX");

	Vector4 color;
	Node *light_node;

	if ( _curlight < 0 ) {
		//	カレントライトなし(シーンを参照)
		if ( hasParameter( material, "u_ambientColor" ) )
			material->setParameterAutoBinding("u_ambientColor", "SCENE_AMBIENT_COLOR");
		if ( hasParameter( material, "u_lightDirection" ) )
			material->setParameterAutoBinding("u_lightDirection", "SCENE_LIGHT_DIRECTION");
		if ( hasParameter( material, "u_lightColor" ) )
			material->setParameterAutoBinding("u_lightColor", "SCENE_LIGHT_COLOR");
	} else {
		//	カレントライトを反映させる
		gpobj *lgt;
		lgt = getObj( _curlight );
		light_node = lgt->_node;
		// ライトの方向設定
		if ( hasParameter( material, "u_lightDirection" ) )
			material->getParameter("u_lightDirection")->bindValue(light_node, &Node::getForwardVectorView);
		// ライトの色設定
		// (リアルタイムに変更を反映させる場合は再設定が必要。現在は未対応)
		Vector3 *vambient;
		vambient = (Vector3 *)&lgt->_vec[GPOBJ_USERVEC_WORK];
		if ( hasParameter( material, "u_lightColor" ) )
			material->getParameter("u_lightColor")->setValue(light_node->getLight()->getColor());
		if ( hasParameter( material, "u_ambientColor" ) )
			material->getParameter("u_ambientColor")->setValue( vambient );
	}

	//material->setParameterAutoBinding("u_ambientColor", "SCENE_AMBIENT_COLOR");
	//material->setParameterAutoBinding("u_lightDirection", "SCENE_LIGHT_DIRECTION");
	//material->setParameterAutoBinding("u_lightColor", "SCENE_LIGHT_COLOR");

	colorVector3( icolor, color );
	if ( hasParameter( material, "u_diffuseColor" ) )
		material->getParameter("u_diffuseColor")->setValue(color);

	gameplay::MaterialParameter *prm_modalpha;
	if ( hasParameter( material, "u_modulateAlpha" ) )
		prm_modalpha = material->getParameter("u_modulateAlpha");
	if ( prm_modalpha ) { prm_modalpha->setValue( 1.0f ); }

	RenderState::StateBlock *state;
	state = material->getStateBlock();

	state->setCullFace( (( matopt & GPOBJ_MATOPT_NOCULL )==0) );
	state->setDepthTest( (( matopt & GPOBJ_MATOPT_NOZTEST )==0) );
	state->setDepthWrite( (( matopt & GPOBJ_MATOPT_NOZWRITE )==0) );

	state->setBlend(true);
	if ( matopt & GPOBJ_MATOPT_BLENDADD ) {
		state->setBlendSrc(RenderState::BLEND_SRC_ALPHA);
		state->setBlendDst(RenderState::BLEND_ONE);
	} else {
		state->setBlendSrc(RenderState::BLEND_SRC_ALPHA);
		state->setBlendDst(RenderState::BLEND_ONE_MINUS_SRC_ALPHA);
	}

}