Scrapping in ne eigene Datei

This commit is contained in:
Yamagi Burmeister 2010-10-21 07:29:20 +00:00
parent cbbf7a7eee
commit 56f27f1e3a
5 changed files with 121 additions and 89 deletions

View file

@ -329,6 +329,7 @@ OPENGL_OBJS = \
build/ref_gl/gl_rmain.o \
build/ref_gl/gl_rmisc.o \
build/ref_gl/gl_rsurf.o \
build/ref_gl/gl_scrap.o \
build/ref_gl/gl_warp.o
# ----------
@ -789,7 +790,10 @@ build/ref_gl/gl_rmisc.o: src/refresh/gl_rmisc.c
build/ref_gl/gl_rsurf.o: src/refresh/gl_rsurf.c
$(CC) $(CFLAGS_OPENGL) -o $@ -c $<
build/ref_gl/gl_scrap.o: src/refresh/gl_scrap.c
$(CC) $(CFLAGS_OPENGL) -o $@ -c $<
build/ref_gl/gl_warp.o: src/refresh/gl_warp.c
$(CC) $(CFLAGS_OPENGL) -o $@ -c $<

View file

@ -1,24 +1,28 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
*/
/* draw.c */
* =======================================================================
*
* Drawing of all images that are not textures
*
* =======================================================================
*/
#include "header/local.h"

View file

@ -30,6 +30,8 @@ Spalten in:
image_t gltextures [ MAX_GLTEXTURES ];
int numgltextures;
int base_textureid; /* gltextures[i] = base_textureid+i */
extern qboolean scrap_dirty;
extern byte scrap_texels [ MAX_SCRAPS ] [ BLOCK_WIDTH * BLOCK_HEIGHT ];
static byte intensitytable [ 256 ];
static unsigned char gammatable [ 256 ];
@ -276,84 +278,6 @@ GL_ImageList_f ( void )
ri.Con_Printf( PRINT_ALL, "Total texel count (not counting mipmaps): %i\n", texels );
}
/*
* scrap allocation
*
* Allocate all the little status bar obejcts into a single texture
* to crutch up inefficient hardware / drivers
*/
#define MAX_SCRAPS 1
#define BLOCK_WIDTH 256
#define BLOCK_HEIGHT 256
int scrap_allocated [ MAX_SCRAPS ] [ BLOCK_WIDTH ];
byte scrap_texels [ MAX_SCRAPS ] [ BLOCK_WIDTH * BLOCK_HEIGHT ];
qboolean scrap_dirty;
/* returns a texture number and the position inside it */
int
Scrap_AllocBlock ( int w, int h, int *x, int *y )
{
int i, j;
int best, best2;
int texnum;
for ( texnum = 0; texnum < MAX_SCRAPS; texnum++ )
{
best = BLOCK_HEIGHT;
for ( i = 0; i < BLOCK_WIDTH - w; i++ )
{
best2 = 0;
for ( j = 0; j < w; j++ )
{
if ( scrap_allocated [ texnum ] [ i + j ] >= best )
{
break;
}
if ( scrap_allocated [ texnum ] [ i + j ] > best2 )
{
best2 = scrap_allocated [ texnum ] [ i + j ];
}
}
if ( j == w )
{ /* this is a valid spot */
*x = i;
*y = best = best2;
}
}
if ( best + h > BLOCK_HEIGHT )
{
continue;
}
for ( i = 0; i < w; i++ )
{
scrap_allocated [ texnum ] [ *x + i ] = best + h;
}
return ( texnum );
}
return ( -1 );
}
int scrap_uploads;
void
Scrap_Upload ( void )
{
scrap_uploads++;
GL_Bind( TEXNUM_SCRAPS );
GL_Upload8( scrap_texels [ 0 ], BLOCK_WIDTH, BLOCK_HEIGHT, false, false );
scrap_dirty = false;
}
void
LoadPCX ( char *filename, byte **pic, byte **palette, int *width, int *height )
{

95
src/refresh/gl_scrap.c Normal file
View file

@ -0,0 +1,95 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Allocate all the little status bar obejcts into a single texture
* to crutch up inefficient hardware / drivers.
*
* =======================================================================
*/
#include "header/local.h"
int scrap_allocated [ MAX_SCRAPS ] [ BLOCK_WIDTH ];
byte scrap_texels [ MAX_SCRAPS ] [ BLOCK_WIDTH * BLOCK_HEIGHT ];
qboolean scrap_dirty;
int scrap_uploads;
/* returns a texture number and the position inside it */
int
Scrap_AllocBlock ( int w, int h, int *x, int *y )
{
int i, j;
int best, best2;
int texnum;
for ( texnum = 0; texnum < MAX_SCRAPS; texnum++ )
{
best = BLOCK_HEIGHT;
for ( i = 0; i < BLOCK_WIDTH - w; i++ )
{
best2 = 0;
for ( j = 0; j < w; j++ )
{
if ( scrap_allocated [ texnum ] [ i + j ] >= best )
{
break;
}
if ( scrap_allocated [ texnum ] [ i + j ] > best2 )
{
best2 = scrap_allocated [ texnum ] [ i + j ];
}
}
if ( j == w )
{ /* this is a valid spot */
*x = i;
*y = best = best2;
}
}
if ( best + h > BLOCK_HEIGHT )
{
continue;
}
for ( i = 0; i < w; i++ )
{
scrap_allocated [ texnum ] [ *x + i ] = best + h;
}
return ( texnum );
}
return ( -1 );
}
void
Scrap_Upload ( void )
{
scrap_uploads++;
GL_Bind( TEXNUM_SCRAPS );
GL_Upload8( scrap_texels [ 0 ], BLOCK_WIDTH, BLOCK_HEIGHT, false, false );
scrap_dirty = false;
}

View file

@ -102,6 +102,10 @@ typedef struct image_s
#define MAX_GLTEXTURES 1024
#define MAX_SCRAPS 1
#define BLOCK_WIDTH 256
#define BLOCK_HEIGHT 256
//===================================================================
typedef enum
@ -327,6 +331,7 @@ void GL_FreeUnusedImages (void);
void GL_TextureAlphaMode( char *string );
void GL_TextureSolidMode( char *string );
int Scrap_AllocBlock ( int w, int h, int *x, int *y );
/*
** GL extension emulation functions