// set texture modulation mode
static void ogl_SetTextureModulation( INDEX iScale)
{
  // check consistency
  ASSERT( _pGfx->gl_eCurrentAPI==GAT_OGL);
#ifndef NDEBUG                 
  // check current modulation
  GLint iRet;
  pglGetTexEnviv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &iRet);
  ASSERT( (GFX_iTexModulation[GFX_iActiveTexUnit]==1 && iRet==GL_MODULATE)
       || (GFX_iTexModulation[GFX_iActiveTexUnit]==2 && iRet==GL_COMBINE_EXT));
  OGL_CHECKERROR;
#endif
  
  // cached?
  ASSERT( iScale==1 || iScale==2);
  if( GFX_iTexModulation[GFX_iActiveTexUnit]==iScale) return;
  GFX_iTexModulation[GFX_iActiveTexUnit] = iScale;

  _sfStats.StartTimer(CStatForm::STI_GFXAPI);

  if( iScale==2) {
    pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
    pglTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT,  GL_MODULATE);
    pglTexEnvf( GL_TEXTURE_ENV, GL_RGB_SCALE_EXT,    2.0f);
  } else {
    pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  } OGL_CHECKERROR;

  _sfStats.StopTimer(CStatForm::STI_GFXAPI);
}
Exemplo n.º 2
0
PDGL_API void pdglTexEnvi(GLenum target, GLenum pname, GLint param)
{
	if(pglTexEnvi)
		{ pglTexEnvi(target, pname, param); return; }
	pglTexEnvi=pdglGetProcAddress("glTexEnvi");
	pglTexEnvi(target, pname, param);
}
Exemplo n.º 3
0
void GAME_EXPORT GL_SetRenderMode( int mode )
{
	pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

	switch( mode )
	{
	case kRenderNormal:
	default:
		pglDisable( GL_BLEND );
		pglDisable( GL_ALPHA_TEST );
		break;
	case kRenderTransColor:
	case kRenderTransTexture:
		pglEnable( GL_BLEND );
		pglDisable( GL_ALPHA_TEST );
		pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
		break;
	case kRenderTransAlpha:
		pglDisable( GL_BLEND );
		pglEnable( GL_ALPHA_TEST );
		break;
	case kRenderGlow:
	case kRenderTransAdd:
		pglEnable( GL_BLEND );
		pglDisable( GL_ALPHA_TEST );
#if defined(XASH_BLEND_ES_WORKAROUND) // Problem with blending exists on every GLES configuration, not only on Android
		pglBlendFunc( GL_ONE, GL_ONE );
#else
		pglBlendFunc( GL_SRC_ALPHA, GL_ONE );
#endif
		break;
	}
}
Exemplo n.º 4
0
void VGUI_SetupDrawingImage( int *pColor )
{
	pglEnable( GL_BLEND );
	pglEnable( GL_ALPHA_TEST );
	pglAlphaFunc( GL_GREATER, 0.0f );
	pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
	pglColor4ub( pColor[0], pColor[1], pColor[2], 255 - pColor[3] );
}
Exemplo n.º 5
0
/*
=================
R_Bloom_DrawEffect
=================
*/
static void R_Bloom_DrawEffect( void )
{
    GL_Bind( GL_TEXTURE0, r_bloomeffecttexture );
    pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
    pglColor4f( r_bloom_alpha->value, r_bloom_alpha->value, r_bloom_alpha->value, 1.0f );
    pglBlendFunc( GL_ONE, GL_ONE );
    pglEnable( GL_BLEND );

    pglBegin( GL_QUADS );
    pglTexCoord2f( 0, sampleText_tch );
    pglVertex2f( curView_x, curView_y );
    pglTexCoord2f( 0, 0 );
    pglVertex2f( curView_x, curView_y+curView_height );
    pglTexCoord2f( sampleText_tcw, 0 );
    pglVertex2f( curView_x+curView_width, curView_y+curView_height );
    pglTexCoord2f( sampleText_tcw, sampleText_tch );
    pglVertex2f( curView_x+curView_width, curView_y );
    pglEnd();

    pglDisable( GL_BLEND );
}
Exemplo n.º 6
0
/*
=============
R_DrawStretchRaw
=============
*/
void R_DrawStretchRaw( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty )
{
	byte		*raw = NULL;
	gltexture_t	*tex;

	if( !GL_Support( GL_ARB_TEXTURE_NPOT_EXT ))
	{
		int	width = 1, height = 1;
	
		// check the dimensions
		width = NearestPOW( cols, true );
		height = NearestPOW( rows, false );

		if( cols != width || rows != height )
		{
			raw = GL_ResampleTexture( data, cols, rows, width, height, false );
			cols = width;
			rows = height;
		}
	}
	else
	{
		raw = (byte *)data;
	}

	if( cols > glConfig.max_2d_texture_size )
		Host_Error( "R_DrawStretchRaw: size %i exceeds hardware limits\n", cols );
	if( rows > glConfig.max_2d_texture_size )
		Host_Error( "R_DrawStretchRaw: size %i exceeds hardware limits\n", rows );

	pglDisable( GL_BLEND );
	pglDisable( GL_ALPHA_TEST );
	pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

	tex = R_GetTexture( tr.cinTexture );
	GL_Bind( GL_TEXTURE0, tr.cinTexture );

	if( cols == tex->width && rows == tex->height )
	{
		if( dirty )
		{
			pglTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, cols, rows, GL_BGRA, GL_UNSIGNED_BYTE, raw );
		}
	}
	else
	{
		tex->width = cols;
		tex->height = rows;
		if( dirty )
		{
			pglTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, cols, rows, 0, GL_BGRA, GL_UNSIGNED_BYTE, raw );
		}
	}

	pglBegin( GL_QUADS );
	pglTexCoord2f( 0, 0 );
	pglVertex2f( x, y );
	pglTexCoord2f( 1, 0 );
	pglVertex2f( x + w, y );
	pglTexCoord2f( 1, 1 );
	pglVertex2f( x + w, y + h );
	pglTexCoord2f( 0, 1 );
	pglVertex2f( x, y + h );
	pglEnd();
}
Exemplo n.º 7
0
void DrawSurfaceDecals( msurface_t *fa )
{
	decal_t		*p;
	cl_entity_t	*e;

	if( !fa->pdecals ) return;

	e = RI.currententity;
	ASSERT( e != NULL );

	if( e->curstate.rendermode == kRenderNormal || e->curstate.rendermode == kRenderTransAlpha )
	{
		pglDepthMask( GL_FALSE );
		pglEnable( GL_BLEND );

		if( e->curstate.rendermode == kRenderTransAlpha )
			pglDisable( GL_ALPHA_TEST );
	}

	if( e->curstate.rendermode == kRenderTransColor )
		pglEnable( GL_TEXTURE_2D );

	if( e->curstate.rendermode == kRenderTransTexture || e->curstate.rendermode == kRenderTransAdd )
		GL_Cull( GL_NONE );

	pglEnable( GL_POLYGON_OFFSET_FILL );
	pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

	if( fa->flags & SURF_TRANSPARENT && glState.stencilEnabled )
	{
		mtexinfo_t	*tex = fa->texinfo;

		for( p = fa->pdecals; p; p = p->pnext )
		{
			if( p->texture )
			{
				float *o, *v;
				int i, numVerts;
				o = R_DecalSetupVerts( p, fa, p->texture, &numVerts );

				pglEnable( GL_STENCIL_TEST );
				pglStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFF );
				pglColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );

				pglStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
				pglBegin( GL_POLYGON );

				for( i = 0, v = o; i < numVerts; i++, v += VERTEXSIZE )
				{
					v[5] = ( DotProduct( v, tex->vecs[0] ) + tex->vecs[0][3] ) / tex->texture->width;
					v[6] = ( DotProduct( v, tex->vecs[1] ) + tex->vecs[1][3] ) / tex->texture->height;

					pglTexCoord2f( v[5], v[6] );
					pglVertex3fv( v );
				}

				pglEnd();
				pglStencilOp( GL_KEEP, GL_KEEP, GL_DECR );

				pglEnable( GL_ALPHA_TEST );
				pglBegin( GL_POLYGON );

				for( i = 0, v = o; i < numVerts; i++, v += VERTEXSIZE )
				{
					pglTexCoord2f( v[5], v[6] );
					pglVertex3fv( v );
				}

				pglEnd();
				pglDisable( GL_ALPHA_TEST );

				pglColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
				pglStencilFunc( GL_EQUAL, 0, 0xFFFFFFFF );
				pglStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
			}
		}
	}

	for( p = fa->pdecals; p; p = p->pnext )
	{
		if( p->texture )
		{
			gltexture_t *glt = R_GetTexture( p->texture );

			// normal HL decal with alpha-channel
			if( glt->flags & TF_HAS_ALPHA )
			{
				// draw transparent decals with GL_MODULATE
				if( glt->fogParams[3] > DECAL_TRANSPARENT_THRESHOLD )
					pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
				else pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
				pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
			}
			else
			{
				// color decal like detail texture. Base color is 127 127 127
				pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
				pglBlendFunc( GL_DST_COLOR, GL_SRC_COLOR );
                              }

			DrawSingleDecal( p, fa );
		}
	}

	if( fa->flags & SURF_TRANSPARENT && glState.stencilEnabled )
		pglDisable( GL_STENCIL_TEST );

	if( e->curstate.rendermode == kRenderNormal || e->curstate.rendermode == kRenderTransAlpha )
	{
		pglDepthMask( GL_TRUE );
		pglDisable( GL_BLEND );

		if( e->curstate.rendermode == kRenderTransAlpha )
			pglEnable( GL_ALPHA_TEST );
	}

	pglDisable( GL_POLYGON_OFFSET_FILL );

	if( e->curstate.rendermode == kRenderTransTexture || e->curstate.rendermode == kRenderTransAdd )
		GL_Cull( GL_FRONT );

	if( e->curstate.rendermode == kRenderTransColor )
		pglDisable( GL_TEXTURE_2D );

	// restore blendfunc here
	if( e->curstate.rendermode == kRenderTransAdd || e->curstate.rendermode == kRenderGlow )
		pglBlendFunc( GL_SRC_ALPHA, GL_ONE );
}
Exemplo n.º 8
0
/*
=================
R_Bloom_GeneratexDiamonds
=================
*/
static void R_Bloom_GeneratexDiamonds( void )
{
    int i, j;
    float intensity;

    // set up sample size workspace
    pglScissor( 0, 0, sample_width, sample_height );
    pglViewport( 0, 0, sample_width, sample_height );
    pglMatrixMode( GL_PROJECTION );
    pglLoadIdentity();
    pglOrtho( 0, sample_width, sample_height, 0, -10, 100 );
    pglMatrixMode( GL_MODELVIEW );
    pglLoadIdentity();

    // copy small scene into r_bloomeffecttexture
    GL_Bind( GL_TEXTURE0, r_bloomeffecttexture );
    pglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height );

    // start modifying the small scene corner
    pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
    pglEnable( GL_BLEND );

    // darkening passes
    if( r_bloom_darken->value )
    {
        pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
        pglBlendFunc( GL_DST_COLOR, GL_ZERO );

        for( i = 0; i < (int)r_bloom_darken->value; i++ )
            R_Bloom_SamplePass( 0, 0 );

        pglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height );
    }

    // bluring passes
    pglBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_COLOR );

    if( r_bloom_diamond_size->value > 7.0f || r_bloom_diamond_size->value <= 3.0f )
    {
        if( r_bloom_diamond_size->value != 8.0f )
            CVAR_SET_FLOAT( "r_bloom_diamond_size", 8.0f );

        for( i = 0; i < r_bloom_diamond_size->value; i++ )
        {
            for( j = 0; j < r_bloom_diamond_size->value; j++ )
            {
                intensity = r_bloom_intensity->value * 0.3f * Diamond8x[i][j];
                if( intensity < 0.01f ) continue;
                pglColor4f( intensity, intensity, intensity, 1.0f );
                R_Bloom_SamplePass( i-4, j-4 );
            }
        }
    }
    else if( r_bloom_diamond_size->value > 5.0f )
    {
        if( r_bloom_diamond_size->value != 6.0f )
            CVAR_SET_FLOAT( "r_bloom_diamond_size", 6.0f );

        for( i = 0; i < r_bloom_diamond_size->value; i++ )
        {
            for( j = 0; j < r_bloom_diamond_size->value; j++ )
            {
                intensity = r_bloom_intensity->value * 0.5f * Diamond6x[i][j];
                if( intensity < 0.01f ) continue;
                pglColor4f( intensity, intensity, intensity, 1.0f );
                R_Bloom_SamplePass( i-3, j-3 );
            }
        }
    }
    else if( r_bloom_diamond_size->value > 3.0f )
    {
        if( r_bloom_diamond_size->value != 4.0f )
            CVAR_SET_FLOAT( "r_bloom_diamond_size", 4.0f );

        for( i = 0; i < r_bloom_diamond_size->value; i++ )
        {
            for( j = 0; j < r_bloom_diamond_size->value; j++ )
            {
                intensity = r_bloom_intensity->value * 0.8f * Diamond4x[i][j];
                if( intensity < 0.01f ) continue;
                pglColor4f( intensity, intensity, intensity, 1.0f );
                R_Bloom_SamplePass( i-2, j-2 );
            }
        }
    }

    pglCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, sample_width, sample_height );

    // restore full screen workspace
    pglScissor( 0, 0, glState.width, glState.height );
    pglViewport( 0, 0, glState.width, glState.height );
    pglMatrixMode( GL_PROJECTION );
    pglLoadIdentity();
    pglOrtho( 0, glState.width, glState.height, 0, -10, 100 );
    pglMatrixMode( GL_MODELVIEW );
    pglLoadIdentity();
}