ref: moved VGUI support API implementation to the engine
This commit is contained in:
parent
107a6aed01
commit
9577a6af21
9 changed files with 233 additions and 613 deletions
|
@ -1057,7 +1057,6 @@ int Con_UtfMoveRight( char *str, int pos, int length );
|
|||
void Con_DefaultColor( int r, int g, int b, qboolean gameui );
|
||||
cl_font_t *Con_GetCurFont( void );
|
||||
cl_font_t *Con_GetFont( int num );
|
||||
void Con_DrawCharacterLen( int number, int *width, int *height );
|
||||
int Con_DrawString( int x, int y, const char *string, rgba_t setColor ); // legacy, use cl_font.c
|
||||
void GAME_EXPORT Con_DrawStringLen( const char *pText, int *length, int *height ); // legacy, use cl_font.c
|
||||
void Con_CharEvent( int key );
|
||||
|
|
|
@ -23,55 +23,180 @@ GNU General Public License for more details.
|
|||
#include "input.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
CVAR_DEFINE_AUTO( vgui_utf8, "0", FCVAR_ARCHIVE, "enable utf-8 support for vgui text" );
|
||||
#define VGUI_MAX_TEXTURES 1024
|
||||
|
||||
static void GAME_EXPORT *VGUI_EngineMalloc( size_t size );
|
||||
static void GAME_EXPORT VGUI_GetMousePos( int *, int * );
|
||||
static void GAME_EXPORT VGUI_CursorSelect( VGUI_DefaultCursor );
|
||||
static byte GAME_EXPORT VGUI_GetColor( int, int );
|
||||
static int GAME_EXPORT VGUI_UtfProcessChar( int in );
|
||||
static qboolean GAME_EXPORT VGUI_IsInGame( void );
|
||||
|
||||
static struct
|
||||
typedef struct vgui_static_s
|
||||
{
|
||||
qboolean initialized;
|
||||
vguiapi_t dllFuncs;
|
||||
VGUI_DefaultCursor cursor;
|
||||
vguiapi_t dllFuncs;
|
||||
|
||||
int textures[VGUI_MAX_TEXTURES];
|
||||
int texture_id;
|
||||
int bound_texture;
|
||||
byte color[4];
|
||||
qboolean enable_texture;
|
||||
|
||||
HINSTANCE hInstance;
|
||||
|
||||
enum VGUI_KeyCode virtualKeyTrans[256];
|
||||
} vgui =
|
||||
{
|
||||
false,
|
||||
{
|
||||
false, // Not initialized yet
|
||||
NULL, // VGUI_DrawInit,
|
||||
NULL, // VGUI_DrawShutdown,
|
||||
NULL, // VGUI_SetupDrawingText,
|
||||
NULL, // VGUI_SetupDrawingRect,
|
||||
NULL, // VGUI_SetupDrawingImage,
|
||||
NULL, // VGUI_BindTexture,
|
||||
NULL, // VGUI_EnableTexture,
|
||||
NULL, // VGUI_CreateTexture,
|
||||
NULL, // VGUI_UploadTexture,
|
||||
NULL, // VGUI_UploadTextureBlock,
|
||||
NULL, // VGUI_DrawQuad,
|
||||
NULL, // VGUI_GetTextureSizes,
|
||||
NULL, // VGUI_GenerateTexture,
|
||||
VGUI_EngineMalloc,
|
||||
VGUI_CursorSelect,
|
||||
VGUI_GetColor,
|
||||
VGUI_IsInGame,
|
||||
Key_EnableTextInput,
|
||||
VGUI_GetMousePos,
|
||||
VGUI_UtfProcessChar,
|
||||
Platform_GetClipboardText,
|
||||
Platform_SetClipboardText,
|
||||
Platform_GetKeyModifiers,
|
||||
},
|
||||
-1
|
||||
} vgui_static_t;
|
||||
|
||||
static vgui_static_t vgui = {
|
||||
false, -1
|
||||
};
|
||||
static CVAR_DEFINE_AUTO( vgui_utf8, "0", FCVAR_ARCHIVE, "enable utf-8 support for vgui text" );
|
||||
|
||||
static void GAME_EXPORT VGUI_DrawInit( void )
|
||||
{
|
||||
memset( vgui.textures, 0, sizeof( vgui.textures ));
|
||||
vgui.texture_id = vgui.bound_texture = 0;
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_DrawShutdown( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 1; i < vgui.texture_id; i++ )
|
||||
ref.dllFuncs.GL_FreeTexture( vgui.textures[i] );
|
||||
}
|
||||
|
||||
static int GAME_EXPORT VGUI_GenerateTexture( void )
|
||||
{
|
||||
if( ++vgui.texture_id >= VGUI_MAX_TEXTURES )
|
||||
Host_Error( "%s: VGUI_MAX_TEXTURES limit exceeded\n", __func__ );
|
||||
|
||||
return vgui.texture_id;
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_UploadTexture( int id, const char *buffer, int width, int height )
|
||||
{
|
||||
rgbdata_t r_image = { 0 };
|
||||
char texName[32];
|
||||
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: bad texture %i. Ignored\n", __func__, id );
|
||||
return;
|
||||
}
|
||||
|
||||
Q_snprintf( texName, sizeof( texName ), "*vgui%i", id );
|
||||
|
||||
r_image.width = width;
|
||||
r_image.height = height;
|
||||
r_image.type = PF_RGBA_32;
|
||||
r_image.size = width * height * 4;
|
||||
r_image.flags = IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA;
|
||||
r_image.buffer = (byte*)buffer;
|
||||
|
||||
vgui.textures[id] = GL_LoadTextureInternal( texName, &r_image, TF_IMAGE );
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_CreateTexture( int id, int width, int height )
|
||||
{
|
||||
rgbdata_t r_image = { 0 };
|
||||
char texName[32];
|
||||
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: bad texture %i. Ignored\n", __func__, id );
|
||||
return;
|
||||
}
|
||||
|
||||
Q_snprintf( texName, sizeof( texName ), "*vgui%i", id );
|
||||
|
||||
r_image.width = width;
|
||||
r_image.height = height;
|
||||
r_image.type = PF_RGBA_32;
|
||||
r_image.size = width * height * 4;
|
||||
r_image.flags = IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA;
|
||||
r_image.buffer = NULL;
|
||||
|
||||
vgui.textures[id] = GL_LoadTextureInternal( texName, &r_image, TF_IMAGE );
|
||||
vgui.bound_texture = id;
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_UploadTextureBlock( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight )
|
||||
{
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES || vgui.textures[id] == 0 )
|
||||
{
|
||||
Con_DPrintf( S_ERROR "%s: bad texture %i. Ignored\n", __func__, id );
|
||||
return;
|
||||
}
|
||||
|
||||
ref.dllFuncs.VGUI_UploadTextureBlock( drawX, drawY, rgba, blockWidth, blockHeight );
|
||||
vgui.bound_texture = id;
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_BindTexture( int id )
|
||||
{
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES || !vgui.textures[id] )
|
||||
id = 1; // NOTE: same as bogus index 2700 in GoldSrc
|
||||
|
||||
ref.dllFuncs.GL_Bind( XASH_TEXTURE0, vgui.textures[id] );
|
||||
vgui.bound_texture = id;
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_GetTextureSizes( int *w, int *h )
|
||||
{
|
||||
int texnum;
|
||||
|
||||
if( vgui.bound_texture )
|
||||
texnum = vgui.textures[vgui.bound_texture];
|
||||
else
|
||||
texnum = R_GetBuiltinTexture( REF_DEFAULT_TEXTURE );
|
||||
|
||||
R_GetTextureParms( w, h, texnum );
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_SetupDrawingRect( int *pColor )
|
||||
{
|
||||
ref.dllFuncs.VGUI_SetupDrawing( true );
|
||||
Vector4Set( vgui.color, pColor[0], pColor[1], pColor[2], 255 - pColor[3] );
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_SetupDrawingText( int *pColor )
|
||||
{
|
||||
ref.dllFuncs.VGUI_SetupDrawing( false );
|
||||
Vector4Set( vgui.color, pColor[0], pColor[1], pColor[2], 255 - pColor[3] );
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_DrawQuad( const vpoint_t *ul, const vpoint_t *lr )
|
||||
{
|
||||
float x, y, w, h;
|
||||
|
||||
if( !ul || !lr )
|
||||
return;
|
||||
|
||||
x = ul->point[0];
|
||||
y = ul->point[1];
|
||||
w = lr->point[0] - x;
|
||||
h = lr->point[1] - y;
|
||||
|
||||
SPR_AdjustSize( &x, &y, &w, &h );
|
||||
|
||||
if( vgui.enable_texture )
|
||||
{
|
||||
float s1, s2, t1, t2;
|
||||
|
||||
s1 = ul->coord[0];
|
||||
t1 = ul->coord[1];
|
||||
s2 = lr->coord[0];
|
||||
t2 = lr->coord[1];
|
||||
|
||||
ref.dllFuncs.Color4ub( vgui.color[0], vgui.color[1], vgui.color[2], vgui.color[3] );
|
||||
ref.dllFuncs.R_DrawStretchPic( x, y, w, h, s1, t1, s2, t2, vgui.textures[vgui.bound_texture] );
|
||||
}
|
||||
else
|
||||
{
|
||||
ref.dllFuncs.FillRGBABlend( x, y, w, h, vgui.color[0], vgui.color[1], vgui.color[2], vgui.color[3] );
|
||||
}
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_EnableTexture( qboolean enable )
|
||||
{
|
||||
vgui.enable_texture = enable;
|
||||
}
|
||||
|
||||
static void GAME_EXPORT *VGUI_EngineMalloc( size_t size )
|
||||
{
|
||||
|
@ -117,33 +242,46 @@ qboolean VGui_IsActive( void )
|
|||
return vgui.initialized;
|
||||
}
|
||||
|
||||
static void VGui_FillAPIFromRef( vguiapi_t *to, const ref_interface_t *from )
|
||||
{
|
||||
to->DrawInit = from->VGUI_DrawInit;
|
||||
to->DrawShutdown = from->VGUI_DrawShutdown;
|
||||
to->SetupDrawingText = from->VGUI_SetupDrawingText;
|
||||
to->SetupDrawingRect = from->VGUI_SetupDrawingRect;
|
||||
to->SetupDrawingImage = from->VGUI_SetupDrawingImage;
|
||||
to->BindTexture = from->VGUI_BindTexture;
|
||||
to->EnableTexture = from->VGUI_EnableTexture;
|
||||
to->CreateTexture = from->VGUI_CreateTexture;
|
||||
to->UploadTexture = from->VGUI_UploadTexture;
|
||||
to->UploadTextureBlock = from->VGUI_UploadTextureBlock;
|
||||
to->DrawQuad = from->VGUI_DrawQuad;
|
||||
to->GetTextureSizes = from->VGUI_GetTextureSizes;
|
||||
to->GenerateTexture = from->VGUI_GenerateTexture;
|
||||
}
|
||||
|
||||
void VGui_RegisterCvars( void )
|
||||
{
|
||||
Cvar_RegisterVariable( &vgui_utf8 );
|
||||
}
|
||||
|
||||
static const vguiapi_t gEngfuncs =
|
||||
{
|
||||
false, // Not initialized yet
|
||||
VGUI_DrawInit, // VGUI_DrawInit,
|
||||
VGUI_DrawShutdown, // VGUI_DrawShutdown,
|
||||
VGUI_SetupDrawingText, // VGUI_SetupDrawingText,
|
||||
VGUI_SetupDrawingRect, // VGUI_SetupDrawingRect,
|
||||
VGUI_SetupDrawingText, // VGUI_SetupDrawingImage, (same as text)
|
||||
VGUI_BindTexture, // VGUI_BindTexture,
|
||||
VGUI_EnableTexture, // VGUI_EnableTexture,
|
||||
VGUI_CreateTexture, // VGUI_CreateTexture,
|
||||
VGUI_UploadTexture, // VGUI_UploadTexture,
|
||||
VGUI_UploadTextureBlock, // VGUI_UploadTextureBlock,
|
||||
VGUI_DrawQuad, // VGUI_DrawQuad,
|
||||
VGUI_GetTextureSizes, // VGUI_GetTextureSizes,
|
||||
VGUI_GenerateTexture, // VGUI_GenerateTexture,
|
||||
VGUI_EngineMalloc,
|
||||
VGUI_CursorSelect,
|
||||
VGUI_GetColor,
|
||||
VGUI_IsInGame,
|
||||
Key_EnableTextInput,
|
||||
VGUI_GetMousePos,
|
||||
VGUI_UtfProcessChar,
|
||||
Platform_GetClipboardText,
|
||||
Platform_SetClipboardText,
|
||||
Platform_GetKeyModifiers,
|
||||
};
|
||||
|
||||
qboolean VGui_LoadProgs( HINSTANCE hInstance )
|
||||
{
|
||||
void (*F)( vguiapi_t* );
|
||||
qboolean client = hInstance != NULL;
|
||||
|
||||
memcpy( &vgui.dllFuncs, &gEngfuncs, sizeof( vgui.dllFuncs ));
|
||||
|
||||
// not loading interface from client.dll, load vgui_support.dll instead
|
||||
if( !client )
|
||||
{
|
||||
|
@ -178,7 +316,6 @@ qboolean VGui_LoadProgs( HINSTANCE hInstance )
|
|||
|
||||
if( F )
|
||||
{
|
||||
VGui_FillAPIFromRef( &vgui.dllFuncs, &ref.dllFuncs );
|
||||
F( &vgui.dllFuncs );
|
||||
|
||||
vgui.initialized = vgui.dllFuncs.initialized = true;
|
||||
|
@ -233,8 +370,9 @@ void VGui_Shutdown( void )
|
|||
if( vgui.hInstance )
|
||||
COM_FreeLibrary( vgui.hInstance );
|
||||
|
||||
// drop pointers to now unloaded vgui_support
|
||||
memcpy( &vgui.dllFuncs, &gEngfuncs, sizeof( vgui.dllFuncs ));
|
||||
vgui.hInstance = NULL;
|
||||
vgui.initialized = false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -627,19 +627,8 @@ typedef struct ref_interface_s
|
|||
void (*CullFace)( TRICULLSTYLE mode );
|
||||
|
||||
// vgui drawing implementation
|
||||
void (*VGUI_DrawInit)( void );
|
||||
void (*VGUI_DrawShutdown)( void );
|
||||
void (*VGUI_SetupDrawingText)( int *pColor );
|
||||
void (*VGUI_SetupDrawingRect)( int *pColor );
|
||||
void (*VGUI_SetupDrawingImage)( int *pColor );
|
||||
void (*VGUI_BindTexture)( int id );
|
||||
void (*VGUI_EnableTexture)( qboolean enable );
|
||||
void (*VGUI_CreateTexture)( int id, int width, int height );
|
||||
void (*VGUI_UploadTexture)( int id, const char *buffer, int width, int height );
|
||||
void (*VGUI_UploadTextureBlock)( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight );
|
||||
void (*VGUI_DrawQuad)( const vpoint_t *ul, const vpoint_t *lr );
|
||||
void (*VGUI_GetTextureSizes)( int *width, int *height );
|
||||
int (*VGUI_GenerateTexture)( void );
|
||||
void (*VGUI_SetupDrawing)( qboolean rect );
|
||||
void (*VGUI_UploadTextureBlock)( int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight );
|
||||
} ref_interface_t;
|
||||
|
||||
typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* engfuncs, ref_globals_t *pGlobals );
|
||||
|
|
|
@ -378,6 +378,28 @@ static qboolean R_SetDisplayTransform( ref_screen_rotation_t rotate, int offset_
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_UploadTextureBlock( int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight )
|
||||
{
|
||||
pglTexSubImage2D( GL_TEXTURE_2D, 0, drawX, drawY, blockWidth, blockHeight, GL_RGBA, GL_UNSIGNED_BYTE, rgba );
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_SetupDrawing( qboolean rect )
|
||||
{
|
||||
pglEnable( GL_BLEND );
|
||||
pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
|
||||
if( rect )
|
||||
{
|
||||
pglDisable( GL_ALPHA_TEST );
|
||||
}
|
||||
else
|
||||
{
|
||||
pglEnable( GL_ALPHA_TEST );
|
||||
pglAlphaFunc( GL_GREATER, 0.0f );
|
||||
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
|
||||
}
|
||||
}
|
||||
|
||||
static void* GAME_EXPORT R_GetProcAddress( const char *name )
|
||||
{
|
||||
#ifdef XASH_GL4ES
|
||||
|
@ -392,7 +414,7 @@ static const char *R_GetConfigName( void )
|
|||
return "opengl";
|
||||
}
|
||||
|
||||
ref_interface_t gReffuncs =
|
||||
static ref_interface_t gReffuncs =
|
||||
{
|
||||
R_Init,
|
||||
R_Shutdown,
|
||||
|
@ -527,19 +549,8 @@ ref_interface_t gReffuncs =
|
|||
TriFogParams,
|
||||
TriCullFace,
|
||||
|
||||
VGUI_DrawInit,
|
||||
VGUI_DrawShutdown,
|
||||
VGUI_SetupDrawingText,
|
||||
VGUI_SetupDrawingRect,
|
||||
VGUI_SetupDrawingImage,
|
||||
VGUI_BindTexture,
|
||||
VGUI_EnableTexture,
|
||||
VGUI_CreateTexture,
|
||||
VGUI_UploadTexture,
|
||||
VGUI_SetupDrawing,
|
||||
VGUI_UploadTextureBlock,
|
||||
VGUI_DrawQuad,
|
||||
VGUI_GetTextureSizes,
|
||||
VGUI_GenerateTexture,
|
||||
};
|
||||
|
||||
int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs, ref_globals_t *globals );
|
||||
|
|
|
@ -497,23 +497,6 @@ void R_ResetRipples( void );
|
|||
void R_AnimateRipples( void );
|
||||
void R_UploadRipples( texture_t *image );
|
||||
|
||||
//
|
||||
// gl_vgui.c
|
||||
//
|
||||
void VGUI_DrawInit( void );
|
||||
void VGUI_DrawShutdown( void );
|
||||
void VGUI_SetupDrawingText( int *pColor );
|
||||
void VGUI_SetupDrawingRect( int *pColor );
|
||||
void VGUI_SetupDrawingImage( int *pColor );
|
||||
void VGUI_BindTexture( int id );
|
||||
void VGUI_EnableTexture( qboolean enable );
|
||||
void VGUI_CreateTexture( int id, int width, int height );
|
||||
void VGUI_UploadTexture( int id, const char *buffer, int width, int height );
|
||||
void VGUI_UploadTextureBlock( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight );
|
||||
void VGUI_DrawQuad( const vpoint_t *ul, const vpoint_t *lr );
|
||||
void VGUI_GetTextureSizes( int *width, int *height );
|
||||
int VGUI_GenerateTexture( void );
|
||||
|
||||
//#include "vid_common.h"
|
||||
|
||||
//
|
||||
|
|
253
ref/gl/gl_vgui.c
253
ref/gl/gl_vgui.c
|
@ -1,253 +0,0 @@
|
|||
/*
|
||||
gl_vgui.c - OpenGL vgui draw methods
|
||||
Copyright (C) 2011 Uncle Mike
|
||||
Copyright (C) 2019 a1batross
|
||||
|
||||
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 3 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.
|
||||
*/
|
||||
|
||||
#include "gl_local.h"
|
||||
|
||||
#define VGUI_MAX_TEXTURES ( MAX_TEXTURES / 2 ) // a half of total textures count
|
||||
|
||||
static int g_textures[VGUI_MAX_TEXTURES];
|
||||
static int g_textureId = 0;
|
||||
static int g_iBoundTexture;
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_DrawInit
|
||||
|
||||
Startup VGUI backend
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_DrawInit( void )
|
||||
{
|
||||
memset( g_textures, 0, sizeof( g_textures ));
|
||||
g_textureId = g_iBoundTexture = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_DrawShutdown
|
||||
|
||||
Release all textures
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_DrawShutdown( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 1; i < g_textureId; i++ )
|
||||
{
|
||||
GL_FreeTexture( g_textures[i] );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_GenerateTexture
|
||||
|
||||
generate unique texture number
|
||||
================
|
||||
*/
|
||||
int GAME_EXPORT VGUI_GenerateTexture( void )
|
||||
{
|
||||
if( ++g_textureId >= VGUI_MAX_TEXTURES )
|
||||
gEngfuncs.Host_Error( "VGUI_GenerateTexture: VGUI_MAX_TEXTURES limit exceeded\n" );
|
||||
return g_textureId;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_UploadTexture
|
||||
|
||||
Upload texture into video memory
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_UploadTexture( int id, const char *buffer, int width, int height )
|
||||
{
|
||||
rgbdata_t r_image;
|
||||
char texName[32];
|
||||
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES )
|
||||
{
|
||||
gEngfuncs.Con_DPrintf( S_ERROR "VGUI_UploadTexture: bad texture %i. Ignored\n", id );
|
||||
return;
|
||||
}
|
||||
|
||||
Q_snprintf( texName, sizeof( texName ), "*vgui%i", id );
|
||||
memset( &r_image, 0, sizeof( r_image ));
|
||||
|
||||
r_image.width = width;
|
||||
r_image.height = height;
|
||||
r_image.type = PF_RGBA_32;
|
||||
r_image.size = r_image.width * r_image.height * 4;
|
||||
r_image.flags = IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA;
|
||||
r_image.buffer = (byte *)buffer;
|
||||
|
||||
g_textures[id] = GL_LoadTextureInternal( texName, &r_image, TF_IMAGE );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_CreateTexture
|
||||
|
||||
Create empty rgba texture and upload them into video memory
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_CreateTexture( int id, int width, int height )
|
||||
{
|
||||
rgbdata_t r_image;
|
||||
char texName[32];
|
||||
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES )
|
||||
{
|
||||
gEngfuncs.Con_Reportf( S_ERROR "VGUI_CreateTexture: bad texture %i. Ignored\n", id );
|
||||
return;
|
||||
}
|
||||
|
||||
Q_snprintf( texName, sizeof( texName ), "*vgui%i", id );
|
||||
memset( &r_image, 0, sizeof( r_image ));
|
||||
|
||||
r_image.width = width;
|
||||
r_image.height = height;
|
||||
r_image.type = PF_RGBA_32;
|
||||
r_image.size = r_image.width * r_image.height * 4;
|
||||
r_image.flags = IMAGE_HAS_ALPHA;
|
||||
r_image.buffer = NULL;
|
||||
|
||||
g_textures[id] = GL_LoadTextureInternal( texName, &r_image, TF_IMAGE|TF_NEAREST );
|
||||
g_iBoundTexture = id;
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_UploadTextureBlock( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight )
|
||||
{
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES || g_textures[id] == 0 || g_textures[id] == tr.whiteTexture )
|
||||
{
|
||||
gEngfuncs.Con_Reportf( S_ERROR "VGUI_UploadTextureBlock: bad texture %i. Ignored\n", id );
|
||||
return;
|
||||
}
|
||||
|
||||
pglTexSubImage2D( GL_TEXTURE_2D, 0, drawX, drawY, blockWidth, blockHeight, GL_RGBA, GL_UNSIGNED_BYTE, rgba );
|
||||
g_iBoundTexture = id;
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_SetupDrawingRect( int *pColor )
|
||||
{
|
||||
pglEnable( GL_BLEND );
|
||||
pglDisable( GL_ALPHA_TEST );
|
||||
pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
pglColor4ub( pColor[0], pColor[1], pColor[2], 255 - pColor[3] );
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_SetupDrawingText( 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] );
|
||||
}
|
||||
|
||||
void GAME_EXPORT 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] );
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_BindTexture( int id )
|
||||
{
|
||||
if( id > 0 && id < VGUI_MAX_TEXTURES && g_textures[id] )
|
||||
{
|
||||
GL_Bind( XASH_TEXTURE0, g_textures[id] );
|
||||
g_iBoundTexture = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOTE: same as bogus index 2700 in GoldSrc
|
||||
id = g_iBoundTexture = 1;
|
||||
GL_Bind( XASH_TEXTURE0, g_textures[id] );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_GetTextureSizes
|
||||
|
||||
returns wide and tall for currently binded texture
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_GetTextureSizes( int *width, int *height )
|
||||
{
|
||||
gl_texture_t *glt;
|
||||
int texnum;
|
||||
|
||||
if( g_iBoundTexture )
|
||||
texnum = g_textures[g_iBoundTexture];
|
||||
else texnum = tr.defaultTexture;
|
||||
|
||||
glt = R_GetTexture( texnum );
|
||||
if( width ) *width = glt->srcWidth;
|
||||
if( height ) *height = glt->srcHeight;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_EnableTexture
|
||||
|
||||
disable texturemode for fill rectangle
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_EnableTexture( qboolean enable )
|
||||
{
|
||||
if( enable ) pglEnable( GL_TEXTURE_2D );
|
||||
else pglDisable( GL_TEXTURE_2D );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_DrawQuad
|
||||
|
||||
generic method to fill rectangle
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_DrawQuad( const vpoint_t *ul, const vpoint_t *lr )
|
||||
{
|
||||
int width, height;
|
||||
float xscale, yscale;
|
||||
|
||||
gEngfuncs.CL_GetScreenInfo( &width, &height );
|
||||
|
||||
xscale = gpGlobals->width / (float)width;
|
||||
yscale = gpGlobals->height / (float)height;
|
||||
|
||||
ASSERT( ul != NULL && lr != NULL );
|
||||
|
||||
pglBegin( GL_QUADS );
|
||||
pglTexCoord2f( ul->coord[0], ul->coord[1] );
|
||||
pglVertex2f( ul->point[0] * xscale, ul->point[1] * yscale );
|
||||
|
||||
pglTexCoord2f( lr->coord[0], ul->coord[1] );
|
||||
pglVertex2f( lr->point[0] * xscale, ul->point[1] * yscale );
|
||||
|
||||
pglTexCoord2f( lr->coord[0], lr->coord[1] );
|
||||
pglVertex2f( lr->point[0] * xscale, lr->point[1] * yscale );
|
||||
|
||||
pglTexCoord2f( ul->coord[0], lr->coord[1] );
|
||||
pglVertex2f( ul->point[0] * xscale, lr->point[1] * yscale );
|
||||
pglEnd();
|
||||
}
|
|
@ -71,8 +71,6 @@ static qboolean GAME_EXPORT Mod_ProcessRenderData( model_t *mod, qboolean create
|
|||
|
||||
if( create )
|
||||
{
|
||||
|
||||
|
||||
switch( mod->type )
|
||||
{
|
||||
case mod_studio:
|
||||
|
@ -392,6 +390,14 @@ byte *GAME_EXPORT Mod_GetCurrentVis( void )
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_UploadTextureBlock( int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight )
|
||||
{
|
||||
}
|
||||
|
||||
static void GAME_EXPORT VGUI_SetupDrawing( qboolean rect )
|
||||
{
|
||||
}
|
||||
|
||||
static const char *R_GetConfigName( void )
|
||||
{
|
||||
return "ref_soft"; // software specific cvars will go to ref_soft.cfg
|
||||
|
@ -402,7 +408,7 @@ static void* GAME_EXPORT R_GetProcAddress( const char *name )
|
|||
return gEngfuncs.GL_GetProcAddress( name );
|
||||
}
|
||||
|
||||
ref_interface_t gReffuncs =
|
||||
static ref_interface_t gReffuncs =
|
||||
{
|
||||
R_Init,
|
||||
R_Shutdown,
|
||||
|
@ -537,19 +543,8 @@ ref_interface_t gReffuncs =
|
|||
TriFogParams,
|
||||
TriCullFace,
|
||||
|
||||
VGUI_DrawInit,
|
||||
VGUI_DrawShutdown,
|
||||
VGUI_SetupDrawingText,
|
||||
VGUI_SetupDrawingRect,
|
||||
VGUI_SetupDrawingImage,
|
||||
VGUI_BindTexture,
|
||||
VGUI_EnableTexture,
|
||||
VGUI_CreateTexture,
|
||||
VGUI_UploadTexture,
|
||||
VGUI_SetupDrawing,
|
||||
VGUI_UploadTextureBlock,
|
||||
VGUI_DrawQuad,
|
||||
VGUI_GetTextureSizes,
|
||||
VGUI_GenerateTexture,
|
||||
};
|
||||
|
||||
int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs, ref_globals_t *globals );
|
||||
|
|
|
@ -563,23 +563,6 @@ void R_DrawClouds( void );
|
|||
void EmitWaterPolys( msurface_t *warp, qboolean reverse );
|
||||
#endif
|
||||
|
||||
//
|
||||
// gl_vgui.c
|
||||
//
|
||||
void VGUI_DrawInit( void );
|
||||
void VGUI_DrawShutdown( void );
|
||||
void VGUI_SetupDrawingText( int *pColor );
|
||||
void VGUI_SetupDrawingRect( int *pColor );
|
||||
void VGUI_SetupDrawingImage( int *pColor );
|
||||
void VGUI_BindTexture( int id );
|
||||
void VGUI_EnableTexture( qboolean enable );
|
||||
void VGUI_CreateTexture( int id, int width, int height );
|
||||
void VGUI_UploadTexture( int id, const char *buffer, int width, int height );
|
||||
void VGUI_UploadTextureBlock( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight );
|
||||
void VGUI_DrawQuad( const vpoint_t *ul, const vpoint_t *lr );
|
||||
void VGUI_GetTextureSizes( int *width, int *height );
|
||||
int VGUI_GenerateTexture( void );
|
||||
|
||||
//
|
||||
// r_polyse.c
|
||||
//
|
||||
|
|
|
@ -1,225 +0,0 @@
|
|||
/*
|
||||
gl_vgui.c - OpenGL vgui draw methods
|
||||
Copyright (C) 2011 Uncle Mike
|
||||
Copyright (C) 2019 a1batross
|
||||
|
||||
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 3 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.
|
||||
*/
|
||||
|
||||
#include "r_local.h"
|
||||
|
||||
#define VGUI_MAX_TEXTURES ( MAX_TEXTURES / 2 ) // a half of total textures count
|
||||
|
||||
static int g_textures[VGUI_MAX_TEXTURES];
|
||||
static int g_textureId = 0;
|
||||
static int g_iBoundTexture;
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_DrawInit
|
||||
|
||||
Startup VGUI backend
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_DrawInit( void )
|
||||
{
|
||||
memset( g_textures, 0, sizeof( g_textures ));
|
||||
g_textureId = g_iBoundTexture = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_DrawShutdown
|
||||
|
||||
Release all textures
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_DrawShutdown( void )
|
||||
{
|
||||
int i;
|
||||
|
||||
for( i = 1; i < g_textureId; i++ )
|
||||
{
|
||||
GL_FreeTexture( g_textures[i] );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_GenerateTexture
|
||||
|
||||
generate unique texture number
|
||||
================
|
||||
*/
|
||||
int GAME_EXPORT VGUI_GenerateTexture( void )
|
||||
{
|
||||
if( ++g_textureId >= VGUI_MAX_TEXTURES )
|
||||
gEngfuncs.Host_Error( "VGUI_GenerateTexture: VGUI_MAX_TEXTURES limit exceeded\n" );
|
||||
return g_textureId;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_UploadTexture
|
||||
|
||||
Upload texture into video memory
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_UploadTexture( int id, const char *buffer, int width, int height )
|
||||
{
|
||||
rgbdata_t r_image;
|
||||
char texName[32];
|
||||
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES )
|
||||
{
|
||||
gEngfuncs.Con_DPrintf( S_ERROR "VGUI_UploadTexture: bad texture %i. Ignored\n", id );
|
||||
return;
|
||||
}
|
||||
|
||||
Q_snprintf( texName, sizeof( texName ), "*vgui%i", id );
|
||||
memset( &r_image, 0, sizeof( r_image ));
|
||||
|
||||
r_image.width = width;
|
||||
r_image.height = height;
|
||||
r_image.type = PF_RGBA_32;
|
||||
r_image.size = r_image.width * r_image.height * 4;
|
||||
r_image.flags = IMAGE_HAS_COLOR|IMAGE_HAS_ALPHA;
|
||||
r_image.buffer = (byte *)buffer;
|
||||
|
||||
g_textures[id] = GL_LoadTextureInternal( texName, &r_image, TF_IMAGE );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_CreateTexture
|
||||
|
||||
Create empty rgba texture and upload them into video memory
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_CreateTexture( int id, int width, int height )
|
||||
{
|
||||
rgbdata_t r_image;
|
||||
char texName[32];
|
||||
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES )
|
||||
{
|
||||
gEngfuncs.Con_Reportf( S_ERROR "VGUI_CreateTexture: bad texture %i. Ignored\n", id );
|
||||
return;
|
||||
}
|
||||
|
||||
Q_snprintf( texName, sizeof( texName ), "*vgui%i", id );
|
||||
memset( &r_image, 0, sizeof( r_image ));
|
||||
|
||||
r_image.width = width;
|
||||
r_image.height = height;
|
||||
r_image.type = PF_RGBA_32;
|
||||
r_image.size = r_image.width * r_image.height * 4;
|
||||
r_image.flags = IMAGE_HAS_ALPHA;
|
||||
r_image.buffer = NULL;
|
||||
|
||||
g_textures[id] = GL_LoadTextureInternal( texName, &r_image, TF_IMAGE|TF_NEAREST );
|
||||
g_iBoundTexture = id;
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_UploadTextureBlock( int id, int drawX, int drawY, const byte *rgba, int blockWidth, int blockHeight )
|
||||
{
|
||||
if( id <= 0 || id >= VGUI_MAX_TEXTURES || g_textures[id] == 0 || g_textures[id] == tr.whiteTexture )
|
||||
{
|
||||
gEngfuncs.Con_Reportf( S_ERROR "VGUI_UploadTextureBlock: bad texture %i. Ignored\n", id );
|
||||
return;
|
||||
}
|
||||
|
||||
//pglTexSubImage2D( GL_TEXTURE_2D, 0, drawX, drawY, blockWidth, blockHeight, GL_RGBA, GL_UNSIGNED_BYTE, rgba );
|
||||
g_iBoundTexture = id;
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_SetupDrawingRect( int *pColor )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_SetupDrawingText( int *pColor )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_SetupDrawingImage( int *pColor )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GAME_EXPORT VGUI_BindTexture( int id )
|
||||
{
|
||||
if( id > 0 && id < VGUI_MAX_TEXTURES && g_textures[id] )
|
||||
{
|
||||
GL_Bind( XASH_TEXTURE0, g_textures[id] );
|
||||
g_iBoundTexture = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOTE: same as bogus index 2700 in GoldSrc
|
||||
id = g_iBoundTexture = 1;
|
||||
GL_Bind( XASH_TEXTURE0, g_textures[id] );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_GetTextureSizes
|
||||
|
||||
returns wide and tall for currently binded texture
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_GetTextureSizes( int *width, int *height )
|
||||
{
|
||||
image_t *glt;
|
||||
int texnum;
|
||||
|
||||
if( g_iBoundTexture )
|
||||
texnum = g_textures[g_iBoundTexture];
|
||||
else texnum = tr.defaultTexture;
|
||||
|
||||
glt = R_GetTexture( texnum );
|
||||
if( width ) *width = glt->srcWidth;
|
||||
if( height ) *height = glt->srcHeight;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_EnableTexture
|
||||
|
||||
disable texturemode for fill rectangle
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_EnableTexture( qboolean enable )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
VGUI_DrawQuad
|
||||
|
||||
generic method to fill rectangle
|
||||
================
|
||||
*/
|
||||
void GAME_EXPORT VGUI_DrawQuad( const vpoint_t *ul, const vpoint_t *lr )
|
||||
{
|
||||
int width, height;
|
||||
float xscale, yscale;
|
||||
|
||||
gEngfuncs.CL_GetScreenInfo( &width, &height );
|
||||
|
||||
xscale = gpGlobals->width / (float)width;
|
||||
yscale = gpGlobals->height / (float)height;
|
||||
|
||||
ASSERT( ul != NULL && lr != NULL );
|
||||
}
|
Loading…
Add table
Reference in a new issue