예제 #1
0
파일: graphics.cpp 프로젝트: funcman/bsgl
void CALL BSGL_Impl::Gfx_RenderTriple(const bsglTriple* triple) {
    if( (CurPrimType != BSGLPRIM_TRIPLES)
    ||  (nPrim >= VERTEX_BUFFER_SIZE/BSGLPRIM_TRIPLES)
    ||  (CurTexture != triple->tex)
    ||  (CurBlendMode != triple->blend) ) {
        _render_batch();

        CurPrimType = BSGLPRIM_TRIPLES;
        if( CurBlendMode != triple->blend ) {
            _SetBlendMode(triple->blend);
        }
        if( CurTexture != triple->tex ) {
            if( triple->tex ) {
#if !defined(Q_OS_IOS) && !defined(Q_OS_ANDROID)
                glBindTexture(GL_TEXTURE_2D, *(GLuint*)triple->tex);
            }else {
                glBindTexture(GL_TEXTURE_2D, 0);
#else
                setTextureUnit(*(GLuint*)triple->tex);
            }else {
                setTextureUnit(0);
#endif
            }
            CurTexture = triple->tex;
        }
예제 #2
0
SkyboxShader::SkyboxShader() : Shader("skybox_vert.glsl", "skybox_frag.glsl") {
	addUniform("worldToViewMatrix");
	addUniform("viewToProjectionMatrix");
	addUniform("modColour");
	addUniform("ambientLight");
	setTextureUnit("theTexture");
}
예제 #3
0
//-----------------------------------------------------------------------
bool FFPTexturing::preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass)
{
	//count the number of texture units we need to process
	size_t validTexUnits = 0;
	for (unsigned short i=0; i < srcPass->getNumTextureUnitStates(); ++i)
	{		
		if (isProcessingNeeded(srcPass->getTextureUnitState(i)))
		{
			++validTexUnits;
		}
	}

	setTextureUnitCount(validTexUnits);

	// Build texture stage sub states.
	for (unsigned short i=0; i < srcPass->getNumTextureUnitStates(); ++i)
	{		
		TextureUnitState* texUnitState = srcPass->getTextureUnitState(i);								

		if (isProcessingNeeded(texUnitState))
		{
			setTextureUnit(i, texUnitState);	
		}
	}	

	return true;
}
예제 #4
0
파일: OpenGL.cpp 프로젝트: Leandros/love2d
void OpenGL::bindTextureToUnit(GLuint texture, int textureunit, bool restoreprev)
{
	if (textureunit < 0 || (size_t) textureunit >= state.boundTextures.size())
		throw love::Exception("Invalid texture unit index.");

	if (texture != state.boundTextures[textureunit])
	{
		int oldtextureunit = state.curTextureUnit;
		setTextureUnit(textureunit);

		state.boundTextures[textureunit] = texture;
		glBindTexture(GL_TEXTURE_2D, texture);

		if (restoreprev)
			setTextureUnit(oldtextureunit);
	}
}
ForwardAmbientLightShader::ForwardAmbientLightShader() : Shader("forward_ambient_vert.glsl",
																"forward_ambient_frag.glsl") {
	addUniform("ambientLight");
	addUniform("worldToProjectionMatrix");
	addUniform("modelToWorldMatrix");
	addUniform("modColour");

	setTextureUnit("theTexture");
}
예제 #6
0
//-----------------------------------------------------------------------
void FFPTexturing::copyFrom(const SubRenderState& rhs)
{
	const FFPTexturing& rhsTexture = static_cast<const FFPTexturing&>(rhs);

	setTextureUnitCount(rhsTexture.getTextureUnitCount());

	for (unsigned int i=0; i < rhsTexture.getTextureUnitCount(); ++i)
	{
		setTextureUnit(i, rhsTexture.mTextureUnitParamsList[i].mTextureUnitState);
	}		
}
	bool COGLES2SLMaterialRenderer::enableMaterialTexture( const c8* name, int materialId )
	{
		ITexture * t = Driver->getTextureByIndex( materialId );
		COGLES2Texture * tex = reinterpret_cast<COGLES2Texture*>( t );
		if ( !tex )
			return false;
		const GLuint unit = tex->getOGLES2TextureName();

		glActiveTexture( GL_TEXTURE0 + unit );
		glBindTexture( GL_TEXTURE_2D, unit );

		return setTextureUnit( name, unit );
	}
예제 #8
0
//-----------------------------------------------------------------------
bool FFPTexturing::preAddToRenderState(RenderState* renderState, Pass* srcPass, Pass* dstPass)
{
	setTextureUnitCount(srcPass->getNumTextureUnitStates());

	// Build texture stage sub states.
	for (unsigned short i=0; i < srcPass->getNumTextureUnitStates(); ++i)
	{		
		TextureUnitState* texUnitState = srcPass->getTextureUnitState(i);								

		setTextureUnit(i, texUnitState);			
	}	

	return true;
}
예제 #9
0
ForwardSpotLightShader::ForwardSpotLightShader() : LightShader("forward_spot_vert.glsl", "forward_spot_frag.glsl") {
	addUniform("spotLight.pointLight.base.colour");
	addUniform("spotLight.pointLight.base.luminosity");
	addUniform("spotLight.pointLight.base.xray");
	addUniform("spotLight.pointLight.position");
	addUniform("spotLight.pointLight.range");
	addUniform("spotLight.pointLight.attenuation.quadratic");
	addUniform("spotLight.pointLight.attenuation.linear");
	addUniform("spotLight.pointLight.attenuation.constant");
	addUniform("spotLight.direction");
	addUniform("spotLight.cosineFov");

	addUniform("lightSpaceMatrix");
	setTextureUnit("shadowMap");
}
예제 #10
0
CSulShadow::CSulShadow( osg::Group* pSceneRoot ) :
osg::TexGenNode(),
m_posLight( 100.0f, 100.0f, 100.0f ),
m_fileShaderFrag(""),
m_fileShaderVert(""),
m_size_squared( 1024 )
{
//	setStateSet( osg::StateAttribute::ON | osg::StateAttribute::PROTECTED );
	getStateSet()->setAttribute( 
		getStateSet()->getAttribute( osg::StateAttribute::TEXGEN ),
		osg::StateAttribute::ON | osg::StateAttribute::PROTECTED );
	
	

	m_rSceneRoot = pSceneRoot;

	m_rCasters = new osg::Group;

	setTextureUnit( 3 );
}
예제 #11
0
void GrGpuGLFixed::resetContext() {
    INHERITED::resetContext();

    GR_GL(Disable(GR_GL_TEXTURE_2D));

    for (int s = 0; s < kNumStages; ++s) {
        setTextureUnit(s);
        GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_TEXTURE_ENV_MODE, GR_GL_COMBINE));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_RGB,   GR_GL_MODULATE));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_RGB,      GR_GL_TEXTURE0+s));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_RGB,      GR_GL_PREVIOUS));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_RGB,  GR_GL_SRC_COLOR));

        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_COMBINE_ALPHA, GR_GL_MODULATE));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC0_ALPHA, GR_GL_TEXTURE0+s));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND0_ALPHA, GR_GL_SRC_ALPHA));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_SRC1_ALPHA, GR_GL_PREVIOUS));
        GR_GL(TexEnvi(GR_GL_TEXTURE_ENV, GR_GL_OPERAND1_ALPHA, GR_GL_SRC_ALPHA));

        // color oprand0 changes between GL_SRC_COLR and GL_SRC_ALPHA depending
        // upon whether we have a (premultiplied) RGBA texture or just an ALPHA
        // texture, e.g.:
        //glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,  GL_SRC_COLOR);
        fHWRGBOperand0[s] = (TextureEnvRGBOperands) -1;
    }

    fHWGeometryState.fVertexLayout = 0;
    fHWGeometryState.fVertexOffset  = ~0;
    GR_GL(EnableClientState(GR_GL_VERTEX_ARRAY));
    GR_GL(DisableClientState(GR_GL_TEXTURE_COORD_ARRAY));
    GR_GL(ShadeModel(GR_GL_FLAT));
    GR_GL(DisableClientState(GR_GL_COLOR_ARRAY));

    GR_GL(PointSize(1.f));

    GrGLClearErr();
    fTextVerts = false;

    fBaseVertex = 0xffffffff;
}
예제 #12
0
bool GrGpuGLFixed::flushGraphicsState(GrPrimitiveType type) {

    bool usingTextures[kNumStages];

    for (int s = 0; s < kNumStages; ++s) {
        usingTextures[s] = VertexUsesStage(s, fGeometrySrc.fVertexLayout);

        if (usingTextures[s] && fCurrDrawState.fSamplerStates[s].isGradient()) {
            unimpl("Fixed pipe doesn't support radial/sweep gradients");
            return false;
        }
    }

    if (GR_GL_SUPPORT_ES1) {
        if (BlendCoefReferencesConstant(fCurrDrawState.fSrcBlend) ||
            BlendCoefReferencesConstant(fCurrDrawState.fDstBlend)) {
            unimpl("ES1 doesn't support blend constant");
            return false;
        }
    }

    if (!flushGLStateCommon(type)) {
        return false;
    }

    if (fDirtyFlags.fRenderTargetChanged) {
        flushProjectionMatrix();
    }

    for (int s = 0; s < kNumStages; ++s) {
        bool wasUsingTexture = VertexUsesStage(s, fHWGeometryState.fVertexLayout);
        if (usingTextures[s] != wasUsingTexture) {
            setTextureUnit(s);
            if (usingTextures[s]) {
                GR_GL(Enable(GR_GL_TEXTURE_2D));
            } else {
                GR_GL(Disable(GR_GL_TEXTURE_2D));
            }
        }
    }

    uint32_t vertColor = (fGeometrySrc.fVertexLayout & kColor_VertexLayoutBit);
    uint32_t prevVertColor = (fHWGeometryState.fVertexLayout &
                              kColor_VertexLayoutBit);

    if (vertColor != prevVertColor) {
        if (vertColor) {
            GR_GL(ShadeModel(GR_GL_SMOOTH));
            // invalidate the immediate mode color
            fHWDrawState.fColor = GrColor_ILLEGAL;
        } else {
            GR_GL(ShadeModel(GR_GL_FLAT));
        }
    }


    if (!vertColor && fHWDrawState.fColor != fCurrDrawState.fColor) {
        GR_GL(Color4ub(GrColorUnpackR(fCurrDrawState.fColor),
                       GrColorUnpackG(fCurrDrawState.fColor),
                       GrColorUnpackB(fCurrDrawState.fColor),
                       GrColorUnpackA(fCurrDrawState.fColor)));
        fHWDrawState.fColor = fCurrDrawState.fColor;
    }

    // set texture environment, decide whether we are modulating by RGB or A.
    for (int s = 0; s < kNumStages; ++s) {
        if (usingTextures[s]) {
            GrGLTexture* texture = (GrGLTexture*)fCurrDrawState.fTextures[s];
            if (NULL != texture) {
                TextureEnvRGBOperands nextRGBOperand0 =
                    (GrPixelConfigIsAlphaOnly(texture->config())) ?
                        kAlpha_TextureEnvRGBOperand :
                        kColor_TextureEnvRGBOperand;
                if (fHWRGBOperand0[s] != nextRGBOperand0) {
                    setTextureUnit(s);
                    GR_GL(TexEnvi(GR_GL_TEXTURE_ENV,
                                  GR_GL_OPERAND0_RGB,
                                  (nextRGBOperand0==kAlpha_TextureEnvRGBOperand) ?
                                    GR_GL_SRC_ALPHA :
                                    GR_GL_SRC_COLOR));
                    fHWRGBOperand0[s] = nextRGBOperand0;
                }

                if (((1 << s) & fDirtyFlags.fTextureChangedMask) ||
                    (fHWDrawState.fSamplerStates[s].getMatrix() !=
                     getSamplerMatrix(s))) {

                    GrMatrix texMat = getSamplerMatrix(s);
                    AdjustTextureMatrix(texture,
                                        GrSamplerState::kNormal_SampleMode,
                                        &texMat);
                    GrGpuMatrix glm;
                    glm.set(texMat);
                    setTextureUnit(s);
                    GR_GL(MatrixMode(GR_GL_TEXTURE));
                    GR_GL(LoadMatrixf(glm.fMat));
                    recordHWSamplerMatrix(s, getSamplerMatrix(s));
                }
            } else {
                GrAssert(!"Rendering with texture vert flag set but no bound texture");
                return false;
            }
        }
    }

    if (fHWDrawState.fViewMatrix != fCurrDrawState.fViewMatrix) {
        GrGpuMatrix glm;
        glm.set(fCurrDrawState.fViewMatrix);
        GR_GL(MatrixMode(GR_GL_MODELVIEW));
        GR_GL(LoadMatrixf(glm.fMat));
        fHWDrawState.fViewMatrix =
        fCurrDrawState.fViewMatrix;
    }
    resetDirtyFlags();
    return true;
}