Пример #1
0
void sgMaterial::setTexture(unsigned int tex, sgTexture *texptr)
{
	if(tex == -1)
	{
		textures.push_back(texptr);
		getUniforms();
		return;
	}

	if(tex > textures.size())
		return;

	textures[tex] = texptr;
	getUniforms();
}
Пример #2
0
void sgMaterial::setTexture(unsigned int tex, const char *texfile, bool mipmaps)
{
	if(tex == -1 || tex >= textures.size())
	{
		textures.push_back(sgTexture::getTexture(texfile, mipmaps));
		getUniforms();
		return;
	}

	if(tex >= textures.size())
		return;

	textures[tex] = sgTexture::getTexture(texfile, mipmaps);
	getUniforms();
}
Пример #3
0
void sgMaterial::setShader(sgShader::BuiltInShaders shad)
{
	if(sgRenderer::oglversion <= 1)
		return;

	shader = sgShader::getShader(shad);
	getUniforms();
}
Пример #4
0
void sgMaterial::setShader(const char *vsname, const char *fsname)
{
	if(sgRenderer::oglversion <= 1)
		return;

	shader = sgShader::getShader(vsname, fsname);
	getUniforms();
}
Пример #5
0
void TranslatorHLSL::translate(TIntermNode *root, int compileOptions)
{
    const ShBuiltInResources &resources = getResources();
    int numRenderTargets = resources.EXT_draw_buffers ? resources.MaxDrawBuffers : 1;

    sh::OutputHLSL outputHLSL(getShaderType(), getShaderVersion(), getExtensionBehavior(),
        getSourcePath(), getOutputType(), numRenderTargets, getUniforms(), compileOptions);

    outputHLSL.output(root, getInfoSink().obj);

    mInterfaceBlockRegisterMap = outputHLSL.getInterfaceBlockRegisterMap();
    mUniformRegisterMap = outputHLSL.getUniformRegisterMap();
}
Пример #6
0
void sgMaterial::setDefault()
{
	culling = true;
	cullmode = GL_CCW;

	blending = false;
	blendsource = GL_ONE;
	blenddestination = GL_ONE_MINUS_SRC_ALPHA;

	lighting = true;
	colors = true;
	ambient.r = 0.2;
	ambient.g = 0.2;
	ambient.b = 0.2;
	ambient.a = 1.0;
	diffuse.r = 0.8;
	diffuse.g = 0.8;
	diffuse.b = 0.8;
	diffuse.a = 1.0;
	specular.r = 0.0;
	specular.g = 0.0;
	specular.b = 0.0;
	specular.a = 1.0;
	shininess = 0;
	emissive.r = 0.0;
	emissive.g = 0.0;
	emissive.b = 0.0;
	emissive.a = 1.0;

	alphatest = false;
	alphatestvalue = 0.75;

	depthtest = true;
	depthtestmode = GL_LEQUAL;
	depthwrite = true;

	mattex.makeIdentity();

	if(sgRenderer::oglversion > 1)
	{
		if(shader == NULL)
			shader = sgShader::getShader(sgShader::BIS_TEXTURE);

		getUniforms();
	}else
	{
		shader = NULL;
	}

}
void SFGL20UniformData::evaluateUniforms(void* prog) {
    SFGL20AbstractProgram* program=(SFGL20AbstractProgram*)prog;
    this->program=(SFGLSLSet*)program;

    gridUniforms.clear();

    SFPrimitive* primitive=program->getPrimitive();
    if(primitive!=0) {
        for (int i = 0; i < primitive->getBlocks().size(); i++) {
            SFProgramComponent* component=primitive->getComponents().at(i);
            SFPipelineRegister* reg=primitive->getBlocks()[i]->getRegister();
            vector<SFPipelineGrid*> grids=component->getGrid();
            for(int j=0; j<grids.size(); i++) {
                gridUniforms.push_back(getUniforms(reg->getName(), *grids.at(i)));
            }
        }
    }

    //vector<GLuint> textures;
    this->transformTextures.clear();
    transformStructureUniforms=evaluateStructureUniforms(program->getTransforms(),&transformTextures);
    //this->transformTextures=listToInts(textures);
    //textures.clear();
    this->materialTextures.clear();
    materialStructureUniforms=evaluateStructureUniforms(program->getMaterials(),&materialTextures);

    this->lightTextures.clear();
    lightStructureUniforms=evaluateStructureUniforms(program->getLight(),&this->lightTextures);
    //this->lightTextures=listToInts(textures);

    mainUniforms=new int[3];
    SFGLSLSet* set=program;
    mainUniforms[0]=glGetUniformLocation(set->getProgram(),"projection");
    mainUniforms[1]=glGetUniformLocation(set->getProgram(),"modelview");
    mainUniforms[2]=glGetUniformLocation(set->getProgram(),"vectorsModelview");

}
Пример #8
0
	void readyProgramsForUse()
	{
		getUniforms(simpleUIProgram, UNI_SIMPLE_UI_COUNT, simpleUIUniformNames, simpleUIUniforms);
		getUniforms(linGradProgram,  UNI_LIN_GRAD_COUNT,  linGradUniformNames,  linGradUniforms);
	}
Пример #9
0
void TranslatorHLSL::translate(TIntermNode *root, int compileOptions)
{
    const ShBuiltInResources &resources = getResources();
    int numRenderTargets = resources.EXT_draw_buffers ? resources.MaxDrawBuffers : 1;

    sh::AddDefaultReturnStatements(root);

    SeparateDeclarations(root);

    // TODO (oetuaho): Sequence operators should also be split in case there is dynamic indexing of
    // a vector or matrix as an l-value inside (RemoveDynamicIndexing transformation step generates
    // statements in this case).
    SplitSequenceOperator(root,
                          IntermNodePatternMatcher::kExpressionReturningArray |
                              IntermNodePatternMatcher::kUnfoldedShortCircuitExpression |
                              IntermNodePatternMatcher::kDynamicIndexingOfVectorOrMatrixInLValue,
                          getTemporaryIndex(), getSymbolTable(), getShaderVersion());

    // Note that SeparateDeclarations needs to be run before UnfoldShortCircuitToIf.
    UnfoldShortCircuitToIf(root, getTemporaryIndex());

    SeparateExpressionsReturningArrays(root, getTemporaryIndex());

    // Note that SeparateDeclarations needs to be run before SeparateArrayInitialization.
    SeparateArrayInitialization(root);

    // HLSL doesn't support arrays as return values, we'll need to make functions that have an array
    // as a return value to use an out parameter to transfer the array data instead.
    ArrayReturnValueToOutParameter(root, getTemporaryIndex());

    if (!shouldRunLoopAndIndexingValidation(compileOptions))
    {
        // HLSL doesn't support dynamic indexing of vectors and matrices.
        RemoveDynamicIndexing(root, getTemporaryIndex(), getSymbolTable(), getShaderVersion());
    }

    // Work around D3D9 bug that would manifest in vertex shaders with selection blocks which
    // use a vertex attribute as a condition, and some related computation in the else block.
    if (getOutputType() == SH_HLSL_3_0_OUTPUT && getShaderType() == GL_VERTEX_SHADER)
    {
        sh::RewriteElseBlocks(root, getTemporaryIndex());
    }

    bool precisionEmulation =
        getResources().WEBGL_debug_shader_precision && getPragma().debugShaderPrecision;

    if (precisionEmulation)
    {
        EmulatePrecision emulatePrecision(getSymbolTable(), getShaderVersion());
        root->traverse(&emulatePrecision);
        emulatePrecision.updateTree();
        emulatePrecision.writeEmulationHelpers(getInfoSink().obj, getShaderVersion(),
                                               getOutputType());
    }

    if ((compileOptions & SH_EXPAND_SELECT_HLSL_INTEGER_POW_EXPRESSIONS) != 0)
    {
        sh::ExpandIntegerPowExpressions(root, getTemporaryIndex());
    }

    sh::OutputHLSL outputHLSL(getShaderType(), getShaderVersion(), getExtensionBehavior(),
        getSourcePath(), getOutputType(), numRenderTargets, getUniforms(), compileOptions);

    outputHLSL.output(root, getInfoSink().obj);

    mInterfaceBlockRegisterMap = outputHLSL.getInterfaceBlockRegisterMap();
    mUniformRegisterMap = outputHLSL.getUniformRegisterMap();
}