Exemplo n.º 1
0
/*
** GL_Bind
*/
void GL_Bind( image_t *image ) {
	int texnum;

	if ( !image ) {
		ri.Printf( PRINT_WARNING, "GL_Bind: NULL image\n" );
		texnum = tr.defaultImage->texnum;
	} else {
		texnum = image->texnum;
	}

	if ( r_nobind->integer && tr.dlightImage ) {		// performance evaluation option
		texnum = tr.dlightImage->texnum;
	}

	if ( glState.currenttextures[glState.currenttmu] != texnum ) {
		if ( image ) {
			image->frameUsed = tr.frameCount;
		}
		glState.currenttextures[glState.currenttmu] = texnum;
		if (image && image->flags & IMGFLAG_CUBEMAP)
			qglBindTexture( GL_TEXTURE_CUBE_MAP, texnum );
		else
			qglBindTexture( GL_TEXTURE_2D, texnum );
	}
}
Exemplo n.º 2
0
bool Gui_SetScreenTexture(void *data, int w, int h, int bpp)
{
    GLenum       texture_format;
    GLuint       color_depth;

    if(bpp == 32)        // Contains an alpha channel
    {
        texture_format = GL_RGBA;
        color_depth = GL_RGBA;
    }
    else if(bpp == 24)   // No alpha channel
    {
        texture_format = GL_RGB;
        color_depth = GL_RGB;
    }
    else
    {
        return false;
    }

    // Bind the texture object
    qglBindTexture(GL_TEXTURE_2D, load_screen_tex);

    // Set the texture's stretching properties
    qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    // Edit the texture object's image data using the information SDL_Surface gives us
    qglTexImage2D(GL_TEXTURE_2D, 0, color_depth, w, h, 0,
                 texture_format, GL_UNSIGNED_BYTE, data);
    qglBindTexture(GL_TEXTURE_2D, 0);

    return true;
}
Exemplo n.º 3
0
/*
** GL_BindMultitexture
*/
void
GL_BindMultitexture(Img *image0, GLuint env0, Img *image1, GLuint env1)
{
	int texnum0, texnum1;

	texnum0 = image0->texnum;
	texnum1 = image1->texnum;

	if(r_nobind->integer && tr.dlightImage){	/* performance evaluation option */
		texnum0 = texnum1 = tr.dlightImage->texnum;
	}

	if(glState.currenttextures[1] != texnum1){
		GL_SelectTexture(1);
		image1->frameUsed = tr.frameCount;
		glState.currenttextures[1] = texnum1;
		qglBindTexture(GL_TEXTURE_2D, texnum1);
	}
	if(glState.currenttextures[0] != texnum0){
		GL_SelectTexture(0);
		image0->frameUsed = tr.frameCount;
		glState.currenttextures[0] = texnum0;
		qglBindTexture(GL_TEXTURE_2D, texnum0);
	}
}
Exemplo n.º 4
0
static void RB_BloomDownSample( void ) {
	GLenum target;
	int width, height;
	GLint loc;

	GL_SelectTexture(0);
	qglDisable(GL_TEXTURE_2D);
	qglEnable(GL_TEXTURE_RECTANGLE_ARB);
	target = GL_TEXTURE_RECTANGLE_ARB;

	width = glConfig.vidWidth;
	height = glConfig.vidHeight;

	qglBindTexture(target, tr.backBufferTexture);

	qglCopyTexSubImage2D(target, 0, 0, 0, 0, 0, glConfig.vidWidth, glConfig.vidHeight);

	GL_SelectTexture(1);
	qglDisable(GL_TEXTURE_2D);
	qglEnable(GL_TEXTURE_RECTANGLE_ARB);
	qglBindTexture(target, tr.bloomTexture);

	qglUseProgramObjectARB(tr.downSample1Sp);
	loc = qglGetUniformLocationARB(tr.downSample1Sp, "backBufferTex");
	if (loc < 0) {
		Com_Error(ERR_DROP, "%s() couldn't get backBufferTex", __FUNCTION__);
	}
	qglUniform1iARB(loc, 0);

	//qglDisable(GL_BLEND);

    qglBegin(GL_QUADS);

	qglMultiTexCoord2iARB(GL_TEXTURE0_ARB, 0, 0);
	qglMultiTexCoord2iARB(GL_TEXTURE1_ARB, 0, 0);
	qglVertex2i(0, tr.bloomHeight);

	qglMultiTexCoord2iARB(GL_TEXTURE0_ARB, width, 0);
	qglMultiTexCoord2iARB(GL_TEXTURE1_ARB, width, 0);
	qglVertex2i(tr.bloomWidth, tr.bloomHeight);

	qglMultiTexCoord2iARB(GL_TEXTURE0_ARB, width, height);
	qglMultiTexCoord2iARB(GL_TEXTURE1_ARB, width, height);
	qglVertex2i(tr.bloomWidth, 0);

	qglMultiTexCoord2iARB(GL_TEXTURE0_ARB, 0, height);
	qglMultiTexCoord2iARB(GL_TEXTURE1_ARB, 0, height);
	qglVertex2i(0, 0);

	qglEnd();

	qglUseProgramObjectARB(0);

	qglDisable(GL_TEXTURE_RECTANGLE_ARB);
	qglDisable(GL_TEXTURE_2D);

	GL_SelectTexture(0);
	qglDisable(GL_TEXTURE_RECTANGLE_ARB);
	qglEnable(GL_TEXTURE_2D);
}
Exemplo n.º 5
0
void gld_BindFlat(GLTexture *gltexture, unsigned int flags)
{
  const unsigned char *flat;
  unsigned char *buffer;
  int w, h;

  if (!gltexture || gltexture->textype != GLDT_FLAT)
  {
    qglBindTexture(GL_TEXTURE_2D, 0);
    last_glTexID = NULL;
    return;
  }

#ifdef HAVE_LIBSDL_IMAGE
  if (gld_LoadHiresTex(gltexture, CR_DEFAULT))
  {
    gld_SetTexClamp(gltexture, flags);
    last_glTexID = gltexture->texid_p;
    return;
  }
#endif

  gld_GetTextureTexID(gltexture, CR_DEFAULT); 

  if (last_glTexID == gltexture->texid_p)
  {
    gld_SetTexClamp(gltexture, flags);
    return;
  }

  last_glTexID = gltexture->texid_p;

  if (*gltexture->texid_p != 0)
  {
    qglBindTexture(GL_TEXTURE_2D, *gltexture->texid_p);
    gld_SetTexClamp(gltexture, flags);
    return;
  }

  flat=W_CacheLumpNum(gltexture->index);
  buffer=(unsigned char*)Z_Malloc(gltexture->buffer_size,PU_STATIC,0);
  if (!(gltexture->flags & GLTEXTURE_MIPMAP) && gl_paletted_texture)
    memset(buffer,transparent_pal_index,gltexture->buffer_size);
  else
    memset(buffer,0,gltexture->buffer_size);
  gld_AddFlatToTexture(gltexture, buffer, flat, !(gltexture->flags & GLTEXTURE_MIPMAP) && gl_paletted_texture);
  if (*gltexture->texid_p == 0)
    qglGenTextures(1, gltexture->texid_p);
  qglBindTexture(GL_TEXTURE_2D, *gltexture->texid_p);

  buffer = gld_HQResize(gltexture, buffer, gltexture->buffer_width, gltexture->buffer_height, &w, &h);

  gld_BuildTexture(gltexture, buffer, false, w, h);

  gld_SetTexClamp(gltexture, flags);

  W_UnlockLumpNum(gltexture->index);
}
Exemplo n.º 6
0
int gld_wipe_doMelt(int ticks, int *y_lookup)
{
  int i;
  int total_w, total_h;
  float fU1, fU2, fV1, fV2;

  total_w = gld_GetTexDimension(SCREENWIDTH);
  total_h = gld_GetTexDimension(SCREENHEIGHT);

  fU1 = 0.0f;
  fV1 = (float)SCREENHEIGHT / (float)total_h;
  fU2 = (float)SCREENWIDTH / (float)total_w;
  fV2 = 0.0f;
  
  gld_EnableTexture2D(GL_TEXTURE0_ARB, true);
  
  qglBindTexture(GL_TEXTURE_2D, wipe_scr_end_tex);
  qglColor3f(1.0f, 1.0f, 1.0f);

  qglBegin(GL_TRIANGLE_STRIP);
  {
    qglTexCoord2f(fU1, fV1); qglVertex2f(0.0f, 0.0f);
    qglTexCoord2f(fU1, fV2); qglVertex2f(0.0f, (float)SCREENHEIGHT);
    qglTexCoord2f(fU2, fV1); qglVertex2f((float)SCREENWIDTH, 0.0f);
    qglTexCoord2f(fU2, fV2); qglVertex2f((float)SCREENWIDTH, (float)SCREENHEIGHT);
  }
  qglEnd();
  
  qglBindTexture(GL_TEXTURE_2D, wipe_scr_start_tex);
  qglColor3f(1.0f, 1.0f, 1.0f);
  
  qglBegin(GL_QUAD_STRIP);
  
  for (i=0; i <= SCREENWIDTH; i++)
  {
    int yoffs = MAX(0, y_lookup[i]);
    
    float tx = (float) i / total_w;
    float sx = (float) i;
    float sy = (float) yoffs;
    
    qglTexCoord2f(tx, fV1); qglVertex2f(sx, sy);
    qglTexCoord2f(tx, fV2); qglVertex2f(sx, sy + (float)SCREENHEIGHT);
  }
  
  qglEnd();
  
  return 0;
}
Exemplo n.º 7
0
/*
===============
CreateDSTTex_ARB

Create the texture which warps texture shaders
===============
*/
void CreateDSTTex_ARB (void)
{
	unsigned char	dist[DST_SIZE][DST_SIZE][4];
	int				x,y;

	srand(GetTickCount());
	for (x=0; x<DST_SIZE; x++)
		for (y=0; y<DST_SIZE; y++) {
			dist[x][y][0] = rand()%255;
			dist[x][y][1] = rand()%255;
			dist[x][y][2] = rand()%48;
			dist[x][y][3] = rand()%48;
		}

	qglGenTextures(1,&dst_texture_ARB);
	qglBindTexture(GL_TEXTURE_2D, dst_texture_ARB);
	qglTexImage2D (GL_TEXTURE_2D, 0, 4, DST_SIZE, DST_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, dist);

	qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	qglHint(GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST);
	qglTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
}
Exemplo n.º 8
0
/*
=================
R_BindAnimatedImage

=================
*/
static void R_BindAnimatedImage( textureBundle_t *bundle ) {
    int		index;

    if ( bundle->isVideoMap ) {
        ri.CIN_RunCinematic(bundle->videoMapHandle);
        ri.CIN_UploadCinematic(bundle->videoMapHandle);
        return;
    }

    if ( bundle->isRenderTarget ) {
        qglBindTexture (GL_TEXTURE_2D, bundle->renderTarget);
        return;
    }

    if ( bundle->numImageAnimations <= 1 ) {
        GL_Bind( bundle->image[0] );
        return;
    }

    // it is necessary to do this messy calc to make sure animations line up
    // exactly with waveforms of the same frequency
    index = myftol( tess.shaderTime * bundle->imageAnimationSpeed * FUNCTABLE_SIZE );
    index >>= FUNCTABLE_SIZE2;

    if ( index < 0 ) {
        index = 0;	// may happen with shader time offsets
    }
    index %= bundle->numImageAnimations;

    GL_Bind( bundle->image[ index ] );
}
Exemplo n.º 9
0
void Terrain_DrawFace( brush_t *brush, terrainFace_t *terraface ) {
	terrainMesh_t	*pm;
	terravert_t		a0;
	terravert_t		a1;
	terravert_t		a2;

	pm = brush->pTerrain;
   
	Terrain_GetTriangle( pm, terraface->index, &a0, &a1, &a2 );

	qglBindTexture( GL_TEXTURE_2D, terraface->texture->texture_number );
	qglBegin( GL_TRIANGLES );

	// first tri
	qglColor4fv( a0.rgba );
	qglTexCoord2fv( a0.tc );
	qglVertex3fv( a0.xyz );

	qglColor4fv( a1.rgba );
	qglTexCoord2fv( a1.tc );
	qglVertex3fv( a1.xyz );

	qglColor4fv( a2.rgba );
	qglTexCoord2fv( a2.tc );
	qglVertex3fv( a2.xyz );

	qglEnd ();
}
Exemplo n.º 10
0
GLuint CaptureScreenAsTexID(void)
{
  GLuint id;

  gld_EnableTexture2D(GL_TEXTURE0_ARB, true);
 
  qglGenTextures(1, &id);
  qglBindTexture(GL_TEXTURE_2D, id);
  
  qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

#ifdef ANDROID
  qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
#else
  qglTexImage2D(GL_TEXTURE_2D, 0, 3,
#endif
    gld_GetTexDimension(SCREENWIDTH), gld_GetTexDimension(SCREENHEIGHT), 
    0, GL_RGB, GL_UNSIGNED_BYTE, 0);

  qglCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, SCREENWIDTH, SCREENHEIGHT);

  return id;
}
Exemplo n.º 11
0
/*
* RB_BindImage
*/
void RB_BindImage( int tmu, const image_t *tex )
{
    GLuint texnum;

    assert( tex != NULL );
    assert( tex->texnum != 0 );

    if( tex->missing ) {
        tex = rsh.noTexture;
    } else if( !tex->loaded ) {
        // not yet loaded from disk
        tex = tex->flags & IT_CUBEMAP ? rsh.whiteCubemapTexture : rsh.whiteTexture;
    } else if( rsh.noTexture && ( r_nobind->integer && tex->texnum != 0 ) ) {
        // performance evaluation option
        tex = rsh.noTexture;
    }

    if( rb.gl.flushTextures ) {
        rb.gl.flushTextures = false;
        memset( rb.gl.currentTextures, 0, sizeof( rb.gl.currentTextures ) );
    }

    texnum = tex->texnum;
    if( rb.gl.currentTextures[tmu] == texnum )
        return;

    rb.gl.currentTextures[tmu] = texnum;

    RB_SelectTextureUnit( tmu );

    qglBindTexture( R_TextureTarget( tex->flags, NULL ), tex->texnum );

    rb.stats.c_totalBinds++;
}
Exemplo n.º 12
0
unsigned char* gld_GetTextureBuffer(GLuint texid, int miplevel, int *width, int *height)
{
  int w, h;
  static unsigned char *buf = NULL;
  static int buf_size = 512 * 256 * 4;

  if (!buf)
  {
    buf = malloc(buf_size);
  }

  if (texid)
  {
    qglBindTexture(GL_TEXTURE_2D, texid);
  }

  qglGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_WIDTH, &w);
  qglGetTexLevelParameteriv(GL_TEXTURE_2D, miplevel, GL_TEXTURE_HEIGHT, &h);
  if (w * h * 4 > buf_size)
  {
    free(buf);
    buf_size = w * h * 4;
    buf = malloc(buf_size);
  }
  qglGetTexImage(GL_TEXTURE_2D, miplevel, GL_RGBA, GL_UNSIGNED_BYTE, buf);

  if (width)
    *width = w;
  if (height)
    *height = h;

  return buf;
}
Exemplo n.º 13
0
/**
 * @brief GL_Bind
 * @param[in,out] image
 */
void GL_Bind(image_t *image)
{
	int texnum;

	if (!image)
	{
		Ren_Warning("GL_Bind: NULL image\n");
		texnum = tr.defaultImage->texnum;
	}
	else
	{
		texnum = image->texnum;
	}

	if (r_noBind->integer && tr.dlightImage)            // performance evaluation option
	{
		texnum = tr.dlightImage->texnum;
	}

	if (glState.currenttextures[glState.currenttmu] != texnum)
	{
		if (image)
		{
			image->frameUsed = tr.frameCount;
		}

		glState.currenttextures[glState.currenttmu] = texnum;
		qglBindTexture(GL_TEXTURE_2D, texnum);
	}
}
Exemplo n.º 14
0
void RB_ExecuteBackEndCommands( const emptyCommand_t *cmds ) {
	// r_debugRenderToTexture
	int	c_draw3d = 0, c_draw2d = 0, c_setBuffers = 0, c_swapBuffers = 0, c_copyRenders = 0;

	if ( cmds->commandId == RC_NOP && !cmds->next ) {
		return;
	}

	backEndStartTime = Sys_Milliseconds();

	// needed for editor rendering
	RB_SetDefaultGLState();

	// upload any image loads that have completed
	globalImages->CompleteBackgroundImageLoads();

	for ( ; cmds ; cmds = (const emptyCommand_t *)cmds->next ) {
		switch ( cmds->commandId ) {
		case RC_NOP:
			break;
		case RC_DRAW_VIEW:
			RB_DrawView( cmds );
			if ( ((const drawSurfsCommand_t *)cmds)->viewDef->viewEntitys ) {
				c_draw3d++;
			}
			else {
				c_draw2d++;
			}
			break;
		case RC_SET_BUFFER:
			RB_SetBuffer( cmds );
			c_setBuffers++;
			break;
		case RC_SWAP_BUFFERS:
			RB_SwapBuffers( cmds );
			c_swapBuffers++;
			break;
		case RC_COPY_RENDER:
			RB_CopyRender( cmds );
			c_copyRenders++;
			break;
		default:
			common->Error( "RB_ExecuteBackEndCommands: bad commandId" );
			break;
		}
	}

	// go back to the default texture so the editor doesn't mess up a bound image
	qglBindTexture( GL_TEXTURE_2D, 0 );
	backEnd.glState.tmu[0].current2DMap = -1;

	// stop rendering on this thread
	backEndFinishTime = Sys_Milliseconds();
	backEnd.pc.msec = backEndFinishTime - backEndStartTime;

	if ( r_debugRenderToTexture.GetInteger() == 1 ) {
		common->Printf( "3d: %i, 2d: %i, SetBuf: %i, SwpBuf: %i, CpyRenders: %i, CpyFrameBuf: %i\n", c_draw3d, c_draw2d, c_setBuffers, c_swapBuffers, c_copyRenders, backEnd.c_copyFrameBuffer );
		backEnd.c_copyFrameBuffer = 0;
	}
}
Exemplo n.º 15
0
void GL_BindNullTextures()
{
	int i;

	if (glRefConfig.directStateAccess)
	{
		for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
		{
			qglBindMultiTexture(GL_TEXTURE0_ARB + i, GL_TEXTURE_2D, 0);
			glDsaState.textures[i] = 0;
		}
	}
	else
	{
		for (i = 0; i < NUM_TEXTURE_BUNDLES; i++)
		{
			qglActiveTextureARB(GL_TEXTURE0_ARB + i);
			qglBindTexture(GL_TEXTURE_2D, 0);
			glDsaState.textures[i] = 0;
		}

		qglActiveTextureARB(GL_TEXTURE0_ARB);
		glDsaState.texunit = GL_TEXTURE0_ARB;
	}
}
Exemplo n.º 16
0
void GLRB_RestoreTextureState( void )
{
    // Flush textures; reset texture state
	Com_Memset( glState.currenttextures, 0, sizeof( glState.currenttextures ) );
	if ( qglBindTexture ) {
		if ( qglActiveTextureARB ) {
			GL_SelectTexture( 1 );
			qglBindTexture( GL_TEXTURE_2D, 0 );
			GL_SelectTexture( 0 );
			qglBindTexture( GL_TEXTURE_2D, 0 );
		} else {
			qglBindTexture( GL_TEXTURE_2D, 0 );
		}
	}

    GL_SetDefaultState();
}
Exemplo n.º 17
0
/*
** GL_BindMultitexture
*/
void GL_BindMultitexture( image_t *image0, GLuint env0, image_t *image1, GLuint env1 ) {
	int		texnum0, texnum1;

	texnum0 = image0->texnum;
	texnum1 = image1->texnum;

	if ( glState.currenttextures[1] != texnum1 ) {
		GL_SelectTexture( 1 );
		image1->frameUsed = tr.frameCount;
		glState.currenttextures[1] = texnum1;
		qglBindTexture( GL_TEXTURE_2D, texnum1 );
	}
	if ( glState.currenttextures[0] != texnum0 ) {
		GL_SelectTexture( 0 );
		image0->frameUsed = tr.frameCount;
		glState.currenttextures[0] = texnum0;
		qglBindTexture( GL_TEXTURE_2D, texnum0 );
	}
}
Exemplo n.º 18
0
GLvoid APIENTRY GLDSA_BindMultiTexture(GLenum texunit, GLenum target, GLuint texture)
{
	if (glDsaState.texunit != texunit)
	{
		qglActiveTextureARB(texunit);
		glDsaState.texunit = texunit;
	}

	qglBindTexture(target, texture);
}
Exemplo n.º 19
0
void GL_Bind (int texnum)
{
	extern	image_t	*draw_chars;

	if (gl_nobind->value && draw_chars)		// performance evaluation option
		texnum = draw_chars->texnum;
	if ( gl_state.currenttextures[gl_state.currenttmu] == texnum)
		return;
	gl_state.currenttextures[gl_state.currenttmu] = texnum;
	qglBindTexture (GL_TEXTURE_2D, texnum);
}
Exemplo n.º 20
0
Arquivo: gl_draw.c Projeto: ZwS/qudos
/*
 * ============= Draw_Pic =============
 */
void
Draw_Pic(int x, int y, char *pic, float alpha)
{
	image_t        *gl;

	gl = Draw_FindPic(pic);
	if (!gl) {
		ri.Con_Printf(PRINT_ALL, "Can't find pic: %s\n", pic);
		return;
	}
	if (scrap_dirty)
		Scrap_Upload();

	if (((gl_config.renderer == GL_RENDERER_MCD) || (gl_config.renderer & GL_RENDERER_RENDITION)) && !gl->has_alpha)
		qglDisable(GL_ALPHA_TEST);

	/* add alpha support */
	{
		qglDisable(GL_ALPHA_TEST);

		qglBindTexture(GL_TEXTURE_2D, gl->texnum);

		GL_TexEnv(GL_MODULATE);
		qglColor4f(1, 1, 1, 0.999);	/* need <1 for trans to work */
		qglEnable(GL_BLEND);
		qglDepthMask(false);
	}

	GL_Bind(gl->texnum);
	qglBegin(GL_QUADS);
	qglTexCoord2f(gl->sl, gl->tl);
	qglVertex2f(x, y);
	qglTexCoord2f(gl->sh, gl->tl);
	qglVertex2f(x + gl->width, y);
	qglTexCoord2f(gl->sh, gl->th);
	qglVertex2f(x + gl->width, y + gl->height);
	qglTexCoord2f(gl->sl, gl->th);
	qglVertex2f(x, y + gl->height);
	qglEnd();

	/* add alpha support */
	{
		qglDepthMask(true);
		GL_TexEnv(GL_REPLACE);
		qglDisable(GL_BLEND);
		qglColor4f(1, 1, 1, 1);

		qglEnable(GL_ALPHA_TEST);
	}

	if (((gl_config.renderer == GL_RENDERER_MCD) || (gl_config.renderer & GL_RENDERER_RENDITION)) && !gl->has_alpha)
		qglEnable(GL_ALPHA_TEST);
}
Exemplo n.º 21
0
/*
* RB_BeginRegistration
*/
void RB_BeginRegistration( void )
{
    int i;

    RB_RegisterStreamVBOs();
    RB_BindVBO( 0, 0 );

    // unbind all texture targets on all TMUs
    for( i = MAX_TEXTURE_UNITS - 1; i >= 0; i-- ) {
        RB_SelectTextureUnit( i );

        qglBindTexture( GL_TEXTURE_CUBE_MAP_ARB, 0 );
        if( glConfig.ext.texture_array )
            qglBindTexture( GL_TEXTURE_2D_ARRAY_EXT, 0 );
        if( glConfig.ext.texture3D )
            qglBindTexture( GL_TEXTURE_3D_EXT, 0 );
        qglBindTexture( GL_TEXTURE_2D, 0 );
    }

    RB_FlushTextureCache();
}
Exemplo n.º 22
0
/*
* RB_BindTexture
*/
void RB_BindTexture( int tmu, const image_t *tex )
{
	GLuint texnum;

	assert( tex != NULL );

	if( r_nobind->integer && r_notexture && tex->texnum != 0 )  // performance evaluation option
		tex = r_notexture;

	RB_SelectTextureUnit( tmu );

	texnum = tex->texnum;
	if( rb.gl.currentTextures[tmu] == texnum )
		return;

	rb.gl.anyTexturesBound = 1;
	rb.gl.currentTextures[tmu] = texnum;
	if( tex->flags & IT_CUBEMAP )
		qglBindTexture( GL_TEXTURE_CUBE_MAP_ARB, texnum );
	else
		qglBindTexture( GL_TEXTURE_2D, texnum );
}
Exemplo n.º 23
0
static void RB_BloomBrightness( void ) {
	GLenum target;
	int width, height;
	GLint loc;

	GL_SelectTexture(0);
	qglDisable(GL_TEXTURE_2D);
	qglEnable(GL_TEXTURE_RECTANGLE_ARB);
	target = GL_TEXTURE_RECTANGLE_ARB;

	width = tr.bloomWidth;
	height = tr.bloomHeight;

	qglBindTexture(target, tr.bloomTexture);
	qglCopyTexSubImage2D(target, 0, 0, 0, 0, glConfig.vidHeight - height, width, height);

	qglUseProgramObjectARB(tr.brightPassSp);
	loc = qglGetUniformLocationARB(tr.brightPassSp, "backBufferTex");
	if (loc < 0) {
		Com_Error(ERR_DROP, "%s() couldn't get backBufferTex", __FUNCTION__);
	}

	qglUniform1iARB(loc, 0);
	loc = qglGetUniformLocationARB(tr.brightPassSp, "p_brightthreshold");
	if (loc < 0) {
		Com_Error(ERR_DROP, "%s() couldn't get p_brightthreshold", __FUNCTION__);
	}
	qglUniform1fARB(loc, (GLfloat)r_BloomBrightThreshold->value);

	qglBegin(GL_QUADS);

	qglTexCoord2i(0, 0);
	qglVertex2i(0, height);

	qglTexCoord2i(width, 0);
	qglVertex2i(width, height);

	qglTexCoord2i(width, height);
	qglVertex2i(width, 0);

	qglTexCoord2i(0, height);
	qglVertex2i(0, 0);

	qglEnd();

	qglUseProgramObjectARB(0);

	qglDisable(GL_TEXTURE_RECTANGLE_ARB);
	qglEnable(GL_TEXTURE_2D);
}
Exemplo n.º 24
0
/*
** GL_BindToTMU
*/
void GL_BindToTMU( image_t *image, int tmu )
{
	int		texnum;
	int     oldtmu = glState.currenttmu;

	if (!image)
		texnum = 0;
	else
		texnum = image->texnum;

	if ( glState.currenttextures[tmu] != texnum ) {
		GL_SelectTexture( tmu );
		if (image)
			image->frameUsed = tr.frameCount;
		glState.currenttextures[tmu] = texnum;

		if (image && (image->flags & IMGFLAG_CUBEMAP))
			qglBindTexture( GL_TEXTURE_CUBE_MAP, texnum );
		else
			qglBindTexture( GL_TEXTURE_2D, texnum );
		GL_SelectTexture( oldtmu );
	}
}
Exemplo n.º 25
0
/*
 ==================
 GL_BindTexture
 ==================
*/
void GL_BindTexture (texture_t *texture){

	if (texture->frameUsed != rg.frameCount){
		texture->frameUsed = rg.frameCount;

		rg.pc.textures++;
		rg.pc.textureBytes += texture->size;
	}

	if (glState.texture[glState.texUnit] == texture)
		return;
	glState.texture[glState.texUnit] = texture;

	qglBindTexture(texture->target, texture->textureId);
}
Exemplo n.º 26
0
static int setupScreenKeyboardButton( int buttonID, Uint8 * charBuf )
{
	// TODO: softstretch with antialiasing
	int w, h,  format;
	GLTexture_t * data = NULL;
	int texture_w, texture_h;
	
	if( buttonID < 1 )
		data = &arrowImages;
	else
		data = &(buttonImages[buttonID-1]);


	memcpy(&w, charBuf, sizeof(int));
	memcpy(&h, charBuf + sizeof(int), sizeof(int));
	memcpy(&format, charBuf + 2*sizeof(int), sizeof(int));
	w = ntohl(w);
	h = ntohl(h);
	format = ntohl(format);
	
	texture_w = power_of_2(w);
	texture_h = power_of_2(h);
	data->w = texture_w;
	data->h = texture_h;
	LOGI("data w:%d, h:%d\n", w, h);

	qglEnable(GL_TEXTURE_2D);

	qglGenTextures(1, &data->id);
	
	qglBindTexture(GL_TEXTURE_2D, data->id);
	LOGI("On-screen keyboard generated OpenGL texture ID %x", data->id);

	qglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_w, texture_h, 0, GL_RGBA,
					format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1, NULL);
	qglPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	
	qglTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA,
						format ? GL_UNSIGNED_SHORT_4_4_4_4 : GL_UNSIGNED_SHORT_5_5_5_1,
						charBuf + 3*sizeof(int) );

	qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	qglDisable(GL_TEXTURE_2D);

	return 3*sizeof(int) + w * h * 2;
}
Exemplo n.º 27
0
/*
** GL_Bind
*/
void GL_Bind( image_t *image ) {
	int texnum;

	if ( !image ) {
		ri.Printf( PRINT_WARNING, "GL_Bind: NULL image\n" );
		texnum = tr.defaultImage->texnum;
	} else {
		texnum = image->texnum;
	}

	if ( glState.currenttextures[glState.currenttmu] != texnum ) {
		image->frameUsed = tr.frameCount;
		glState.currenttextures[glState.currenttmu] = texnum;
		qglBindTexture (GL_TEXTURE_2D, texnum);
	}
}
Exemplo n.º 28
0
/*
** GL_BindToTMU
*/
void
GL_BindToTMU(Img *image, int tmu)
{
	int texnum;
	int oldtmu = glState.currenttmu;

	texnum = image->texnum;

	if(glState.currenttextures[tmu] != texnum){
		GL_SelectTexture(tmu);
		image->frameUsed = tr.frameCount;
		glState.currenttextures[tmu] = texnum;
		qglBindTexture(GL_TEXTURE_2D, texnum);
		GL_SelectTexture(oldtmu);
	}
}
Exemplo n.º 29
0
static inline void drawCharTex(GLTexture_t * tex, SDL_Rect * src, SDL_Rect * dest, 
	Uint8 r, Uint8 g, Uint8 b, Uint8 a)
{
	GLint cropRect[4];
	/*
	GLfloat texColor[4];
	static const float onediv255 = 1.0f / 255.0f;
	*/
	if( !dest->h || !dest->w )
		return;

	qglBindTexture(GL_TEXTURE_2D, tex->id);

	qglColor4x(r * 0x100, g * 0x100, b * 0x100,  200 * 0x100 );

	//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);

	qglTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	qglEnable(GL_BLEND);
	qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	qglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	#if 0
	dest->x = dest->x*320/screen_width;
	dest->y = dest->y*200/screen_height;
	dest->w = dest->w*320/screen_width;
	dest->h = dest->h*200/screen_height;
	DrawQuad(dest->x, 200 - dest->y - dest->h, dest->w, dest->h, 
		0, 0, 1/*tex->w*/, 1/*tex->h*/);
#endif


	cropRect[0] = 0;
	cropRect[1] = tex->h;
	cropRect[2] = tex->w;
	cropRect[3] = -tex->h;
	if(src)
	{//left down width hight
		cropRect[0] = src->x;
		cropRect[1] = src->h; // TODO: check if height works as expected in inverted GL coords
		cropRect[2] = src->w;
		cropRect[3] = -src->h; // TODO: check if height works as expected in inverted GL coords
	}
	qglTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
	glDrawTexiOES(dest->x, screen_height - dest->y - dest->h, 0, dest->w, dest->h);
}
Exemplo n.º 30
0
/*
================
DrawFullFace
================
*/
void DrawFullFace (curveBlock_t *cb, cubeFace_t *cf) {
	int		k;
	float	*next;

  if (bevelBrush) {
    return;
  }

	// set the texturing matrix
  FaceTextureVectors (cf->brushFace, STfromXYZ);


	if (curveFile) {
		vec3_t	vecs[4];

		for (k = 0 ; k < 4 ; k++) {
			VectorCopy (cb->points[cf->points[k]], vecs[k]);
		}

		fprintf (curveFile, "FACE {\n");
		fprintf (curveFile, "4\n");
		fprintf (curveFile, "textures/%s\n", cf->brushFace->texdef.name);
		Write2DMatrix (curveFile, 2, 4, (float *)STfromXYZ);
		Write2DMatrix (curveFile, 4, 3, (float *)vecs);
		fprintf (curveFile, "}\n");
		return;
	}

	qglBindTexture (GL_TEXTURE_2D, cf->brushFace->d_texture->texture_number);

  float fColor[3];
  SetColor(cf->brushFace, fColor);


	qglBegin (GL_POLYGON);
	for (k = 0 ; k < 4 ; k++) {
		next = cb->points[cf->points[k]];
		qglTexCoord2f (DotProduct(next, STfromXYZ[0]) + STfromXYZ[0][3],
			DotProduct(next, STfromXYZ[1]) + STfromXYZ[1][3]);
		qglVertex3fv (next);
	  DecColor(fColor);
	}
	qglEnd ();
}