void COGL_FragmentProgramCombiner::GenerateCombinerSettingConstants(int index)
{
    float *pf;
    pf = GetEnvColorfv();
    pglProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 1, pf);
    OPENGL_CHECK_ERRORS;
    pf = GetPrimitiveColorfv();
    pglProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 2, pf);
    OPENGL_CHECK_ERRORS;

    float frac = gRDP.LODFrac / 255.0f;
    float tempf[4] = {frac,frac,frac,frac};
    pglProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 3, tempf);
    OPENGL_CHECK_ERRORS;

    float frac2 = gRDP.primLODFrac / 255.0f;
    float tempf2[4] = {frac2,frac2,frac2,frac2};
    pglProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 4, tempf2);
    OPENGL_CHECK_ERRORS;

    float tempf3[4] = {0,0,0,0};
    pglProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, tempf3);
    OPENGL_CHECK_ERRORS;
    pglProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 6, tempf3);
    OPENGL_CHECK_ERRORS;
}
Ejemplo n.º 2
0
void COGLColorCombinerTNT2::GenerateCombinerSettingConstants(int index)
{
    TNT2CombinerSaveType &res = m_vCompiledTNTSettings[index];
    for( int i=0; i<2; i++ )
    {
        float *fv;
        glActiveTextureARB(GL_TEXTURE0_ARB+i);
        switch( res.units[i].constant & MUX_MASK )
        {
        case MUX_PRIM:
            fv = GetPrimitiveColorfv();
            glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,fv);
            break;
        case MUX_ENV:
            fv = GetEnvColorfv();
            glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,fv);
            break;
        case MUX_LODFRAC:
            {
                float frac = gRDP.LODFrac / 255.0f;
                float tempf[4] = {frac,frac,frac,frac};
                glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,tempf);
                break;
            }
        case MUX_PRIMLODFRAC:
            {
                float frac = gRDP.primLODFrac / 255.0f;
                float tempf[4] = {frac,frac,frac,frac};
                glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,tempf);
                break;
            }
        }
    }
}
Ejemplo n.º 3
0
void COGLColorCombinerNvidia::GenerateNVRegisterCombinerSettingConstants(int index)
{
    NVRegisterCombinerSettingType &info = m_vCompiledSettings[index];
    uint8 consts[2] = {info.constant0,info.constant1};

    float *pf;

    for( int i=0; i<2; i++ )
    {
        switch( consts[i] )
        {
        case MUX_PRIM:
            pf = GetPrimitiveColorfv();
            pglCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV+i,pf);
            break;
        case MUX_ENV:
            pf = GetEnvColorfv();
            pglCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV+i,pf);
            break;
        case MUX_LODFRAC:
        case MUX_PRIMLODFRAC:
            {
                float frac = gRDP.primLODFrac / 255.0f;
                float tempf[4] = {frac,frac,frac,frac};
                pglCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV+i,tempf);
                break;
            }
        }
    }
}
void COGL_FragmentProgramCombiner::GenerateCombinerSettingConstants(int index)
{
    OGLShaderCombinerSaveType prog = m_vCompiledShaders[index];

    glUseProgram(prog.programID);
    float *pf;
    if(prog.EnvColorLocation != -1)
    {
        pf = GetEnvColorfv();
        glUniform4fv(prog.EnvColorLocation,1, pf);
        OPENGL_CHECK_ERRORS;
    }

    if(prog.PrimColorLocation != -1)
    {
        pf = GetPrimitiveColorfv();
        glUniform4fv(prog.PrimColorLocation,1, pf);
        OPENGL_CHECK_ERRORS;
    }

    if(prog.EnvFracLocation != -1)
    {
        float frac = gRDP.LODFrac / 255.0f;
        float tempf[4] = {frac,frac,frac,frac};
        glUniform4fv(prog.EnvFracLocation,1, tempf);
        OPENGL_CHECK_ERRORS;
    }

    if(prog.PrimFracLocation != -1)
    {
        float frac2 = gRDP.primLODFrac / 255.0f;
        float tempf2[4] = {frac2,frac2,frac2,frac2};
        glUniform4fv(prog.PrimFracLocation,1, tempf2);
        OPENGL_CHECK_ERRORS;
    }

	if(prog.FogColorLocation != -1)
    {
        glUniform4f(prog.FogColorLocation, gRDP.fvFogColor[0],gRDP.fvFogColor[1],gRDP.fvFogColor[2], gRDP.fvFogColor[3]);
        OPENGL_CHECK_ERRORS;
    }
	
	if(prog.FogMinMaxLocation != -1)	
	{
        glUniform2f(prog.FogMinMaxLocation,gRSPfFogMin,gRSPfFogMax);
        OPENGL_CHECK_ERRORS;
    }
	
    if(prog.AlphaRefLocation != -1)
	{
        glUniform1f(prog.AlphaRefLocation,m_AlphaRef);
		OPENGL_CHECK_ERRORS;
	}
}
void COGL_FragmentProgramCombiner::GenerateCombinerSettingConstants(int index)
{
    OGLShaderCombinerSaveType prog = m_vCompiledShaders[index];

    glUseProgram(prog.programID);
    float *pf;
    if(prog.EnvColorLocation != -1)
    {
        pf = GetEnvColorfv();
        glUniform4fv(prog.EnvColorLocation,1, pf);
        OPENGL_CHECK_ERRORS;
    }

    if(prog.PrimColorLocation != -1)
    {
        pf = GetPrimitiveColorfv();
        glUniform4fv(prog.PrimColorLocation,1, pf);
        OPENGL_CHECK_ERRORS;
    }

    if(prog.EnvFracLocation != -1)
    {
        float frac = gRDP.LODFrac / 255.0f;
        float tempf[4] = {frac,frac,frac,frac};
        glUniform4fv(prog.EnvFracLocation,1, tempf);
        OPENGL_CHECK_ERRORS;
    }

    if(prog.PrimFracLocation != -1)
    {
        float frac2 = gRDP.primLODFrac / 255.0f;
        float tempf2[4] = {frac2,frac2,frac2,frac2};
        glUniform4fv(prog.PrimFracLocation,1, tempf2);
        OPENGL_CHECK_ERRORS;
    }

    //if(prog.FogColorLocation != -1 && prog.FogMinMaxLocation != -1)
    //{
    //    //Pass fog colour and distance, use 0 alpha if fog disabled
    //    glUniform4f(prog.FogColorLocation, gRDP.fvFogColor[0],gRDP.fvFogColor[1],gRDP.fvFogColor[2],
    //        gRSP.bFogEnabled ? gRDP.fvFogColor[0] : 0.0f);
    //    glUniform2f(prog.FogMinMaxLocation,gRSPfFogMin,gRSPfFogMax);
    //}

    if(prog.AlphaRefLocation != -1)
        glUniform1f(prog.AlphaRefLocation,m_AlphaRef);
    OPENGL_CHECK_ERRORS;
}
Ejemplo n.º 6
0
void CDirectXPixelShaderCombiner::InitCombinerCycle12(void)
{
	// Step 1: set pixel shader
	int idx = FindCompiledShader();
	if( idx < 0 )	idx = GeneratePixelShaderFromMux();

	gD3DDevWrapper.SetPixelShader(m_pixelShaderList[idx].pShader);

	// Step 2: set constant colors
	float *pf;
	pf = GetPrimitiveColorfv();
	gD3DDevWrapper.SetPixelShaderConstant(2,pf);

	pf = GetEnvColorfv();
	gD3DDevWrapper.SetPixelShaderConstant(3,pf);

	float frac = gRDP.LODFrac / 255.0f;
	float tempf[4] = {frac,frac,frac,frac};
	gD3DDevWrapper.SetPixelShaderConstant(4,tempf);

	float frac2 = gRDP.primLODFrac / 255.0f;
	float tempf2[4] = {frac2,frac2,frac2,frac2};
	gD3DDevWrapper.SetPixelShaderConstant(5,tempf2);

	m_pD3DRender->m_curCombineInfo.nStages = 2;
	m_pD3DRender->m_curCombineInfo.stages[0].dwTexture = 0;
	m_pD3DRender->m_curCombineInfo.stages[1].dwTexture = 1;

	// Step 3: set textures
	if( m_bTex0Enabled ) 
	{
		m_pD3DRender->SetTexelRepeatFlags(gRSP.curTile);

		if( g_textures[gRSP.curTile].m_pCTexture != NULL )
			gD3DDevWrapper.SetTexture( 0, g_textures[gRSP.curTile].m_lpsTexturePtr );
	}

	if( m_bTex1Enabled )
	{
		m_pD3DRender->SetTexelRepeatFlags((gRSP.curTile+1)&7);
		if( g_textures[(gRSP.curTile+1)&7].m_pCTexture != NULL )
			gD3DDevWrapper.SetTexture( 1, g_textures[(gRSP.curTile+1)&7].m_lpsTexturePtr );
	}

	gRDP.texturesAreReloaded = false;
}
void COGLColorCombiner4::GenerateCombinerSettingConstants(int index)
{
    OGLExtCombinerSaveType &res = m_vCompiledSettings[index];

    float *fv;
    float tempf[4];

    bool isused = true;

    if( res.primIsUsed )
    {
        fv = GetPrimitiveColorfv(); // CONSTANT COLOR
    }
    else if( res.envIsUsed )
    {
        fv = GetEnvColorfv();   // CONSTANT COLOR
    }
    else if( res.lodFracIsUsed )
    {
        float frac = gRDP.LODFrac / 255.0f;
        tempf[0] = tempf[1] = tempf[2] = tempf[3] = frac;
        fv = &tempf[0];
    }
    else
    {
        isused = false;
    }

    if( isused )
    {
        for( int i=0; i<res.numOfUnits; i++ )
        {
            glActiveTexture(GL_TEXTURE0+i);
            OPENGL_CHECK_ERRORS;
//            glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,fv);
            OPENGL_CHECK_ERRORS;
        }
    }
}
void COGL_FragmentProgramCombiner::GenerateCombinerSettingConstants(int index)
{
    OGLShaderCombinerSaveType &prog = m_vCompiledShaders[index];

    UseProgram(prog.programID);
    float *pf;
    if(prog.EnvColorLocation != -1)
    {
        pf = GetEnvColorfv();
        if (memcmp(pf, prog.EnvColors, sizeof(prog.EnvColors))) {
            memcpy(prog.EnvColors, pf, sizeof(prog.EnvColors));
            glUniform4fv(prog.EnvColorLocation, 1, pf);
            OPENGL_CHECK_ERRORS;
        }
    }

    if(prog.PrimColorLocation != -1)
    {
        pf = GetPrimitiveColorfv();
        if (memcmp(pf, prog.PrimColors, sizeof(prog.PrimColors))) {
            memcpy(prog.PrimColors, pf, sizeof(prog.PrimColors));
            glUniform4fv(prog.PrimColorLocation, 1, pf);
            OPENGL_CHECK_ERRORS;
        }
    }

    if(prog.EnvFracLocation != -1)
    {
        // avoid slow float compare..
        if( *(int *)&gRDP.LODFrac != *(int *)&prog.EnvLODFrac ) {
            prog.EnvLODFrac = gRDP.LODFrac;
            float frac = gRDP.LODFrac / 255.0f;
            float tempf[4] = {frac,frac,frac,frac};
            glUniform4fv(prog.EnvFracLocation, 1, tempf);
            OPENGL_CHECK_ERRORS;
        }
    }

    if(prog.PrimFracLocation != -1)
    {
        if( *(int *)&gRDP.primLODFrac != *(int *)&prog.PrimLODFrac ) {
            prog.PrimLODFrac = gRDP.primLODFrac;
            float frac2 = gRDP.primLODFrac / 255.0f;
            float tempf2[4] = {frac2,frac2,frac2,frac2};
            glUniform4fv(prog.PrimFracLocation, 1, tempf2);
            OPENGL_CHECK_ERRORS;
        }
    }

    if(prog.FogColorLocation != -1)
    {
        pf = &gRDP.fvFogColor[0];
        if (memcmp(pf, prog.FogColors, sizeof(prog.FogColors))) {
            memcpy(prog.FogColors, pf, sizeof(prog.FogColors));
            glUniform4fv(prog.FogColorLocation, 1, pf);
            OPENGL_CHECK_ERRORS;
        }
    }
	
    if(prog.FogMinMaxLocation != -1)	
    {
        if( gRSPfFogMin != prog.FogMin || gRSPfFogMax != prog.FogMax ) {
            prog.FogMin = gRSPfFogMin;
            prog.FogMax = gRSPfFogMax;
            glUniform2f(prog.FogMinMaxLocation,gRSPfFogMin,gRSPfFogMax);
            OPENGL_CHECK_ERRORS;
        }
    }
	
    if(prog.AlphaRefLocation != -1)
    {
        if( m_AlphaRef != prog.AlphaRef ) {
            prog.AlphaRef = m_AlphaRef;
            glUniform1f(prog.AlphaRefLocation, m_AlphaRef);
            OPENGL_CHECK_ERRORS;
        }
    }
}
Ejemplo n.º 9
0
void COGLColorCombiner::InitCombinerCycle12(void)
{
    m_pOGLRender->DisableMultiTexture();
    if( !m_bTexelsEnable )
    {
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        OPENGL_CHECK_ERRORS;
        m_pOGLRender->EnableTexUnit(0,FALSE);
        return;
    }

    uint32 mask = 0x1f;
    COGLTexture* pTexture = g_textures[gRSP.curTile].m_pCOGLTexture;
    if( pTexture )
    {
        m_pOGLRender->EnableTexUnit(0,TRUE);
        m_pOGLRender->BindTexture(pTexture->m_dwTextureName, 0);
        m_pOGLRender->SetAllTexelRepeatFlag();
    }
#ifdef DEBUGGER
    else
    {
        DebuggerAppendMsg("Check me, texture is NULL");
    }
#endif

    bool texIsUsed = m_pDecodedMux->isUsed(MUX_TEXEL0);
    bool shadeIsUsedInColor = m_pDecodedMux->isUsedInCycle(MUX_SHADE, 0, COLOR_CHANNEL);
    bool texIsUsedInColor = m_pDecodedMux->isUsedInCycle(MUX_TEXEL0, 0, COLOR_CHANNEL);

    if( texIsUsed )
    {
        // Parse the simplified the mux, because the OGL 1.1 combiner function is so much
        // limited, we only parse the 1st N64 combiner setting and only the RGB part

        N64CombinerType & comb = m_pDecodedMux->m_n64Combiners[0];
        switch( m_pDecodedMux->mType )
        {
        case CM_FMT_TYPE_NOT_USED:
        case CM_FMT_TYPE_D:             // = A
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            OPENGL_CHECK_ERRORS;
            break;
        case CM_FMT_TYPE_A_ADD_D:           // = A+D
            if( shadeIsUsedInColor && texIsUsedInColor )
            {
                if( m_bSupportAdd )
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);
                else
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
            }
            else if( texIsUsedInColor )
            {
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            }
            else
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
            OPENGL_CHECK_ERRORS;
            break;
        case CM_FMT_TYPE_A_SUB_B:           // = A-B
            if( shadeIsUsedInColor && texIsUsedInColor )
            {
                if( m_bSupportSubtract )
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_SUBTRACT_ARB);
                else
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
            }
            else if( texIsUsedInColor )
            {
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            }
            else
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
            OPENGL_CHECK_ERRORS;
            break;
        case CM_FMT_TYPE_A_MOD_C:           // = A*C
        case CM_FMT_TYPE_A_MOD_C_ADD_D: // = A*C+D
            if( shadeIsUsedInColor && texIsUsedInColor )
            {
                if( ((comb.c & mask) == MUX_SHADE && !(comb.c&MUX_COMPLEMENT)) || 
                    ((comb.a & mask) == MUX_SHADE && !(comb.a&MUX_COMPLEMENT)) )
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                else
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            }
            else if( texIsUsedInColor )
            {
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            }
            else
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
            OPENGL_CHECK_ERRORS;
            break;
        case CM_FMT_TYPE_A_LERP_B_C:    // = A*C+D
            if( (comb.b&mask) == MUX_SHADE && (comb.c&mask)==MUX_TEXEL0 && ((comb.a&mask)==MUX_PRIM||(comb.a&mask)==MUX_ENV))
            {
                float *fv;
                if( (comb.a&mask)==MUX_PRIM )
                {
                    fv = GetPrimitiveColorfv();
                }
                else
                {
                    fv = GetEnvColorfv();
                }

                glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,fv);
                OPENGL_CHECK_ERRORS;
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
                OPENGL_CHECK_ERRORS;
                break;
            }
        default:        // = (A-B)*C+D
            if( shadeIsUsedInColor )
            {
                if( ((comb.c & mask) == MUX_SHADE && !(comb.c&MUX_COMPLEMENT)) || 
                    ((comb.a & mask) == MUX_SHADE && !(comb.a&MUX_COMPLEMENT)) )
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
                else
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            }
            else
            {
                glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            }
            OPENGL_CHECK_ERRORS;
            break;
        }
    }
    else
    {
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
        OPENGL_CHECK_ERRORS;
    }
}