From 99bd7c81da5b8fd9c970fddf429bfe92713683e2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 18 Feb 2019 21:25:26 +0300 Subject: [PATCH] ref: render code moved out of engine, doesn't compile, first API prototype --- common/defaults.h | 4 + common/ref_api.h | 209 +++ common/render_api.h | 2 +- engine/client/avi/avi_win.c | 1 - engine/client/cl_cmds.c | 59 +- engine/client/cl_debug.c | 3 +- engine/client/cl_demo.c | 3 +- engine/client/cl_frame.c | 36 +- engine/client/cl_game.c | 430 ++---- engine/client/cl_gameui.c | 55 +- engine/client/cl_main.c | 8 +- engine/client/cl_mobile.c | 13 +- engine/client/cl_netgraph.c | 32 +- engine/client/cl_parse.c | 25 +- engine/client/cl_pmove.c | 2 +- engine/client/cl_qparse.c | 7 +- engine/client/cl_remap.c | 69 +- engine/client/cl_scrn.c | 63 +- engine/client/cl_tent.c | 74 +- engine/client/cl_tent.h | 16 +- engine/client/cl_video.c | 5 +- engine/client/cl_view.c | 55 +- engine/client/client.h | 3 +- engine/client/console.c | 104 +- engine/client/in_joy.c | 1 - engine/client/in_touch.c | 1766 ------------------------ engine/client/input.c | 13 +- engine/client/mod_dbghulls.c | 66 +- engine/client/ref_common.c | 189 +++ engine/client/ref_common.h | 54 + engine/client/s_main.c | 3 +- engine/client/vgui/vgui_draw.c | 276 +--- engine/client/vid_common.c | 17 +- engine/client/vid_common.h | 21 - engine/common/common.h | 5 +- engine/common/crtlib.h | 1 + engine/common/custom.c | 3 +- engine/common/gamma.c | 3 +- engine/common/imagelib/img_utils.c | 3 +- engine/common/mathlib.c | 47 + engine/common/mathlib.h | 3 + engine/common/mod_bmodel.c | 37 +- engine/common/mod_local.h | 2 - engine/common/mod_studio.c | 7 +- engine/common/model.c | 33 +- engine/common/pm_debug.c | 5 +- engine/platform/sdl/events.c | 23 +- engine/platform/sdl/in_sdl.c | 1 - engine/platform/sdl/vid_sdl.c | 468 +------ engine/server/sv_game.c | 7 +- engine/server/sv_phys.c | 13 +- engine/server/sv_save.c | 3 +- {engine/client => ref_gl}/gl_alias.c | 0 {engine/client => ref_gl}/gl_backend.c | 46 + {engine/client => ref_gl}/gl_beams.c | 8 +- ref_gl/gl_context.c | 491 +++++++ {engine/client => ref_gl}/gl_cull.c | 0 ref_gl/gl_dbghulls.c | 93 ++ {engine/client => ref_gl}/gl_decals.c | 0 {engine/client => ref_gl}/gl_draw.c | 0 {engine/client => ref_gl}/gl_export.h | 0 {engine/client => ref_gl}/gl_frustum.c | 0 {engine/client => ref_gl}/gl_frustum.h | 0 {engine/client => ref_gl}/gl_image.c | 15 - {engine/client => ref_gl}/gl_local.h | 48 +- {engine/client => ref_gl}/gl_refrag.c | 0 {engine/client => ref_gl}/gl_rlight.c | 0 {engine/client => ref_gl}/gl_rmain.c | 2 +- {engine/client => ref_gl}/gl_rmath.c | 49 +- {engine/client => ref_gl}/gl_rmisc.c | 23 - {engine/client => ref_gl}/gl_rpart.c | 0 {engine/client => ref_gl}/gl_rsurf.c | 0 {engine/client => ref_gl}/gl_sprite.c | 0 {engine/client => ref_gl}/gl_studio.c | 27 - ref_gl/gl_triapi.c | 335 +++++ ref_gl/gl_vgui.c | 242 ++++ {engine/client => ref_gl}/gl_warp.c | 2 +- ref_gl/wscript | 50 + wscript | 8 +- 79 files changed, 2320 insertions(+), 3467 deletions(-) create mode 100644 common/ref_api.h delete mode 100644 engine/client/in_touch.c create mode 100644 engine/client/ref_common.c create mode 100644 engine/client/ref_common.h rename {engine/client => ref_gl}/gl_alias.c (100%) rename {engine/client => ref_gl}/gl_backend.c (96%) rename {engine/client => ref_gl}/gl_beams.c (99%) create mode 100644 ref_gl/gl_context.c rename {engine/client => ref_gl}/gl_cull.c (100%) create mode 100644 ref_gl/gl_dbghulls.c rename {engine/client => ref_gl}/gl_decals.c (100%) rename {engine/client => ref_gl}/gl_draw.c (100%) rename {engine/client => ref_gl}/gl_export.h (100%) rename {engine/client => ref_gl}/gl_frustum.c (100%) rename {engine/client => ref_gl}/gl_frustum.h (100%) rename {engine/client => ref_gl}/gl_image.c (99%) rename {engine/client => ref_gl}/gl_local.h (96%) rename {engine/client => ref_gl}/gl_refrag.c (100%) rename {engine/client => ref_gl}/gl_rlight.c (100%) rename {engine/client => ref_gl}/gl_rmain.c (99%) rename {engine/client => ref_gl}/gl_rmath.c (89%) rename {engine/client => ref_gl}/gl_rmisc.c (91%) rename {engine/client => ref_gl}/gl_rpart.c (100%) rename {engine/client => ref_gl}/gl_rsurf.c (100%) rename {engine/client => ref_gl}/gl_sprite.c (100%) rename {engine/client => ref_gl}/gl_studio.c (99%) create mode 100644 ref_gl/gl_triapi.c create mode 100644 ref_gl/gl_vgui.c rename {engine/client => ref_gl}/gl_warp.c (99%) create mode 100644 ref_gl/wscript diff --git a/common/defaults.h b/common/defaults.h index 7eb68476..0df60a07 100644 --- a/common/defaults.h +++ b/common/defaults.h @@ -150,6 +150,10 @@ Default build-depended cvar and constant values #define DEFAULT_FULLSCREEN 1 #endif +#ifndef DEFAULT_RENDERER + #define DEFAULT_RENDERER "ref_gl" +#endif + #if TARGET_OS_IPHONE #define DEFAULT_CON_MAXFRAC "0.5" #else diff --git a/common/ref_api.h b/common/ref_api.h new file mode 100644 index 00000000..d30f03d3 --- /dev/null +++ b/common/ref_api.h @@ -0,0 +1,209 @@ +/* +ref_api.h - Xash3D render dll API +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. +*/ +#pragma once +#ifndef REF_API +#define REF_API + +#include "vgui_api.h" +#include "render_api.h" +#include "triangleapi.h" +#include "const.h" +#include "cl_entity.h" +#include "com_model.h" +#include "studio.h" +#include "r_efx.h" + +#define REF_API_VERSION 1 + +typedef struct ref_globals_s +{ + qboolean developer; + + // viewport width and height + int width; + int height; + qboolean fullScreen; + qboolean wideScreen; + + vec3_t vieworg; + vec3_t viewangles; + vec3_t vforward, vright, vup; + + cl_entity_t *currententity; + model_t *currentmodel; + + float fov_x, fov_y; +} ref_globals_t; + +enum +{ + GL_KEEP_UNIT = -1, + XASH_TEXTURE0 = 0, + XASH_TEXTURE1, + XASH_TEXTURE2, + XASH_TEXTURE3, // g-cont. 4 units should be enough + XASH_TEXTURE4, // mittorn. bump+detail needs 5 for single-pass + MAX_TEXTURE_UNITS = 32 // can't access to all over units without GLSL or cg +}; + +enum // r_speeds counters +{ + RS_ACTIVE_TENTS = 0, +}; + +enum ref_shared_texture_e +{ + REF_DEFAULT_TEXTURE, + REF_GRAY_TEXTURE, + REF_WHITE_TEXTURE, + REF_SOLIDSKY_TEXTURE, + REF_ALPHASKY_TEXTURE, +}; + +typedef struct ref_api_s +{ + // TriApi helper + int (*TriGetRenderMode)( void ); +} ref_api_t; + +struct mip_s; + +// render callbacks +typedef struct ref_interface_s +{ + // construct, destruct + qboolean (*R_Init)( qboolean context ); // context is true if you need context management + const char *(*R_GetInitError)( void ); + void (*R_Shutdown)( void ); + + // + void (*GL_InitExtensions)( void ); + void (*GL_ClearExtensions)( void ); + + + void (*R_BeginFrame)( qboolean clearScene ); + void (*R_RenderScene)( void ); + // void (*R_RenderFrame)( struct ref_viewpass_s *rvp ); part of RenderInterface + void (*R_EndFrame)( void ); + void (*R_PushScene)( void ); + void (*R_PopScene)( void ); + // void (*R_ClearScene)( void ); part of RenderInterface + void (*GL_BackendStartFrame)( void ); + void (*GL_BackendEndFrame)( void ); + + void (*R_ClearScreen)( void ); // clears color buffer on GL + void (*R_AllowFog)( qboolean allow ); + void (*GL_SetRenderMode)( int renderMode ); + + int (*R_AddEntity)( int entityType, cl_entity_t *ent ); + + // view info + qboolean (*IsNormalPass)( void ); + + // debug + void (*R_ShowTextures)( void ); + void (*R_ShowTree)( void ); + void (*R_IncrementSpeedsCounter)( int counterType ); + + // texture management + const byte *(*GL_TextureData)( unsigned int texnum ); + const char *(*R_GetTextureName)( int idx ); + const byte *(*R_GetTextureOriginalBuffer)( int idx ); // not always available + int (*GL_LoadTextureFromBuffer)( const char *name, rgbdata_t *pic, texFlags_t flags, qboolean update ); + int (*R_GetBuiltinTexture)( enum ref_shared_texture_e type ); + void (*R_FreeSharedTexture)( enum ref_shared_texture_e type ); + void (*GL_ProcessTexture)( int texnum, float gamma, int topColor, int bottomColor ); + void (*R_SetupSky)( const char *skyname ); + + + // 2D + void (*R_Set2DMode)( qboolean enable ); + void (*R_DrawStretchRaw)( float x, float y, float w, float h, int cols, int rows, const byte *data, qboolean dirty ); + void (*R_DrawStretchPic)( float x, float y, float w, float h, float s1, float t1, float s2, float t2, int texnum ); + void (*R_DrawTileClear)( int x, int y, int w, int h ); + void (*FillRGBA)( float x, float y, float w, float h, int r, int g, int b, int a ); // in screen space + void (*FillRGBABlend)( float x, float y, float w, float h, int r, int g, int b, int a ); // in screen space + + // screenshot, cubemapshot + qboolean (*VID_ScreenShot)( const char *filename, int shot_type ); + qboolean (*VID_CubemapShot)( const char *base, uint size, const float *vieworg, qboolean skyshot ); + + // light + colorVec (*R_LightPoint)( const float *p ); + + void (*R_AddEfrags)( struct cl_entity_s *ent ); + void (*R_RemoveEfrags)( struct cl_entity_s *ent ); + + // decals + // Shoots a decal onto the surface of the BSP. position is the center of the decal in world coords + void (*R_DecalShoot)( int textureIndex, int entityIndex, int modelIndex, vec3_t pos, int flags, float scale ); + void (*R_DecalRemoveAll)( int texture ); + int (*R_CreateDecalList)( struct decallist_s *pList ); + void (*R_ClearAllDecals)( void ); + + // studio interface + float (*R_StudioEstimateFrame)( cl_entity_t *e, mstudioseqdesc_t *pseqdesc ); + void (*R_StudioLerpMovement)( cl_entity_t *e, double time, vec3_t origin, vec3_t angles ); + + // bmodel + void (*R_InitSkyClouds)( struct mip_s *mt, struct texture_s *tx, qboolean custom_palette ); + void (*GL_SubdivideSurface)( msurface_t *fa ); + + // sprites + void (*R_GetSpriteParms)( int *frameWidth, int *frameHeight, int *numFrames, int currentFrame, const model_t *pSprite ); + + // model management + // flags ignored for everything except spritemodels + void (*Mod_LoadModel)( modtype_t desiredType, model_t *mod, const byte *buf, qboolean *loaded, int flags ); + void (*Mod_LoadMapSprite)( struct model_s *mod, const void *buffer, size_t size, qboolean *loaded ); + void (*Mod_UnloadModel)( model_t *mod ); + void (*Mod_StudioLoadTextures)( model_t *mod, void *data ); + void (*Mod_StudioUnloadTextures)( void *data ); + + // particle renderer + void (*CL_Particle)( const vec3_t origin, int color, float life, int zpos, int zvel ); // debug thing + + // Xash3D Render Interface + render_api_t *RenderAPI; // partial RenderAPI implementation + render_interface_t *RenderIface; // compatible RenderInterface implementation: renderer should call client RenderInterface by itself + + // TriAPI Interface + // NOTE: implementation isn't required to be compatible + void (*TriRenderMode)( int mode ); + void (*Begin)( int primitiveCode ); + void (*End)( void ); + void (*Color4f)( float r, float g, float b, float a ); + void (*Color4ub)( unsigned char r, unsigned char g, unsigned char b, unsigned char a ); + void (*TexCoord2f)( float u, float v ); + void (*Vertex3fv)( const float *worldPnt ); + void (*Vertex3f)( float x, float y, float z ); + int (*SpriteTexture)( struct model_s *pSpriteModel, int frame ); + int (*WorldToScreen)( const float *world, float *screen ); // Returns 1 if it's z clipped + void (*Fog)( float flFogColor[3], float flStart, float flEnd, int bOn ); //Works just like GL_FOG, flFogColor is r/g/b. + void (*ScreenToWorld)( const float *screen, float *world ); + void (*GetMatrix)( const int pname, float *matrix ); + void (*FogParams)( float flDensity, int iFogSkybox ); + void (*CullFace)( TRICULLSTYLE mode ); + + // vgui drawing implementation + vguiapi_t *VGuiAPI; + + // efx api + efx_api_t *EfxAPI; +} ref_interface_t; + +typedef int (*REFAPI)( int version, ref_interface_t *pFunctionTable, ref_api_t* engfuncs, ref_globals_t *pGlobals ); + +#endif // REF_API diff --git a/common/render_api.h b/common/render_api.h index f8c9ecf5..ef4f4c76 100644 --- a/common/render_api.h +++ b/common/render_api.h @@ -254,7 +254,7 @@ typedef struct render_interface_s // clear decals by engine request (e.g. for demo recording or vid_restart) void (*R_ClearStudioDecals)( void ); // grab r_speeds message - qboolean (*R_SpeedsMessage)( char *out, size_t size ); + qboolean (*R_SpeedsMessage)( char *out, size_t size ); // alloc or destroy model custom data void (*Mod_ProcessUserData)( struct model_s *mod, qboolean create, const byte *buffer ); // alloc or destroy entity custom data diff --git a/engine/client/avi/avi_win.c b/engine/client/avi/avi_win.c index 616e2ca2..19651c14 100644 --- a/engine/client/avi/avi_win.c +++ b/engine/client/avi/avi_win.c @@ -16,7 +16,6 @@ GNU General Public License for more details. #ifdef _WIN32 #include "common.h" #include "client.h" -#include "gl_local.h" #include // video for windows // msvfw32.dll exports diff --git a/engine/client/cl_cmds.c b/engine/client/cl_cmds.c index a5d711d6..fca37845 100644 --- a/engine/client/cl_cmds.c +++ b/engine/client/cl_cmds.c @@ -15,7 +15,6 @@ GNU General Public License for more details. #include "common.h" #include "client.h" -#include "gl_local.h" /* ==================== @@ -344,7 +343,7 @@ void CL_LevelShot_f( void ) // check for exist if( cls.demoplayback && ( cls.demonum != -1 )) { - Q_sprintf( cls.shotname, "levelshots/%s_%s.bmp", cls.demoname, glState.wideScreen ? "16x9" : "4x3" ); + Q_sprintf( cls.shotname, "levelshots/%s_%s.bmp", cls.demoname, refState.wideScreen ? "16x9" : "4x3" ); Q_snprintf( filename, sizeof( filename ), "%s.dem", cls.demoname ); // make sure what levelshot is newer than demo @@ -353,7 +352,7 @@ void CL_LevelShot_f( void ) } else { - Q_sprintf( cls.shotname, "levelshots/%s_%s.bmp", clgame.mapname, glState.wideScreen ? "16x9" : "4x3" ); + Q_sprintf( cls.shotname, "levelshots/%s_%s.bmp", clgame.mapname, refState.wideScreen ? "16x9" : "4x3" ); // make sure what levelshot is newer than bsp ft1 = FS_FileTime( cl.worldmodel->name, false ); @@ -424,53 +423,7 @@ void CL_SetSky_f( void ) return; } - R_SetupSky( Cmd_Argv( 1 )); -} - -/* -================ -SCR_TimeRefresh_f - -timerefresh [noflip] -================ -*/ -void SCR_TimeRefresh_f( void ) -{ - int i; - double start, stop; - double time; - - if( cls.state != ca_active ) - return; - - start = Sys_DoubleTime(); - - // run without page flipping like GoldSrc - if( Cmd_Argc() == 1 ) - { - pglDrawBuffer( GL_FRONT ); - for( i = 0; i < 128; i++ ) - { - RI.viewangles[1] = i / 128.0 * 360.0f; - R_RenderScene(); - } - pglFinish(); - R_EndFrame(); - } - else - { - for( i = 0; i < 128; i++ ) - { - R_BeginFrame( true ); - RI.viewangles[1] = i / 128.0 * 360.0f; - R_RenderScene(); - R_EndFrame(); - } - } - - stop = Sys_DoubleTime (); - time = (stop - start); - Con_Printf( "%f seconds (%f fps)\n", time, 128 / time ); + ref.dllFuncs.R_SetupSky( Cmd_Argv( 1 )); } /* @@ -482,6 +435,6 @@ viewpos (level-designer helper) */ void SCR_Viewpos_f( void ) { - Con_Printf( "org ( %g %g %g )\n", RI.vieworg[0], RI.vieworg[1], RI.vieworg[2] ); - Con_Printf( "ang ( %g %g %g )\n", RI.viewangles[0], RI.viewangles[1], RI.viewangles[2] ); -} \ No newline at end of file + Con_Printf( "org ( %g %g %g )\n", refState.vieworg[0], refState.vieworg[1], refState.vieworg[2] ); + Con_Printf( "ang ( %g %g %g )\n", refState.viewangles[0], refState.viewangles[1], refState.viewangles[2] ); +} diff --git a/engine/client/cl_debug.c b/engine/client/cl_debug.c index 4704b800..e483cb23 100644 --- a/engine/client/cl_debug.c +++ b/engine/client/cl_debug.c @@ -17,7 +17,6 @@ GNU General Public License for more details. #include "client.h" #include "net_encode.h" #include "particledef.h" -#include "gl_local.h" #include "cl_tent.h" #include "shake.h" #include "hltv.h" @@ -239,4 +238,4 @@ void CL_WriteMessageHistory( void ) if( host_developer.value >= DEV_EXTENDED ) CL_WriteErrorMessage( MSG_GetNumBytesRead( msg ) - 1, msg ); cls_message_debug.parsing = false; -} \ No newline at end of file +} diff --git a/engine/client/cl_demo.c b/engine/client/cl_demo.c index f3e9e69a..0106780d 100644 --- a/engine/client/cl_demo.c +++ b/engine/client/cl_demo.c @@ -15,7 +15,6 @@ GNU General Public License for more details. #include "common.h" #include "client.h" -#include "gl_local.h" #include "net_encode.h" #define dem_unknown 0 // unknown command @@ -500,7 +499,7 @@ void CL_DrawDemoRecording( void ) Q_memprint( pos ), (int)(cls.demotime / 60.0f ), (int)fmod( cls.demotime, 60.0f )); Con_DrawStringLen( string, &len, NULL ); - Con_DrawString(( glState.width - len ) >> 1, glState.height >> 4, string, color ); + Con_DrawString(( refState.width - len ) >> 1, refState.height >> 4, string, color ); } /* diff --git a/engine/client/cl_frame.c b/engine/client/cl_frame.c index bf964fc6..bf675485 100644 --- a/engine/client/cl_frame.c +++ b/engine/client/cl_frame.c @@ -17,7 +17,6 @@ GNU General Public License for more details. #include "client.h" #include "net_encode.h" #include "entity_types.h" -#include "gl_local.h" #include "pm_local.h" #include "cl_tent.h" #include "studio.h" @@ -226,6 +225,33 @@ void CL_UpdateLatchedVars( cl_entity_t *ent ) memcpy( ent->latched.prevblending, ent->prevstate.blending, sizeof( ent->latched.prevblending )); } +/* +==================== +CL_GetStudioEstimatedFrame + +==================== +*/ +float CL_GetStudioEstimatedFrame( cl_entity_t *ent ) +{ + studiohdr_t *pstudiohdr; + mstudioseqdesc_t *pseqdesc; + int sequence; + + if( ent->model != NULL && ent->model->type == mod_studio ) + { + pstudiohdr = (studiohdr_t *)Mod_StudioExtradata( ent->model ); + + if( pstudiohdr ) + { + sequence = bound( 0, ent->curstate.sequence, pstudiohdr->numseq - 1 ); + pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + sequence; + return ref.dllFuncs.R_StudioEstimateFrame( ent, pseqdesc ); + } + } + + return 0; +} + /* ==================== CL_ResetLatchedVars @@ -942,7 +968,7 @@ qboolean CL_AddVisibleEntity( cl_entity_t *ent, int entityType ) CL_AddCustomBeam( ent ); return true; } - else if( !R_AddEntity( ent, entityType )) + else if( !ref.dllFuncs.R_AddEntity( ent, entityType )) { return false; } @@ -1191,7 +1217,7 @@ void CL_LinkPacketEntities( frame_t *frame ) if( ent->model->type == mod_studio ) { if( interpolate && FBitSet( host.features, ENGINE_COMPUTE_STUDIO_LERP )) - R_StudioLerpMovement( ent, cl.time, ent->origin, ent->angles ); + ref.dllFuncs.R_StudioLerpMovement( ent, cl.time, ent->origin, ent->angles ); } } @@ -1262,7 +1288,7 @@ void CL_EmitEntities( void ) { if( cl.paused ) return; // don't waste time - R_ClearScene (); + RefRenderIface->R_ClearScene (); // not in server yet, no entities to redraw if( cls.state != ca_active || !cl.validsequence ) @@ -1330,7 +1356,7 @@ qboolean CL_GetEntitySpatialization( channel_t *ch ) if(( ch->entnum - 1 ) == cl.playernum ) { - VectorCopy( RI.vieworg, ch->origin ); + VectorCopy( refState.vieworg, ch->origin ); return true; } diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 7494c8e0..f1a9c50c 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -25,7 +25,6 @@ GNU General Public License for more details. #include "input.h" #include "shake.h" #include "sprite.h" -#include "gl_local.h" #include "library.h" #include "vgui_draw.h" #include "sound.h" // SND_STOP_LOOPING @@ -278,18 +277,18 @@ static int CL_AdjustXPos( float x, int width, int totalWidth ) if( x == -1 ) { - xPos = ( glState.width - width ) * 0.5f; + xPos = ( refState.width - width ) * 0.5f; } else { if ( x < 0 ) - xPos = (1.0f + x) * glState.width - totalWidth; // Alight right + xPos = (1.0f + x) * refState.width - totalWidth; // Alight right else // align left - xPos = x * glState.width; + xPos = x * refState.width; } - if( xPos + width > glState.width ) - xPos = glState.width - width; + if( xPos + width > refState.width ) + xPos = refState.width - width; else if( xPos < 0 ) xPos = 0; @@ -309,19 +308,19 @@ static int CL_AdjustYPos( float y, int height ) if( y == -1 ) // centered? { - yPos = ( glState.height - height ) * 0.5f; + yPos = ( refState.height - height ) * 0.5f; } else { // Alight bottom? if( y < 0 ) - yPos = (1.0f + y) * glState.height - height; // Alight bottom + yPos = (1.0f + y) * refState.height - height; // Alight bottom else // align top - yPos = y * glState.height; + yPos = y * refState.height; } - if( yPos + height > glState.height ) - yPos = glState.height - height; + if( yPos + height > refState.height ) + yPos = refState.height - height; else if( yPos < 0 ) yPos = 0; @@ -383,8 +382,8 @@ static void SPR_AdjustSize( float *x, float *y, float *w, float *h ) if( !x && !y && !w && !h ) return; // scale for screen sizes - xscale = glState.width / (float)clgame.scrInfo.iWidth; - yscale = glState.height / (float)clgame.scrInfo.iHeight; + xscale = refState.width / (float)clgame.scrInfo.iWidth; + yscale = refState.height / (float)clgame.scrInfo.iHeight; if( x ) *x *= xscale; if( y ) *y *= yscale; @@ -407,8 +406,8 @@ void PicAdjustSize( float *x, float *y, float *w, float *h ) if( !x && !y && !w && !h ) return; // scale for screen sizes - xscale = glState.width / (float)clgame.scrInfo.iWidth; - yscale = glState.height / (float)clgame.scrInfo.iHeight; + xscale = refState.width / (float)clgame.scrInfo.iWidth; + yscale = refState.height / (float)clgame.scrInfo.iHeight; if( x ) *x *= xscale; if( y ) *y *= yscale; @@ -482,7 +481,7 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei int w, h; // assume we get sizes from image - R_GetSpriteParms( &w, &h, NULL, frame, clgame.ds.pSprite ); + ref.dllFuncs.R_GetSpriteParms( &w, &h, NULL, frame, clgame.ds.pSprite ); width = w; height = h; @@ -520,10 +519,9 @@ static void SPR_DrawGeneric( int frame, float x, float y, float width, float hei // scale for screen sizes SPR_AdjustSize( &x, &y, &width, &height ); - texnum = R_GetSpriteTexture( clgame.ds.pSprite, frame ); - pglColor4ubv( clgame.ds.spriteColor ); - pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, texnum ); + texnum = ref.dllFuncs.SpriteTexture( clgame.ds.pSprite, frame ); + ref.dllFuncs.Color4ub( clgame.ds.spriteColor[0], clgame.ds.spriteColor[1], clgame.ds.spriteColor[2], clgame.ds.spriteColor[3] ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, texnum ); } /* @@ -581,7 +579,7 @@ void CL_DrawCenterPrint( void ) for( j = 0; j < lineLength; j++ ) { - if( x >= 0 && y >= 0 && x <= glState.width ) + if( x >= 0 && y >= 0 && x <= refState.width ) x += Con_DrawCharacter( x, y, line[j], colorDefault ); } y += charHeight; @@ -629,13 +627,14 @@ void CL_DrawScreenFade( void ) iFadeAlpha = bound( 0, iFadeAlpha, sf->fadealpha ); } - pglColor4ub( sf->fader, sf->fadeg, sf->fadeb, iFadeAlpha ); + ref.dllFuncs.Color4ub( sf->fader, sf->fadeg, sf->fadeb, iFadeAlpha ); if( sf->fadeFlags & FFADE_MODULATE ) - GL_SetRenderMode( kRenderTransAdd ); - else GL_SetRenderMode( kRenderTransTexture ); - R_DrawStretchPic( 0, 0, glState.width, glState.height, 0, 0, 1, 1, tr.whiteTexture ); - pglColor4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransAdd ); + else ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.R_DrawStretchPic( 0, 0, refState.width, refState.height, 0, 0, 1, 1, + ref.dllFuncs.R_GetBuiltinTexture( REF_WHITE_TEXTURE )); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } /* @@ -913,10 +912,10 @@ void CL_DrawCrosshair( void ) vec3_t forward; vec3_t point, screen; - VectorAdd( RI.viewangles, cl.crosshairangle, angles ); + VectorAdd( refState.viewangles, cl.crosshairangle, angles ); AngleVectors( angles, forward, NULL, NULL ); - VectorAdd( RI.vieworg, forward, point ); - R_WorldToScreen( point, screen ); + VectorAdd( refState.vieworg, forward, point ); + ref.dllFuncs.WorldToScreen( point, screen ); x += ( clgame.viewport[2] >> 1 ) * screen[0] + 0.5f; y += ( clgame.viewport[3] >> 1 ) * screen[1] + 0.5f; @@ -950,8 +949,8 @@ static void CL_DrawLoading( float percent ) x = ( clgame.scrInfo.iWidth - width ) >> 1; y = ( clgame.scrInfo.iHeight - height) >> 1; - xscale = glState.width / (float)clgame.scrInfo.iWidth; - yscale = glState.height / (float)clgame.scrInfo.iHeight; + xscale = refState.width / (float)clgame.scrInfo.iWidth; + yscale = refState.height / (float)clgame.scrInfo.iHeight; x *= xscale; y *= yscale; @@ -959,26 +958,26 @@ static void CL_DrawLoading( float percent ) height *= yscale; if( cl_allow_levelshots->value ) - { - pglColor4ub( 128, 128, 128, 255 ); - GL_SetRenderMode( kRenderTransTexture ); - R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.loadingBar ); + { + ref.dllFuncs.Color4ub( 128, 128, 128, 255 ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.loadingBar ); step = (float)width / 100.0f; right = (int)ceil( percent * step ); s2 = (float)right / width; width = right; - pglColor4ub( 208, 152, 0, 255 ); - GL_SetRenderMode( kRenderTransTexture ); - R_DrawStretchPic( x, y, width, height, 0, 0, s2, 1, cls.loadingBar ); - pglColor4ub( 255, 255, 255, 255 ); + ref.dllFuncs.Color4ub( 208, 152, 0, 255 ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, s2, 1, cls.loadingBar ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } else { - pglColor4ub( 255, 255, 255, 255 ); - GL_SetRenderMode( kRenderTransTexture ); - R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.loadingBar ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.loadingBar ); } } @@ -998,17 +997,17 @@ static void CL_DrawPause( void ) x = ( clgame.scrInfo.iWidth - width ) >> 1; y = ( clgame.scrInfo.iHeight - height) >> 1; - xscale = glState.width / (float)clgame.scrInfo.iWidth; - yscale = glState.height / (float)clgame.scrInfo.iHeight; + xscale = refState.width / (float)clgame.scrInfo.iWidth; + yscale = refState.height / (float)clgame.scrInfo.iHeight; x *= xscale; y *= yscale; width *= xscale; height *= yscale; - pglColor4ub( 255, 255, 255, 255 ); - GL_SetRenderMode( kRenderTransTexture ); - R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.pauseIcon ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, cls.pauseIcon ); } void CL_DrawHUD( int state ) @@ -1097,7 +1096,7 @@ void CL_LinkUserMessage( char *pszName, const int svc_num, int iSize ) void CL_FreeEntity( cl_entity_t *pEdict ) { Assert( pEdict != NULL ); - R_RemoveEfrags( pEdict ); + ref.dllFuncs.R_RemoveEfrags( pEdict ); CL_KillDeadBeams( pEdict ); } @@ -1112,7 +1111,7 @@ void CL_ClearWorld( void ) world->model = cl.worldmodel; world->index = 0; - clgame.ds.cullMode = GL_FRONT; + clgame.ds.cullMode = TRI_FRONT; clgame.numStatics = 0; } @@ -1227,7 +1226,7 @@ static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite, else { Con_Reportf( S_ERROR "Could not load HUD sprite %s\n", szSpriteName ); - Mod_UnloadSpriteModel( m_pSprite ); + ref.dllFuncs.Mod_UnloadModel( m_pSprite ); return false; } } @@ -1236,14 +1235,14 @@ static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite, ASSERT( buf != NULL ); if( type == SPR_MAPSPRITE ) - Mod_LoadMapSprite( m_pSprite, buf, size, &loaded ); - else Mod_LoadSpriteModel( m_pSprite, buf, &loaded, texFlags ); + ref.dllFuncs.Mod_LoadMapSprite( m_pSprite, buf, size, &loaded ); + else ref.dllFuncs.Mod_LoadModel( mod_sprite, m_pSprite, buf, &loaded, texFlags ); Mem_Free( buf ); if( !loaded ) { - Mod_UnloadSpriteModel( m_pSprite ); + ref.dllFuncs.Mod_UnloadModel( m_pSprite ); return false; } @@ -1399,7 +1398,7 @@ static int pfnSPR_Frames( HSPRITE hPic ) { int numFrames; - R_GetSpriteParms( NULL, NULL, &numFrames, 0, CL_GetSpritePointer( hPic )); + ref.dllFuncs.R_GetSpriteParms( NULL, NULL, &numFrames, 0, CL_GetSpritePointer( hPic )); return numFrames; } @@ -1414,7 +1413,7 @@ static int pfnSPR_Height( HSPRITE hPic, int frame ) { int sprHeight; - R_GetSpriteParms( NULL, &sprHeight, NULL, frame, CL_GetSpritePointer( hPic )); + ref.dllFuncs.R_GetSpriteParms( NULL, &sprHeight, NULL, frame, CL_GetSpritePointer( hPic )); return sprHeight; } @@ -1429,7 +1428,7 @@ static int pfnSPR_Width( HSPRITE hPic, int frame ) { int sprWidth; - R_GetSpriteParms( &sprWidth, NULL, NULL, frame, CL_GetSpritePointer( hPic )); + ref.dllFuncs.R_GetSpriteParms( &sprWidth, NULL, NULL, frame, CL_GetSpritePointer( hPic )); return sprWidth; } @@ -1457,8 +1456,7 @@ pfnSPR_Draw */ static void pfnSPR_Draw( int frame, int x, int y, const wrect_t *prc ) { - pglDisable( GL_BLEND ); - + ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); SPR_DrawGeneric( frame, x, y, -1, -1, prc ); } @@ -1470,14 +1468,21 @@ pfnSPR_DrawHoles */ static void pfnSPR_DrawHoles( int frame, int x, int y, const wrect_t *prc ) { +#if 1 // REFTODO + ref.dllFuncs.GL_SetRenderMode( kRenderTransColor ); +#else pglEnable( GL_ALPHA_TEST ); pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); pglEnable( GL_BLEND ); - +#endif SPR_DrawGeneric( frame, x, y, -1, -1, prc ); +#if 1 + ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); +#else pglDisable( GL_ALPHA_TEST ); pglDisable( GL_BLEND ); +#endif } /* @@ -1488,12 +1493,20 @@ pfnSPR_DrawAdditive */ static void pfnSPR_DrawAdditive( int frame, int x, int y, const wrect_t *prc ) { +#if 1 // REFTODO + ref.dllFuncs.GL_SetRenderMode( kRenderTransAdd ); +#else pglEnable( GL_BLEND ); pglBlendFunc( GL_ONE, GL_ONE ); +#endif SPR_DrawGeneric( frame, x, y, -1, -1, prc ); +#if 1 // REFTODO + ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); +#else pglDisable( GL_BLEND ); +#endif } /* @@ -1603,6 +1616,9 @@ void CL_FillRGBA( int x, int y, int w, int h, int r, int g, int b, int a ) SPR_AdjustSize( &_x, &_y, &_w, &_h ); +#if 1 + ref.dllFuncs.FillRGBA( _x, _y, _w, _h, r, g, b, a ); +#else pglDisable( GL_TEXTURE_2D ); pglEnable( GL_BLEND ); pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); @@ -1619,6 +1635,7 @@ void CL_FillRGBA( int x, int y, int w, int h, int r, int g, int b, int a ) pglColor3f( 1.0f, 1.0f, 1.0f ); pglEnable( GL_TEXTURE_2D ); pglDisable( GL_BLEND ); +#endif } /* @@ -1638,14 +1655,14 @@ int CL_GetScreenInfo( SCREENINFO *pscrinfo ) if( scale_factor && scale_factor != 1.0f) { - clgame.scrInfo.iWidth = (float)glState.width / scale_factor; - clgame.scrInfo.iHeight = (float)glState.height / scale_factor; + clgame.scrInfo.iWidth = (float)refState.width / scale_factor; + clgame.scrInfo.iHeight = (float)refState.height / scale_factor; clgame.scrInfo.iFlags |= SCRINFO_STRETCHED; } else { - clgame.scrInfo.iWidth = glState.width; - clgame.scrInfo.iHeight = glState.height; + clgame.scrInfo.iWidth = refState.width; + clgame.scrInfo.iHeight = refState.height; clgame.scrInfo.iFlags &= ~SCRINFO_STRETCHED; } @@ -2848,8 +2865,10 @@ pfnSPR_DrawGeneric */ static void GAME_EXPORT pfnSPR_DrawGeneric( int frame, int x, int y, const wrect_t *prc, int blendsrc, int blenddst, int width, int height ) { +#if 0 // REFTODO: pglEnable( GL_BLEND ); pglBlendFunc( blendsrc, blenddst ); // g-cont. are params is valid? +#endif SPR_DrawGeneric( frame, x, y, width, height, prc ); } @@ -3018,6 +3037,9 @@ void GAME_EXPORT CL_FillRGBABlend( int x, int y, int w, int h, int r, int g, int SPR_AdjustSize( &_x, &_y, &_w, &_h ); +#if 1 // REFTODO: + ref.dllFuncs.FillRGBABlend( _x, _y, _w, _h, r, g, b, a ); +#else pglDisable( GL_TEXTURE_2D ); pglEnable( GL_BLEND ); pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); @@ -3034,6 +3056,7 @@ void GAME_EXPORT CL_FillRGBABlend( int x, int y, int w, int h, int r, int g, int pglColor3f( 1.0f, 1.0f, 1.0f ); pglEnable( GL_TEXTURE_2D ); pglDisable( GL_BLEND ); +#endif } /* @@ -3078,111 +3101,31 @@ char *pfnParseFile( char *data, char *token ) /* ================= -TriApi implementation +TriAPI implementation ================= */ /* -============= +================= TriRenderMode - -set rendermode -============= +================= */ void TriRenderMode( int mode ) { - switch( mode ) - { - case kRenderNormal: - pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - pglDisable( GL_BLEND ); - pglDepthMask( GL_TRUE ); - break; - case kRenderTransAlpha: - pglEnable( GL_BLEND ); - pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - pglDepthMask( GL_FALSE ); - break; - case kRenderTransColor: - case kRenderTransTexture: - pglEnable( GL_BLEND ); - pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); - break; - case kRenderGlow: - case kRenderTransAdd: - pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); - pglEnable( GL_BLEND ); - pglDepthMask( GL_FALSE ); - break; - } - clgame.ds.renderMode = mode; + ref.dllFuncs.TriRenderMode( mode ); } /* -============= -TriBegin - -begin triangle sequence -============= -*/ -void TriBegin( int mode ) -{ - switch( mode ) - { - case TRI_POINTS: - mode = GL_POINTS; - break; - case TRI_TRIANGLES: - mode = GL_TRIANGLES; - break; - case TRI_TRIANGLE_FAN: - mode = GL_TRIANGLE_FAN; - break; - case TRI_QUADS: - mode = GL_QUADS; - break; - case TRI_LINES: - mode = GL_LINES; - break; - case TRI_TRIANGLE_STRIP: - mode = GL_TRIANGLE_STRIP; - break; - case TRI_QUAD_STRIP: - mode = GL_QUAD_STRIP; - break; - case TRI_POLYGON: - default: mode = GL_POLYGON; - break; - } - - pglBegin( mode ); -} - -/* -============= -TriEnd - -draw triangle sequence -============= -*/ -void TriEnd( void ) -{ - pglEnd(); -} - -/* -============= +================= TriColor4f - -============= +================= */ void TriColor4f( float r, float g, float b, float a ) { if( clgame.ds.renderMode == kRenderTransAlpha ) - pglColor4ub( r * 255.9f, g * 255.9f, b * 255.9f, a * 255.0f ); - else pglColor4f( r * a, g * a, b * a, 1.0 ); + ref.dllFuncs.Color4ub( r * 255.9f, g * 255.9f, b * 255.9f, a * 255.0f ); + else ref.dllFuncs.Color4f( r * a, g * a, b * a, 1.0 ); clgame.ds.triRGBA[0] = r; clgame.ds.triRGBA[1] = g; @@ -3193,7 +3136,6 @@ void TriColor4f( float r, float g, float b, float a ) /* ============= TriColor4ub - ============= */ void TriColor4ub( byte r, byte g, byte b, byte a ) @@ -3203,46 +3145,12 @@ void TriColor4ub( byte r, byte g, byte b, byte a ) clgame.ds.triRGBA[2] = b * (1.0f / 255.0f); clgame.ds.triRGBA[3] = a * (1.0f / 255.0f); - pglColor4f( clgame.ds.triRGBA[0], clgame.ds.triRGBA[1], clgame.ds.triRGBA[2], 1.0f ); -} - -/* -============= -TriTexCoord2f - -============= -*/ -void TriTexCoord2f( float u, float v ) -{ - pglTexCoord2f( u, v ); -} - -/* -============= -TriVertex3fv - -============= -*/ -void TriVertex3fv( const float *v ) -{ - pglVertex3fv( v ); -} - -/* -============= -TriVertex3f - -============= -*/ -void TriVertex3f( float x, float y, float z ) -{ - pglVertex3f( x, y, z ); + ref.dllFuncs.Color4f( clgame.ds.triRGBA[0], clgame.ds.triRGBA[1], clgame.ds.triRGBA[2], 1.0f ); } /* ============= TriBrightness - ============= */ void TriBrightness( float brightness ) @@ -3253,56 +3161,23 @@ void TriBrightness( float brightness ) g = clgame.ds.triRGBA[1] * clgame.ds.triRGBA[3] * brightness; b = clgame.ds.triRGBA[2] * clgame.ds.triRGBA[3] * brightness; - pglColor4f( r, g, b, 1.0f ); + ref.dllFuncs.Color4f( r, g, b, 1.0f ); } /* ============= TriCullFace - ============= */ -void TriCullFace( TRICULLSTYLE mode ) +void TriCullFace( TRICULLSTYLE style ) { - switch( mode ) - { - case TRI_FRONT: - clgame.ds.cullMode = GL_FRONT; - break; - default: - clgame.ds.cullMode = GL_NONE; - break; - } - - GL_Cull( clgame.ds.cullMode ); -} - -/* -============= -TriSpriteTexture - -bind current texture -============= -*/ -int TriSpriteTexture( model_t *pSpriteModel, int frame ) -{ - int gl_texturenum; - - if(( gl_texturenum = R_GetSpriteTexture( pSpriteModel, frame )) == 0 ) - return 0; - - if( gl_texturenum <= 0 || gl_texturenum > MAX_TEXTURES ) - gl_texturenum = tr.defaultTexture; - - GL_Bind( XASH_TEXTURE0, gl_texturenum ); - - return 1; + clgame.ds.cullMode = style; + ref.dllFuncs.CullFace( style ); } /* ============= TriWorldToScreen - convert world coordinates (x,y,z) into screen (x, y) ============= */ @@ -3310,7 +3185,7 @@ int TriWorldToScreen( float *world, float *screen ) { int retval; - retval = R_WorldToScreen( world, screen ); + retval = ref.dllFuncs.WorldToScreen( world, screen ); screen[0] = 0.5f * screen[0] * (float)clgame.viewport[2]; screen[1] = -0.5f * screen[1] * (float)clgame.viewport[3]; @@ -3320,60 +3195,6 @@ int TriWorldToScreen( float *world, float *screen ) return retval; } -/* -============= -TriFog - -enables global fog on the level -============= -*/ -void TriFog( float flFogColor[3], float flStart, float flEnd, int bOn ) -{ - // overrided by internal fog - if( RI.fogEnabled ) return; - RI.fogCustom = bOn; - - // check for invalid parms - if( flEnd <= flStart ) - { - RI.fogCustom = false; - pglDisable( GL_FOG ); - return; - } - - if( RI.fogCustom ) - pglEnable( GL_FOG ); - else pglDisable( GL_FOG ); - - // copy fog params - RI.fogColor[0] = flFogColor[0] / 255.0f; - RI.fogColor[1] = flFogColor[1] / 255.0f; - RI.fogColor[2] = flFogColor[2] / 255.0f; - RI.fogStart = flStart; - RI.fogColor[3] = 1.0f; - RI.fogDensity = 0.0f; - RI.fogSkybox = true; - RI.fogEnd = flEnd; - - pglFogi( GL_FOG_MODE, GL_LINEAR ); - pglFogfv( GL_FOG_COLOR, RI.fogColor ); - pglFogf( GL_FOG_START, RI.fogStart ); - pglFogf( GL_FOG_END, RI.fogEnd ); - pglHint( GL_FOG_HINT, GL_NICEST ); -} - -/* -============= -TriGetMatrix - -very strange export -============= -*/ -void TriGetMatrix( const int pname, float *matrix ) -{ - pglGetFloatv( pname, matrix ); -} - /* ============= TriBoxInPVS @@ -3383,13 +3204,12 @@ check box in pvs (absmin, absmax) */ int TriBoxInPVS( float *mins, float *maxs ) { - return Mod_BoxVisible( mins, maxs, Mod_GetCurrentVis( )); + return Mod_BoxVisible( mins, maxs, RefRenderIface->Mod_GetCurrentVis( )); } /* ============= TriLightAtPoint - NOTE: dlights are ignored ============= */ @@ -3399,7 +3219,7 @@ void TriLightAtPoint( float *pos, float *value ) if( !pos || !value ) return; - vLightColor = R_LightPoint( pos ); + vLightColor = ref.dllFuncs.R_LightPoint( pos ); value[0] = vLightColor.r; value[1] = vLightColor.g; @@ -3409,7 +3229,6 @@ void TriLightAtPoint( float *pos, float *value ) /* ============= TriColor4fRendermode - Heavy legacy of Quake... ============= */ @@ -3418,23 +3237,19 @@ void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ) if( clgame.ds.renderMode == kRenderTransAlpha ) { clgame.ds.triRGBA[3] = a / 255.0f; - pglColor4f( r, g, b, a ); + ref.dllFuncs.Color4f( r, g, b, a ); } - else pglColor4f( r * a, g * a, b * a, 1.0f ); + else ref.dllFuncs.Color4f( r * a, g * a, b * a, 1.0f ); } -/* -============= -TriForParams - -============= -*/ -void TriFogParams( float flDensity, int iFogSkybox ) +int TriSpriteTexture( model_t *pSpriteModel, int frame ) { - RI.fogDensity = flDensity; - RI.fogSkybox = iFogSkybox; + if( ref.dllFuncs.SpriteTexture( pSpriteModel, frame )) + return 1; + return 0; } + /* ================= DemoApi implementation @@ -3788,35 +3603,14 @@ float Voice_GetControlFloat( VoiceTweakControl iControl ) { return 1.0f; } + static void GAME_EXPORT VGui_ViewportPaintBackground( int extents[4] ) { // stub } // shared between client and server -triangleapi_t gTriApi = -{ - TRI_API_VERSION, - TriRenderMode, - TriBegin, - TriEnd, - TriColor4f, - TriColor4ub, - TriTexCoord2f, - TriVertex3fv, - TriVertex3f, - TriBrightness, - TriCullFace, - TriSpriteTexture, - R_WorldToScreen, // NOTE: XPROJECT, YPROJECT should be done in client.dll - TriFog, - R_ScreenToWorld, - TriGetMatrix, - TriBoxInPVS, - TriLightAtPoint, - TriColor4fRendermode, - TriFogParams, -}; +triangleapi_t gTriApi; static efx_api_t gEfxApi = { @@ -4234,8 +4028,10 @@ qboolean CL_LoadProgs( const char *name ) CL_InitViewBeams (); CL_InitTempEnts (); +#if 0 // REFTODO: if( !R_InitRenderAPI()) // Xash3D extension Con_Reportf( S_WARN "CL_LoadProgs: couldn't get render API\n" ); +#endif if( !Mobile_Init() ) // Xash3D FWGS extension: mobile interface Con_Reportf( S_WARN "CL_LoadProgs: couldn't get mobility API\n" ); diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index c288d7a9..b4d6ee1f 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -16,10 +16,10 @@ GNU General Public License for more details. #include "common.h" #include "client.h" #include "const.h" -#include "gl_local.h" #include "library.h" #include "input.h" #include "server.h" // !!svgame.hInstance +#include "vid_common.h" static MENUAPI GetMenuAPI; static ADDTOUCHBUTTONTOLIST pfnAddTouchButtonToList; @@ -203,7 +203,7 @@ static void UI_DrawLogo( const char *filename, float x, float y, float width, fl redraw = true; } - R_DrawStretchRaw( x, y, width, height, gameui.logo_xres, gameui.logo_yres, cin_data, redraw ); + ref.dllFuncs.R_DrawStretchRaw( x, y, width, height, gameui.logo_xres, gameui.logo_yres, cin_data, redraw ); } static int UI_GetLogoWidth( void ) @@ -360,8 +360,8 @@ static void PIC_DrawGeneric( float x, float y, float width, float height, const return; PicAdjustSize( &x, &y, &width, &height ); - R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, gameui.ds.gl_texturenum ); - pglColor4ub( 255, 255, 255, 255 ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, gameui.ds.gl_texturenum ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } /* @@ -390,7 +390,7 @@ static HIMAGE pfnPIC_Load( const char *szPicName, const byte *image_buf, int ima SetBits( flags, TF_IMAGE ); Image_SetForceFlags( IL_LOAD_DECAL ); // allow decal images for menu - tx = GL_LoadTexture( szPicName, image_buf, image_size, flags ); + tx = RefRenderAPI->GL_LoadTexture( szPicName, image_buf, image_size, flags ); Image_ClearForceFlags(); return tx; @@ -439,7 +439,7 @@ void pfnPIC_Set( HIMAGE hPic, int r, int g, int b, int a ) g = bound( 0, g, 255 ); b = bound( 0, b, 255 ); a = bound( 0, a, 255 ); - pglColor4ub( r, g, b, a ); + ref.dllFuncs.Color4ub( r, g, b, a ); } /* @@ -450,7 +450,7 @@ pfnPIC_Draw */ void pfnPIC_Draw( int x, int y, int width, int height, const wrect_t *prc ) { - GL_SetRenderMode( kRenderNormal ); + ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); PIC_DrawGeneric( x, y, width, height, prc ); } @@ -462,7 +462,7 @@ pfnPIC_DrawTrans */ void pfnPIC_DrawTrans( int x, int y, int width, int height, const wrect_t *prc ) { - GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); PIC_DrawGeneric( x, y, width, height, prc ); } @@ -474,7 +474,7 @@ pfnPIC_DrawHoles */ void pfnPIC_DrawHoles( int x, int y, int width, int height, const wrect_t *prc ) { - GL_SetRenderMode( kRenderTransAlpha ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransAlpha ); PIC_DrawGeneric( x, y, width, height, prc ); } @@ -486,7 +486,7 @@ pfnPIC_DrawAdditive */ void pfnPIC_DrawAdditive( int x, int y, int width, int height, const wrect_t *prc ) { - GL_SetRenderMode( kRenderTransAdd ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransAdd ); PIC_DrawGeneric( x, y, width, height, prc ); } @@ -553,10 +553,10 @@ static void pfnFillRGBA( int x, int y, int width, int height, int r, int g, int g = bound( 0, g, 255 ); b = bound( 0, b, 255 ); a = bound( 0, a, 255 ); - pglColor4ub( r, g, b, a ); - GL_SetRenderMode( kRenderTransTexture ); - R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, tr.whiteTexture ); - pglColor4ub( 255, 255, 255, 255 ); + ref.dllFuncs.Color4ub( r, g, b, a ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, ref.dllFuncs.R_GetBuiltinTexture( REF_WHITE_TEXTURE ) ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } /* @@ -614,7 +614,7 @@ static void pfnDrawCharacter( int ix, int iy, int iwidth, int iheight, int ch, i color[0] = (ulRGBA & 0xFF0000) >> 16; color[1] = (ulRGBA & 0xFF00) >> 8; color[2] = (ulRGBA & 0xFF) >> 0; - pglColor4ubv( color ); + ref.dllFuncs.Color4ub( color[0], color[1], color[2], color[3] ); col = (ch & 15) * 0.0625f + (0.5f / 256.0f); row = (ch >> 4) * 0.0625f + (0.5f / 256.0f); @@ -629,9 +629,9 @@ static void pfnDrawCharacter( int ix, int iy, int iwidth, int iheight, int ch, i if( gameui.ds.scissor_test && !PIC_Scissor( &x, &y, &width, &height, &s1, &t1, &s2, &t2 )) return; - GL_SetRenderMode( kRenderTransTexture ); - R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, hFont ); - pglColor4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, hFont ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } /* @@ -702,8 +702,8 @@ for drawing playermodel previews */ static void pfnClearScene( void ) { - R_PushScene(); - R_ClearScene(); + ref.dllFuncs.R_PushScene(); + RefRenderIface->R_ClearScene(); } /* @@ -726,10 +726,10 @@ static void pfnRenderScene( const ref_viewpass_t *rvp ) // don't allow special modes from menu copy.flags = 0; - R_Set2DMode( false ); - R_RenderFrame( © ); - R_Set2DMode( true ); - R_PopScene(); + ref.dllFuncs.R_Set2DMode( false ); + RefRenderIface->GL_RenderFrame( © ); + ref.dllFuncs.R_Set2DMode( true ); + ref.dllFuncs.R_PopScene(); } /* @@ -741,7 +741,7 @@ adding player model into visible list */ static int pfnAddEntity( int entityType, cl_entity_t *ent ) { - if( !R_AddEntity( ent, entityType )) + if( !ref.dllFuncs.R_AddEntity( ent, entityType )) return false; return true; } @@ -946,6 +946,11 @@ static void pfnStartBackgroundTrack( const char *introTrack, const char *mainTra S_StartBackgroundTrack( introTrack, mainTrack, 0, false ); } +static void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor ) +{ + ref.dllFuncs.GL_ProcessTexture( texnum, gamma, topColor, bottomColor ); +} + // engine callbacks static ui_enginefuncs_t gEngfuncs = { diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index f1fc316f..8021e555 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -17,11 +17,11 @@ GNU General Public License for more details. #include "client.h" #include "net_encode.h" #include "cl_tent.h" -#include "gl_local.h" #include "input.h" #include "kbutton.h" #include "vgui_draw.h" #include "library.h" +#include "vid_common.h" #define MAX_TOTAL_CMDS 32 #define MAX_CMD_BUFFER 8000 @@ -1779,7 +1779,7 @@ void CL_SetupOverviewParams( void ) // calculate nearest aspect mapAspect = world.size[!ov->rotated] / world.size[ov->rotated]; - screenAspect = (float)glState.width / (float)glState.height; + screenAspect = (float)refState.width / (float)refState.height; aspect = Q_max( mapAspect, screenAspect ); ov->zNear = world.maxs[2]; @@ -2936,7 +2936,7 @@ void CL_Init( void ) // unreliable buffer. unsed for unreliable commands and voice stream MSG_Init( &cls.datagram, "cls.datagram", cls.datagram_buf, sizeof( cls.datagram_buf )); - IN_TouchInit(); + // IN_TouchInit(); Con_LoadHistory(); if( !CL_LoadProgs( va( "%s/%s", GI->dll_path, SI.clientlib))) @@ -2968,7 +2968,7 @@ void CL_Shutdown( void ) Host_WriteVideoConfig (); } - IN_TouchShutdown (); + // IN_TouchShutdown (); Joy_Shutdown (); CL_CloseDemoHeader (); IN_Shutdown (); diff --git a/engine/client/cl_mobile.c b/engine/client/cl_mobile.c index af11a7aa..53a350d3 100644 --- a/engine/client/cl_mobile.c +++ b/engine/client/cl_mobile.c @@ -19,7 +19,6 @@ GNU General Public License for more details. #include "client.h" #include "mobility_int.h" #include "library.h" -#include "gl_local.h" #include "input.h" #include "platform/platform.h" @@ -101,12 +100,12 @@ static mobile_engfuncs_t gpMobileEngfuncs = MOBILITY_API_VERSION, pfnVibrate, pfnEnableTextInput, - IN_TouchAddClientButton, - IN_TouchAddDefaultButton, - (void*)IN_TouchHideButtons, - IN_TouchRemoveButton, - (void*)IN_TouchSetClientOnly, - IN_TouchResetDefaultButtons, + NULL, // IN_TouchAddClientButton, + NULL, // IN_TouchAddDefaultButton, + NULL, // (void*)IN_TouchHideButtons, + NULL, // IN_TouchRemoveButton, + NULL, // (void*)IN_TouchSetClientOnly, + NULL, // IN_TouchResetDefaultButtons, pfnDrawScaledCharacter, Sys_Warn, pfnGetNativeObject, diff --git a/engine/client/cl_netgraph.c b/engine/client/cl_netgraph.c index 9f6b5734..fddcf82b 100644 --- a/engine/client/cl_netgraph.c +++ b/engine/client/cl_netgraph.c @@ -15,7 +15,6 @@ GNU General Public License for more details. #include "common.h" #include "client.h" -#include "gl_local.h" #define NET_TIMINGS 1024 #define NET_TIMINGS_MASK (NET_TIMINGS - 1) @@ -75,12 +74,12 @@ NetGraph_FillRGBA shortcut */ static void NetGraph_DrawRect( wrect_t *rect, byte colors[4] ) { - pglColor4ubv( colors ); // color for this quad + ref.dllFuncs.Color4ub( colors[0], colors[1], colors[2], colors[3] ); // color for this quad - pglVertex2f( rect->left, rect->top ); - pglVertex2f( rect->left + rect->right, rect->top ); - pglVertex2f( rect->left + rect->right, rect->top + rect->bottom ); - pglVertex2f( rect->left, rect->top + rect->bottom ); + ref.dllFuncs.Vertex3f( rect->left, rect->top, 0 ); + ref.dllFuncs.Vertex3f( rect->left + rect->right, rect->top, 0 ); + ref.dllFuncs.Vertex3f( rect->left + rect->right, rect->top + rect->bottom, 0 ); + ref.dllFuncs.Vertex3f( rect->left, rect->top + rect->bottom, 0 ); } /* @@ -595,8 +594,8 @@ NetGraph_GetScreenPos void NetGraph_GetScreenPos( wrect_t *rect, int *w, int *x, int *y ) { rect->left = rect->top = 0; - rect->right = glState.width; - rect->bottom = glState.height; + rect->right = refState.width; + rect->bottom = refState.height; *w = Q_min( NET_TIMINGS, net_graphwidth->value ); if( rect->right < *w + 10 ) @@ -652,20 +651,17 @@ void SCR_DrawNetGraph( void ) if( net_graph->value < 3 ) { - pglEnable( GL_BLEND ); - pglDisable( GL_TEXTURE_2D ); - pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); - pglBegin( GL_QUADS ); // draw all the fills as a long solid sequence of quads for speedup reasons + ref.dllFuncs.GL_SetRenderMode( kRenderTransAdd ); + + ref.dllFuncs.Begin( TRI_QUADS ); // draw all the fills as a long solid sequence of quads for speedup reasons // NOTE: fill colors without texture at this point NetGraph_DrawDataUsage( x, y, w ); NetGraph_DrawTimes( rect, x, w ); - pglEnd(); - pglColor4ub( 255, 255, 255, 255 ); - pglEnable( GL_TEXTURE_2D ); - pglDisable( GL_BLEND ); + ref.dllFuncs.End(); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); + ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); } } @@ -680,4 +676,4 @@ void CL_InitNetgraph( void ) packet_loss = packet_choke = 0.0; NetGraph_InitColors(); -} \ No newline at end of file +} diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index ac6321c3..62921872 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -17,7 +17,6 @@ GNU General Public License for more details. #include "client.h" #include "net_encode.h" #include "particledef.h" -#include "gl_local.h" #include "cl_tent.h" #include "shake.h" #include "hltv.h" @@ -250,7 +249,7 @@ void CL_ParseMovevars( sizebuf_t *msg ) // update sky if changed if( Q_strcmp( clgame.oldmovevars.skyName, clgame.movevars.skyName ) && cl.video_prepped ) - R_SetupSky( clgame.movevars.skyName ); + ref.dllFuncs.R_SetupSky( clgame.movevars.skyName ); memcpy( &clgame.oldmovevars, &clgame.movevars, sizeof( movevars_t )); clgame.entities->curstate.scale = clgame.movevars.waveHeight; @@ -350,7 +349,7 @@ void CL_ParseStaticEntity( sizebuf_t *msg ) } } - R_AddEfrags( ent ); // add link + ref.dllFuncs.R_AddEfrags( ent ); // add link } @@ -658,7 +657,7 @@ void CL_RemoveCustomization( int nPlayerNum, customization_t *pRemove ) if( pList->resource.type == t_decal ) { if( cls.state == ca_active ) - R_DecalRemoveAll( pList->nUserData1 ); + ref.dllFuncs.R_DecalRemoveAll( pList->nUserData1 ); FS_FreeImage( pList->pInfo ); } } @@ -960,8 +959,8 @@ void CL_ParseServerData( sizebuf_t *msg ) // get splash name if( cls.demoplayback && ( cls.demonum != -1 )) - Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", cls.demoname, glState.wideScreen ? "16x9" : "4x3" )); - else Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", clgame.mapname, glState.wideScreen ? "16x9" : "4x3" )); + Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", cls.demoname, refState.wideScreen ? "16x9" : "4x3" )); + else Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", clgame.mapname, refState.wideScreen ? "16x9" : "4x3" )); Cvar_SetValue( "scr_loading", 0.0f ); // reset progress bar if(( cl_allow_levelshots->value && !cls.changelevel ) || cl.background ) @@ -1548,7 +1547,7 @@ void CL_RegisterResources( sizebuf_t *msg ) CL_ClearWorld (); // tell rendering system we have a new set of models. - R_NewMap (); + RefRenderIface->R_NewMap (); CL_SetupOverviewParams(); @@ -1559,7 +1558,7 @@ void CL_RegisterResources( sizebuf_t *msg ) for( i = 1, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ ) { if( mod->needload == NL_UNREFERENCED && COM_CheckString( mod->name )) - Mod_UnloadSpriteModel( mod ); + ref.dllFuncs.Mod_UnloadModel( mod ); } Mod_FreeUnused (); @@ -2466,8 +2465,8 @@ void CL_ParseLegacyServerData( sizebuf_t *msg ) // get splash name if( cls.demoplayback && ( cls.demonum != -1 )) - Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", cls.demoname, glState.wideScreen ? "16x9" : "4x3" )); - else Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", clgame.mapname, glState.wideScreen ? "16x9" : "4x3" )); + Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", cls.demoname, refState.wideScreen ? "16x9" : "4x3" )); + else Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", clgame.mapname, refState.wideScreen ? "16x9" : "4x3" )); Cvar_SetValue( "scr_loading", 0.0f ); // reset progress bar if(( cl_allow_levelshots->value && !cls.changelevel ) || cl.background ) @@ -2560,7 +2559,7 @@ void CL_LegacyParseStaticEntity( sizebuf_t *msg ) } } - R_AddEfrags( ent ); // add link + ref.dllFuncs.R_AddEfrags( ent ); // add link } @@ -3132,7 +3131,7 @@ void CL_LegacyPrecache_f( void ) clgame.entities->model = cl.worldmodel; // tell rendering system we have a new set of models. - R_NewMap (); + RefRenderIface->R_NewMap (); CL_SetupOverviewParams(); @@ -3143,7 +3142,7 @@ void CL_LegacyPrecache_f( void ) for( i = 1, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ ) { if( mod->needload == NL_UNREFERENCED && COM_CheckString( mod->name )) - Mod_UnloadSpriteModel( mod ); + ref.dllFuncs.Mod_UnloadModel( mod ); } // Mod_FreeUnused (); diff --git a/engine/client/cl_pmove.c b/engine/client/cl_pmove.c index 3e6e27b9..ab4bbfdf 100644 --- a/engine/client/cl_pmove.c +++ b/engine/client/cl_pmove.c @@ -989,7 +989,7 @@ void CL_InitClientMove( void ) // common utilities clgame.pmove->PM_Info_ValueForKey = Info_ValueForKey; - clgame.pmove->PM_Particle = CL_Particle; + clgame.pmove->PM_Particle = ref.dllFuncs.CL_Particle; // ref should be initialized here already clgame.pmove->PM_TestPlayerPosition = pfnTestPlayerPosition; clgame.pmove->Con_NPrintf = Con_NPrintf; clgame.pmove->Con_DPrintf = Con_DPrintf; diff --git a/engine/client/cl_qparse.c b/engine/client/cl_qparse.c index 270d709e..36e90091 100644 --- a/engine/client/cl_qparse.c +++ b/engine/client/cl_qparse.c @@ -17,7 +17,6 @@ GNU General Public License for more details. #include "client.h" #include "net_encode.h" #include "particledef.h" -#include "gl_local.h" #include "cl_tent.h" #include "shake.h" #include "hltv.h" @@ -303,8 +302,8 @@ static void CL_ParseQuakeServerInfo( sizebuf_t *msg ) // get splash name if( cls.demoplayback && ( cls.demonum != -1 )) - Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", cls.demoname, glState.wideScreen ? "16x9" : "4x3" )); - else Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", clgame.mapname, glState.wideScreen ? "16x9" : "4x3" )); + Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", cls.demoname, refState.wideScreen ? "16x9" : "4x3" )); + else Cvar_Set( "cl_levelshot_name", va( "levelshots/%s_%s", clgame.mapname, refState.wideScreen ? "16x9" : "4x3" )); Cvar_SetValue( "scr_loading", 0.0f ); // reset progress bar if(( cl_allow_levelshots->value && !cls.changelevel ) || cl.background ) @@ -684,7 +683,7 @@ static void CL_ParseQuakeStaticEntity( sizebuf_t *msg ) } } - R_AddEfrags( ent ); // add link + ref.dllFuncs.R_AddEfrags( ent ); // add link } /* diff --git a/engine/client/cl_remap.c b/engine/client/cl_remap.c index 637dc4ed..dec5815c 100644 --- a/engine/client/cl_remap.c +++ b/engine/client/cl_remap.c @@ -15,7 +15,6 @@ GNU General Public License for more details. #include "common.h" #include "client.h" -#include "gl_local.h" #include "studio.h" /* @@ -101,7 +100,7 @@ Dupliacte texture with remap pixels */ void CL_DuplicateTexture( mstudiotexture_t *ptexture, int topcolor, int bottomcolor ) { - gl_texture_t *glt; + const char *name; texture_t *tx = NULL; char texname[128]; int i, index; @@ -111,13 +110,13 @@ void CL_DuplicateTexture( mstudiotexture_t *ptexture, int topcolor, int bottomco // save off the real texture index index = ptexture->index; - glt = R_GetTexture( index ); - Q_snprintf( texname, sizeof( texname ), "#%i_%s", RI.currententity->curstate.number, glt->name + 1 ); + name = ref.dllFuncs.R_GetTextureName( index ); + Q_snprintf( texname, sizeof( texname ), "#%i_%s", refState.currententity->curstate.number, name + 1 ); // search for pixels - for( i = 0; i < RI.currentmodel->numtextures; i++ ) + for( i = 0; i < refState.currentmodel->numtextures; i++ ) { - tx = RI.currentmodel->textures[i]; + tx = refState.currentmodel->textures[i]; if( tx->gl_texturenum == index ) break; // found } @@ -129,7 +128,7 @@ void CL_DuplicateTexture( mstudiotexture_t *ptexture, int topcolor, int bottomco memcpy( paletteBackup, pal, 768 ); raw = CL_CreateRawTextureFromPixels( tx, &size, topcolor, bottomcolor ); - ptexture->index = GL_LoadTexture( texname, raw, size, TF_FORCE_COLOR ); // do copy + ptexture->index = RefRenderAPI->GL_LoadTexture( texname, raw, size, TF_FORCE_COLOR ); // do copy // restore original palette memcpy( pal, paletteBackup, 768 ); @@ -144,31 +143,31 @@ Update texture top and bottom colors */ void CL_UpdateStudioTexture( mstudiotexture_t *ptexture, int topcolor, int bottomcolor ) { - gl_texture_t *glt; rgbdata_t *pic; texture_t *tx = NULL; char texname[128], name[128], mdlname[128]; + const char *origtexname; int i, index; size_t size; byte paletteBackup[768]; byte *raw, *pal; // save off the real texture index - glt = R_GetTexture( ptexture->index ); + origtexname = ref.dllFuncs.R_GetTextureName( ptexture->index ); // build name of original texture - Q_strncpy( mdlname, RI.currentmodel->name, sizeof( mdlname )); + Q_strncpy( mdlname, refState.currentmodel->name, sizeof( mdlname )); COM_FileBase( ptexture->name, name ); COM_StripExtension( mdlname ); Q_snprintf( texname, sizeof( texname ), "#%s/%s.mdl", mdlname, name ); - index = GL_FindTexture( texname ); + index = RefRenderAPI->GL_FindTexture( texname ); if( !index ) return; // couldn't find texture // search for pixels - for( i = 0; i < RI.currentmodel->numtextures; i++ ) + for( i = 0; i < refState.currentmodel->numtextures; i++ ) { - tx = RI.currentmodel->textures[i]; + tx = refState.currentmodel->textures[i]; if( tx->gl_texturenum == index ) break; // found } @@ -180,14 +179,14 @@ void CL_UpdateStudioTexture( mstudiotexture_t *ptexture, int topcolor, int botto memcpy( paletteBackup, pal, 768 ); raw = CL_CreateRawTextureFromPixels( tx, &size, topcolor, bottomcolor ); - pic = FS_LoadImage( glt->name, raw, size ); + pic = FS_LoadImage( origtexname, raw, size ); if( !pic ) { - Con_DPrintf( S_ERROR "Couldn't update texture %s\n", glt->name ); + Con_DPrintf( S_ERROR "Couldn't update texture %s\n", origtexname ); return; } - index = GL_UpdateTextureInternal( glt->name, pic, 0 ); + index = GL_UpdateTextureInternal( origtexname, pic, 0 ); FS_FreeImage( pic ); // restore original palette @@ -209,15 +208,15 @@ void CL_UpdateAliasTexture( unsigned short *texture, int skinnum, int topcolor, rgbdata_t skin, *pic; texture_t *tx; - if( !texture || !RI.currentmodel->textures ) + if( !texture || !refState.currentmodel->textures ) return; // no remapinfo in model - tx = RI.currentmodel->textures[skinnum]; + tx = refState.currentmodel->textures[skinnum]; if( !tx ) return; // missing texture ? if( *texture == 0 ) { - Q_snprintf( texname, sizeof( texname ), "%s:remap%i_%i", RI.currentmodel->name, skinnum, RI.currententity->index ); + Q_snprintf( texname, sizeof( texname ), "%s:remap%i_%i", refState.currentmodel->name, skinnum, refState.currententity->index ); skin.width = tx->width; skin.height = tx->height; skin.depth = skin.numMips = 1; @@ -232,7 +231,7 @@ void CL_UpdateAliasTexture( unsigned short *texture, int skinnum, int topcolor, } // and now we can remap with internal routines - GL_ProcessTexture( *texture, -1.0f, topcolor, bottomcolor ); + ref.dllFuncs.GL_ProcessTexture( *texture, -1.0f, topcolor, bottomcolor ); } /* @@ -251,10 +250,10 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) mstudiotexture_t *src, *dst; int i, size; - if( !RI.currententity ) return; - i = ( RI.currententity == &clgame.viewent ) ? clgame.maxEntities : RI.currententity->curstate.number; + if( !refState.currententity ) return; + i = ( refState.currententity == &clgame.viewent ) ? clgame.maxEntities : refState.currententity->curstate.number; - if( !RI.currentmodel || ( RI.currentmodel->type != mod_alias && RI.currentmodel->type != mod_studio )) + if( !refState.currentmodel || ( refState.currentmodel->type != mod_alias && refState.currentmodel->type != mod_studio )) { // entity has changed model by another type, release remap info if( clgame.remap_info[i] ) @@ -266,7 +265,7 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) } // model doesn't contains remap textures - if( RI.currentmodel->numtextures <= 0 ) + if( refState.currentmodel->numtextures <= 0 ) { // entity has changed model with no remap textures if( clgame.remap_info[i] ) @@ -277,16 +276,16 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) return; } - if( RI.currentmodel->type == mod_studio ) + if( refState.currentmodel->type == mod_studio ) { - phdr = (studiohdr_t *)Mod_StudioExtradata( RI.currentmodel ); + phdr = (studiohdr_t *)Mod_StudioExtradata( refState.currentmodel ); if( !phdr ) return; // bad model? src = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); dst = (clgame.remap_info[i] ? clgame.remap_info[i]->ptexture : NULL); // NOTE: we must copy all the structures 'mstudiotexture_t' for easy access when model is rendering - if( !CL_CmpStudioTextures( phdr->numtextures, src, dst ) || clgame.remap_info[i]->model != RI.currentmodel ) + if( !CL_CmpStudioTextures( phdr->numtextures, src, dst ) || clgame.remap_info[i]->model != refState.currentmodel ) { // this code catches studiomodel change with another studiomodel with remap textures // e.g. playermodel 'barney' with playermodel 'gordon' @@ -318,13 +317,13 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) CL_DuplicateTexture( &dst[i], topcolor, bottomcolor ); } } - else if( RI.currentmodel->type == mod_alias ) + else if( refState.currentmodel->type == mod_alias ) { - ahdr = (aliashdr_t *)Mod_AliasExtradata( RI.currentmodel ); + ahdr = (aliashdr_t *)Mod_AliasExtradata( refState.currentmodel ); if( !ahdr ) return; // bad model? // NOTE: we must copy all the structures 'mstudiotexture_t' for easy access when model is rendering - if( !clgame.remap_info[i] || clgame.remap_info[i]->model != RI.currentmodel ) + if( !clgame.remap_info[i] || clgame.remap_info[i]->model != refState.currentmodel ) { // this code catches studiomodel change with another studiomodel with remap textures // e.g. playermodel 'barney' with playermodel 'gordon' @@ -337,7 +336,7 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) return; } - info->numtextures = RI.currentmodel->numtextures; + info->numtextures = refState.currentmodel->numtextures; // alias remapping is easy CL_UpdateRemapInfo( topcolor, bottomcolor ); @@ -348,7 +347,7 @@ void CL_AllocRemapInfo( int topcolor, int bottomcolor ) return; } - info->model = RI.currentmodel; + info->model = refState.currentmodel; } /* @@ -363,7 +362,7 @@ void CL_UpdateRemapInfo( int topcolor, int bottomcolor ) remap_info_t *info; int i; - i = ( RI.currententity == &clgame.viewent ) ? clgame.maxEntities : RI.currententity->curstate.number; + i = ( refState.currententity == &clgame.viewent ) ? clgame.maxEntities : refState.currententity->curstate.number; info = clgame.remap_info[i]; if( !info ) return; // no remap info @@ -403,11 +402,11 @@ void CL_FreeRemapInfo( remap_info_t *info ) if( info->ptexture != NULL ) { if( FBitSet( info->ptexture[i].flags, STUDIO_NF_COLORMAP )) - GL_FreeTexture( info->ptexture[i].index ); + RefRenderAPI->GL_FreeTexture( info->ptexture[i].index ); } if( info->textures[i] != 0 ) - GL_FreeTexture( info->textures[i] ); + RefRenderAPI->GL_FreeTexture( info->textures[i] ); } Mem_Free( info ); // release struct diff --git a/engine/client/cl_scrn.c b/engine/client/cl_scrn.c index 65f590b3..d9150110 100644 --- a/engine/client/cl_scrn.c +++ b/engine/client/cl_scrn.c @@ -15,7 +15,6 @@ GNU General Public License for more details. #include "common.h" #include "client.h" -#include "gl_local.h" #include "vgui_draw.h" #include "qfont.h" #include "input.h" @@ -99,7 +98,7 @@ void SCR_DrawFPS( int height ) } Con_DrawStringLen( fpsstring, &offset, NULL ); - Con_DrawString( glState.width - offset - 4, height, fpsstring, color ); + Con_DrawString( refState.width - offset - 4, height, fpsstring, color ); } /* @@ -148,7 +147,7 @@ void SCR_NetSpeeds( void ) Q_snprintf( msg, sizeof( msg ), "sv fps: ^1%4i min, ^3%4i cur, ^2%4i max\ncl fps: ^1%4i min, ^3%4i cur, ^2%4i max\nGame Time: %02d:%02d\nTotal received from server: %s\nTotal sent to server: %s\n", min_svfps, cur_svfps, max_svfps, min_clfps, cur_clfps, max_clfps, (int)(time / 60.0f ), (int)fmod( time, 60.0f ), Q_memprint( cls.netchan.total_received ), Q_memprint( cls.netchan.total_sended )); - x = glState.width - 320; + x = refState.width - 320; y = 384; Con_DrawStringLen( NULL, NULL, &height ); @@ -181,13 +180,13 @@ void SCR_RSpeeds( void ) if( !host.allow_console ) return; - if( R_SpeedsMessage( msg, sizeof( msg ))) + if( RefRenderIface->R_SpeedsMessage( msg, sizeof( msg ))) { int x, y, height; char *p, *start, *end; rgba_t color; - x = glState.width - 340; + x = refState.width - 340; y = 64; Con_DrawStringLen( NULL, NULL, &height ); @@ -246,25 +245,25 @@ void SCR_MakeScreenShot( void ) switch( cls.scrshot_action ) { case scrshot_normal: - iRet = VID_ScreenShot( cls.shotname, VID_SCREENSHOT ); + iRet = ref.dllFuncs.VID_ScreenShot( cls.shotname, VID_SCREENSHOT ); break; case scrshot_snapshot: - iRet = VID_ScreenShot( cls.shotname, VID_SNAPSHOT ); + iRet = ref.dllFuncs.VID_ScreenShot( cls.shotname, VID_SNAPSHOT ); break; case scrshot_plaque: - iRet = VID_ScreenShot( cls.shotname, VID_LEVELSHOT ); + iRet = ref.dllFuncs.VID_ScreenShot( cls.shotname, VID_LEVELSHOT ); break; case scrshot_savegame: - iRet = VID_ScreenShot( cls.shotname, VID_MINISHOT ); + iRet = ref.dllFuncs.VID_ScreenShot( cls.shotname, VID_MINISHOT ); break; case scrshot_envshot: - iRet = VID_CubemapShot( cls.shotname, viewsize, cls.envshot_vieworg, false ); + iRet = ref.dllFuncs.VID_CubemapShot( cls.shotname, viewsize, cls.envshot_vieworg, false ); break; case scrshot_skyshot: - iRet = VID_CubemapShot( cls.shotname, viewsize, cls.envshot_vieworg, true ); + iRet = ref.dllFuncs.VID_CubemapShot( cls.shotname, viewsize, cls.envshot_vieworg, true ); break; case scrshot_mapshot: - iRet = VID_ScreenShot( cls.shotname, VID_MAPSHOT ); + iRet = ref.dllFuncs.VID_ScreenShot( cls.shotname, VID_MAPSHOT ); break; case scrshot_inactive: return; @@ -295,9 +294,9 @@ void SCR_DrawPlaque( void ) { if(( cl_allow_levelshots->value && !cls.changelevel ) || cl.background ) { - int levelshot = GL_LoadTexture( cl_levelshot_name->string, NULL, 0, TF_IMAGE ); - GL_SetRenderMode( kRenderNormal ); - R_DrawStretchPic( 0, 0, glState.width, glState.height, 0, 0, 1, 1, levelshot ); + int levelshot = RefRenderAPI->GL_LoadTexture( cl_levelshot_name->string, NULL, 0, TF_IMAGE ); + ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); + ref.dllFuncs.R_DrawStretchPic( 0, 0, refState.width, refState.height, 0, 0, 1, 1, levelshot ); if( !cl.background ) CL_DrawHUD( CL_LOADING ); } } @@ -367,7 +366,7 @@ SCR_DirtyScreen void SCR_DirtyScreen( void ) { SCR_AddDirtyPoint( 0, 0 ); - SCR_AddDirtyPoint( glState.width - 1, glState.height - 1 ); + SCR_AddDirtyPoint( refState.width - 1, refState.height - 1 ); } /* @@ -419,7 +418,7 @@ void SCR_TileClear( void ) { // clear above view screen i = clear.y2 < top-1 ? clear.y2 : top - 1; - R_DrawTileClear( clear.x1, clear.y1, clear.x2 - clear.x1 + 1, i - clear.y1 + 1 ); + ref.dllFuncs.R_DrawTileClear( clear.x1, clear.y1, clear.x2 - clear.x1 + 1, i - clear.y1 + 1 ); clear.y1 = top; } @@ -427,7 +426,7 @@ void SCR_TileClear( void ) { // clear below view screen i = clear.y1 > bottom + 1 ? clear.y1 : bottom + 1; - R_DrawTileClear( clear.x1, i, clear.x2 - clear.x1 + 1, clear.y2 - i + 1 ); + ref.dllFuncs.R_DrawTileClear( clear.x1, i, clear.x2 - clear.x1 + 1, clear.y2 - i + 1 ); clear.y2 = bottom; } @@ -435,7 +434,7 @@ void SCR_TileClear( void ) { // clear left of view screen i = clear.x2 < left - 1 ? clear.x2 : left - 1; - R_DrawTileClear( clear.x1, clear.y1, i - clear.x1 + 1, clear.y2 - clear.y1 + 1 ); + ref.dllFuncs.R_DrawTileClear( clear.x1, clear.y1, i - clear.x1 + 1, clear.y2 - clear.y1 + 1 ); clear.x1 = left; } @@ -443,7 +442,7 @@ void SCR_TileClear( void ) { // clear left of view screen i = clear.x1 > right + 1 ? clear.x1 : right + 1; - R_DrawTileClear( i, clear.y1, clear.x2 - i + 1, clear.y2 - clear.y1 + 1 ); + ref.dllFuncs.R_DrawTileClear( i, clear.y1, clear.x2 - i + 1, clear.y2 - clear.y1 + 1 ); clear.x2 = right; } } @@ -495,7 +494,7 @@ qboolean SCR_LoadFixedWidthFont( const char *fontname ) if( !FS_FileExists( fontname, false )) return false; - cls.creditsFont.hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_IMAGE|TF_KEEP_SOURCE ); + cls.creditsFont.hFontTexture = RefRenderAPI->GL_LoadTexture( fontname, NULL, 0, TF_IMAGE|TF_KEEP_SOURCE ); R_GetTextureParms( &fontWidth, NULL, cls.creditsFont.hFontTexture ); cls.creditsFont.charHeight = clgame.scrInfo.iCharHeight = fontWidth / 16; cls.creditsFont.type = FONT_FIXED; @@ -527,7 +526,7 @@ qboolean SCR_LoadVariableWidthFont( const char *fontname ) if( !FS_FileExists( fontname, false )) return false; - cls.creditsFont.hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_IMAGE ); + cls.creditsFont.hFontTexture = RefRenderAPI->GL_LoadTexture( fontname, NULL, 0, TF_IMAGE ); R_GetTextureParms( &fontWidth, NULL, cls.creditsFont.hFontTexture ); // half-life font with variable chars witdh @@ -636,24 +635,24 @@ void SCR_RegisterTextures( void ) // register gfx.wad images if( FS_FileExists( "gfx/paused.lmp", false )) - cls.pauseIcon = GL_LoadTexture( "gfx/paused.lmp", NULL, 0, TF_IMAGE ); + cls.pauseIcon = RefRenderAPI->GL_LoadTexture( "gfx/paused.lmp", NULL, 0, TF_IMAGE ); else if( FS_FileExists( "gfx/pause.lmp", false )) - cls.pauseIcon = GL_LoadTexture( "gfx/pause.lmp", NULL, 0, TF_IMAGE ); + cls.pauseIcon = RefRenderAPI->GL_LoadTexture( "gfx/pause.lmp", NULL, 0, TF_IMAGE ); if( FS_FileExists( "gfx/lambda.lmp", false )) { if( cl_allow_levelshots->value ) - cls.loadingBar = GL_LoadTexture( "gfx/lambda.lmp", NULL, 0, TF_IMAGE|TF_LUMINANCE ); - else cls.loadingBar = GL_LoadTexture( "gfx/lambda.lmp", NULL, 0, TF_IMAGE ); + cls.loadingBar = RefRenderAPI->GL_LoadTexture( "gfx/lambda.lmp", NULL, 0, TF_IMAGE|TF_LUMINANCE ); + else cls.loadingBar = RefRenderAPI->GL_LoadTexture( "gfx/lambda.lmp", NULL, 0, TF_IMAGE ); } else if( FS_FileExists( "gfx/loading.lmp", false )) { if( cl_allow_levelshots->value ) - cls.loadingBar = GL_LoadTexture( "gfx/loading.lmp", NULL, 0, TF_IMAGE|TF_LUMINANCE ); - else cls.loadingBar = GL_LoadTexture( "gfx/loading.lmp", NULL, 0, TF_IMAGE ); + cls.loadingBar = RefRenderAPI->GL_LoadTexture( "gfx/loading.lmp", NULL, 0, TF_IMAGE|TF_LUMINANCE ); + else cls.loadingBar = RefRenderAPI->GL_LoadTexture( "gfx/loading.lmp", NULL, 0, TF_IMAGE ); } - cls.tileImage = GL_LoadTexture( "gfx/backtile.lmp", NULL, 0, TF_NOMIPMAP ); + cls.tileImage = RefRenderAPI->GL_LoadTexture( "gfx/backtile.lmp", NULL, 0, TF_NOMIPMAP ); } /* @@ -695,11 +694,11 @@ void SCR_VidInit( void ) // update screen sizes for menu if( gameui.globals ) { - gameui.globals->scrWidth = glState.width; - gameui.globals->scrHeight = glState.height; + gameui.globals->scrWidth = refState.width; + gameui.globals->scrHeight = refState.height; } - VGui_Startup( glState.width, glState.height ); + VGui_Startup( refState.width, refState.height ); CL_ClearSpriteTextures(); // now all hud sprites are invalid diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index 53529be9..60fdc61c 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -20,7 +20,6 @@ GNU General Public License for more details. #include "triangleapi.h" #include "cl_tent.h" #include "pm_local.h" -#include "gl_local.h" #include "studio.h" #include "wadfile.h" // acess decal size #include "sound.h" @@ -225,7 +224,7 @@ int CL_FxBlend( cl_entity_t *e ) blend = e->curstate.renderamt + 0x10 * sin( cl.time * 8 + offset ); break; case kRenderFxFadeSlow: - if( RP_NORMALPASS( )) + if( ref.dllFuncs.IsNormalPass( )) { if( e->curstate.renderamt > 0 ) e->curstate.renderamt -= 1; @@ -234,7 +233,7 @@ int CL_FxBlend( cl_entity_t *e ) blend = e->curstate.renderamt; break; case kRenderFxFadeFast: - if( RP_NORMALPASS( )) + if( ref.dllFuncs.IsNormalPass( )) { if( e->curstate.renderamt > 3 ) e->curstate.renderamt -= 4; @@ -243,7 +242,7 @@ int CL_FxBlend( cl_entity_t *e ) blend = e->curstate.renderamt; break; case kRenderFxSolidSlow: - if( RP_NORMALPASS( )) + if( ref.dllFuncs.IsNormalPass( )) { if( e->curstate.renderamt < 255 ) e->curstate.renderamt += 1; @@ -252,7 +251,7 @@ int CL_FxBlend( cl_entity_t *e ) blend = e->curstate.renderamt; break; case kRenderFxSolidFast: - if( RP_NORMALPASS( )) + if( ref.dllFuncs.IsNormalPass( )) { if( e->curstate.renderamt < 252 ) e->curstate.renderamt += 4; @@ -288,8 +287,8 @@ int CL_FxBlend( cl_entity_t *e ) case kRenderFxHologram: case kRenderFxDistort: VectorCopy( e->origin, tmp ); - VectorSubtract( tmp, RI.vieworg, tmp ); - dist = DotProduct( tmp, RI.vforward ); + VectorSubtract( tmp, refState.vieworg, tmp ); + dist = DotProduct( tmp, refState.vforward ); // turn off distance fade if( e->curstate.renderfx == kRenderFxDistort ) @@ -522,7 +521,7 @@ int CL_TempEntAddEntity( cl_entity_t *pEntity ) // add to list if( CL_AddVisibleEntity( pEntity, ET_TEMPENTITY )) - r_stats.c_active_tents_count++; + ref.dllFuncs.R_IncrementSpeedsCounter( RS_ACTIVE_TENTS ); return 1; } @@ -2958,8 +2957,8 @@ void CL_TestLights( void ) r = 64 * ((i % 4) - 1.5f ); f = 64 * ( i / 4) + 128; - for( j = 0; j < 3; j++ ) - dl->origin[j] = RI.vieworg[j] + RI.vforward[j] * f + RI.vright[j] * r; + VectorMAM( f, refState.vforward, r, refState.vright, dl->origin ); + VectorAdd( dl->origin, refState.vieworg, dl->origin ); dl->color.r = ((((i % 6) + 1) & 1)>>0) * 255; dl->color.g = ((((i % 6) + 1) & 2)>>1) * 255; @@ -2976,18 +2975,6 @@ DECAL MANAGEMENT ============================================================== */ -/* -=============== -CL_DecalShoot - -normal temporary decal -=============== -*/ -void CL_DecalShoot( int textureIndex, int entityIndex, int modelIndex, float *pos, int flags ) -{ - R_DecalShoot( textureIndex, entityIndex, modelIndex, pos, flags, 1.0f ); -} - /* =============== CL_FireCustomDecal @@ -2997,7 +2984,19 @@ custom temporary decal */ void CL_FireCustomDecal( int textureIndex, int entityIndex, int modelIndex, float *pos, int flags, float scale ) { - R_DecalShoot( textureIndex, entityIndex, modelIndex, pos, flags, scale ); + ref.dllFuncs.R_DecalShoot( textureIndex, entityIndex, modelIndex, pos, flags, scale ); +} + +/* +=============== +CL_DecalShoot + +normal temporary decal +=============== +*/ +void CL_DecalShoot( int textureIndex, int entityIndex, int modelIndex, float *pos, int flags ) +{ + CL_FireCustomDecal( textureIndex, entityIndex, modelIndex, pos, flags, 1.0f ); } /* @@ -3028,7 +3027,7 @@ void CL_PlayerDecal( int playernum, int customIndex, int entityIndex, float *pos } } - R_DecalShoot( textureIndex, entityIndex, 0, pos, FDECAL_CUSTOM, 1.0f ); + CL_DecalShoot( textureIndex, entityIndex, 0, pos, FDECAL_CUSTOM ); } /* @@ -3068,7 +3067,7 @@ int CL_DecalIndex( int id ) if( cl.decal_index[id] == 0 ) { Image_SetForceFlags( IL_LOAD_DECAL ); - cl.decal_index[id] = GL_LoadTexture( host.draw_decals[id], NULL, 0, TF_DECAL ); + cl.decal_index[id] = RefRenderAPI->GL_LoadTexture( host.draw_decals[id], NULL, 0, TF_DECAL ); Image_ClearForceFlags(); } @@ -3085,7 +3084,7 @@ remove all decals with specified texture void CL_DecalRemoveAll( int textureIndex ) { int id = bound( 0, textureIndex, MAX_DECALS - 1 ); - R_DecalRemoveAll( cl.decal_index[id] ); + ref.dllFuncs.R_DecalRemoveAll( cl.decal_index[id] ); } /* @@ -3114,6 +3113,29 @@ void CL_ClearEfrags( void ) clgame.free_efrags[i].entnext = &clgame.free_efrags[i+1]; clgame.free_efrags[i].entnext = NULL; } + +/* +======================= +R_ClearStaticEntities + +e.g. by demo request +======================= +*/ +void CL_ClearStaticEntities( void ) +{ + int i; + + if( host.type == HOST_DEDICATED ) + return; + + // clear out efrags in case the level hasn't been reloaded + for( i = 0; i < cl.worldmodel->numleafs; i++ ) + cl.worldmodel->leafs[i+1].efrags = NULL; + + clgame.numStatics = 0; + + CL_ClearEfrags (); +} /* ============== diff --git a/engine/client/cl_tent.h b/engine/client/cl_tent.h index 6c991ec7..fa5c5b1c 100644 --- a/engine/client/cl_tent.h +++ b/engine/client/cl_tent.h @@ -101,20 +101,16 @@ void R_BeamKill( int deadEntity ); // TriAPI -void TriBegin( int mode ); -void TriTexCoord2f( float u, float v ); -void TriVertex3fv( const float *v ); -void TriVertex3f( float x, float y, float z ); -int TriBoxInPVS( float *mins, float *maxs ); +void TriRenderMode( int mode ); void TriColor4f( float r, float g, float b, float a ); -int TriSpriteTexture( model_t *pSpriteModel, int frame ); -void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ); -int TriWorldToScreen( float *world, float *screen ); void TriColor4ub( byte r, byte g, byte b, byte a ); void TriBrightness( float brightness ); -void TriRenderMode( int mode ); void TriCullFace( TRICULLSTYLE mode ); -void TriEnd( void ); +int TriWorldToScreen( float *world, float *screen ); +int TriBoxInPVS( float *mins, float *maxs ); +void TriLightAtPoint( float *pos, float *value ); +void TriColor4fRendermode( float r, float g, float b, float a, int rendermode ); +int TriSpriteTexture( model_t *pSpriteModel, int frame ); extern model_t *cl_sprite_dot; extern model_t *cl_sprite_shell; diff --git a/engine/client/cl_video.c b/engine/client/cl_video.c index d386ac20..87bc933a 100644 --- a/engine/client/cl_video.c +++ b/engine/client/cl_video.c @@ -15,7 +15,6 @@ GNU General Public License for more details. #include "common.h" #include "client.h" -#include "gl_local.h" /* ================================================================= @@ -180,7 +179,7 @@ qboolean SCR_DrawCinematic( void ) qboolean redraw = false; byte *frame = NULL; - if( !glw_state.initialized || cin_time <= 0.0f ) + if( !ref.initialized || cin_time <= 0.0f ) return false; if( cin_frame != last_frame ) @@ -190,7 +189,7 @@ qboolean SCR_DrawCinematic( void ) redraw = true; } - R_DrawStretchRaw( 0, 0, glState.width, glState.height, xres, yres, frame, redraw ); + ref.dllFuncs.R_DrawStretchRaw( 0, 0, refState.width, refState.height, xres, yres, frame, redraw ); return true; } diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index 0e93b736..4245edc9 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -17,7 +17,6 @@ GNU General Public License for more details. #include "client.h" #include "const.h" #include "entity_types.h" -#include "gl_local.h" #include "vgui_draw.h" #include "sound.h" @@ -59,17 +58,17 @@ void V_CalcViewRect( void ) } size /= 100.0; - clgame.viewport[2] = glState.width * size; - clgame.viewport[3] = glState.height * size; + clgame.viewport[2] = refState.width * size; + clgame.viewport[3] = refState.height * size; - if( clgame.viewport[3] > glState.height - sb_lines ) - clgame.viewport[3] = glState.height - sb_lines; - if( clgame.viewport[3] > glState.height ) - clgame.viewport[3] = glState.height; + if( clgame.viewport[3] > refState.height - sb_lines ) + clgame.viewport[3] = refState.height - sb_lines; + if( clgame.viewport[3] > refState.height ) + clgame.viewport[3] = refState.height; - clgame.viewport[0] = ( glState.width - clgame.viewport[2] ) / 2; + clgame.viewport[0] = ( refState.width - clgame.viewport[2] ) / 2; if( full ) clgame.viewport[1] = 0; - else clgame.viewport[1] = ( glState.height - sb_lines - clgame.viewport[3] ) / 2; + else clgame.viewport[1] = ( refState.height - sb_lines - clgame.viewport[3] ) / 2; } @@ -113,8 +112,8 @@ void V_SetRefParams( ref_params_t *fd ) memset( fd, 0, sizeof( ref_params_t )); // probably this is not needs - VectorCopy( RI.vieworg, fd->vieworg ); - VectorCopy( RI.viewangles, fd->viewangles ); + VectorCopy( refState.vieworg, fd->vieworg ); + VectorCopy( refState.viewangles, fd->viewangles ); fd->frametime = host.frametime; fd->time = cl.time; @@ -183,7 +182,7 @@ void V_RefApplyOverview( ref_viewpass_t *rvp ) return; // NOTE: Xash3D may use 16:9 or 16:10 aspects - aspect = (float)glState.width / (float)glState.height; + aspect = (float)refState.width / (float)refState.height; size_x = fabs( 8192.0f / ov->flZoom ); size_y = fabs( 8192.0f / (ov->flZoom * aspect )); @@ -216,7 +215,7 @@ void V_RefApplyOverview( ref_viewpass_t *rvp ) SetBits( rvp->flags, RF_DRAW_OVERVIEW ); - Mod_SetOrthoBounds( mins, maxs ); + RefRenderIface->GL_OrthoBounds( mins, maxs ); } /* @@ -254,7 +253,7 @@ void V_GetRefParams( ref_params_t *fd, ref_viewpass_t *rvp ) rvp->fov_y = V_CalcFov( &rvp->fov_x, clgame.viewport[2], clgame.viewport[3] ); // adjust FOV for widescreen - if( glState.wideScreen && r_adjust_fov->value ) + if( refState.wideScreen && r_adjust_fov->value ) V_AdjustFov( &rvp->fov_x, &rvp->fov_y, clgame.viewport[2], clgame.viewport[3], false ); rvp->flags = 0; @@ -273,7 +272,7 @@ V_PreRender qboolean V_PreRender( void ) { // too early - if( !glw_state.initialized ) + if( !ref.initialized ) return false; if( host.status == HOST_NOFOCUS ) @@ -293,7 +292,7 @@ qboolean V_PreRender( void ) return false; } - R_BeginFrame( !cl.paused ); + ref.dllFuncs.R_BeginFrame( !cl.paused ); return true; } @@ -318,9 +317,9 @@ void V_RenderView( void ) V_CalcViewRect (); // compute viewport rectangle V_SetRefParams( &rp ); V_SetupViewModel (); - R_Set2DMode( false ); + ref.dllFuncs.R_Set2DMode( false ); SCR_DirtyScreen(); - GL_BackendStartFrame (); + ref.dllFuncs.GL_BackendStartFrame (); do { @@ -330,11 +329,15 @@ void V_RenderView( void ) if( viewnum == 0 && FBitSet( rvp.flags, RF_ONLY_CLIENTDRAW )) { +#if 0 pglClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); pglClear( GL_COLOR_BUFFER_BIT ); +#else + ref.dllFuncs.R_ClearScreen(); +#endif } - R_RenderFrame( &rvp ); + RefRenderIface->GL_RenderFrame( &rvp ); S_UpdateFrame( &rvp ); viewnum++; @@ -342,7 +345,7 @@ void V_RenderView( void ) // draw debug triangles on a server SV_DrawDebugTriangles (); - GL_BackendEndFrame (); + ref.dllFuncs.GL_BackendEndFrame (); } /* @@ -356,8 +359,8 @@ void V_PostRender( void ) static double oldtime; qboolean draw_2d = false; - R_AllowFog( false ); - R_Set2DMode( true ); + ref.dllFuncs.R_AllowFog( false ); + ref.dllFuncs.R_Set2DMode( true ); if( cls.state == ca_active && cls.signon == SIGNONS && cls.scrshot_action != scrshot_mapshot ) { @@ -383,8 +386,8 @@ void V_PostRender( void ) SV_DrawOrthoTriangles(); CL_DrawDemoRecording(); CL_DrawHUD( CL_CHANGELEVEL ); - R_ShowTextures(); - R_ShowTree(); + ref.dllFuncs.R_ShowTextures(); + ref.dllFuncs.R_ShowTree(); Con_DrawConsole(); UI_UpdateMenu( host.realtime ); Con_DrawVersion(); @@ -394,6 +397,6 @@ void V_PostRender( void ) } SCR_MakeScreenShot(); - R_AllowFog( true ); - R_EndFrame(); + ref.dllFuncs.R_AllowFog( true ); + ref.dllFuncs.R_EndFrame(); } diff --git a/engine/client/client.h b/engine/client/client.h index aad6123a..dad32413 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -31,6 +31,7 @@ GNU General Public License for more details. #include "netchan.h" #include "net_api.h" #include "world.h" +#include "ref_common.h" #define MAX_DEMOS 32 #define MAX_MOVIES 8 @@ -378,7 +379,7 @@ typedef struct qboolean adjust_size; // allow to adjust scale for fonts int renderMode; // override kRenderMode from TriAPI - int cullMode; // override CULL FACE from TriAPI + TRICULLSTYLE cullMode; // override CULL FACE from TriAPI // holds text color rgba_t textColor; diff --git a/engine/client/console.c b/engine/client/console.c index 080b663c..ffa03512 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -18,7 +18,6 @@ GNU General Public License for more details. #include "keydefs.h" #include "protocol.h" // get the protocol version #include "con_nprint.h" -#include "gl_local.h" #include "qfont.h" #include "wadfile.h" @@ -443,8 +442,8 @@ void Con_CheckResize( void ) if( con.curFont && con.curFont->hFontTexture ) charWidth = con.curFont->charWidths['O'] - 1; - width = ( glState.width / charWidth ) - 2; - if( !glw_state.initialized ) width = (640 / 5); + width = ( refState.width / charWidth ) - 2; + if( !ref.initialized ) width = (640 / 5); if( width == con.linewidth ) return; @@ -532,7 +531,7 @@ static qboolean Con_LoadFixedWidthFont( const char *fontname, cl_font_t *font ) return false; // keep source to print directly into conback image - font->hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_FONT|TF_KEEP_SOURCE ); + font->hFontTexture = RefRenderAPI->GL_LoadTexture( fontname, NULL, 0, TF_FONT|TF_KEEP_SOURCE ); R_GetTextureParms( &fontWidth, NULL, font->hFontTexture ); if( font->hFontTexture && fontWidth != 0 ) @@ -568,7 +567,7 @@ static qboolean Con_LoadVariableWidthFont( const char *fontname, cl_font_t *font if( !FS_FileExists( fontname, false )) return false; - font->hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_FONT|TF_NEAREST ); + font->hFontTexture = RefRenderAPI->GL_LoadTexture( fontname, NULL, 0, TF_FONT|TF_NEAREST ); R_GetTextureParms( &fontWidth, NULL, font->hFontTexture ); // setup consolefont @@ -651,9 +650,9 @@ static void Con_LoadConchars( void ) Con_LoadConsoleFont( i, con.chars + i ); // select properly fontsize - if( glState.width <= 640 ) + if( refState.width <= 640 ) fontSize = 0; - else if( glState.width >= 1280 ) + else if( refState.width >= 1280 ) fontSize = 2; else fontSize = 1; @@ -805,7 +804,7 @@ int Con_UtfMoveRight( char *str, int pos, int length ) return pos+1; } -static void Con_DrawCharToConback( int num, byte *conchars, byte *dest ) +static void Con_DrawCharToConback( int num, const byte *conchars, byte *dest ) { int row, col; byte *source; @@ -843,8 +842,8 @@ static void Con_TextAdjustSize( int *x, int *y, int *w, int *h ) if( !x && !y && !w && !h ) return; // scale for screen sizes - xscale = (float)glState.width / (float)clgame.scrInfo.iWidth; - yscale = (float)glState.height / (float)clgame.scrInfo.iHeight; + xscale = (float)refState.width / (float)clgame.scrInfo.iWidth; + yscale = (float)refState.height / (float)clgame.scrInfo.iHeight; if( x ) *x *= xscale; if( y ) *y *= yscale; @@ -863,7 +862,6 @@ static int Con_DrawGenericChar( int x, int y, int number, rgba_t color ) { int width, height; float s1, t1, s2, t2; - gl_texture_t *glt; wrect_t *rc; number &= 255; @@ -879,18 +877,15 @@ static int Con_DrawGenericChar( int x, int y, int number, rgba_t color ) return 0; rc = &con.curFont->fontRc[number]; - glt = R_GetTexture( con.curFont->hFontTexture ); - width = glt->srcWidth; - height = glt->srcHeight; + R_GetTextureParms( &width, &height, con.curFont->hFontTexture ); if( !width || !height ) return con.curFont->charWidths[number]; // don't apply color to fixed fonts it's already colored - if( con.curFont->type != FONT_FIXED || glt->format == GL_LUMINANCE8_ALPHA8 ) - pglColor4ubv( color ); - else pglColor4ub( 255, 255, 255, color[3] ); - R_GetTextureParms( &width, &height, con.curFont->hFontTexture ); + if( con.curFont->type != FONT_FIXED || RENDER_GET_PARM( PARM_TEX_GLFORMAT, 0x8045 ) ) // GL_LUMINANCE8_ALPHA8 + ref.dllFuncs.Color4ub( color[0], color[1], color[2], color[3] ); + else ref.dllFuncs.Color4ub( 255, 255, 255, color[3] ); // calc rectangle s1 = (float)rc->left / width; @@ -902,8 +897,8 @@ static int Con_DrawGenericChar( int x, int y, int number, rgba_t color ) if( clgame.ds.adjust_size ) Con_TextAdjustSize( &x, &y, &width, &height ); - R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, con.curFont->hFontTexture ); - pglColor4ub( 255, 255, 255, 255 ); // don't forget reset color + ref.dllFuncs.R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, con.curFont->hFontTexture ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); // don't forget reset color return con.curFont->charWidths[number]; } @@ -943,7 +938,7 @@ client version of routine */ int Con_DrawCharacter( int x, int y, int number, rgba_t color ) { - GL_SetRenderMode( kRenderTransTexture ); + ref.dllFuncs.GL_SetRenderMode( kRenderTransTexture ); return Con_DrawGenericChar( x, y, number, color ); } @@ -1064,7 +1059,7 @@ int Con_DrawGenericString( int x, int y, const char *string, rgba_t setColor, qb s++; } - pglColor4ub( 255, 255, 255, 255 ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); return drawLen; } @@ -1627,10 +1622,12 @@ void Field_DrawInputLine( int x, int y, field_t *edit ) if( host.key_overstrike && cursorChar ) { // overstrike cursor +#if 0 pglEnable( GL_BLEND ); pglDisable( GL_ALPHA_TEST ); pglBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA ); pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); +#endif Con_DrawGenericChar( x + curPos, y, cursorChar, colorDefault ); } else @@ -1854,7 +1851,7 @@ int Con_DrawDebugLines( void ) int defaultX; int y = 20; - defaultX = glState.width / 4; + defaultX = refState.width / 4; for( i = 0; i < MAX_DBG_NOTIFY; i++ ) { @@ -1864,10 +1861,10 @@ int Con_DrawDebugLines( void ) int fontTall; Con_DrawStringLen( con.notify[i].szNotify, &len, &fontTall ); - x = glState.width - Q_max( defaultX, len ) - 10; + x = refState.width - Q_max( defaultX, len ) - 10; fontTall += 1; - if( y + fontTall > glState.height - 20 ) + if( y + fontTall > refState.height - 20 ) return count; count++; @@ -1896,7 +1893,7 @@ void Con_DrawDebug( void ) { Q_snprintf( dlstring, sizeof( dlstring ), "Downloading [%d remaining]: ^2%s^7 %5.1f%% time %.f secs", host.downloadcount, host.downloadfile, scr_download->value, Sys_DoubleTime() - timeStart ); - x = glState.width - 500; + x = refState.width - 500; y = con.curFont->charHeight * 1.05f; Con_DrawString( x, y, dlstring, g_color_table[7] ); } @@ -1962,7 +1959,7 @@ void Con_DrawNotify( void ) Field_DrawInputLine( x + len, y, &con.chat ); } - pglColor4ub( 255, 255, 255, 255 ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } /* @@ -2034,9 +2031,9 @@ void Con_DrawSolidConsole( int lines ) if( lines <= 0 ) return; // draw the background - GL_SetRenderMode( kRenderNormal ); - pglColor4ub( 255, 255, 255, 255 ); // to prevent grab color from screenfade - R_DrawStretchPic( 0, lines - glState.width * 3 / 4, glState.width, glState.width * 3 / 4, 0, 0, 1, 1, con.background ); + ref.dllFuncs.GL_SetRenderMode( kRenderNormal ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); // to prevent grab color from screenfade + ref.dllFuncs.R_DrawStretchPic( 0, lines - refState.width * 3 / 4, refState.width, refState.width * 3 / 4, 0, 0, 1, 1, con.background ); if( !con.curFont || !host.allow_console ) return; // nothing to draw @@ -2054,10 +2051,10 @@ void Con_DrawSolidConsole( int lines ) Q_snprintf( curbuild, MAX_STRING, "%s %i/%s (%s-%s build %i)", XASH_ENGINE_NAME, PROTOCOL_VERSION, XASH_VERSION, Q_buildos(), Q_buildarch(), Q_buildnum( )); Con_DrawStringLen( curbuild, &stringLen, &charH ); - start = glState.width - stringLen; + start = refState.width - stringLen; stringLen = Con_StringLength( curbuild ); - fraction = lines / (float)glState.height; + fraction = lines / (float)refState.height; color[3] = Q_min( fraction * 2.0f, 1.0f ) * 255; // fadeout version number for( i = 0; i < stringLen; i++ ) @@ -2101,7 +2098,7 @@ void Con_DrawSolidConsole( int lines ) y = lines - ( con.curFont->charHeight * 1.2f ); SCR_DrawFPS( max( y, 4 )); // to avoid to hide fps counter - pglColor4ub( 255, 255, 255, 255 ); + ref.dllFuncs.Color4ub( 255, 255, 255, 255 ); } /* @@ -2124,7 +2121,7 @@ void Con_DrawConsole( void ) { if(( Cvar_VariableInteger( "cl_background" ) || Cvar_VariableInteger( "sv_background" )) && cls.key_dest != key_console ) con.vislines = con.showlines = 0; - else con.vislines = con.showlines = glState.height; + else con.vislines = con.showlines = refState.height; } else { @@ -2141,7 +2138,7 @@ void Con_DrawConsole( void ) case ca_disconnected: if( cls.key_dest != key_menu ) { - Con_DrawSolidConsole( glState.height ); + Con_DrawSolidConsole( refState.height ); Key_SetKeyDest( key_console ); } break; @@ -2156,7 +2153,7 @@ void Con_DrawConsole( void ) if( Cvar_VariableInteger( "cl_background" ) || Cvar_VariableInteger( "sv_background" )) { if( cls.key_dest == key_console ) - Con_DrawSolidConsole( glState.height ); + Con_DrawSolidConsole( refState.height ); } else { @@ -2183,7 +2180,7 @@ void Con_DrawVersion( void ) // draws the current build byte *color = g_color_table[7]; int i, stringLen, width = 0, charH; - int start, height = glState.height; + int start, height = refState.height; qboolean draw_version = false; string curbuild; @@ -2209,7 +2206,7 @@ void Con_DrawVersion( void ) else Q_snprintf( curbuild, MAX_STRING, "v%i/%s (%s-%s build %i)", PROTOCOL_VERSION, XASH_VERSION, Q_buildos(), Q_buildarch(), Q_buildnum( )); Con_DrawStringLen( curbuild, &stringLen, &charH ); - start = glState.width - stringLen * 1.05f; + start = refState.width - stringLen * 1.05f; stringLen = Con_StringLength( curbuild ); height -= charH * 1.05f; @@ -2232,8 +2229,8 @@ void Con_RunConsole( void ) if( host.allow_console && cls.key_dest == key_console ) { if( cls.state < ca_active || cl.first_frame ) - con.showlines = glState.height; // full screen - else con.showlines = (glState.height >> 1); // half screen + con.showlines = refState.height; // full screen + else con.showlines = (refState.height >> 1); // half screen } else con.showlines = 0; // none visible @@ -2322,28 +2319,28 @@ void Con_VidInit( void ) { // trying to load truecolor image first if( FS_FileExists( "gfx/shell/conback.bmp", false ) || FS_FileExists( "gfx/shell/conback.tga", false )) - con.background = GL_LoadTexture( "gfx/shell/conback", NULL, 0, TF_IMAGE ); + con.background = RefRenderAPI->GL_LoadTexture( "gfx/shell/conback", NULL, 0, TF_IMAGE ); if( !con.background ) { if( FS_FileExists( "cached/conback640", false )) - con.background = GL_LoadTexture( "cached/conback640", NULL, 0, TF_IMAGE ); + con.background = RefRenderAPI->GL_LoadTexture( "cached/conback640", NULL, 0, TF_IMAGE ); else if( FS_FileExists( "cached/conback", false )) - con.background = GL_LoadTexture( "cached/conback", NULL, 0, TF_IMAGE ); + con.background = RefRenderAPI->GL_LoadTexture( "cached/conback", NULL, 0, TF_IMAGE ); } } else { // trying to load truecolor image first if( FS_FileExists( "gfx/shell/loading.bmp", false ) || FS_FileExists( "gfx/shell/loading.tga", false )) - con.background = GL_LoadTexture( "gfx/shell/loading", NULL, 0, TF_IMAGE ); + con.background = RefRenderAPI->GL_LoadTexture( "gfx/shell/loading", NULL, 0, TF_IMAGE ); if( !con.background ) { if( FS_FileExists( "cached/loading640", false )) - con.background = GL_LoadTexture( "cached/loading640", NULL, 0, TF_IMAGE ); + con.background = RefRenderAPI->GL_LoadTexture( "cached/loading640", NULL, 0, TF_IMAGE ); else if( FS_FileExists( "cached/loading", false )) - con.background = GL_LoadTexture( "cached/loading", NULL, 0, TF_IMAGE ); + con.background = RefRenderAPI->GL_LoadTexture( "cached/loading", NULL, 0, TF_IMAGE ); } } @@ -2352,7 +2349,7 @@ void Con_VidInit( void ) { qboolean draw_to_console = false; int length = 0; - gl_texture_t *chars; + byte *buf; // NOTE: only these games want to draw build number into console background if( !Q_stricmp( FS_Gamedir(), "id1" )) @@ -2364,7 +2361,8 @@ void Con_VidInit( void ) if( !Q_stricmp( FS_Gamedir(), "rogue" )) draw_to_console = true; - if( draw_to_console && con.curFont && ( chars = R_GetTexture( con.curFont->hFontTexture )) != NULL && chars->original ) + if( draw_to_console && con.curFont && + ( buf = ref.dllFuncs.R_GetTextureOriginalBuffer( con.curFont->hFontTexture )) != NULL ) { lmp_t *cb = (lmp_t *)FS_LoadFile( "gfx/conback.lmp", &length, false ); char ver[64]; @@ -2377,19 +2375,19 @@ void Con_VidInit( void ) dest = (byte *)(cb + 1) + 320 * 186 + 320 - 11 - 8 * Q_strlen( ver ); y = Q_strlen( ver ); for( x = 0; x < y; x++ ) - Con_DrawCharToConback( ver[x], chars->original->buffer, dest + (x << 3)); - con.background = GL_LoadTexture( "#gfx/conback.lmp", (byte *)cb, length, TF_IMAGE ); + Con_DrawCharToConback( ver[x], buf, dest + (x << 3)); + con.background = RefRenderAPI->GL_LoadTexture( "#gfx/conback.lmp", (byte *)cb, length, TF_IMAGE ); } if( cb ) Mem_Free( cb ); } if( !con.background ) // trying the load unmodified conback - con.background = GL_LoadTexture( "gfx/conback.lmp", NULL, 0, TF_IMAGE ); + con.background = RefRenderAPI->GL_LoadTexture( "gfx/conback.lmp", NULL, 0, TF_IMAGE ); } // missed console image will be replaced as gray background like X-Ray or Crysis - if( con.background == tr.defaultTexture || con.background == 0 ) - con.background = tr.grayTexture; + if( con.background == ref.dllFuncs.R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ) || con.background == 0 ) + con.background = ref.dllFuncs.R_GetBuiltinTexture( REF_GRAY_TEXTURE ); } /* diff --git a/engine/client/in_joy.c b/engine/client/in_joy.c index 53ec5ba5..46de098d 100644 --- a/engine/client/in_joy.c +++ b/engine/client/in_joy.c @@ -20,7 +20,6 @@ GNU General Public License for more details. #include "input.h" #include "keydefs.h" #include "client.h" -#include "gl_local.h" #include "platform/platform.h" #ifndef SHRT_MAX diff --git a/engine/client/in_touch.c b/engine/client/in_touch.c deleted file mode 100644 index 4c38088c..00000000 --- a/engine/client/in_touch.c +++ /dev/null @@ -1,1766 +0,0 @@ -/* -touch.c - touchscreen support prototype -Copyright (C) 2015 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. -*/ - -#ifndef XASH_DEDICATED -#include "common.h" -#include "gl_local.h" -#include "input.h" -#include "mobility_int.h" -#include "client.h" -#include "math.h" -#include "vgui_draw.h" -#ifdef XASH_SDL -#include -#endif -#include "platform/platform.h" - -typedef enum -{ - touch_command, // Just tap a button - touch_move, // Like a joystick stick. - touch_joy, // Like a joystick stick, centered. - touch_dpad, // Only two directions. - touch_look // Like a touchpad. -} touchButtonType; - -typedef enum -{ - state_none = 0, - state_edit, - state_edit_move -} touchState; - -typedef enum -{ - round_none = 0, - round_grid, - round_aspect -} touchRound; - - - -typedef struct touchbutton2_s -{ - // Touch button type: tap, stick or slider - touchButtonType type; - // Field of button in pixels - float x1, y1, x2, y2; - // Button texture - int texture; - rgba_t color; - char texturefile[256]; - char command[256]; - char name[32]; - int finger; - int flags; - float fade; - float fadespeed; - float fadeend; - float aspect; - // Double-linked list - struct touchbutton2_s *next; - struct touchbutton2_s *prev; - -} touchbutton2_t; - -typedef struct touchdefaultbutton_s -{ - char name[32]; - char texturefile[256]; - char command[256]; - float x1, y1, x2, y2; - rgba_t color; - touchRound round; - float aspect; - int flags; -} touchdefaultbutton_t; - -typedef struct touchbuttonlist_s -{ - touchbutton2_t *first; - touchbutton2_t *last; -} touchbuttonlist_t; - -struct touch_s -{ - qboolean initialized; - touchbuttonlist_t list_user; - byte *mempool; - touchState state; - int look_finger; - int move_finger; - touchbutton2_t *move; - float move_start_x; - float move_start_y; - float forward; - float side; - float yaw; - float pitch; - // editing - touchbutton2_t *edit; - touchbutton2_t *selection; - int resize_finger; - qboolean showbuttons; - qboolean clientonly; - rgba_t scolor; - int swidth; - qboolean precision; - // textures - int showtexture; - int hidetexture; - int resettexture; - int closetexture; - int joytexture; // touch indicator - qboolean configchanged; -} touch; - -touchdefaultbutton_t g_DefaultButtons[256]; -int g_LastDefaultButton; - -convar_t *touch_pitch; -convar_t *touch_yaw; -convar_t *touch_forwardzone; -convar_t *touch_sidezone; -convar_t *touch_nonlinear_look; -convar_t *touch_pow_mult; -convar_t *touch_pow_factor; -convar_t *touch_exp_mult; -convar_t *touch_grid_enable; -convar_t *touch_grid_count; -convar_t *touch_config_file; -convar_t *touch_enable; -convar_t *touch_in_menu; -convar_t *touch_joy_radius; -convar_t *touch_dpad_radius; -convar_t *touch_move_indicator; -convar_t *touch_highlight_r; -convar_t *touch_highlight_g; -convar_t *touch_highlight_b; -convar_t *touch_highlight_a; -convar_t *touch_precise_amount; -convar_t *touch_joy_texture; - -// code looks smaller with it -#define B(x) button->x -#define SCR_W ((float)glState.width) -#define SCR_H ((float)glState.height) -#define TO_SCRN_Y(x) (glState.height * (x)) -#define TO_SCRN_X(x) (glState.width * (x)) - - -int pfnDrawCharacter( int x, int y, int number, int r, int g, int b ); -static void IN_TouchCheckCoords( float *x1, float *y1, float *x2, float *y2 ); - -void IN_TouchWriteConfig( void ) -{ - file_t *f; - char newconfigfile[64]; - char oldconfigfile[64]; - - if( !touch.list_user.first ) return; - - if( Sys_CheckParm( "-nowriteconfig" ) || !touch.configchanged ) - return; - - Con_Reportf( "IN_TouchWriteConfig(): %s\n", touch_config_file->string ); - - Q_snprintf( newconfigfile, 64, "%s.new", touch_config_file->string ); - Q_snprintf( oldconfigfile, 64, "%s.bak", touch_config_file->string ); - - f = FS_Open( newconfigfile, "w", true ); - if( f ) - { - touchbutton2_t *button; - FS_Printf( f, "//=======================================================================\n"); - FS_Printf( f, "//\tCopyright SDLash3D team & XashXT group %s ©\n", Q_timestamp( TIME_YEAR_ONLY )); - FS_Printf( f, "//\t\t\ttouchscreen config\n" ); - FS_Printf( f, "//=======================================================================\n" ); - FS_Printf( f, "\ntouch_config_file \"%s\"\n", touch_config_file->string ); - FS_Printf( f, "\n// touch cvars\n" ); - FS_Printf( f, "\n// sensitivity settings\n" ); - FS_Printf( f, "touch_pitch \"%f\"\n", touch_pitch->value ); - FS_Printf( f, "touch_yaw \"%f\"\n", touch_yaw->value ); - FS_Printf( f, "touch_forwardzone \"%f\"\n", touch_forwardzone->value ); - FS_Printf( f, "touch_sidezone \"%f\"\n", touch_sidezone->value ); - FS_Printf( f, "touch_nonlinear_look \"%d\"\n", (int)touch_nonlinear_look->value ); - FS_Printf( f, "touch_pow_factor \"%f\"\n", touch_pow_factor->value ); - FS_Printf( f, "touch_pow_mult \"%f\"\n", touch_pow_mult->value ); - FS_Printf( f, "touch_exp_mult \"%f\"\n", touch_exp_mult->value ); FS_Printf( f, "\n// grid settings\n" ); - FS_Printf( f, "touch_grid_count \"%d\"\n", (int)touch_grid_count->value ); - FS_Printf( f, "touch_grid_enable \"%d\"\n", (int)touch_grid_enable->value ); - FS_Printf( f, "\n// global overstroke (width, r, g, b, a)\n" ); - FS_Printf( f, "touch_set_stroke %d %d %d %d %d\n", touch.swidth, touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] ); - FS_Printf( f, "\n// highlight when pressed\n" ); - FS_Printf( f, "touch_highlight_r \"%f\"\n", touch_highlight_r->value ); - FS_Printf( f, "touch_highlight_g \"%f\"\n", touch_highlight_g->value ); - FS_Printf( f, "touch_highlight_b \"%f\"\n", touch_highlight_b->value ); - FS_Printf( f, "touch_highlight_a \"%f\"\n", touch_highlight_a->value ); - FS_Printf( f, "\n// _joy and _dpad options\n" ); - FS_Printf( f, "touch_dpad_radius \"%f\"\n", touch_dpad_radius->value ); - FS_Printf( f, "touch_joy_radius \"%f\"\n", touch_joy_radius->value ); - FS_Printf( f, "\n// how much slowdown when Precise Look button pressed\n" ); - FS_Printf( f, "touch_precise_amount \"%f\"\n", touch_precise_amount->value ); - FS_Printf( f, "\n// enable/disable move indicator\n" ); - FS_Printf( f, "touch_move_indicator \"%d\"\n", (int)touch_move_indicator->value ); - - FS_Printf( f, "\n// reset menu state when execing config\n" ); - FS_Printf( f, "touch_setclientonly 0\n" ); - FS_Printf( f, "\n// touch buttons\n" ); - FS_Printf( f, "touch_removeall\n" ); - for( button = touch.list_user.first; button; button = button->next ) - { - int flags = button->flags; - if( flags & TOUCH_FL_CLIENT ) - continue; //skip temporary buttons - if( flags & TOUCH_FL_DEF_SHOW ) - flags &= ~TOUCH_FL_HIDE; - if( flags & TOUCH_FL_DEF_HIDE ) - flags |= TOUCH_FL_HIDE; - - FS_Printf( f, "touch_addbutton \"%s\" \"%s\" \"%s\" %f %f %f %f %d %d %d %d %d\n", - B(name), B(texturefile), B(command), - B(x1), B(y1), B(x2), B(y2), - B(color[0]), B(color[1]), B(color[2]), B(color[3]), flags ); - } - - FS_Close( f ); - FS_Delete( oldconfigfile ); - FS_Rename( touch_config_file->string, oldconfigfile ); - FS_Delete( touch_config_file->string ); - FS_Rename( newconfigfile, touch_config_file->string ); - } - else Con_Reportf( S_ERROR "Couldn't write %s.\n", touch_config_file->string ); -} - -void IN_TouchExportConfig_f( void ) -{ - file_t *f; - const char *name; - - if( Cmd_Argc() != 2 ) - { - Msg( S_USAGE "touch_exportconfig \n" ); - return; - } - - if( !touch.list_user.first ) return; - - name = Cmd_Argv( 1 ); - - Con_Reportf( "Exporting config to %s\n", name ); - f = FS_Open( name, "w", true ); - if( f ) - { - char profilename[256]; - char profilebase[256]; - touchbutton2_t *button; - if( Q_strstr( name, "touch_presets/" ) ) - { - COM_FileBase( name, profilebase ); - Q_snprintf( profilename, 256, "touch_profiles/%s (copy).cfg", profilebase ); - } - else Q_strncpy( profilename, name, 256 ); - FS_Printf( f, "//=======================================================================\n"); - FS_Printf( f, "//\tCopyright SDLash3D team & XashXT group %s ©\n", Q_timestamp( TIME_YEAR_ONLY )); - FS_Printf( f, "//\t\t\ttouchscreen preset\n" ); - FS_Printf( f, "//=======================================================================\n" ); - FS_Printf( f, "\ntouch_config_file \"%s\"\n", profilename ); - FS_Printf( f, "\n// touch cvars\n" ); - FS_Printf( f, "\n// sensitivity settings\n" ); - FS_Printf( f, "touch_pitch \"%f\"\n", touch_pitch->value ); - FS_Printf( f, "touch_yaw \"%f\"\n", touch_yaw->value ); - FS_Printf( f, "touch_forwardzone \"%f\"\n", touch_forwardzone->value ); - FS_Printf( f, "touch_sidezone \"%f\"\n", touch_sidezone->value ); - FS_Printf( f, "touch_nonlinear_look \"%d\"\n", (int)touch_nonlinear_look->value ); - FS_Printf( f, "touch_pow_factor \"%f\"\n", touch_pow_factor->value ); - FS_Printf( f, "touch_pow_mult \"%f\"\n", touch_pow_mult->value ); - FS_Printf( f, "touch_exp_mult \"%f\"\n", touch_exp_mult->value ); - FS_Printf( f, "\n// grid settings\n" ); - FS_Printf( f, "touch_grid_count \"%d\"\n", (int)touch_grid_count->value ); - FS_Printf( f, "touch_grid_enable \"%d\"\n", (int)touch_grid_enable->value ); - FS_Printf( f, "\n// global overstroke (width, r, g, b, a)\n" ); - FS_Printf( f, "touch_set_stroke %d %d %d %d %d\n", touch.swidth, touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] ); - FS_Printf( f, "\n// highlight when pressed\n" ); - FS_Printf( f, "touch_highlight_r \"%f\"\n", touch_highlight_r->value ); - FS_Printf( f, "touch_highlight_g \"%f\"\n", touch_highlight_g->value ); - FS_Printf( f, "touch_highlight_b \"%f\"\n", touch_highlight_b->value ); - FS_Printf( f, "touch_highlight_a \"%f\"\n", touch_highlight_a->value ); - FS_Printf( f, "\n// _joy and _dpad options\n" ); - FS_Printf( f, "touch_dpad_radius \"%f\"\n", touch_dpad_radius->value ); - FS_Printf( f, "touch_joy_radius \"%f\"\n", touch_joy_radius->value ); - FS_Printf( f, "\n// how much slowdown when Precise Look button pressed\n" ); - FS_Printf( f, "touch_precise_amount \"%f\"\n", touch_precise_amount->value ); - FS_Printf( f, "\n// enable/disable move indicator\n" ); - FS_Printf( f, "touch_move_indicator \"%d\"\n", (int)touch_move_indicator->value ); - - FS_Printf( f, "\n// reset menu state when execing config\n" ); - FS_Printf( f, "touch_setclientonly 0\n" ); - FS_Printf( f, "\n// touch buttons\n" ); - FS_Printf( f, "touch_removeall\n" ); - for( button = touch.list_user.first; button; button = button->next ) - { - float aspect; - int flags = button->flags; - if( flags & TOUCH_FL_CLIENT ) - continue; //skip temporary buttons - if( flags & TOUCH_FL_DEF_SHOW ) - flags &= ~TOUCH_FL_HIDE; - if( flags & TOUCH_FL_DEF_HIDE ) - flags |= TOUCH_FL_HIDE; - - aspect = ( B(y2) - B(y1) ) / ( ( B(x2) - B(x1) ) /(SCR_H/SCR_W) ); - - FS_Printf( f, "touch_addbutton \"%s\" \"%s\" \"%s\" %f %f %f %f %d %d %d %d %d %f\n", - B(name), B(texturefile), B(command), - B(x1), B(y1), B(x2), B(y2), - B(color[0]), B(color[1]), B(color[2]), B(color[3]), flags, aspect ); - } - FS_Printf( f, "\n// round button coordinates to grid\n" ); - FS_Printf( f, "touch_roundall\n" ); - FS_Close( f ); - } - else Con_Reportf( S_ERROR "Couldn't write %s.\n", name ); -} - -void IN_TouchGenetateCode_f( void ) -{ - touchbutton2_t *button; - rgba_t c = {0,0,0,0}; - - if( Cmd_Argc() != 1 ) - { - Msg( S_USAGE "touch_generate_code\n" ); - return; - } - - if( !touch.list_user.first ) return; - - for( button = touch.list_user.first; button; button = button->next ) - { - float aspect; - int flags = button->flags; - if( flags & TOUCH_FL_CLIENT ) - continue; //skip temporary buttons - if( flags & TOUCH_FL_DEF_SHOW ) - flags &= ~TOUCH_FL_HIDE; - if( flags & TOUCH_FL_DEF_HIDE ) - flags |= TOUCH_FL_HIDE; - - aspect = ( B(y2) - B(y1) ) / ( ( B(x2) - B(x1) ) /(SCR_H/SCR_W) ); - if( memcmp( &c, &B(color), sizeof( rgba_t ) ) ) - { - Msg( "MakeRGBA( color, %d, %d, %d, %d );\n", B(color[0]), B(color[1]), B(color[2]), B(color[3]) ); - memcpy( &c, &B(color), sizeof( rgba_t ) ); - } - Msg( "TOUCH_ADDDEFAULT( \"%s\", \"%s\", \"%s\", %f, %f, %f, %f, color, %d, %f, %d );\n", - B(name), B(texturefile), B(command), - B(x1), B(y1), B(x2), B(y2), (B(type) == touch_command)?(fabs( aspect - 1.0f) < 0.0001)?2:1:0, aspect, flags ); - } -} - -void IN_TouchRoundAll_f( void ) -{ - touchbutton2_t *button; - if( !touch_grid_enable->value ) - return; - for( button = touch.list_user.first; button; button = button->next ) - IN_TouchCheckCoords( &B(x1), &B(y1), &B(x2), &B(y2) ); -} - -void IN_TouchListButtons_f( void ) -{ - touchbutton2_t *button; - for( button = touch.list_user.first; button; button = button->next ) - { - Msg( "%s %s %s %f %f %f %f %d %d %d %d %d\n", - B(name), B(texturefile), B(command), - B(x1), B(y1), B(x2), B(y2), - B(color[0]), B(color[1]), B(color[2]), B(color[3]), B(flags) ); - if( B(flags) & TOUCH_FL_CLIENT) - continue; - UI_AddTouchButtonToList( B(name), B(texturefile), B(command),B(color), B(flags) ); - } - touch.configchanged = true; -} - -void IN_TouchStroke_f( void ) -{ - touch.swidth = Q_atoi( Cmd_Argv( 1 ) ); - MakeRGBA( touch.scolor, Q_atoi( Cmd_Argv( 2 ) ), Q_atoi( Cmd_Argv( 3 ) ), Q_atoi( Cmd_Argv( 4 ) ), Q_atoi( Cmd_Argv( 5 ) ) ); -} - -touchbutton2_t *IN_TouchFindButton( touchbuttonlist_t *list, const char *name ) -{ - touchbutton2_t *button; - - for ( button = list->first; button; button = button->next ) - if( !Q_strncmp( button->name, name, 32 ) ) - return button; - return NULL; -} - -touchbutton2_t *IN_TouchFindFirst( touchbuttonlist_t *list, const char *name ) -{ - touchbutton2_t *button; - - for ( button = list->first; button; button = button->next ) - if( ( Q_strstr( name, "*" ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) ) - return button; - return NULL; -} - -void IN_TouchSetClientOnly( qboolean state ) -{ - touch.clientonly = state; - host.mouse_visible = state; -#ifdef XASH_SDL - if( state ) - { - SDL_SetRelativeMouseMode( SDL_FALSE ); - SDL_ShowCursor( true ); - IN_DeactivateMouse(); - } - else - { - SDL_ShowCursor( false ); - SDL_GetRelativeMouseState( 0, 0 ); - } -#endif -} - -void IN_TouchSetClientOnly_f( void ) -{ - IN_TouchSetClientOnly( Q_atoi( Cmd_Argv( 1 ) ) ); -} - -void Touch_RemoveButton( touchbuttonlist_t *list, const char *name ) -{ - touchbutton2_t *button; - - IN_TouchEditClear(); - - while( ( button = IN_TouchFindFirst( &touch.list_user, name ) ) ) - { - if( button->prev ) - button->prev->next = button->next; - else - list->first = button->next; - if( button->next ) - button->next->prev = button->prev; - else - list->last = button->prev; - Mem_Free( button ); - } - -} - -void IN_TouchRemoveButton( const char *name ) -{ - Touch_RemoveButton( &touch.list_user, name ); -} - -void IN_TouchRemoveButton_f( void ) -{ - IN_TouchRemoveButton( Cmd_Argv( 1 ) ); -} - -void IN_TouchRemoveAll_f( void ) -{ - IN_TouchEditClear(); - while( touch.list_user.first ) - { - touchbutton2_t *remove = touch.list_user.first; - touch.list_user.first = touch.list_user.first->next; - Mem_Free ( remove ); - } - touch.list_user.last = NULL; -} - -void IN_TouchSetColor( touchbuttonlist_t *list, const char *name, byte *color ) -{ - touchbutton2_t *button; - for( button = list->first; button; button = button->next ) - { - if( ( Q_strstr( name, "*" ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) ) - MakeRGBA( button->color, color[0], color[1], color[2], color[3] ); - } -} - -void IN_TouchSetTexture( touchbuttonlist_t *list, const char *name, const char *texture ) -{ - touchbutton2_t *button = IN_TouchFindButton( list, name ); - if( !button ) - return; - button->texture = -1; // mark for texture load - Q_strncpy( button->texturefile, texture, sizeof( button->texturefile ) ); -} - -void IN_TouchSetCommand( touchbuttonlist_t *list, const char *name, const char *command ) -{ - touchbutton2_t *button = IN_TouchFindButton( list, name ); - - if( !button ) - return; - - if( !Q_strcmp( command, "_look" ) ) - button->type = touch_look; - if( !Q_strcmp( command, "_move" ) ) - button->type = touch_move; - if( !Q_strcmp( command, "_joy" ) ) - button->type = touch_joy; - if( !Q_strcmp( command, "_dpad" ) ) - button->type = touch_dpad; - - Q_strncpy( button->command, command, sizeof( button->command ) ); -} - -void IN_TouchHideButtons( const char *name, qboolean hide ) -{ - touchbutton2_t *button; - - for( button = touch.list_user.first; button; button = button->next) - { - if( ( Q_strstr( name, "*" ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) ) - { - if( hide ) - button->flags |= TOUCH_FL_HIDE; - else - button->flags &= ~TOUCH_FL_HIDE; - } - } - -} -void IN_TouchHide_f( void ) -{ - IN_TouchHideButtons( Cmd_Argv( 1 ), true ); -} - -void IN_TouchShow_f( void ) -{ - IN_TouchHideButtons( Cmd_Argv( 1 ), false ); -} - -void IN_TouchFadeButtons( touchbuttonlist_t *list, const char *name, float speed, float end, float start ) -{ - touchbutton2_t *button; - for( button = list->first; button; button = button->next) - { - if( ( Q_strstr( name, "*" ) && Q_stricmpext( name, button->name ) ) || !Q_strncmp( name, button->name, 32 ) ) - { - if( start >= 0 ) - button->fade = start; - button->fadespeed = speed; - button->fadeend = end; - } - } -} -void IN_TouchFade_f( void ) -{ - float start = -1; - if( Cmd_Argc() < 4 ) - return; - if( Cmd_Argc() > 4 ) - start = Q_atof( Cmd_Argv( 4 ) ); - IN_TouchFadeButtons( &touch.list_user, Cmd_Argv( 1 ), Q_atof( Cmd_Argv( 2 )), Q_atof( Cmd_Argv( 3 )), start ); -} - -void IN_TouchSetColor_f( void ) -{ - rgba_t color; - if( Cmd_Argc() == 6 ) - { - MakeRGBA( color, Q_atoi( Cmd_Argv(2) ), Q_atoi( Cmd_Argv(3) ), Q_atoi( Cmd_Argv(4) ), Q_atoi( Cmd_Argv(5) ) ); - IN_TouchSetColor( &touch.list_user, Cmd_Argv(1), color ); - return; - } - Msg( S_USAGE "touch_setcolor \n" ); -} - -void IN_TouchSetTexture_f( void ) -{ - if( Cmd_Argc() == 3 ) - { - IN_TouchSetTexture( &touch.list_user, Cmd_Argv( 1 ), Cmd_Argv( 2 ) ); - return; - } - Msg( S_USAGE "touch_settexture \n" ); -} - -void IN_TouchSetFlags_f( void ) -{ - if( Cmd_Argc() == 3 ) - { - touchbutton2_t *button = IN_TouchFindButton( &touch.list_user, Cmd_Argv( 1 ) ); - if( button ) - button->flags = Q_atoi( Cmd_Argv( 2 ) ); - return; - } - Msg( S_USAGE "touch_setflags \n" ); -} - -void IN_TouchSetCommand_f( void ) -{ - if( Cmd_Argc() == 3 ) - { - IN_TouchSetCommand( &touch.list_user, Cmd_Argv( 1 ), Cmd_Argv( 2 ) ); - return; - } - Msg( S_USAGE "touch_command \n" ); -} -void IN_TouchReloadConfig_f( void ) -{ - Cbuf_AddText( va("exec %s\n", touch_config_file->string ) ); -} - -touchbutton2_t *IN_TouchAddButton( touchbuttonlist_t *list, const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, byte *color ) -{ - touchbutton2_t *button = Mem_Malloc( touch.mempool, sizeof( touchbutton2_t ) ); - button->texture = -1; - Q_strncpy( button->texturefile, texture, sizeof( button->texturefile ) ); - Q_strncpy( button->name, name, 32 ); - Touch_RemoveButton( list, name ); //replace if exist - button->x1 = x1; - button->y1 = y1; - button->x2 = x2; - button->y2 = y2; - MakeRGBA( button->color, color[0], color[1], color[2], color[3] ); - button->command[0] = 0; - button->flags = 0; - button->fade = 1; - - // check keywords - if( !Q_strcmp( command, "_look" ) ) - button->type = touch_look; - if( !Q_strcmp( command, "_move" ) ) - button->type = touch_move; - if( !Q_strcmp( command, "_joy" ) ) - button->type = touch_joy; - if( !Q_strcmp( command, "_dpad" ) ) - button->type = touch_dpad; - - Q_strncpy( button->command, command, sizeof( button->command ) ); - button->finger = -1; - button->next = NULL; - button->prev = list->last; - if( list->last ) - list->last->next = button; - list->last = button; - - if( !list->first ) - list->first = button; - - return button; -} - -void IN_TouchAddClientButton( const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags ) -{ - touchbutton2_t *button; - - if( !touch.initialized ) - return; - if( round ) - IN_TouchCheckCoords( &x1, &y1, &x2, &y2 ); - if( round == round_aspect ) - { - y2 = y1 + ( x2 - x1 ) * (SCR_W/SCR_H) * aspect; - } - button = IN_TouchAddButton( &touch.list_user, name, texture, command, x1, y1, x2, y2, color ); - button->flags |= flags | TOUCH_FL_CLIENT | TOUCH_FL_NOEDIT; - button->aspect = aspect; -} - -void IN_TouchLoadDefaults_f( void ) -{ - int i; - for( i = 0; i < g_LastDefaultButton; i++ ) - { - touchbutton2_t *button; - float x1 = g_DefaultButtons[i].x1, - y1 = g_DefaultButtons[i].y1, - x2 = g_DefaultButtons[i].x2, - y2 = g_DefaultButtons[i].y2; - - IN_TouchCheckCoords( &x1, &y1, &x2, &y2 ); - - if( g_DefaultButtons[i].aspect && g_DefaultButtons[i].round == round_aspect ) - { - if( g_DefaultButtons[i].texturefile[0] == '#' ) - y2 = y1 + ( (float)clgame.scrInfo.iCharHeight / (float)clgame.scrInfo.iHeight ) * g_DefaultButtons[i].aspect + touch.swidth*2/SCR_H; - else - y2 = y1 + ( x2 - x1 ) * (SCR_W/SCR_H) * g_DefaultButtons[i].aspect; - } - - IN_TouchCheckCoords( &x1, &y1, &x2, &y2 ); - button = IN_TouchAddButton( &touch.list_user, g_DefaultButtons[i].name, g_DefaultButtons[i].texturefile, g_DefaultButtons[i].command, x1, y1, x2, y2, g_DefaultButtons[i].color ); - button->flags |= g_DefaultButtons[i].flags; - button->aspect = g_DefaultButtons[i].aspect; - } -} - - -// Add default button from client -void IN_TouchAddDefaultButton( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, byte *color, int round, float aspect, int flags ) -{ - if( g_LastDefaultButton >= 255 ) - return; - Q_strncpy( g_DefaultButtons[g_LastDefaultButton].name, name, 32 ); - Q_strncpy( g_DefaultButtons[g_LastDefaultButton].texturefile, texturefile, 256 ); - Q_strncpy( g_DefaultButtons[g_LastDefaultButton].command, command, 256 ); - g_DefaultButtons[g_LastDefaultButton].x1 = x1; - g_DefaultButtons[g_LastDefaultButton].y1 = y1; - g_DefaultButtons[g_LastDefaultButton].x2 = x2; - g_DefaultButtons[g_LastDefaultButton].y2 = y2; - MakeRGBA( g_DefaultButtons[g_LastDefaultButton].color, color[0], color[1], color[2], color[3] ); - g_DefaultButtons[g_LastDefaultButton].round = round; - g_DefaultButtons[g_LastDefaultButton].aspect = aspect; - g_DefaultButtons[g_LastDefaultButton].flags = flags; - g_LastDefaultButton++; -} - -// Client may remove all default buttons from engine -void IN_TouchResetDefaultButtons( void ) -{ - g_LastDefaultButton = 0; -} -void IN_TouchAddButton_f( void ) -{ - rgba_t color; - int argc = Cmd_Argc( ); - - if( argc >= 12 ) - { - touchbutton2_t *button; - MakeRGBA( color, Q_atoi( Cmd_Argv(8) ), Q_atoi( Cmd_Argv(9) ), - Q_atoi( Cmd_Argv(10) ), Q_atoi( Cmd_Argv(11) ) ); - button = IN_TouchAddButton( &touch.list_user, Cmd_Argv(1), Cmd_Argv(2), Cmd_Argv(3), - Q_atof( Cmd_Argv(4) ), Q_atof( Cmd_Argv(5) ), - Q_atof( Cmd_Argv(6) ), Q_atof( Cmd_Argv(7) ) , - color ); - if( argc >= 13 ) - button->flags = Q_atoi( Cmd_Argv(12) ); - if( argc >= 14 ) - { - // Recalculate button coordinates aspect ratio - // This is feature for distributed configs - float aspect = Q_atof( Cmd_Argv(13) ); - if( aspect ) - { - if( B(texturefile)[0] != '#' ) - B(y2) = B(y1) + ( B(x2) - B(x1) ) * (SCR_W/SCR_H) * aspect; - B(aspect) = aspect; - } - } - - return; - } - if( argc == 8 ) - { - MakeRGBA( color, 255, 255, 255, 255 ); - IN_TouchAddButton( &touch.list_user, Cmd_Argv(1), Cmd_Argv(2), Cmd_Argv(3), - Q_atof( Cmd_Argv(4) ), Q_atof( Cmd_Argv(5) ), - Q_atof( Cmd_Argv(6) ), Q_atof( Cmd_Argv(7) ), - color ); - return; - } - if( argc == 4 ) - { - MakeRGBA( color, 255, 255, 255, 255 ); - IN_TouchAddButton( &touch.list_user, Cmd_Argv(1), Cmd_Argv(2), Cmd_Argv(3), 0.4, 0.4, 0.6, 0.6, color ); - return; - } - Msg( S_USAGE "touch_addbutton [ [ r g b a ] ]\n" ); -} - -void IN_TouchEnableEdit_f( void ) -{ - if( touch.state == state_none ) - touch.state = state_edit; - touch.resize_finger = touch.move_finger = touch.look_finger = -1; - touch.move = NULL; - touch.configchanged = true; -} - -void IN_TouchDisableEdit_f( void ) -{ - touch.state = state_none; - if( touch.edit ) - touch.edit->finger = -1; - if( touch.selection ) - touch.selection->finger = -1; - touch.edit = touch.selection = NULL; - touch.resize_finger = touch.move_finger = touch.look_finger = -1; -} - -void IN_TouchDeleteProfile_f( void ) -{ - if( Cmd_Argc() != 2 ) - { - Msg( S_USAGE "touch_deleteprofile \n" ); - return; - } - - // delete profile - FS_Delete( va( "touch_profiles/%s.cfg", Cmd_Argv( 1 ))); -} - - -void IN_TouchInit( void ) -{ - rgba_t color; - if( touch.initialized ) - return; - touch.mempool = Mem_AllocPool( "Touch" ); - //touch.first = touch.last = NULL; - Con_Reportf( "IN_TouchInit()\n"); - touch.move_finger = touch.resize_finger = touch.look_finger = -1; - touch.state = state_none; - touch.showbuttons = true; - touch.clientonly = false; - touch.precision = false; - MakeRGBA( touch.scolor, 255, 255, 255, 255 ); - touch.swidth = 1; - g_LastDefaultButton = 0; - - // fill default buttons list - MakeRGBA( color, 255, 255, 255, 255 ); - IN_TouchAddDefaultButton( "look", "", "_look", 0.500000, 0.000000, 1.000000, 1, color, 0, 0, 0 ); - IN_TouchAddDefaultButton( "move", "", "_move", 0.000000, 0.000000, 0.500000, 1, color, 0, 0, 0 ); - IN_TouchAddDefaultButton( "invnext", "touch_default/next_weap.tga", "invnext", 0.000000, 0.530200, 0.120000, 0.757428, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "invprev", "touch_default/prev_weap.tga", "invprev", 0.000000, 0.075743, 0.120000, 0.302971, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "use", "touch_default/use.tga", "+use", 0.880000, 0.454457, 1.000000, 0.681685, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "jump", "touch_default/jump.tga", "+jump", 0.880000, 0.227228, 1.000000, 0.454457, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "attack", "touch_default/shoot.tga", "+attack", 0.760000, 0.530200, 0.880000, 0.757428, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "attack2", "touch_default/shoot_alt.tga", "+attack2", 0.760000, 0.302971, 0.880000, 0.530200, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "loadquick", "touch_default/load.tga", "loadquick", 0.760000, 0.000000, 0.840000, 0.151486, color, 2, 1, 16 ); - IN_TouchAddDefaultButton( "savequick", "touch_default/save.tga", "savequick", 0.840000, 0.000000, 0.920000, 0.151486, color, 2, 1, 16 ); - IN_TouchAddDefaultButton( "messagemode", "touch_default/keyboard.tga", "messagemode", 0.840000, 0.000000, 0.920000, 0.151486, color, 2, 1, 8 ); - IN_TouchAddDefaultButton( "reload", "touch_default/reload.tga", "+reload", 0.000000, 0.302971, 0.120000, 0.530200, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "flashlight", "touch_default/flash_light_filled.tga", "impulse 100", 0.920000, 0.000000, 1.000000, 0.151486, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "scores", "touch_default/map.tga", "+showscores", 0.760000, 0.000000, 0.840000, 0.151486, color, 2, 1, 8 ); - IN_TouchAddDefaultButton( "show_numbers", "touch_default/show_weapons.tga", "exec touch_default/numbers.cfg", 0.440000, 0.833171, 0.520000, 0.984656, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "duck", "touch_default/crouch.tga", "+duck", 0.880000, 0.757428, 1.000000, 0.984656, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "tduck", "touch_default/tduck.tga", ";+duck", 0.560000, 0.833171, 0.620000, 0.946785, color, 2, 1, 0 ); - IN_TouchAddDefaultButton( "edit", "touch_default/settings.tga", "touch_enableedit", 0.420000, 0.000000, 0.500000, 0.151486, color, 2, 1, 32 ); - IN_TouchAddDefaultButton( "menu", "touch_default/menu.tga", "escape", 0.000000, 0.833171, 0.080000, 0.984656, color, 2, 1, 0 ); - - - Cmd_AddCommand( "touch_addbutton", IN_TouchAddButton_f, "add native touch button" ); - Cmd_AddCommand( "touch_removebutton", IN_TouchRemoveButton_f, "remove native touch button" ); - Cmd_AddCommand( "touch_enableedit", IN_TouchEnableEdit_f, "enable button editing mode" ); - Cmd_AddCommand( "touch_disableedit", IN_TouchDisableEdit_f, "disable button editing mode" ); - Cmd_AddCommand( "touch_settexture", IN_TouchSetTexture_f, "change button texture" ); - Cmd_AddCommand( "touch_setcolor", IN_TouchSetColor_f, "change button color" ); - Cmd_AddCommand( "touch_setcommand", IN_TouchSetCommand_f, "change button command" ); - Cmd_AddCommand( "touch_setflags", IN_TouchSetFlags_f, "change button flags (be careful)" ); - Cmd_AddCommand( "touch_show", IN_TouchShow_f, "show button" ); - Cmd_AddCommand( "touch_hide", IN_TouchHide_f, "hide button" ); - Cmd_AddCommand( "touch_list", IN_TouchListButtons_f, "list buttons" ); - Cmd_AddCommand( "touch_removeall", IN_TouchRemoveAll_f, "remove all buttons" ); - Cmd_AddCommand( "touch_loaddefaults", IN_TouchLoadDefaults_f, "generate config from defaults" ); - Cmd_AddCommand( "touch_roundall", IN_TouchRoundAll_f, "round all buttons coordinates to grid" ); - Cmd_AddCommand( "touch_exportconfig", IN_TouchExportConfig_f, "export config keeping aspect ratio" ); - Cmd_AddCommand( "touch_set_stroke", IN_TouchStroke_f, "set global stroke width and color" ); - Cmd_AddCommand( "touch_setclientonly", IN_TouchSetClientOnly_f, "when 1, only client buttons are shown" ); - Cmd_AddCommand( "touch_reloadconfig", IN_TouchReloadConfig_f, "load config, not saving changes" ); - Cmd_AddCommand( "touch_writeconfig", IN_TouchWriteConfig, "save current config" ); - Cmd_AddCommand( "touch_deleteprofile", IN_TouchDeleteProfile_f, "delete profile by name" ); - Cmd_AddCommand( "touch_generate_code", IN_TouchGenetateCode_f, "create code sample for mobility API" ); - Cmd_AddCommand( "touch_fade", IN_TouchFade_f, "create code sample for mobility API" ); - - // not saved, just runtime state for scripting - touch_in_menu = Cvar_Get( "touch_in_menu", "0", 0, "draw touch in menu (for internal use only)" ); - - // sensitivity configuration - touch_forwardzone = Cvar_Get( "touch_forwardzone", "0.06", 0, "forward touch zone" ); - touch_sidezone = Cvar_Get( "touch_sidezone", "0.06", 0, "side touch zone" ); - touch_pitch = Cvar_Get( "touch_pitch", "90", 0, "touch pitch sensitivity" ); - touch_yaw = Cvar_Get( "touch_yaw", "120", 0, "touch yaw sensitivity" ); - touch_nonlinear_look = Cvar_Get( "touch_nonlinear_look", "0", 0, "enable nonlinear touch look" ); - touch_pow_factor = Cvar_Get( "touch_pow_factor", "1.0", 0, "set > 1 to enable" ); - touch_pow_mult = Cvar_Get( "touch_pow_mult", "300.0", 0, "power multiplier, usually 200-1000" ); - touch_exp_mult = Cvar_Get( "touch_exp_mult", "0", 0, "exponent multiplier, usually 20-200, 0 to disable" ); - - // touch.cfg - touch_grid_count = Cvar_Get( "touch_grid_count", "50", 0, "touch grid count" ); - touch_grid_enable = Cvar_Get( "touch_grid_enable", "1", 0, "enable touch grid" ); - touch_config_file = Cvar_Get( "touch_config_file", "touch.cfg", FCVAR_ARCHIVE, "current touch profile file" ); - touch_precise_amount = Cvar_Get( "touch_precise_amount", "0.5", 0, "sensitivity multiplier for precise-look" ); - touch_highlight_r = Cvar_Get( "touch_highlight_r", "1.0", 0, "highlight r color" ); - touch_highlight_g = Cvar_Get( "touch_highlight_g", "1.0", 0, "highlight g color" ); - touch_highlight_b = Cvar_Get( "touch_highlight_b", "1.0", 0, "highlight b color" ); - touch_highlight_a = Cvar_Get( "touch_highlight_a", "1.0", 0, "highlight alpha" ); - touch_dpad_radius = Cvar_Get( "touch_dpad_radius", "1.0", 0, "dpad radius multiplier" ); - touch_joy_radius = Cvar_Get( "touch_joy_radius", "1.0", 0, "joy radius multiplier" ); - touch_move_indicator = Cvar_Get( "touch_move_indicator", "0.0", 0, "indicate move events (0 to disable)" ); - touch_joy_texture = Cvar_Get( "touch_joy_texture", "touch_default/joy.tga", 0, "texture for move indicator"); - - // input devices cvar - touch_enable = Cvar_Get( "touch_enable", DEFAULT_TOUCH_ENABLE, FCVAR_ARCHIVE, "enable touch controls" ); - touch.initialized = true; -} - -// must be called after executing config.cfg -void IN_TouchInitConfig( void ) -{ - if( !touch.initialized ) - return; - - CL_GetScreenInfo( NULL ); //HACK: update hud screen parameters like iHeight - if( FS_FileExists( touch_config_file->string, true ) ) - Cbuf_AddText( va( "exec \"%s\"\n", touch_config_file->string ) ); - else IN_TouchLoadDefaults_f( ); - touch.closetexture = GL_LoadTexture( "touch_default/edit_close.tga", NULL, 0, TF_NOMIPMAP ); - touch.hidetexture = GL_LoadTexture( "touch_default/edit_hide.tga", NULL, 0, TF_NOMIPMAP ); - touch.showtexture = GL_LoadTexture( "touch_default/edit_show.tga", NULL, 0, TF_NOMIPMAP ); - touch.resettexture = GL_LoadTexture( "touch_default/edit_reset.tga", NULL, 0, TF_NOMIPMAP ); - touch.joytexture = GL_LoadTexture( touch_joy_texture->string, NULL, 0, TF_NOMIPMAP ); - touch.configchanged = false; -} -qboolean IN_TouchIsVisible( touchbutton2_t *button ) -{ - if( !(button->flags & TOUCH_FL_CLIENT) && touch.clientonly ) - return false; // skip nonclient buttons in clientonly mode - - if( touch.state >= state_edit ) - return true; //!!! Draw when editor is open - - if( button->flags & TOUCH_FL_HIDE ) - return false; // skip hidden - - if( button->flags & TOUCH_FL_SP && CL_GetMaxClients() != 1 ) - return false; // skip singleplayer(load, save) buttons in multiplayer - - if( button->flags & TOUCH_FL_MP && CL_GetMaxClients() == 1 ) - return false; // skip multiplayer buttons in singleplayer - - return true; - /* - return ( !touch.clientonly || ( button->flags & TOUCH_FL_CLIENT) ) && - ( - ( touch.state >= state_edit ) - ||( !( button->flags & TOUCH_FL_HIDE ) - && ( !(button->flags & TOUCH_FL_SP) || ( CL_GetMaxClients() == 1 ) ) - && ( !(button->flags & TOUCH_FL_MP) || ( CL_GetMaxClients() != 1 ) ) ) - ); - */ -} - -void Touch_DrawTexture ( float x1, float y1, float x2, float y2, int texture, byte r, byte g, byte b, byte a ) -{ - if( x1 >= x2 ) - return; - - if( y1 >= y2 ) - return; - - pglColor4ub( r, g, b, a ); - R_DrawStretchPic( TO_SCRN_X(x1), - TO_SCRN_Y(y1), - TO_SCRN_X(x2 - x1), - TO_SCRN_Y(y2 - y1), - 0, 0, 1, 1, texture ); -} - -#if defined(_MSC_VER) && (_MSC_VER < 1700) -static __inline int round(float f) -{ - return (int)(f + 0.5); - -} -#endif - -#define GRID_COUNT_X (touch_grid_count->value) -#define GRID_COUNT_Y (touch_grid_count->value * SCR_H / SCR_W) -#define GRID_X (1.0/GRID_COUNT_X) -#define GRID_Y (SCR_W/SCR_H/GRID_COUNT_X) -#define GRID_ROUND_X(x) ((float)round( x * GRID_COUNT_X ) / GRID_COUNT_X) -#define GRID_ROUND_Y(x) ((float)round( x * GRID_COUNT_Y ) / GRID_COUNT_Y) - -static void IN_TouchCheckCoords( float *x1, float *y1, float *x2, float *y2 ) -{ - /// TODO: grid check here - if( *x2 - *x1 < GRID_X * 2 ) - *x2 = *x1 + GRID_X * 2; - if( *y2 - *y1 < GRID_Y * 2) - *y2 = *y1 + GRID_Y * 2; - if( *x1 < 0 ) - *x2 -= *x1, *x1 = 0; - if( *y1 < 0 ) - *y2 -= *y1, *y1 = 0; - if( *y2 > 1 ) - *y1 -= *y2 - 1, *y2 = 1; - if( *x2 > 1 ) - *x1 -= *x2 - 1, *x2 = 1; - if ( touch_grid_enable->value ) - { - *x1 = GRID_ROUND_X( *x1 ); - *x2 = GRID_ROUND_X( *x2 ); - *y1 = GRID_ROUND_Y( *y1 ); - *y2 = GRID_ROUND_Y( *y2 ); - } -} - -float Touch_DrawCharacter( float x, float y, int number, float size ) -{ - float s1, s2, t1, t2, width, height; - int w, h; - wrect_t *prc; - if( !cls.creditsFont.valid ) - return 0; - - number &= 255; - number = Con_UtfProcessChar( number ); - - - R_GetTextureParms( &w, &h, cls.creditsFont.hFontTexture ); - prc = &cls.creditsFont.fontRc[number]; - - s1 = ((float)prc->left) / (float)w; - t1 = ((float)prc->top) / (float)h; - s2 = ((float)prc->right) / (float)w; - t2 = ((float)prc->bottom) / (float)h; - - width = ((float)( prc->right - prc->left )) / 1024.0f * size; - height = ((float)( prc->bottom - prc->top )) / 1024.0f * size; - - R_DrawStretchPic( TO_SCRN_X(x), TO_SCRN_Y(y), TO_SCRN_X(width), TO_SCRN_X(height), s1, t1, s2, t2, cls.creditsFont.hFontTexture ); - return width; -} - -float Touch_DrawText( float x1, float y1, float x2, float y2, const char *s, byte *color, float size ) -{ - float x = x1; - float maxy = y2; - float maxx; - if( x2 ) - maxx = x2 - cls.creditsFont.charWidths['M'] / 1024.0f * size; - else - maxx = 1; - - if( !cls.creditsFont.valid ) - return GRID_X * 2; - Con_UtfProcessChar( 0 ); - - GL_SetRenderMode( kRenderTransAdd ); - - // text is additive and alpha does not work - pglColor4ub( color[0] * ( (float)color[3] /255.0f ), color[1] * ( (float)color[3] /255.0f ), - color[2] * ( (float)color[3] /255.0f ), 255 ); - - while( *s ) - { - while( *s && ( *s != '\n' ) && ( *s != ';' ) && ( x1 < maxx ) ) - x1 += Touch_DrawCharacter( x1, y1, *s++, size ); - y1 += cls.creditsFont.charHeight / 1024.f * size / SCR_H * SCR_W; - - if( y1 >= maxy ) - break; - - if( *s == '\n' || *s == ';' ) - s++; - x1 = x; - } - GL_SetRenderMode( kRenderTransTexture ); - return x1; -} - -void Touch_DrawButtons( touchbuttonlist_t *list ) -{ - touchbutton2_t *button; - - for( button = list->first; button; button = button->next ) - { - if( IN_TouchIsVisible( button ) ) - { - rgba_t color; - MakeRGBA( color, B( color[0] ), B( color[1] ), B( color[2] ), B( color[3] ) ); - - if( B( fadespeed ) ) - { - button->fade += B( fadespeed ) * host.frametime; - button->fade = bound( 0, B(fade), 1 ); - if( ( B( fade ) == 0 ) || ( B(fade) == 1 ) ) - B( fadespeed ) = 0; - if( ( ( B( fade ) >= B( fadeend ) ) && ( B( fadespeed ) > 0 ) ) || - ( ( B( fade ) <= B( fadeend ) ) && ( B( fadespeed ) < 0 ) ) ) - B( fadespeed ) = 0, B( fade ) = B( fadeend ) ; - } - - if( ( B( finger ) != -1 ) && !( B( flags ) & TOUCH_FL_CLIENT ) ) - { - color[0] = bound( 0,(float) color[0] * touch_highlight_r->value, 255 ); - color[1] = bound( 0,(float) color[1] * touch_highlight_g->value, 255 ); - color[2] = bound( 0,(float) color[2] * touch_highlight_b->value, 255 ); - color[3] = bound( 0,(float) color[3] * touch_highlight_a->value, 255 ); - } - - color[3] *= B( fade ); - if( button->texturefile[0] == '#' ) - Touch_DrawText( touch.swidth/SCR_W + B(x1), touch.swidth/SCR_H + B(y1), B(x2), B(y2), button->texturefile + 1, color, B( aspect )?B(aspect):1 ); - else if( button->texturefile[0] ) - { - if( button->texture == -1 ) - { - button->texture = GL_LoadTexture( button->texturefile, NULL, 0, TF_NOMIPMAP ); - } - - if( B(flags) & TOUCH_FL_DRAW_ADDITIVE ) - GL_SetRenderMode( kRenderTransAdd ); - - Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), B(texture), color[0], color[1], color[2], color[3] ); - - GL_SetRenderMode( kRenderTransTexture ); - } - if( B(flags) & TOUCH_FL_STROKE ) - { - pglColor4ub( touch.scolor[0], touch.scolor[1], touch.scolor[2], touch.scolor[3] * B( fade ) ); - R_DrawStretchPic( TO_SCRN_X(B(x1)), - TO_SCRN_Y(B(y1)), - touch.swidth, - TO_SCRN_Y(B(y2)-B(y1)) - touch.swidth, - 0, 0, 1, 1, tr.whiteTexture ); - R_DrawStretchPic( TO_SCRN_X(B(x1)) + touch.swidth, - TO_SCRN_Y(B(y1)), - TO_SCRN_X(B(x2)-B(x1)) - touch.swidth, - touch.swidth, - 0, 0, 1, 1, tr.whiteTexture ); - R_DrawStretchPic( TO_SCRN_X(B(x2))-touch.swidth, - TO_SCRN_Y(B(y1)) + touch.swidth, - touch.swidth, - TO_SCRN_Y(B(y2)-B(y1)) - touch.swidth, - 0, 0, 1, 1, tr.whiteTexture ); - R_DrawStretchPic( TO_SCRN_X(B(x1)), - TO_SCRN_Y(B(y2))-touch.swidth, - TO_SCRN_X(B(x2)-B(x1)) - touch.swidth, - touch.swidth, - 0, 0, 1, 1, tr.whiteTexture ); - pglColor4ub( 255, 255, 255, 255 ); - } - } - if( touch.state >= state_edit ) - { - rgba_t color; - if( !( button->flags & TOUCH_FL_HIDE ) ) - Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), tr.whiteTexture, 255, 255, 0, 32 ); - else - Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), tr.whiteTexture, 128, 128, 128, 128 ); - MakeRGBA( color, 255, 255,127, 255 ); - Con_DrawString( TO_SCRN_X( B(x1) ), TO_SCRN_Y( B(y1) ), B(name), color ); - } - } - -} - -void IN_TouchDraw( void ) -{ - touchbutton2_t *button; - - if( !touch.initialized || (!touch_enable->value && !touch.clientonly) ) - return; - - if( cls.key_dest != key_game && touch_in_menu->value == 0.0f ) - return; - - GL_SetRenderMode( kRenderTransTexture ); - - if( touch.state >= state_edit && touch_grid_enable->value ) - { - float x; - if( touch_in_menu->value ) - Touch_DrawTexture( 0, 0, 1, 1, tr.whiteTexture, 32, 32, 32, 255 ); - else - Touch_DrawTexture( 0, 0, 1, 1, tr.whiteTexture, 0, 0, 0, 112 ); - pglColor4ub( 0, 224, 224, 112 ); - for ( x = 0; x < 1 ; x += GRID_X ) - R_DrawStretchPic( TO_SCRN_X(x), - 0, - 1, - TO_SCRN_Y(1), - 0, 0, 1, 1, tr.whiteTexture ); - for ( x = 0; x < 1 ; x += GRID_Y ) - R_DrawStretchPic( 0, - TO_SCRN_Y(x), - TO_SCRN_X(1), - 1, - 0, 0, 1, 1, tr.whiteTexture ); - } - - Touch_DrawButtons( &touch.list_user ); - - if( touch.state >= state_edit ) - { - rgba_t color; - MakeRGBA( color, 255, 255, 255, 255 ); - if( touch.edit ) - { - float x1 = touch.edit->x1, - y1 = touch.edit->y1, - x2 = touch.edit->x2, - y2 = touch.edit->y2; - IN_TouchCheckCoords( &x1, &y1, &x2, &y2 ); - Touch_DrawTexture( x1, y1, x2, y2, tr.whiteTexture, 0, 255, 0, 32 ); - } - Touch_DrawTexture( 0, 0, GRID_X, GRID_Y, tr.whiteTexture, 255, 255, 255, 64 ); - if( touch.selection ) - { - button = touch.selection; - Touch_DrawTexture( B(x1), B(y1), B(x2), B(y2), tr.whiteTexture, 255, 0, 0, 64 ); - if( touch.showbuttons ) - { - if( button->flags & TOUCH_FL_HIDE ) - { - Touch_DrawTexture( 0, GRID_Y * 8, GRID_X * 2, GRID_Y * 10, touch.showtexture, 255, 255, 255, 255 ); - Touch_DrawText( GRID_X * 2.5, GRID_Y * 8.5, 0, 0, "Show", color, 1.5 ); - } - else - { - Touch_DrawTexture( 0, GRID_Y * 8, GRID_X * 2, GRID_Y * 10, touch.hidetexture, 255, 255, 255, 255 ); - Touch_DrawText( GRID_X * 2.5, GRID_Y * 8.5, 0, 0, "Hide", color, 1.5 ); - } - } - Con_DrawString( 0, TO_SCRN_Y(GRID_Y * 11), "Selection:", color ); - Con_DrawString( Con_DrawString( 0, TO_SCRN_Y(GRID_Y*12), "Name: ", color ), - TO_SCRN_Y(GRID_Y*12), B(name), color ); - Con_DrawString( Con_DrawString( 0, TO_SCRN_Y(GRID_Y*13), "Texture: ", color ), - TO_SCRN_Y(GRID_Y*13), B(texturefile), color ); - Con_DrawString( Con_DrawString( 0, TO_SCRN_Y(GRID_Y*14), "Command: ", color ), - TO_SCRN_Y(GRID_Y*14), B(command), color ); - } - if( touch.showbuttons ) - { - // close - Touch_DrawTexture( 0, GRID_Y * 2, GRID_X * 2, GRID_Y * 4, touch.closetexture, 255, 255, 255, 255 ); - //Con_DrawString( TO_SCRN_X( GRID_X * 2.5 ), TO_SCRN_Y( GRID_Y * 2.5 ), "Close", color ); - Touch_DrawText( GRID_X * 2.5, GRID_Y * 2.5, 0, 0, "Close", color, 1.5 ); - // reset - Touch_DrawTexture( 0, GRID_Y * 5, GRID_X * 2, GRID_Y * 7, touch.resettexture, 255, 255, 255, 255 ); - //Con_DrawString( TO_SCRN_X( GRID_X * 2.5 ), TO_SCRN_Y( GRID_Y * 5.5 ), "Reset", color ); - Touch_DrawText( GRID_X * 2.5, GRID_Y * 5.5, 0, 0, "Reset", color, 1.5 ); - } - } - pglColor4ub( 255, 255, 255, 255 ); - if( ( touch.move_finger != -1 ) && touch.move && touch_move_indicator->value ) - { - float width; - float height; - if( FBitSet( touch_joy_texture->flags, FCVAR_CHANGED ) ) - { - ClearBits( touch_joy_texture->flags, FCVAR_CHANGED ); - touch.joytexture = GL_LoadTexture( touch_joy_texture->string, NULL, 0, TF_NOMIPMAP ); - } - if( touch.move->type == touch_move ) - { - width = touch_sidezone->value; - height = touch_forwardzone->value; - } - else - { - width = (touch.move->x2 - touch.move->x1)/2; - height = (touch.move->y2 - touch.move->y1)/2; - } - pglColor4ub( 255, 255, 255, 128 ); - R_DrawStretchPic( TO_SCRN_X( touch.move_start_x - GRID_X * touch_move_indicator->value ), - TO_SCRN_Y( touch.move_start_y - GRID_Y * touch_move_indicator->value ), - TO_SCRN_X( GRID_X * 2 * touch_move_indicator->value ), TO_SCRN_Y( GRID_Y * 2 * touch_move_indicator->value ), 0, 0, 1, 1, touch.joytexture ); - pglColor4ub( 255, 255, 255, 255 ); - R_DrawStretchPic( TO_SCRN_X( touch.move_start_x + touch.side * width - GRID_X * touch_move_indicator->value ), - TO_SCRN_Y( touch.move_start_y - touch.forward * height - GRID_Y * touch_move_indicator->value ), - TO_SCRN_X( GRID_X * 2 * touch_move_indicator->value ), TO_SCRN_Y( GRID_Y * 2 * touch_move_indicator->value ), 0, 0, 1, 1, touch.joytexture ); - - } - -} - -// clear move and selection state -void IN_TouchEditClear( void ) -{ - // Allow keep move/look fingers when doing touch_removeall - //touch.move_finger = touch.look_finger = -1; - if( touch.state < state_edit ) - return; - touch.state = state_edit; - if( touch.edit ) - touch.edit->finger = -1; - touch.resize_finger = -1; - touch.edit = NULL; - touch.selection = NULL; -} - -static void Touch_EditMove( touchEventType type, int fingerID, float x, float y, float dx, float dy ) -{ - if( touch.edit->finger == fingerID ) - { - if( type == event_up ) // shutdown button move - { - touchbutton2_t *button = touch.edit; - IN_TouchCheckCoords( &B(x1), &B(y1), &B(x2), &B(y2) ); - IN_TouchEditClear(); - if( button->type == touch_command ) - touch.selection = button; - } - if( type == event_motion ) // shutdown button move - { - touch.edit->y1 += dy; - touch.edit->y2 += dy; - touch.edit->x1 += dx; - touch.edit->x2 += dx; - } - } - else - { - if( type == event_down ) // enable resizing - { - if( touch.resize_finger == -1 ) - { - touch.resize_finger = fingerID; - } - } - if( type == event_up ) // disable resizing - { - if( touch.resize_finger == fingerID ) - { - touch.resize_finger = -1; - } - } - if( type == event_motion ) // perform resizing - { - if( touch.resize_finger == fingerID ) - { - touch.edit->y2 += dy; - touch.edit->x2 += dx; - } - } - } -} - -static void Touch_Motion( touchEventType type, int fingerID, float x, float y, float dx, float dy ) -{ - // walk - if( fingerID == touch.move_finger ) - { - // check bounds - if( touch_forwardzone->value <= 0 ) - Cvar_SetValue( "touch_forwardzone", 0.5 ); - if( touch_sidezone->value <= 0 ) - Cvar_SetValue( "touch_sidezone", 0.3 ); - - if( !touch.move || touch.move->type == touch_move ) - { - // move relative to touch start - touch.forward = ( touch.move_start_y - y ) / touch_forwardzone->value; - touch.side = ( x - touch.move_start_x ) / touch_sidezone->value; - } - else if( touch.move->type == touch_joy ) - { - // move relative to joy center - touch.forward = ( ( touch.move->y2 + touch.move->y1 ) - y * 2 ) / ( touch.move->y2 - touch.move->y1 ) * touch_joy_radius->value; - touch.side = ( x * 2 - ( touch.move->x2 + touch.move->x1 ) ) / ( touch.move->x2 - touch.move->x1 ) * touch_joy_radius->value; - } - else if( touch.move->type == touch_dpad ) - { - // like joy, but without acceleration. useful for bhop - touch.forward = round( ( (touch.move->y2 + touch.move->y1) - y * 2 ) / ( touch.move->y2 - touch.move->y1 ) * touch_dpad_radius->value ); - touch.side = round( ( x * 2 - (touch.move->x2 + touch.move->x1) ) / ( touch.move->x2 - touch.move->x1 ) * touch_dpad_radius->value ); - } - - touch.forward = bound( -1, touch.forward, 1 ); - touch.side = bound( -1, touch.side, 1 ); - } - - // process look - if( fingerID == touch.look_finger ) - { - if( touch.precision ) - dx *= touch_precise_amount->value, dy *= touch_precise_amount->value; - - if( touch_nonlinear_look->value ); - { - // save angle, modify only velocity - float dabs = sqrt( dx*dx+dy*dy ); - float dcos = dx/dabs; - float dsin = dy/dabs; - - if( touch_exp_mult->value > 1 ) - dabs = (exp(dabs*touch_exp_mult->value)-1)/touch_exp_mult->value; - if( touch_pow_mult->value > 1 && touch_pow_factor->value > 1 ) - dabs = pow(dabs*touch_pow_mult->value,touch_pow_factor->value)/touch_pow_mult->value; - - dx = dabs * dcos; - dy = dabs * dsin; - } - - // accumulate - touch.yaw -= dx * touch_yaw->value, touch.pitch += dy * touch_pitch->value; - } -} - - -static qboolean Touch_ButtonPress( touchbuttonlist_t *list, touchEventType type, int fingerID, float x, float y, float dx, float dy ) -{ - touchbutton2_t *button; - - // run from end(front) to start(back) - for( button = list->last; button; button = button->prev ) - { - if( type == event_down ) - { - if( ( x > button->x1 && - x < button->x2 ) && - ( y < button->y2 && - y > button->y1 ) ) - { - button->finger = fingerID; - - if( !IN_TouchIsVisible( button ) ) - continue; - - if( button->type == touch_command ) - { - char command[256]; - Q_snprintf( command, sizeof( command ), "%s\n", button->command ); - Cbuf_AddText( command ); - - if( B(flags) & TOUCH_FL_PRECISION ) - touch.precision = true; - } - if( button->type == touch_move || button->type == touch_joy || button->type == touch_dpad ) - { - if( touch.move_finger !=-1 ) - { - button->finger = touch.move_finger; - continue; - } - if( touch.look_finger == fingerID ) - { - touchbutton2_t *newbutton; - touch.move_finger = touch.look_finger = -1; - //touch.move_finger = button->finger = -1; - for( newbutton = list->first; newbutton; newbutton = newbutton->next ) - if( ( newbutton->type == touch_move ) || ( newbutton->type == touch_look ) ) newbutton->finger = -1; - Con_Reportf( "Touch: touch_move on look finger %d!\n", fingerID ); - continue; - } - touch.move_finger = fingerID; - touch.move = button; - if( touch.move->type == touch_move ) - { - touch.move_start_x = x; - touch.move_start_y = y; - } - else if( touch.move->type == touch_joy ) - { - touch.move_start_y = (touch.move->y2 + touch.move->y1) / 2; - touch.move_start_x = (touch.move->x2 + touch.move->x1) / 2; - touch.forward = ((touch.move->y2 + touch.move->y1) - y * 2) / (touch.move->y2 - touch.move->y1); - touch.side = (x * 2 - (touch.move->x2 + touch.move->x1)) / (touch.move->x2 - touch.move->x1); - } - else if( touch.move->type == touch_dpad ) - { - touch.move_start_y = (touch.move->y2 + touch.move->y1) / 2; - touch.move_start_x = (touch.move->x2 + touch.move->x1) / 2; - touch.forward = round(((touch.move->y2 + touch.move->y1) - y * 2) / (touch.move->y2 - touch.move->y1)); - touch.side = round((x * 2 - (touch.move->x2 + touch.move->x1)) / (touch.move->x2 - touch.move->x1)); - } - } - if( button->type == touch_look ) - { - if( touch.look_finger !=-1 ) - { - button->finger = touch.look_finger; - continue; - } - if( touch.move_finger == fingerID ) - { - touchbutton2_t *newbutton; - // This is an error, try recover - touch.move_finger = touch.look_finger = -1; - for( newbutton = list->first; newbutton; newbutton = newbutton->next ) - if( ( newbutton->type == touch_move ) || ( newbutton->type == touch_look ) ) newbutton->finger = -1; - Con_Reportf( "Touch: touch_look on move finger %d!\n", fingerID ); - continue; - } - touch.look_finger = fingerID; - } - } - } - if( type == event_up ) - { - if( fingerID == button->finger ) - { - button->finger = -1; - if( !IN_TouchIsVisible( button ) ) - continue; - - if( ( button->type == touch_command ) && ( button->command[0] == '+' ) ) - { - char command[256]; - Q_snprintf( command, sizeof( command ), "%s\n", button->command ); - command[0] = '-'; - Cbuf_AddText( command ); - if( B(flags) & TOUCH_FL_PRECISION ) - touch.precision = false; - } - if( button->type == touch_move || button->type == touch_joy || button->type == touch_dpad ) - { - touch.move_finger = -1; - touch.forward = touch.side = 0; - touch.move = NULL; - } - if( button->type == touch_look ) - { - touch.look_finger = -1; - } - } - } - } - - return false; -} - -static qboolean Touch_ButtonEdit( touchEventType type, int fingerID, float x, float y, float dx, float dy ) -{ - touchbutton2_t *button; - - // edit buttons are on y1 - if( type == event_down ) - { - if( (x < GRID_X) && (y < GRID_Y) ) - { - touch.showbuttons ^= true; - return true; - } - if( touch.showbuttons && ( x < GRID_X * 2 ) ) - { - if( ( y > GRID_Y * 2 ) && ( y < GRID_Y * 4 ) ) // close button - { - IN_TouchDisableEdit_f(); - if( touch_in_menu->value ) - { - Cvar_Set( "touch_in_menu", "0" ); - } - else - IN_TouchWriteConfig(); - return true; - } - if( ( y > GRID_Y * 5 ) && ( y < GRID_Y * 7 ) ) // reset button - { - IN_TouchReloadConfig_f(); - return true; - } - if( ( y > GRID_Y * 8 ) && ( y < GRID_Y * 10 ) && touch.selection ) // hide button - { - touch.selection->flags ^= TOUCH_FL_HIDE; - return true; - } - } - } - - // run from end(front) to start(back) - for( button = touch.list_user.last; button; button = button->prev ) - { - if( type == event_down ) - { - if( ( x > button->x1 && - x < button->x2 ) && - ( y < button->y2 && - y > button->y1 ) ) - { - button->finger = fingerID; - - // do not edit NOEDIT buttons - if( button->flags & TOUCH_FL_NOEDIT ) - continue; - - touch.edit = button; - touch.selection = NULL; - // Make button last to bring it up - if( ( button->next ) && ( button->type == touch_command ) ) - { - if( button->prev ) - button->prev->next = button->next; - else - touch.list_user.first = button->next; - - button->next->prev = button->prev; - touch.list_user.last->next = button; - button->prev = touch.list_user.last; - button->next = NULL; - touch.list_user.last = button; - } - touch.state = state_edit_move; - return true; - } - } - if( type == event_up ) - if( fingerID == button->finger ) - button->finger = -1; - } - - if( type == event_down ) - touch.selection = NULL; - - return false; -} - -static int Touch_ControlsEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy ) -{ - touchbutton2_t *button; - - if( touch.state == state_edit_move ) - { - Touch_EditMove( type, fingerID, x, y, dx, dy ); - return 1; - } - - if( touch.state == state_edit && Touch_ButtonEdit( type, fingerID, x, y, dx, dy ) ) - return true; - if( Touch_ButtonPress( &touch.list_user, type, fingerID, x, y, dx, dy ) ) - return true; - if( type == event_motion ) - Touch_Motion( type, fingerID, x, y, dx, dy ); - return true; -} - -int IN_TouchEvent( touchEventType type, int fingerID, float x, float y, float dx, float dy ) -{ - - // simulate menu mouse click - if( cls.key_dest != key_game && !touch_in_menu->value ) - { - touch.move_finger = touch.resize_finger = touch.look_finger = -1; - // Hack for keyboard, hope it help - if( cls.key_dest == key_console || cls.key_dest == key_message ) - { - Key_EnableTextInput( true, true ); - if( cls.key_dest == key_console ) - { - static float y1 = 0; - y1 += dy; - if( dy > 0.4 ) - Con_Bottom(); - if( y1 > 0.01 ) - { - Con_PageUp( 1 ); - y1 = 0; - } - if( y1 < -0.01 ) - { - Con_PageDown( 1 ); - y1 = 0; - } - } - - // exit of console area - if( type == event_down && x < 0.1f && y > 0.9f ) - Cbuf_AddText( "escape\n" ); - } - UI_MouseMove( TO_SCRN_X(x), TO_SCRN_Y(y) ); - //Con_Reportf( "touch %d %d\n", TO_SCRN_X(x), TO_SCRN_Y(y) ); - if( type == event_down ) - Key_Event( K_MOUSE1, true ); - if( type == event_up ) - Key_Event( K_MOUSE1, false ); - return 0; - } - - - if( VGui_IsActive() ) - { - VGui_MouseMove( TO_SCRN_X(x), TO_SCRN_Y(y) ); - - if( type != event_motion ) - VGui_KeyEvent( K_MOUSE1, type == event_down ? 1 : 0 ); - - // allow scoreboard scroll - if( host.mouse_visible && type == event_motion ) - return 0; - } - - if( !touch.initialized || (!touch_enable->value && !touch.clientonly) ) - { -#if 0 - if( type == event_down ) - Key_Event( K_MOUSE1, true ); - if( type == event_up ) - Key_Event( K_MOUSE1, false ); - Android_AddMove( dx * (float)glState.width, dy * glState.height ); -#endif - return 0; - } - - if( clgame.dllFuncs.pfnTouchEvent && clgame.dllFuncs.pfnTouchEvent( type, fingerID, x, y, dx, dy ) ) - return true; - - return Touch_ControlsEvent( type, fingerID, x, y, dx, dy ); -} - -void IN_TouchMove( float *forward, float *side, float *yaw, float *pitch ) -{ - *forward += touch.forward; - *side += touch.side; - *yaw += touch.yaw; - *pitch += touch.pitch; - touch.yaw = touch.pitch = 0; -} - -void IN_TouchKeyEvent( int key, int down ) -{ - int xi, yi; - float x, y; - - if( touch_enable->value ) - return; - - if( !touch.clientonly ) - return; - - Platform_GetMousePos( &xi, &yi ); - - x = xi/SCR_W; - y = yi/SCR_H; - - Touch_ControlsEvent( !down, key == K_MOUSE1?0:1, x, y, 0, 0 ); -} - -void IN_TouchShutdown( void ) -{ - if( !touch.initialized ) - return; - IN_TouchRemoveAll_f(); - Cmd_RemoveCommand( "touch_addbutton" ); - Cmd_RemoveCommand( "touch_removebutton" ); - Cmd_RemoveCommand( "touch_enableedit" ); - Cmd_RemoveCommand( "touch_disableedit" ); - Cmd_RemoveCommand( "touch_settexture" ); - Cmd_RemoveCommand( "touch_setcolor" ); - Cmd_RemoveCommand( "touch_setcommand" ); - Cmd_RemoveCommand( "touch_setflags" ); - Cmd_RemoveCommand( "touch_show" ); - Cmd_RemoveCommand( "touch_hide" ); - Cmd_RemoveCommand( "touch_list" ); - Cmd_RemoveCommand( "touch_removeall" ); - Cmd_RemoveCommand( "touch_loaddefaults" ); - Cmd_RemoveCommand( "touch_roundall" ); - Cmd_RemoveCommand( "touch_exportconfig" ); - Cmd_RemoveCommand( "touch_set_stroke" ); - Cmd_RemoveCommand( "touch_setclientonly" ); - Cmd_RemoveCommand( "touch_reloadconfig" ); - Cmd_RemoveCommand( "touch_writeconfig" ); - Cmd_RemoveCommand( "touch_generate_code" ); - - touch.initialized = false; - Mem_FreePool( &touch.mempool ); -} -#endif diff --git a/engine/client/input.c b/engine/client/input.c index d8ced306..80880f0d 100644 --- a/engine/client/input.c +++ b/engine/client/input.c @@ -17,7 +17,6 @@ GNU General Public License for more details. #include "input.h" #include "client.h" #include "vgui_draw.h" -#include "gl_local.h" #ifdef XASH_SDL #include @@ -143,7 +142,7 @@ void IN_ToggleClientMouse( int newstate, int oldstate ) { // reset mouse pos, so cancel effect in game #ifdef XASH_SDL - if( touch_enable->value ) + if( 0 ) // touch_enable->value ) { SDL_SetRelativeMouseMode( SDL_FALSE ); SDL_SetWindowGrab( host.hWnd, SDL_FALSE ); @@ -518,7 +517,7 @@ void IN_CollectInput( float *forward, float *side, float *pitch, float *yaw, qbo } Joy_FinalizeMove( forward, side, yaw, pitch ); - IN_TouchMove( forward, side, yaw, pitch ); + // IN_TouchMove( forward, side, yaw, pitch ); if( look_filter->value ) { @@ -551,15 +550,15 @@ void IN_EngineAppendMove( float frametime, usercmd_t *cmd, qboolean active ) if( active ) { - float sensitivity = ( (float)RI.fov_x / (float)90.0f ); + float sensitivity = ( (float)refState.fov_x / (float)90.0f ); IN_CollectInput( &forward, &side, &pitch, &yaw, in_mouseinitialized, m_enginemouse->value ); IN_JoyAppendMove( cmd, forward, side ); - RI.viewangles[YAW] += yaw * sensitivity; - RI.viewangles[PITCH] += pitch * sensitivity; - RI.viewangles[PITCH] = bound( -90, RI.viewangles[PITCH], 90 ); + refState.viewangles[YAW] += yaw * sensitivity; + refState.viewangles[PITCH] += pitch * sensitivity; + refState.viewangles[PITCH] = bound( -90, refState.viewangles[PITCH], 90 ); } } diff --git a/engine/client/mod_dbghulls.c b/engine/client/mod_dbghulls.c index edf27a31..769b43b9 100644 --- a/engine/client/mod_dbghulls.c +++ b/engine/client/mod_dbghulls.c @@ -1,5 +1,5 @@ /* -mod_bmodel.c - loading & handling world and brushmodels +mod_dbghulls.c - loading & handling world and brushmodels Copyright (C) 2016 Uncle Mike This program is free software: you can redistribute it and/or modify @@ -16,7 +16,6 @@ GNU General Public License for more details. #include "mod_local.h" #include "mathlib.h" #include "world.h" -#include "gl_local.h" #include "client.h" #define MAX_CLIPNODE_DEPTH 256 // should never exceeds @@ -713,66 +712,3 @@ void Mod_ReleaseHullPolygons( void ) } world.num_hull_models = 0; } - -void R_DrawWorldHull( void ) -{ - hull_model_t *hull = &world.hull_models[0]; - winding_t *poly; - int i; - - if( FBitSet( r_showhull->flags, FCVAR_CHANGED )) - { - int val = bound( 0, (int)r_showhull->value, 3 ); - if( val ) Mod_CreatePolygonsForHull( val ); - ClearBits( r_showhull->flags, FCVAR_CHANGED ); - } - - if( !CVAR_TO_BOOL( r_showhull )) - return; - pglDisable( GL_TEXTURE_2D ); - - list_for_each_entry( poly, &hull->polys, chain ) - { - srand((unsigned int)poly); - pglColor3f( rand() % 256 / 255.0, rand() % 256 / 255.0, rand() % 256 / 255.0 ); - pglBegin( GL_POLYGON ); - for( i = 0; i < poly->numpoints; i++ ) - pglVertex3fv( poly->p[i] ); - pglEnd(); - } - pglEnable( GL_TEXTURE_2D ); -} - -void R_DrawModelHull( void ) -{ - hull_model_t *hull; - winding_t *poly; - int i; - - if( !CVAR_TO_BOOL( r_showhull )) - return; - - if( !RI.currentmodel || RI.currentmodel->name[0] != '*' ) - return; - - i = atoi( RI.currentmodel->name + 1 ); - if( i < 1 || i >= world.num_hull_models ) - return; - - hull = &world.hull_models[i]; - - pglPolygonOffset( 1.0f, 2.0 ); - pglEnable( GL_POLYGON_OFFSET_FILL ); - pglDisable( GL_TEXTURE_2D ); - list_for_each_entry( poly, &hull->polys, chain ) - { - srand((unsigned int)poly); - pglColor3f( rand() % 256 / 255.0, rand() % 256 / 255.0, rand() % 256 / 255.0 ); - pglBegin( GL_POLYGON ); - for( i = 0; i < poly->numpoints; i++ ) - pglVertex3fv( poly->p[i] ); - pglEnd(); - } - pglEnable( GL_TEXTURE_2D ); - pglDisable( GL_POLYGON_OFFSET_FILL ); -} diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c new file mode 100644 index 00000000..30dbf8e3 --- /dev/null +++ b/engine/client/ref_common.c @@ -0,0 +1,189 @@ +#include "common.h" +#include "client.h" +#include "library.h" +#include "cl_tent.h" + +struct ref_state_s ref; +ref_globals_t refState; + +convar_t *gl_vsync; +convar_t *gl_showtextures; +convar_t *vid_displayfrequency; +convar_t *vid_fullscreen; +convar_t *r_decals; +convar_t *r_adjust_fov; + +void R_GetTextureParms( int *w, int *h, int texnum ) +{ + if( w ) *w = RENDER_GET_PARM( PARM_TEX_WIDTH, texnum ); + if( h ) *h = RENDER_GET_PARM( PARM_TEX_HEIGHT, texnum ); +} + +void VID_InitDefaultResolution( void ) +{ + refState.width = 640; + refState.height = 480; +} + +/* +================ +GL_FreeImage + +Frees image by name +================ +*/ +void GL_FreeImage( const char *name ) +{ + int texnum; + + if(( texnum = RefRenderAPI->GL_FindTexture( name )) != 0 ) + RefRenderAPI->GL_FreeTexture( texnum ); +} + +static int TriGetRenderMode( void ) +{ + return clgame.ds.renderMode; +} + +static ref_api_t gEngfuncs = +{ + TriGetRenderMode +}; + +static void R_UnloadProgs( void ) +{ + if( !ref.hInstance ) return; + + // deinitialize renderer + ref.dllFuncs.R_Shutdown(); + + Cvar_FullSet( "host_refloaded", "0", FCVAR_READ_ONLY ); + + COM_FreeLibrary( ref.hInstance ); + ref.hInstance = NULL; + + memset( &refState, 0, sizeof( refState )); + + Cvar_Unlink( FCVAR_RENDERINFO | FCVAR_GLCONFIG ); + Cmd_Unlink( CMD_REFDLL ); +} + +static void CL_FillTriAPIFromRef( triangleapi_t *dst, const ref_interface_t *src ) +{ + dst->version = TRI_API_VERSION; + dst->Begin = src->Begin; + dst->RenderMode = TriRenderMode; + dst->End = src->End; + dst->Color4f = TriColor4f; + dst->Color4ub = TriColor4ub; + dst->TexCoord2f = src->TexCoord2f; + dst->Vertex3f = src->Vertex3f; + dst->Vertex3fv = src->Vertex3fv; + dst->Brightness = TriBrightness; + dst->CullFace = TriCullFace; + dst->SpriteTexture = TriSpriteTexture; + dst->WorldToScreen = TriWorldToScreen; + dst->Fog = src->Fog; + dst->ScreenToWorld = src->ScreenToWorld; + dst->GetMatrix = src->GetMatrix; + dst->BoxInPVS = TriBoxInPVS; + dst->LightAtPoint = TriLightAtPoint; + dst->Color4fRendermode = TriColor4fRendermode; + dst->FogParams = src->FogParams; +} + +static qboolean R_LoadProgs( const char *name ) +{ + extern triangleapi_t gTriApi; + static ref_api_t gpEngfuncs; + REFAPI GetRefAPI; // single export + + if( ref.hInstance ) R_UnloadProgs(); + +#ifdef XASH_INTERNAL_GAMELIBS + if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) )) + { + return false; + } +#else + if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) )) + { + FS_AllowDirectPaths( true ); + if( !(ref.hInstance = COM_LoadLibrary( name, false, true ) )) + { + FS_AllowDirectPaths( false ); + return false; + } + + } +#endif + + FS_AllowDirectPaths( false ); + + if( ( GetRefAPI = (REFAPI)COM_GetProcAddress( ref.hInstance, "GetRefAPI" )) == NULL ) + { + COM_FreeLibrary( ref.hInstance ); + Con_Reportf( "R_LoadProgs: can't init renderer API\n" ); + ref.hInstance = NULL; + return false; + } + + // make local copy of engfuncs to prevent overwrite it with user dll + memcpy( &gpEngfuncs, &gEngfuncs, sizeof( gpEngfuncs )); + + if( !GetRefAPI( REF_API_VERSION, &ref.dllFuncs, &gpEngfuncs, &refState )) + { + COM_FreeLibrary( ref.hInstance ); + Con_Reportf( "R_LoadProgs: can't init renderer API: wrong version\n" ); + ref.hInstance = NULL; + return false; + } + + refState.developer = host.allow_console; + + if( !ref.dllFuncs.R_Init( true ) ) + { + COM_FreeLibrary( ref.hInstance ); + Con_Reportf( "R_LoadProgs: can't init renderer: %s\n", ref.dllFuncs.R_GetInitError() ); + ref.hInstance = NULL; + return false; + } + + Cvar_FullSet( "host_refloaded", "1", FCVAR_READ_ONLY ); + ref.initialized = true; + + // initialize TriAPI callbacks + CL_FillTriAPIFromRef( &gTriApi, &ref.dllFuncs ); + + return true; +} + +void R_Shutdown( void ) +{ + R_UnloadProgs(); + ref.initialized = false; +} + +void R_Init( void ) +{ + char refdll[64]; + + if( !Sys_GetParmFromCmdLine( "-ref", refdll ) ) + { + Q_strncpy( refdll, DEFAULT_RENDERER, sizeof( refdll )); + } + + gl_vsync = Cvar_Get( "gl_vsync", "0", FCVAR_ARCHIVE, "enable vertical syncronization" ); + gl_showtextures = Cvar_Get( "gl_showtextures", "0", FCVAR_CHEAT, "show all uploaded textures" ); + vid_displayfrequency = Cvar_Get ( "vid_displayfrequency", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "fullscreen refresh rate" ); + vid_fullscreen = Cvar_Get( "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" ); + r_adjust_fov = Cvar_Get( "r_adjust_fov", "1", FCVAR_ARCHIVE, "making FOV adjustment for wide-screens" ); + r_decals = Cvar_Get( "r_decals", "4096", FCVAR_ARCHIVE, "sets the maximum number of decals" ); + + if( !R_LoadProgs( refdll )) + { + R_Shutdown(); + Host_Error( "Can't initialize %s renderer!\n", refdll ); + return; + } +} diff --git a/engine/client/ref_common.h b/engine/client/ref_common.h new file mode 100644 index 00000000..686af18d --- /dev/null +++ b/engine/client/ref_common.h @@ -0,0 +1,54 @@ +/* +ref_common.h - Xash3D render dll API +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. +*/ +#pragma once +#ifndef REF_COMMON_H +#define REF_COMMON_H + +#include "ref_api.h" + +#define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP) +#define TF_FONT (TF_NOMIPMAP|TF_CLAMP) +#define TF_IMAGE (TF_NOMIPMAP|TF_CLAMP) +#define TF_DECAL (TF_CLAMP) + +#define RP_LOCALCLIENT( e ) ((e) != NULL && (e)->index == ( cl.playernum + 1 ) && e->player ) + +struct ref_state_s +{ + qboolean initialized; + + HINSTANCE hInstance; + ref_interface_t dllFuncs; +}; + +extern struct ref_state_s ref; +extern ref_globals_t refState; + +// handy API wrappers +void R_GetTextureParms( int *w, int *h, int texnum ); +#define RefRenderAPI ref.dllFuncs.RenderAPI +#define RefRenderIface ref.dllFuncs.RenderIface +#define RENDER_GET_PARM( parm, arg ) RefRenderAPI->RenderGetParm( (parm), (arg) ) +#define GL_LoadTextureInternal( name, pic, flags ) ref.dllFuncs.GL_LoadTextureFromBuffer( name, pic, flags, false ) +#define GL_UpdateTextureInternal( name, pic, flags ) ref.dllFuncs.GL_LoadTextureFromBuffer( name, pic, flags, true ) + +// common engine and renderer cvars +extern convar_t *r_decals; +extern convar_t *r_adjust_fov; + +extern convar_t *vid_fullscreen; +extern convar_t *vid_displayfrequency; + +#endif // REF_COMMON_H diff --git a/engine/client/s_main.c b/engine/client/s_main.c index e8345344..32fd884c 100644 --- a/engine/client/s_main.c +++ b/engine/client/s_main.c @@ -17,7 +17,6 @@ GNU General Public License for more details. #include "sound.h" #include "client.h" #include "con_nprint.h" -#include "gl_local.h" #include "pm_local.h" #include "platform/platform.h" @@ -926,7 +925,7 @@ void S_StartSound( const vec3_t pos, int ent, int chan, sound_t handle, float fv // and we didn't find it (it's not playing), go ahead and start it up } - if( !pos ) pos = RI.vieworg; + if( !pos ) pos = refState.vieworg; if( chan == CHAN_STREAM ) SetBits( flags, SND_STOP_LOOPING ); diff --git a/engine/client/vgui/vgui_draw.c b/engine/client/vgui/vgui_draw.c index 0a2eae48..fff795bc 100644 --- a/engine/client/vgui/vgui_draw.c +++ b/engine/client/vgui/vgui_draw.c @@ -18,12 +18,11 @@ GNU General Public License for more details. #include #include "common.h" #include "client.h" -#include "gl_local.h" #include "vgui_draw.h" #include "vgui_api.h" #include "library.h" #include "keydefs.h" -#include "gl_local.h" +#include "ref_common.h" #ifdef XASH_SDL #include static SDL_Cursor* s_pDefaultCursor[20]; @@ -38,20 +37,6 @@ static enum VGUI_DefaultCursor s_currentCursor; static HINSTANCE s_pVGuiSupport; // vgui_support library static convar_t *vgui_utf8 = NULL; -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 ); - // Helper functions for vgui backend /*void VGUI_HideCursor( void ) @@ -78,8 +63,8 @@ qboolean GAME_EXPORT VGUI_IsInGame( void ) void GAME_EXPORT VGUI_GetMousePos( int *_x, int *_y ) { - float xscale = (float)glState.width / (float)clgame.scrInfo.iWidth; - float yscale = (float)glState.height / (float)clgame.scrInfo.iHeight; + float xscale = (float)refState.width / (float)clgame.scrInfo.iWidth; + float yscale = (float)refState.height / (float)clgame.scrInfo.iHeight; int x, y; Platform_GetMousePos( &x, &y ); @@ -176,19 +161,19 @@ int GAME_EXPORT VGUI_UtfProcessChar( int in ) vguiapi_t vgui = { false, // Not initialized yet - VGUI_DrawInit, - VGUI_DrawShutdown, - VGUI_SetupDrawingText, - VGUI_SetupDrawingRect, - VGUI_SetupDrawingImage, - VGUI_BindTexture, - VGUI_EnableTexture, - VGUI_CreateTexture, - VGUI_UploadTexture, - VGUI_UploadTextureBlock, - VGUI_DrawQuad, - VGUI_GetTextureSizes, - VGUI_GenerateTexture, + 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_ShowCursor, VGUI_HideCursor,*/ @@ -521,237 +506,12 @@ void VGui_KeyEvent( int key, int down ) void VGui_MouseMove( int x, int y ) { - float xscale = (float)glState.width / (float)clgame.scrInfo.iWidth; - float yscale = (float)glState.height / (float)clgame.scrInfo.iHeight; + float xscale = (float)refState.width / (float)clgame.scrInfo.iWidth; + float yscale = (float)refState.height / (float)clgame.scrInfo.iHeight; if( vgui.initialized ) vgui.MouseMove( x / xscale, y / yscale ); } -/* -================ -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 ) - Sys_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 ) - { - 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 ) - { - 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 ) - { - 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 ) -{ - float xscale = glState.width / (float)clgame.scrInfo.iWidth; - float yscale = glState.height / (float)clgame.scrInfo.iHeight; - - 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(); -} - void VGui_Paint() { if(vgui.initialized) diff --git a/engine/client/vid_common.c b/engine/client/vid_common.c index b7a6188d..ec3d63b3 100644 --- a/engine/client/vid_common.c +++ b/engine/client/vid_common.c @@ -15,7 +15,6 @@ GNU General Public License for more details. #include "common.h" #include "client.h" -#include "gl_local.h" #include "mod_local.h" #include "input.h" #include "vid_common.h" @@ -31,7 +30,6 @@ convar_t *gl_wgl_msaa_samples; convar_t *gl_lightmap_nearest; convar_t *gl_keeptjunctions; convar_t *gl_emboss_scale; -convar_t *gl_showtextures; convar_t *gl_detailscale; convar_t *gl_check_errors; convar_t *gl_polyoffset; @@ -76,9 +74,9 @@ convar_t *vid_highdpi; byte *r_temppool; -ref_globals_t tr; +gl_globals_t tr; glconfig_t glConfig; -glstate_t glState; +glstate_t glState; glwstate_t glw_state; /* @@ -445,7 +443,6 @@ void GL_InitCommands( void ) r_lighting_extended = Cvar_Get( "r_lighting_extended", "1", FCVAR_ARCHIVE, "allow to get lighting from world and bmodels" ); r_lighting_modulate = Cvar_Get( "r_lighting_modulate", "0.6", FCVAR_ARCHIVE, "lightstyles modulate scale" ); r_lighting_ambient = Cvar_Get( "r_lighting_ambient", "0.3", FCVAR_ARCHIVE, "map ambient lighting scale" ); - r_adjust_fov = Cvar_Get( "r_adjust_fov", "1", FCVAR_ARCHIVE, "making FOV adjustment for wide-screens" ); r_novis = Cvar_Get( "r_novis", "0", 0, "ignore vis information (perfomance test)" ); r_nocull = Cvar_Get( "r_nocull", "0", 0, "ignore frustrum culling (perfomance test)" ); r_detailtextures = Cvar_Get( "r_detailtextures", "1", FCVAR_ARCHIVE, "enable detail textures support, use '2' for autogenerate detail.txt" ); @@ -455,7 +452,7 @@ void GL_InitCommands( void ) r_traceglow = Cvar_Get( "r_traceglow", "1", FCVAR_ARCHIVE, "cull flares behind models" ); r_lightmap = Cvar_Get( "r_lightmap", "0", FCVAR_CHEAT, "lightmap debugging tool" ); r_drawentities = Cvar_Get( "r_drawentities", "1", FCVAR_CHEAT, "render entities" ); - r_decals = Cvar_Get( "r_decals", "4096", FCVAR_ARCHIVE, "sets the maximum number of decals" ); + r_decals = engine.Cvar_Find( "r_decals" ); window_xpos = Cvar_Get( "_window_xpos", "130", FCVAR_RENDERINFO, "window position by horizontal" ); window_ypos = Cvar_Get( "_window_ypos", "48", FCVAR_RENDERINFO, "window position by vertical" ); @@ -463,13 +460,13 @@ void GL_InitCommands( void ) gl_texture_nearest = Cvar_Get( "gl_texture_nearest", "0", FCVAR_ARCHIVE, "disable texture filter" ); gl_lightmap_nearest = Cvar_Get( "gl_lightmap_nearest", "0", FCVAR_ARCHIVE, "disable lightmap filter" ); gl_check_errors = Cvar_Get( "gl_check_errors", "1", FCVAR_ARCHIVE, "ignore video engine errors" ); - gl_vsync = Cvar_Get( "gl_vsync", "0", FCVAR_ARCHIVE, "enable vertical syncronization" ); + gl_vsync = engine.Cvar_Find( "gl_vsync" ); gl_detailscale = Cvar_Get( "gl_detailscale", "4.0", FCVAR_ARCHIVE, "default scale applies while auto-generate list of detail textures" ); gl_texture_anisotropy = Cvar_Get( "gl_anisotropy", "8", FCVAR_ARCHIVE, "textures anisotropic filter" ); gl_texture_lodbias = Cvar_Get( "gl_texture_lodbias", "0.0", FCVAR_ARCHIVE, "LOD bias for mipmapped textures (perfomance|quality)" ); gl_keeptjunctions = Cvar_Get( "gl_keeptjunctions", "1", FCVAR_ARCHIVE, "removing tjuncs causes blinking pixels" ); gl_emboss_scale = Cvar_Get( "gl_emboss_scale", "0", FCVAR_ARCHIVE|FCVAR_LATCH, "fake bumpmapping scale" ); - gl_showtextures = Cvar_Get( "r_showtextures", "0", FCVAR_CHEAT, "show all uploaded textures" ); + gl_showtextures = engine.Cvar_Find( "r_showtextures" ); gl_finish = Cvar_Get( "gl_finish", "0", FCVAR_ARCHIVE, "use glFinish instead of glFlush" ); gl_nosort = Cvar_Get( "gl_nosort", "0", FCVAR_ARCHIVE, "disable sorting of translucent surfaces" ); gl_clear = Cvar_Get( "gl_clear", "0", FCVAR_ARCHIVE, "clearing screen after each frame" ); @@ -487,8 +484,8 @@ void GL_InitCommands( void ) vid_gamma = Cvar_Get( "gamma", "2.5", FCVAR_ARCHIVE, "gamma amount" ); vid_brightness = Cvar_Get( "brightness", "0.0", FCVAR_ARCHIVE, "brightness factor" ); - vid_fullscreen = Cvar_Get( "fullscreen", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable fullscreen mode" ); - vid_displayfrequency = Cvar_Get ( "vid_displayfrequency", "0", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "fullscreen refresh rate" ); + vid_fullscreen = engine.Cvar_Find( "fullscreen" ); + vid_displayfrequency = engine.Cvar_Find ( "vid_displayfrequency" ); vid_highdpi = Cvar_Get( "vid_highdpi", "1", FCVAR_RENDERINFO|FCVAR_VIDRESTART, "enable High-DPI mode" ); Cmd_AddCommand( "r_info", R_RenderInfo_f, "display renderer info" ); diff --git a/engine/client/vid_common.h b/engine/client/vid_common.h index 3047f584..329776ea 100644 --- a/engine/client/vid_common.h +++ b/engine/client/vid_common.h @@ -5,33 +5,12 @@ #define FCONTEXT_CORE_PROFILE BIT( 0 ) #define FCONTEXT_DEBUG_ARB BIT( 1 ) -typedef struct vidmode_s -{ - const char *desc; - int width; - int height; -} vidmode_t; - -// minimal recommended resolution -#define VID_MIN_WIDTH 640 -#define VID_MIN_HEIGHT 480 - -// -// vid_common.c -// -qboolean VID_SetMode( void ); #define GL_CheckForErrors() GL_CheckForErrors_( __FILE__, __LINE__ ) void GL_CheckForErrors_( const char *filename, const int fileline ); const char *GL_ErrorString( int err ); void GL_UpdateSwapInterval( void ); qboolean GL_Support( int r_ext ); -void VID_CheckChanges( void ); int GL_MaxTextureUnits( void ); -qboolean R_Init( void ); -void R_Shutdown( void ); -const char *VID_GetModeString( int vid_mode ); -void R_SaveVideoMode( int w, int h ); -void VID_StartupGamma( void ); void GL_CheckExtension( const char *name, const dllfunc_t *funcs, const char *cvarname, int r_ext ); void GL_SetExtension( int r_ext, int enable ); diff --git a/engine/common/common.h b/engine/common/common.h index 6a728b1b..7778fc96 100644 --- a/engine/common/common.h +++ b/engine/common/common.h @@ -1029,9 +1029,8 @@ void SV_BroadcastCommand( const char *fmt, ... ) _format( 1 ); qboolean SV_RestoreCustomDecal( struct decallist_s *entry, edict_t *pEdict, qboolean adjacent ); void SV_BroadcastPrintf( sv_client_t *ignore, char *fmt, ... ) _format( 2 ); int R_CreateDecalList( struct decallist_s *pList ); -void R_DecalRemoveAll( int texture ); void R_ClearAllDecals( void ); -void R_ClearStaticEntities( void ); +void CL_ClearStaticEntities( void ); qboolean S_StreamGetCurrentState( char *currentTrack, char *loopTrack, int *position ); struct cl_entity_s *CL_GetEntityByIndex( int index ); struct player_info_s *CL_GetPlayerInfo( int playerIndex ); @@ -1058,7 +1057,6 @@ int SV_GetSaveComment( const char *savename, char *comment ); qboolean SV_NewGame( const char *mapName, qboolean loadGame ); void SV_ClipPMoveToEntity( struct physent_s *pe, const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, struct pmtrace_s *tr ); void CL_ClipPMoveToEntity( struct physent_s *pe, const vec3_t start, vec3_t mins, vec3_t maxs, const vec3_t end, struct pmtrace_s *tr ); -void CL_Particle( const vec3_t origin, int color, float life, int zpos, int zvel ); // debug thing void SV_SysError( const char *error_string ); void SV_ShutdownGame( void ); void SV_ExecLoadLevel( void ); @@ -1104,7 +1102,6 @@ qboolean LZSS_IsCompressed( const byte *source ); uint LZSS_GetActualSize( const byte *source ); byte *LZSS_Compress( byte *pInput, int inputLength, uint *pOutputSize ); uint LZSS_Decompress( const byte *pInput, byte *pOutput ); -const byte *GL_TextureData( unsigned int texnum ); void GL_FreeImage( const char *name ); void VID_InitDefaultResolution( void ); void UI_SetActiveMenu( qboolean fActive ); diff --git a/engine/common/crtlib.h b/engine/common/crtlib.h index c9ee170c..20f08fef 100644 --- a/engine/common/crtlib.h +++ b/engine/common/crtlib.h @@ -37,6 +37,7 @@ enum #define CMD_CLIENTDLL BIT( 1 ) // added by client.dll #define CMD_GAMEUIDLL BIT( 2 ) // added by GameUI.dll #define CMD_LOCALONLY BIT( 3 ) // restricted from server commands +#define CMD_REFDLL BIT( 4 ) // added by ref.dll typedef void (*xcommand_t)( void ); diff --git a/engine/common/custom.c b/engine/common/custom.c index a379b38b..7b8c2736 100644 --- a/engine/common/custom.c +++ b/engine/common/custom.c @@ -15,6 +15,7 @@ GNU General Public License for more details. #include "common.h" #include "custom.h" +#include "ref_common.h" qboolean CustomDecal_Validate( void *raw, int nFileSize ) { @@ -48,7 +49,7 @@ void COM_ClearCustomizationList( customization_t *pHead, qboolean bCleanDecals ) if( pCurrent->resource.type == t_decal ) { if( bCleanDecals && CL_Active( )) - R_DecalRemoveAll( pCurrent->nUserData1 ); + ref.dllFuncs.R_DecalRemoveAll( pCurrent->nUserData1 ); } #endif diff --git a/engine/common/gamma.c b/engine/common/gamma.c index e4ccabaa..a7b7d010 100644 --- a/engine/common/gamma.c +++ b/engine/common/gamma.c @@ -15,7 +15,6 @@ GNU General Public License for more details. #include "common.h" #include -#include "gl_local.h" //----------------------------------------------------------------------------- // Gamma conversion support @@ -85,4 +84,4 @@ byte LightToTexGamma( byte b ) byte TextureToGamma( byte b ) { return texgammatable[b]; -} \ No newline at end of file +} diff --git a/engine/common/imagelib/img_utils.c b/engine/common/imagelib/img_utils.c index 934dfb54..13e6bb7e 100644 --- a/engine/common/imagelib/img_utils.c +++ b/engine/common/imagelib/img_utils.c @@ -16,7 +16,6 @@ GNU General Public License for more details. #include "imagelib.h" #include "mathlib.h" #include "mod_local.h" -#include "gl_export.h" #define LERPBYTE( i ) r = resamplerow1[i]; out[i] = (byte)(((( resamplerow2[i] - r ) * lerp)>>16 ) + r ) #define FILTER_SIZE 5 @@ -1534,4 +1533,4 @@ qboolean Image_Process( rgbdata_t **pix, int width, int height, uint flags, floa image.force_flags = 0; return result; -} \ No newline at end of file +} diff --git a/engine/common/mathlib.c b/engine/common/mathlib.c index 62f98ad0..f8928a41 100644 --- a/engine/common/mathlib.c +++ b/engine/common/mathlib.c @@ -762,3 +762,50 @@ void QuaternionSlerp( const vec4_t p, const vec4_t q, float t, vec4_t qt ) QuaternionSlerpNoAlign( p, q2, t, qt ); } + +/* +==================== +V_CalcFov +==================== +*/ +float V_CalcFov( float *fov_x, float width, float height ) +{ + float x, half_fov_y; + + if( *fov_x < 1.0f || *fov_x > 179.0f ) + *fov_x = 90.0f; // default value + + x = width / tan( DEG2RAD( *fov_x ) * 0.5f ); + half_fov_y = atan( height / x ); + + return RAD2DEG( half_fov_y ) * 2; +} + +/* +==================== +V_AdjustFov +==================== +*/ +void V_AdjustFov( float *fov_x, float *fov_y, float width, float height, qboolean lock_x ) +{ + float x, y; + + if( width * 3 == 4 * height || width * 4 == height * 5 ) + { + // 4:3 or 5:4 ratio + return; + } + + if( lock_x ) + { + *fov_y = 2 * atan((width * 3) / (height * 4) * tan( *fov_y * M_PI / 360.0 * 0.5 )) * 360 / M_PI; + return; + } + + y = V_CalcFov( fov_x, 640, 480 ); + x = *fov_x; + + *fov_x = V_CalcFov( &y, height, width ); + if( *fov_x < x ) *fov_x = x; + else *fov_y = y; +} diff --git a/engine/common/mathlib.h b/engine/common/mathlib.h index f939dc10..c3a7dccf 100644 --- a/engine/common/mathlib.h +++ b/engine/common/mathlib.h @@ -193,6 +193,9 @@ void Matrix4x4_OriginFromMatrix( const matrix4x4 in, float *out ); void Matrix4x4_Transpose( matrix4x4 out, const matrix4x4 in1 ); qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 ); +float V_CalcFov( float *fov_x, float width, float height ); +void V_AdjustFov( float *fov_x, float *fov_y, float width, float height, qboolean lock_x ); + extern vec3_t vec3_origin; extern int boxpnt[6][4]; extern const matrix3x4 matrix3x4_identity; diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index dad9490c..3452b632 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -20,7 +20,6 @@ GNU General Public License for more details. #include "studio.h" #include "wadfile.h" #include "world.h" -#include "gl_local.h" #include "enginefeatures.h" #include "client.h" #include "server.h" // LUMP_ error codes @@ -1033,7 +1032,7 @@ static void Mod_CalcSurfaceExtents( msurface_t *surf ) info->lightextents[i] = surf->extents[i]; } -#ifndef XASH_DEDICATED +#if !defined XASH_DEDICATED && 0 // REFTODO: if( !FBitSet( tex->flags, TEX_SPECIAL ) && ( surf->extents[i] > 16384 ) && ( tr.block_size == BLOCK_SIZE_DEFAULT )) Con_Reportf( S_ERROR "Bad surface extents %i\n", surf->extents[i] ); #endif // XASH_DEDICATED @@ -1802,10 +1801,8 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) { #ifndef XASH_DEDICATED // release old sky layers first - GL_FreeTexture( tr.solidskyTexture ); - GL_FreeTexture( tr.alphaskyTexture ); - tr.solidskyTexture = 0; - tr.alphaskyTexture = 0; + ref.dllFuncs.R_FreeSharedTexture( REF_SOLIDSKY_TEXTURE ); + ref.dllFuncs.R_FreeSharedTexture( REF_SOLIDSKY_TEXTURE ); #endif } @@ -1830,7 +1827,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) Q_strncpy( tx->name, "*default", sizeof( tx->name )); #ifndef XASH_DEDICATED - tx->gl_texturenum = tr.defaultTexture; + tx->gl_texturenum = ref.dllFuncs.R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ); tx->width = tx->height = 16; #endif continue; // missed @@ -1850,7 +1847,6 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) tx->width = mt->width; tx->height = mt->height; - if( mt->offsets[0] > 0 ) { int size = (int)sizeof( mip_t ) + ((mt->width * mt->height * 85)>>6); @@ -1876,9 +1872,10 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) // check for multi-layered sky texture (quake1 specific) if( bmod->isworld && !Q_strncmp( mt->name, "sky", 3 ) && (( mt->width / mt->height ) == 2 )) { - R_InitSkyClouds( mt, tx, custom_palette ); // load quake sky + ref.dllFuncs.R_InitSkyClouds( mt, tx, custom_palette ); // load quake sky - if( tr.solidskyTexture && tr.alphaskyTexture ) + if( ref.dllFuncs.R_GetBuiltinTexture( REF_SOLIDSKY_TEXTURE ) && + ref.dllFuncs.R_GetBuiltinTexture( REF_ALPHASKY_TEXTURE ) ) SetBits( world.flags, FWORLD_SKYSPHERE ); continue; } @@ -1899,7 +1896,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) if( FS_FileExists( texpath, false )) { - tx->gl_texturenum = GL_LoadTexture( texpath, NULL, 0, TF_ALLOW_EMBOSS ); + tx->gl_texturenum = RefRenderAPI->GL_LoadTexture( texpath, NULL, 0, TF_ALLOW_EMBOSS ); bmod->wadlist.wadusage[j]++; // this wad are really used break; } @@ -1915,7 +1912,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) if( custom_palette ) size += sizeof( short ) + 768; Q_snprintf( texname, sizeof( texname ), "#%s:%s.mip", loadstat.name, mt->name ); - tx->gl_texturenum = GL_LoadTexture( texname, (byte *)mt, size, TF_ALLOW_EMBOSS ); + tx->gl_texturenum = RefRenderAPI->GL_LoadTexture( texname, (byte *)mt, size, TF_ALLOW_EMBOSS ); } // if texture is completely missed @@ -1923,11 +1920,11 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) { if( host.type != HOST_DEDICATED ) Con_DPrintf( S_ERROR "unable to find %s.mip\n", mt->name ); - tx->gl_texturenum = tr.defaultTexture; + tx->gl_texturenum = ref.dllFuncs.R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ); } // check for luma texture - if( FBitSet( R_GetTexture( tx->gl_texturenum )->flags, TF_HAS_LUMA )) + if( FBitSet( RENDER_GET_PARM( PARM_TEX_FLAGS, tx->gl_texturenum ), TF_HAS_LUMA )) { Q_snprintf( texname, sizeof( texname ), "#%s:%s_luma.mip", loadstat.name, mt->name ); @@ -1938,7 +1935,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) int size = (int)sizeof( mip_t ) + ((mt->width * mt->height * 85)>>6); if( custom_palette ) size += sizeof( short ) + 768; - tx->fb_texturenum = GL_LoadTexture( texname, (byte *)mt, size, TF_MAKELUMA ); + tx->fb_texturenum = RefRenderAPI->GL_LoadTexture( texname, (byte *)mt, size, TF_MAKELUMA ); } else { @@ -1963,7 +1960,7 @@ static void Mod_LoadTextures( dbspmodel_t *bmod ) } // okay, loading it from wad or hi-res version - tx->fb_texturenum = GL_LoadTexture( texname, src, srcSize, TF_MAKELUMA ); + tx->fb_texturenum = RefRenderAPI->GL_LoadTexture( texname, src, srcSize, TF_MAKELUMA ); if( src ) Mem_Free( src ); } } @@ -2246,7 +2243,7 @@ static void Mod_LoadSurfaces( dbspmodel_t *bmod ) #ifndef XASH_DEDICATED // TODO: Do we need subdivide on server? if( FBitSet( out->flags, SURF_DRAWTURB )) - GL_SubdivideSurface( out ); // cut up polygon for warps + ref.dllFuncs.GL_SubdivideSurface( out ); // cut up polygon for warps #endif } @@ -2822,11 +2819,11 @@ void Mod_UnloadBrushModel( model_t *mod ) for( i = 0; i < mod->numtextures; i++ ) { tx = mod->textures[i]; - if( !tx || tx->gl_texturenum == tr.defaultTexture ) + if( !tx || tx->gl_texturenum == ref.dllFuncs.R_GetBuiltinTexture( REF_DEFAULT_TEXTURE ) ) continue; // free slot - GL_FreeTexture( tx->gl_texturenum ); // main texture - GL_FreeTexture( tx->fb_texturenum ); // luma texture + RefRenderAPI->GL_FreeTexture( tx->gl_texturenum ); // main texture + RefRenderAPI->GL_FreeTexture( tx->fb_texturenum ); // luma texture } #endif Mem_FreePool( &mod->mempool ); diff --git a/engine/common/mod_local.h b/engine/common/mod_local.h index b83d9491..ed3f39de 100644 --- a/engine/common/mod_local.h +++ b/engine/common/mod_local.h @@ -222,8 +222,6 @@ void R_StudioCalcBoneQuaternion( int frame, float s, mstudiobone_t *pbone, mstud void R_StudioCalcBonePosition( int frame, float s, mstudiobone_t *pbone, mstudioanim_t *panim, vec3_t adj, vec3_t pos ); void *R_StudioGetAnim( studiohdr_t *m_pStudioHeader, model_t *m_pSubModel, mstudioseqdesc_t *pseqdesc ); void Mod_StudioComputeBounds( void *buffer, vec3_t mins, vec3_t maxs, qboolean ignore_sequences ); -void Mod_StudioLoadTextures( model_t *mod, void *data ); -void Mod_StudioUnloadTextures( void *data ); int Mod_HitgroupForStudioHull( int index ); void Mod_ClearStudioCache( void ); diff --git a/engine/common/mod_studio.c b/engine/common/mod_studio.c index fc6d1da9..283b829c 100644 --- a/engine/common/mod_studio.c +++ b/engine/common/mod_studio.c @@ -18,6 +18,7 @@ GNU General Public License for more details. #include "studio.h" #include "r_studioint.h" #include "library.h" +#include "ref_common.h" typedef int (*STUDIOAPI)( int, sv_blending_interface_t**, server_studio_api_t*, float (*transform)[3][4], float (*bones)[MAXSTUDIOBONES][3][4] ); @@ -1065,7 +1066,7 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ) } else { - Mod_StudioLoadTextures( mod, thdr ); + ref.dllFuncs.Mod_StudioLoadTextures( mod, thdr ); // give space for textures and skinrefs size1 = thdr->numtextures * sizeof( mstudiotexture_t ); @@ -1092,7 +1093,7 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded ) loadmodel->cache.data = Mem_Calloc( loadmodel->mempool, phdr->length ); memcpy( loadmodel->cache.data, buffer, phdr->length ); phdr = (studiohdr_t *)loadmodel->cache.data; // get the new pointer on studiohdr - Mod_StudioLoadTextures( mod, phdr ); + ref.dllFuncs.Mod_StudioLoadTextures( mod, phdr ); // NOTE: we wan't keep raw textures in memory. just cutoff model pointer above texture base loadmodel->cache.data = Mem_Realloc( loadmodel->mempool, loadmodel->cache.data, phdr->texturedataindex ); @@ -1148,7 +1149,7 @@ void Mod_UnloadStudioModel( model_t *mod ) return; // not a studio #ifndef XASH_DEDICATED - Mod_StudioUnloadTextures( mod->cache.data ); + ref.dllFuncs.Mod_StudioUnloadTextures( mod->cache.data ); #endif Mem_FreePool( &mod->mempool ); memset( mod, 0, sizeof( *mod )); diff --git a/engine/common/model.c b/engine/common/model.c index d80cb199..7e21cb60 100644 --- a/engine/common/model.c +++ b/engine/common/model.c @@ -20,7 +20,6 @@ GNU General Public License for more details. #include "studio.h" #include "wadfile.h" #include "world.h" -#include "gl_local.h" #include "enginefeatures.h" #include "client.h" #include "server.h" @@ -112,24 +111,9 @@ static void Mod_FreeModel( model_t *mod ) if( mod->name[0] != '*' ) Mod_FreeUserData( mod ); - // select the properly unloader - switch( mod->type ) - { - case mod_sprite: - Mod_UnloadSpriteModel( mod ); - break; -#ifndef XASH_DEDICATED - case mod_alias: - Mod_UnloadAliasModel( mod ); - break; -#endif - case mod_studio: - Mod_UnloadStudioModel( mod ); - break; - case mod_brush: - Mod_UnloadBrushModel( mod ); - break; - } + // notify renderer about unloading + if( ref.dllFuncs.Mod_UnloadModel ) + ref.dllFuncs.Mod_UnloadModel( mod ); memset( mod, 0, sizeof( *mod )); } @@ -303,21 +287,18 @@ model_t *Mod_LoadModel( model_t *mod, qboolean crash ) switch( *(uint *)buf ) { case IDSTUDIOHEADER: - Mod_LoadStudioModel( mod, buf, &loaded ); + ref.dllFuncs.Mod_LoadModel( mod_studio, mod, buf, &loaded, 0 ); break; case IDSPRITEHEADER: - Mod_LoadSpriteModel( mod, buf, &loaded, 0 ); + ref.dllFuncs.Mod_LoadModel( mod_sprite, mod, buf, &loaded, 0 ); break; - // TODO: Load alias models on dedicated too? -#ifndef XASH_DEDICATED case IDALIASHEADER: - Mod_LoadAliasModel( mod, buf, &loaded ); + ref.dllFuncs.Mod_LoadModel( mod_alias, mod, buf, &loaded, 0 ); break; -#endif case Q1BSP_VERSION: case HLBSP_VERSION: case QBSP2_VERSION: - Mod_LoadBrushModel( mod, buf, &loaded ); + ref.dllFuncs.Mod_LoadModel( mod_brush, mod, buf, &loaded, 0 ); break; default: Mem_Free( buf ); diff --git a/engine/common/pm_debug.c b/engine/common/pm_debug.c index 22f52db6..983bf145 100644 --- a/engine/common/pm_debug.c +++ b/engine/common/pm_debug.c @@ -16,6 +16,7 @@ GNU General Public License for more details. #include "common.h" #include "mathlib.h" #include "pm_local.h" +#include "ref_common.h" // expand debugging BBOX particle hulls by this many units. #define BOX_GAP 0.0f @@ -41,7 +42,7 @@ void PM_ParticleLine( const vec3_t start, const vec3_t end, int pcolor, float li while( curdist <= len ) { VectorMA( start, curdist, diff, pos ); - CL_Particle( pos, pcolor, life, 0, zvel ); + ref.dllFuncs.CL_Particle( pos, pcolor, life, 0, zvel ); curdist += 2.0f; } #endif // XASH_DEDICATED @@ -89,4 +90,4 @@ void PM_DrawBBox( const vec3_t mins, const vec3_t maxs, const vec3_t origin, int PM_DrawRectangle( p[boxpnt[i][1]], p[boxpnt[i][0]], p[boxpnt[i][2]], p[boxpnt[i][3]], pcolor, life ); } #endif // XASH_DEDICATED -} \ No newline at end of file +} diff --git a/engine/platform/sdl/events.c b/engine/platform/sdl/events.c index d7f1d70a..c4f07255 100644 --- a/engine/platform/sdl/events.c +++ b/engine/platform/sdl/events.c @@ -24,7 +24,6 @@ GNU General Public License for more details. #include "events.h" #include "sound.h" #include "vid_common.h" -#include "gl_local.h" static int wheelbutton; @@ -214,10 +213,10 @@ static void SDLash_EventFilter( SDL_Event *event ) #ifdef TOUCHEMU if( mdown ) IN_TouchEvent( event_motion, 0, - event->motion.x/(float)glState.width, - event->motion.y/(float)glState.height, - event->motion.xrel/(float)glState.width, - event->motion.yrel/(float)glState.height ); + event->motion.x/(float)refState.width, + event->motion.y/(float)refState.height, + event->motion.xrel/(float)refState.width, + event->motion.yrel/(float)refState.height ); SDL_ShowCursor( true ); #endif break; @@ -227,8 +226,8 @@ static void SDLash_EventFilter( SDL_Event *event ) #ifdef TOUCHEMU mdown = event->button.state != SDL_RELEASED; IN_TouchEvent( event_down, 0, - event->button.x/(float)glState.width, - event->button.y/(float)glState.height, 0, 0); + event->button.x/(float)refState.width, + event->button.y/(float)refState.height, 0, 0); #else SDLash_MouseEvent( event->button ); #endif @@ -289,13 +288,13 @@ static void SDLash_EventFilter( SDL_Event *event ) if( scale == 2 ) { - x /= (float)glState.width; - y /= (float)glState.height; - dx /= (float)glState.width; - dy /= (float)glState.height; + x /= (float)refState.width; + y /= (float)refState.height; + dx /= (float)refState.width; + dy /= (float)refState.height; } - IN_TouchEvent( type, event->tfinger.fingerId, x, y, dx, dy ); + // IN_TouchEvent( type, event->tfinger.fingerId, x, y, dx, dy ); break; } diff --git a/engine/platform/sdl/in_sdl.c b/engine/platform/sdl/in_sdl.c index 38363a7c..7d1de45b 100644 --- a/engine/platform/sdl/in_sdl.c +++ b/engine/platform/sdl/in_sdl.c @@ -23,7 +23,6 @@ GNU General Public License for more details. #include "events.h" #include "sound.h" #include "vid_common.h" -#include "gl_local.h" static SDL_Joystick *joy; static SDL_GameController *gamecontroller; diff --git a/engine/platform/sdl/vid_sdl.c b/engine/platform/sdl/vid_sdl.c index 80ba4e05..4d0b78d4 100644 --- a/engine/platform/sdl/vid_sdl.c +++ b/engine/platform/sdl/vid_sdl.c @@ -16,7 +16,6 @@ GNU General Public License for more details. #include #include "common.h" #include "client.h" -#include "gl_local.h" #include "mod_local.h" #include "input.h" #include "vid_common.h" @@ -25,191 +24,6 @@ GNU General Public License for more details. static vidmode_t *vidmodes = NULL; static int num_vidmodes = 0; static int context_flags = 0; -#define GL_CALL( x ) #x, (void**)&p##x -static dllfunc_t opengl_110funcs[] = -{ - { GL_CALL( glClearColor ) }, - { GL_CALL( glClear ) }, - { GL_CALL( glAlphaFunc ) }, - { GL_CALL( glBlendFunc ) }, - { GL_CALL( glCullFace ) }, - { GL_CALL( glDrawBuffer ) }, - { GL_CALL( glReadBuffer ) }, - { GL_CALL( glAccum ) }, - { GL_CALL( glEnable ) }, - { GL_CALL( glDisable ) }, - { GL_CALL( glEnableClientState ) }, - { GL_CALL( glDisableClientState ) }, - { GL_CALL( glGetBooleanv ) }, - { GL_CALL( glGetDoublev ) }, - { GL_CALL( glGetFloatv ) }, - { GL_CALL( glGetIntegerv ) }, - { GL_CALL( glGetError ) }, - { GL_CALL( glGetString ) }, - { GL_CALL( glFinish ) }, - { GL_CALL( glFlush ) }, - { GL_CALL( glClearDepth ) }, - { GL_CALL( glDepthFunc ) }, - { GL_CALL( glDepthMask ) }, - { GL_CALL( glDepthRange ) }, - { GL_CALL( glFrontFace ) }, - { GL_CALL( glDrawElements ) }, - { GL_CALL( glDrawArrays ) }, - { GL_CALL( glColorMask ) }, - { GL_CALL( glIndexPointer ) }, - { GL_CALL( glVertexPointer ) }, - { GL_CALL( glNormalPointer ) }, - { GL_CALL( glColorPointer ) }, - { GL_CALL( glTexCoordPointer ) }, - { GL_CALL( glArrayElement ) }, - { GL_CALL( glColor3f ) }, - { GL_CALL( glColor3fv ) }, - { GL_CALL( glColor4f ) }, - { GL_CALL( glColor4fv ) }, - { GL_CALL( glColor3ub ) }, - { GL_CALL( glColor4ub ) }, - { GL_CALL( glColor4ubv ) }, - { GL_CALL( glTexCoord1f ) }, - { GL_CALL( glTexCoord2f ) }, - { GL_CALL( glTexCoord3f ) }, - { GL_CALL( glTexCoord4f ) }, - { GL_CALL( glTexCoord1fv ) }, - { GL_CALL( glTexCoord2fv ) }, - { GL_CALL( glTexCoord3fv ) }, - { GL_CALL( glTexCoord4fv ) }, - { GL_CALL( glTexGenf ) }, - { GL_CALL( glTexGenfv ) }, - { GL_CALL( glTexGeni ) }, - { GL_CALL( glVertex2f ) }, - { GL_CALL( glVertex3f ) }, - { GL_CALL( glVertex3fv ) }, - { GL_CALL( glNormal3f ) }, - { GL_CALL( glNormal3fv ) }, - { GL_CALL( glBegin ) }, - { GL_CALL( glEnd ) }, - { GL_CALL( glLineWidth ) }, - { GL_CALL( glPointSize ) }, - { GL_CALL( glMatrixMode ) }, - { GL_CALL( glOrtho ) }, - { GL_CALL( glRasterPos2f ) }, - { GL_CALL( glFrustum ) }, - { GL_CALL( glViewport ) }, - { GL_CALL( glPushMatrix ) }, - { GL_CALL( glPopMatrix ) }, - { GL_CALL( glPushAttrib ) }, - { GL_CALL( glPopAttrib ) }, - { GL_CALL( glLoadIdentity ) }, - { GL_CALL( glLoadMatrixd ) }, - { GL_CALL( glLoadMatrixf ) }, - { GL_CALL( glMultMatrixd ) }, - { GL_CALL( glMultMatrixf ) }, - { GL_CALL( glRotated ) }, - { GL_CALL( glRotatef ) }, - { GL_CALL( glScaled ) }, - { GL_CALL( glScalef ) }, - { GL_CALL( glTranslated ) }, - { GL_CALL( glTranslatef ) }, - { GL_CALL( glReadPixels ) }, - { GL_CALL( glDrawPixels ) }, - { GL_CALL( glStencilFunc ) }, - { GL_CALL( glStencilMask ) }, - { GL_CALL( glStencilOp ) }, - { GL_CALL( glClearStencil ) }, - { GL_CALL( glIsEnabled ) }, - { GL_CALL( glIsList ) }, - { GL_CALL( glIsTexture ) }, - { GL_CALL( glTexEnvf ) }, - { GL_CALL( glTexEnvfv ) }, - { GL_CALL( glTexEnvi ) }, - { GL_CALL( glTexParameterf ) }, - { GL_CALL( glTexParameterfv ) }, - { GL_CALL( glTexParameteri ) }, - { GL_CALL( glHint ) }, - { GL_CALL( glPixelStoref ) }, - { GL_CALL( glPixelStorei ) }, - { GL_CALL( glGenTextures ) }, - { GL_CALL( glDeleteTextures ) }, - { GL_CALL( glBindTexture ) }, - { GL_CALL( glTexImage1D ) }, - { GL_CALL( glTexImage2D ) }, - { GL_CALL( glTexSubImage1D ) }, - { GL_CALL( glTexSubImage2D ) }, - { GL_CALL( glCopyTexImage1D ) }, - { GL_CALL( glCopyTexImage2D ) }, - { GL_CALL( glCopyTexSubImage1D ) }, - { GL_CALL( glCopyTexSubImage2D ) }, - { GL_CALL( glScissor ) }, - { GL_CALL( glGetTexImage ) }, - { GL_CALL( glGetTexEnviv ) }, - { GL_CALL( glPolygonOffset ) }, - { GL_CALL( glPolygonMode ) }, - { GL_CALL( glPolygonStipple ) }, - { GL_CALL( glClipPlane ) }, - { GL_CALL( glGetClipPlane ) }, - { GL_CALL( glShadeModel ) }, - { GL_CALL( glGetTexLevelParameteriv ) }, - { GL_CALL( glGetTexLevelParameterfv ) }, - { GL_CALL( glFogfv ) }, - { GL_CALL( glFogf ) }, - { GL_CALL( glFogi ) }, - { NULL , NULL } -}; - -static dllfunc_t debugoutputfuncs[] = -{ - { GL_CALL( glDebugMessageControlARB ) }, - { GL_CALL( glDebugMessageInsertARB ) }, - { GL_CALL( glDebugMessageCallbackARB ) }, - { GL_CALL( glGetDebugMessageLogARB ) }, - { NULL , NULL } -}; - -static dllfunc_t multitexturefuncs[] = -{ - { GL_CALL( glMultiTexCoord1f ) }, - { GL_CALL( glMultiTexCoord2f ) }, - { GL_CALL( glMultiTexCoord3f ) }, - { GL_CALL( glMultiTexCoord4f ) }, - { GL_CALL( glActiveTexture ) }, - { GL_CALL( glActiveTextureARB ) }, - { GL_CALL( glClientActiveTexture ) }, - { GL_CALL( glClientActiveTextureARB ) }, - { NULL , NULL } -}; - -static dllfunc_t texture3dextfuncs[] = -{ - { GL_CALL( glTexImage3D ) }, - { GL_CALL( glTexSubImage3D ) }, - { GL_CALL( glCopyTexSubImage3D ) }, - { NULL , NULL } -}; - -static dllfunc_t texturecompressionfuncs[] = -{ - { GL_CALL( glCompressedTexImage3DARB ) }, - { GL_CALL( glCompressedTexImage2DARB ) }, - { GL_CALL( glCompressedTexImage1DARB ) }, - { GL_CALL( glCompressedTexSubImage3DARB ) }, - { GL_CALL( glCompressedTexSubImage2DARB ) }, - { GL_CALL( glCompressedTexSubImage1DARB ) }, - { GL_CALL( glGetCompressedTexImage ) }, - { NULL , NULL } -}; - -static dllfunc_t vbofuncs[] = -{ - { GL_CALL( glBindBufferARB ) }, - { GL_CALL( glDeleteBuffersARB ) }, - { GL_CALL( glGenBuffersARB ) }, - { GL_CALL( glIsBufferARB ) }, - { GL_CALL( glMapBufferARB ) }, - { GL_CALL( glUnmapBufferARB ) }, // , - { GL_CALL( glBufferDataARB ) }, - { GL_CALL( glBufferSubDataARB ) }, - { NULL, NULL} -}; - static void GL_SetupAttributes( void ); int R_MaxVideoModes( void ) @@ -348,39 +162,6 @@ static void WIN_SetDPIAwareness( void ) } #endif -/* -======================== -DebugCallback - -For ARB_debug_output -======================== -*/ -static void APIENTRY GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLuint severity, GLint length, const GLcharARB *message, GLvoid *userParam ) -{ - switch( type ) - { - case GL_DEBUG_TYPE_ERROR_ARB: - Con_Printf( S_OPENGL_ERROR "%s\n", message ); - break; - case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: - Con_Printf( S_OPENGL_WARN "%s\n", message ); - break; - case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: - Con_Printf( S_OPENGL_WARN "%s\n", message ); - break; - case GL_DEBUG_TYPE_PORTABILITY_ARB: - if( host_developer.value < DEV_EXTENDED ) - return; - Con_Printf( S_OPENGL_WARN "%s\n", message ); - break; - case GL_DEBUG_TYPE_PERFORMANCE_ARB: - Con_Printf( S_OPENGL_NOTE "%s\n", message ); - break; - case GL_DEBUG_TYPE_OTHER_ARB: - default: Con_Printf( S_OPENGL_NOTE "%s\n", message ); - break; - } -} /* ================= @@ -897,251 +678,6 @@ qboolean R_Init_Video( void ) return true; } -#ifdef XASH_GLES -void GL_InitExtensionsGLES( void ) -{ - // intialize wrapper type -#ifdef XASH_NANOGL - glConfig.context = CONTEXT_TYPE_GLES_1_X; - glConfig.wrapper = GLES_WRAPPER_NANOGL; -#elif defined( XASH_WES ) - glConfig.context = CONTEXT_TYPE_GLES_2_X; - glConfig.wrapper = GLES_WRAPPER_WES; -#endif - - glConfig.hardware_type = GLHW_GENERIC; - - // initalize until base opengl functions loaded - GL_SetExtension( GL_DRAW_RANGEELEMENTS_EXT, true ); - GL_SetExtension( GL_ARB_MULTITEXTURE, true ); - pglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &glConfig.max_texture_units ); - glConfig.max_texture_coords = glConfig.max_texture_units = 4; - - GL_SetExtension( GL_ENV_COMBINE_EXT, true ); - GL_SetExtension( GL_DOT3_ARB_EXT, true ); - GL_SetExtension( GL_TEXTURE_3D_EXT, false ); - GL_SetExtension( GL_SGIS_MIPMAPS_EXT, true ); // gles specs - GL_SetExtension( GL_ARB_VERTEX_BUFFER_OBJECT_EXT, true ); // gles specs - - // hardware cubemaps - GL_CheckExtension( "GL_OES_texture_cube_map", NULL, "gl_texture_cubemap", GL_TEXTURECUBEMAP_EXT ); - - if( GL_Support( GL_TEXTURECUBEMAP_EXT )) - pglGetIntegerv( GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &glConfig.max_cubemap_size ); - - GL_SetExtension( GL_ARB_SEAMLESS_CUBEMAP, false ); - - GL_SetExtension( GL_EXT_POINTPARAMETERS, false ); - GL_CheckExtension( "GL_OES_texture_npot", NULL, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT ); - - GL_SetExtension( GL_TEXTURE_COMPRESSION_EXT, false ); - GL_SetExtension( GL_CUSTOM_VERTEX_ARRAY_EXT, false ); - GL_SetExtension( GL_CLAMPTOEDGE_EXT, true ); // by gles1 specs - GL_SetExtension( GL_ANISOTROPY_EXT, false ); - GL_SetExtension( GL_TEXTURE_LODBIAS, false ); - GL_SetExtension( GL_CLAMP_TEXBORDER_EXT, false ); - GL_SetExtension( GL_BLEND_MINMAX_EXT, false ); - GL_SetExtension( GL_BLEND_SUBTRACT_EXT, false ); - GL_SetExtension( GL_SEPARATESTENCIL_EXT, false ); - GL_SetExtension( GL_STENCILTWOSIDE_EXT, false ); - GL_SetExtension( GL_TEXTURE_ENV_ADD_EXT,false ); - GL_SetExtension( GL_SHADER_OBJECTS_EXT, false ); - GL_SetExtension( GL_SHADER_GLSL100_EXT, false ); - GL_SetExtension( GL_VERTEX_SHADER_EXT,false ); - GL_SetExtension( GL_FRAGMENT_SHADER_EXT, false ); - GL_SetExtension( GL_SHADOW_EXT, false ); - GL_SetExtension( GL_ARB_DEPTH_FLOAT_EXT, false ); - GL_SetExtension( GL_OCCLUSION_QUERIES_EXT,false ); - GL_CheckExtension( "GL_OES_depth_texture", NULL, "gl_depthtexture", GL_DEPTH_TEXTURE ); - - glConfig.texRectangle = glConfig.max_2d_rectangle_size = 0; // no rectangle - - Cvar_FullSet( "gl_allow_mirrors", "0", CVAR_READ_ONLY); // No support for GLES - -} -#else -void GL_InitExtensionsBigGL() -{ - // intialize wrapper type - glConfig.context = CONTEXT_TYPE_GL; - glConfig.wrapper = GLES_WRAPPER_NONE; - - if( Q_stristr( glConfig.renderer_string, "geforce" )) - glConfig.hardware_type = GLHW_NVIDIA; - else if( Q_stristr( glConfig.renderer_string, "quadro fx" )) - glConfig.hardware_type = GLHW_NVIDIA; - else if( Q_stristr(glConfig.renderer_string, "rv770" )) - glConfig.hardware_type = GLHW_RADEON; - else if( Q_stristr(glConfig.renderer_string, "radeon hd" )) - glConfig.hardware_type = GLHW_RADEON; - else if( Q_stristr( glConfig.renderer_string, "eah4850" ) || Q_stristr( glConfig.renderer_string, "eah4870" )) - glConfig.hardware_type = GLHW_RADEON; - else if( Q_stristr( glConfig.renderer_string, "radeon" )) - glConfig.hardware_type = GLHW_RADEON; - else if( Q_stristr( glConfig.renderer_string, "intel" )) - glConfig.hardware_type = GLHW_INTEL; - else glConfig.hardware_type = GLHW_GENERIC; - - // multitexture - glConfig.max_texture_units = glConfig.max_texture_coords = glConfig.max_teximage_units = 1; - GL_CheckExtension( "GL_ARB_multitexture", multitexturefuncs, "gl_arb_multitexture", GL_ARB_MULTITEXTURE ); - - if( GL_Support( GL_ARB_MULTITEXTURE )) - { - pglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &glConfig.max_texture_units ); - } - - if( glConfig.max_texture_units == 1 ) - GL_SetExtension( GL_ARB_MULTITEXTURE, false ); - - // 3d texture support - GL_CheckExtension( "GL_EXT_texture3D", texture3dextfuncs, "gl_texture_3d", GL_TEXTURE_3D_EXT ); - - if( GL_Support( GL_TEXTURE_3D_EXT )) - { - pglGetIntegerv( GL_MAX_3D_TEXTURE_SIZE, &glConfig.max_3d_texture_size ); - - if( glConfig.max_3d_texture_size < 32 ) - { - GL_SetExtension( GL_TEXTURE_3D_EXT, false ); - Con_Printf( S_ERROR "GL_EXT_texture3D reported bogus GL_MAX_3D_TEXTURE_SIZE, disabled\n" ); - } - } - - // 2d texture array support - GL_CheckExtension( "GL_EXT_texture_array", texture3dextfuncs, "gl_texture_2d_array", GL_TEXTURE_ARRAY_EXT ); - - if( GL_Support( GL_TEXTURE_ARRAY_EXT )) - pglGetIntegerv( GL_MAX_ARRAY_TEXTURE_LAYERS_EXT, &glConfig.max_2d_texture_layers ); - - // cubemaps support - GL_CheckExtension( "GL_ARB_texture_cube_map", NULL, "gl_texture_cubemap", GL_TEXTURE_CUBEMAP_EXT ); - - if( GL_Support( GL_TEXTURE_CUBEMAP_EXT )) - { - pglGetIntegerv( GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &glConfig.max_cubemap_size ); - - // check for seamless cubemaps too - GL_CheckExtension( "GL_ARB_seamless_cube_map", NULL, "gl_texture_cubemap_seamless", GL_ARB_SEAMLESS_CUBEMAP ); - } - - GL_CheckExtension( "GL_ARB_texture_non_power_of_two", NULL, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT ); - GL_CheckExtension( "GL_ARB_texture_compression", texturecompressionfuncs, "gl_dds_hardware_support", GL_TEXTURE_COMPRESSION_EXT ); - GL_CheckExtension( "GL_EXT_texture_edge_clamp", NULL, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT ); - if( !GL_Support( GL_CLAMPTOEDGE_EXT )) - GL_CheckExtension( "GL_SGIS_texture_edge_clamp", NULL, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT ); - - glConfig.max_texture_anisotropy = 0.0f; - GL_CheckExtension( "GL_EXT_texture_filter_anisotropic", NULL, "gl_ext_anisotropic_filter", GL_ANISOTROPY_EXT ); - if( GL_Support( GL_ANISOTROPY_EXT )) - pglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glConfig.max_texture_anisotropy ); - -#ifdef _WIN32 // Win32 only drivers? - // g-cont. because lodbias it too glitchy on Intel's cards - if( glConfig.hardware_type != GLHW_INTEL ) -#endif - GL_CheckExtension( "GL_EXT_texture_lod_bias", NULL, "gl_texture_mipmap_biasing", GL_TEXTURE_LOD_BIAS ); - - if( GL_Support( GL_TEXTURE_LOD_BIAS )) - pglGetFloatv( GL_MAX_TEXTURE_LOD_BIAS_EXT, &glConfig.max_texture_lod_bias ); - - GL_CheckExtension( "GL_ARB_texture_border_clamp", NULL, "gl_ext_texborder_clamp", GL_CLAMP_TEXBORDER_EXT ); - GL_CheckExtension( "GL_ARB_depth_texture", NULL, "gl_depthtexture", GL_DEPTH_TEXTURE ); - GL_CheckExtension( "GL_ARB_texture_float", NULL, "gl_arb_texture_float", GL_ARB_TEXTURE_FLOAT_EXT ); - GL_CheckExtension( "GL_ARB_depth_buffer_float", NULL, "gl_arb_depth_float", GL_ARB_DEPTH_FLOAT_EXT ); - GL_CheckExtension( "GL_EXT_gpu_shader4", NULL, NULL, GL_EXT_GPU_SHADER4 ); // don't confuse users - GL_CheckExtension( "GL_ARB_shading_language_100", NULL, "gl_glslprogram", GL_SHADER_GLSL100_EXT ); - GL_CheckExtension( "GL_ARB_vertex_buffer_object", vbofuncs, "gl_vertex_buffer_object", GL_ARB_VERTEX_BUFFER_OBJECT_EXT ); - - // rectangle textures support - GL_CheckExtension( "GL_ARB_texture_rectangle", NULL, "gl_texture_rectangle", GL_TEXTURE_2D_RECT_EXT ); - - // this won't work without extended context - if( glw_state.extended ) - GL_CheckExtension( "GL_ARB_debug_output", debugoutputfuncs, "gl_debug_output", GL_DEBUG_OUTPUT ); - - if( GL_Support( GL_SHADER_GLSL100_EXT )) - { - pglGetIntegerv( GL_MAX_TEXTURE_COORDS_ARB, &glConfig.max_texture_coords ); - pglGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &glConfig.max_teximage_units ); - - // check for hardware skinning - pglGetIntegerv( GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &glConfig.max_vertex_uniforms ); - pglGetIntegerv( GL_MAX_VERTEX_ATTRIBS_ARB, &glConfig.max_vertex_attribs ); - -#ifdef _WIN32 // Win32 only drivers? - if( glConfig.hardware_type == GLHW_RADEON && glConfig.max_vertex_uniforms > 512 ) - glConfig.max_vertex_uniforms /= 4; // radeon returns not correct info -#endif - } - else - { - // just get from multitexturing - glConfig.max_texture_coords = glConfig.max_teximage_units = glConfig.max_texture_units; - } - - pglGetIntegerv( GL_MAX_TEXTURE_SIZE, &glConfig.max_2d_texture_size ); - if( glConfig.max_2d_texture_size <= 0 ) glConfig.max_2d_texture_size = 256; - - if( GL_Support( GL_TEXTURE_2D_RECT_EXT )) - pglGetIntegerv( GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &glConfig.max_2d_rectangle_size ); - -#ifndef XASH_GL_STATIC - // enable gldebug if allowed - if( GL_Support( GL_DEBUG_OUTPUT )) - { - if( host_developer.value ) - { - Con_Reportf( "Installing GL_DebugOutput...\n"); - pglDebugMessageCallbackARB( GL_DebugOutput, NULL ); - - // force everything to happen in the main thread instead of in a separate driver thread - pglEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB ); - } - - // enable all the low priority messages - pglDebugMessageControlARB( GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW_ARB, 0, NULL, true ); - } -#endif -} -#endif - -void GL_InitExtensions( void ) -{ - // initialize gl extensions - GL_CheckExtension( "OpenGL 1.1.0", opengl_110funcs, NULL, GL_OPENGL_110 ); - - // get our various GL strings - glConfig.vendor_string = pglGetString( GL_VENDOR ); - glConfig.renderer_string = pglGetString( GL_RENDERER ); - glConfig.version_string = pglGetString( GL_VERSION ); - glConfig.extensions_string = pglGetString( GL_EXTENSIONS ); - Con_Reportf( "^3Video^7: %s\n", glConfig.renderer_string ); - -#ifdef XASH_GLES - GL_InitExtensionsGLES(); -#else - GL_InitExtensionsBigGL(); -#endif - - if( GL_Support( GL_TEXTURE_2D_RECT_EXT )) - pglGetIntegerv( GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &glConfig.max_2d_rectangle_size ); - - Cvar_Get( "gl_max_size", va( "%i", glConfig.max_2d_texture_size ), 0, "opengl texture max dims" ); - Cvar_Set( "gl_anisotropy", va( "%f", bound( 0, gl_texture_anisotropy->value, glConfig.max_texture_anisotropy ))); - - if( GL_Support( GL_TEXTURE_COMPRESSION_EXT )) - Image_AddCmdFlags( IL_DDS_HARDWARE ); - - // MCD has buffering issues -#ifdef _WIN32 - if( Q_strstr( glConfig.renderer_string, "gdi" )) - Cvar_SetValue( "gl_finish", 1 ); -#endif - - tr.framecount = tr.visframecount = 1; - glw_state.initialized = true; -} rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen ) { @@ -1271,9 +807,7 @@ void R_Free_Video( void ) R_FreeVideoModes(); - // now all extensions are disabled - memset( glConfig.extension, 0, sizeof( glConfig.extension )); - glw_state.initialized = false; + ref.dllFuncs.GL_ClearExtensions(); } #endif // XASH_DEDICATED diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 3c9cac80..88e9666b 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -22,6 +22,7 @@ GNU General Public License for more details. #include "studio.h" #include "const.h" #include "render_api.h" // modelstate_t +#include "ref_common.h" // decals #define ENTVARS_COUNT ARRAYSIZE( gEntvarsDescription ) @@ -552,7 +553,7 @@ void SV_RestartStaticEnts( void ) int i; // remove all the static entities on the client - R_ClearStaticEntities(); + CL_ClearStaticEntities(); // resend them again for( i = 0; i < sv.num_static_entities; i++ ) @@ -616,10 +617,10 @@ void SV_RestartDecals( void ) // g-cont. add space for studiodecals if present host.decalList = (decallist_t *)Z_Calloc( sizeof( decallist_t ) * MAX_RENDER_DECALS * 2 ); - host.numdecals = R_CreateDecalList( host.decalList ); + host.numdecals = ref.dllFuncs.R_CreateDecalList( host.decalList ); // remove decals from map - R_ClearAllDecals(); + ref.dllFuncs.R_ClearAllDecals(); // write decals into reliable datagram msg = SV_GetReliableDatagram(); diff --git a/engine/server/sv_phys.c b/engine/server/sv_phys.c index efd74a2c..be97503d 100644 --- a/engine/server/sv_phys.c +++ b/engine/server/sv_phys.c @@ -18,7 +18,7 @@ GNU General Public License for more details. #include "const.h" #include "library.h" #include "triangleapi.h" -#include "gl_export.h" +#include "ref_common.h" typedef int (*PHYSICAPI)( int, server_physics_api_t*, physics_interface_t* ); #ifndef XASH_DEDICATED @@ -1884,17 +1884,19 @@ void SV_DrawDebugTriangles( void ) if( svgame.physFuncs.DrawDebugTriangles != NULL ) { +#if 0 // debug draws only pglDisable( GL_BLEND ); pglDepthMask( GL_FALSE ); pglDisable( GL_TEXTURE_2D ); - +#endif // draw wireframe overlay svgame.physFuncs.DrawDebugTriangles (); - +#if 0 pglEnable( GL_TEXTURE_2D ); pglDepthMask( GL_TRUE ); pglEnable( GL_BLEND ); +#endif } } @@ -2001,6 +2003,11 @@ const char* pfnGetModelName( int modelindex ) return sv.model_precache[modelindex]; } +static const byte *GL_TextureData( unsigned int texnum ) +{ + return ref.dllFuncs.GL_TextureData( texnum ); +} + static server_physics_api_t gPhysicsAPI = { SV_LinkEdict, diff --git a/engine/server/sv_save.c b/engine/server/sv_save.c index 25dc0d3c..f2a2fa79 100644 --- a/engine/server/sv_save.c +++ b/engine/server/sv_save.c @@ -19,6 +19,7 @@ GNU General Public License for more details. #include "const.h" #include "render_api.h" // decallist_t #include "sound.h" // S_GetDynamicSounds +#include "ref_common.h" // decals /* ============================================================================== @@ -1129,7 +1130,7 @@ static void SaveClientState( SAVERESTOREDATA *pSaveData, const char *level, int decalList = (decallist_t *)Z_Calloc( sizeof( decallist_t ) * MAX_RENDER_DECALS * 2 ); // initialize client header - header.decalCount = R_CreateDecalList( decalList ); + header.decalCount = ref.dllFuncs.R_CreateDecalList( decalList ); header.entityCount = sv.num_static_entities; if( !changelevel ) diff --git a/engine/client/gl_alias.c b/ref_gl/gl_alias.c similarity index 100% rename from engine/client/gl_alias.c rename to ref_gl/gl_alias.c diff --git a/engine/client/gl_backend.c b/ref_gl/gl_backend.c similarity index 96% rename from engine/client/gl_backend.c rename to ref_gl/gl_backend.c index 84c7a352..99963bb1 100644 --- a/engine/client/gl_backend.c +++ b/ref_gl/gl_backend.c @@ -839,3 +839,49 @@ void R_ShowTree( void ) Con_NPrintf( 0, "max recursion %d\n", tr.max_recursion ); } + +/* +================ +SCR_TimeRefresh_f + +timerefresh [noflip] +================ +*/ +void SCR_TimeRefresh_f( void ) +{ + int i; + double start, stop; + double time; + + if( cls.state != ca_active ) + return; + + start = Sys_DoubleTime(); + + // run without page flipping like GoldSrc + if( Cmd_Argc() == 1 ) + { + pglDrawBuffer( GL_FRONT ); + for( i = 0; i < 128; i++ ) + { + refState.viewangles[1] = i / 128.0 * 360.0f; + R_RenderScene(); + } + pglFinish(); + R_EndFrame(); + } + else + { + for( i = 0; i < 128; i++ ) + { + ref.dllFuncs.R_BeginFrame( true ); + refState.viewangles[1] = i / 128.0 * 360.0f; + ref.dllFuncs.R_RenderScene(); + ref.dllFuncs.R_EndFrame(); + } + } + + stop = Sys_DoubleTime (); + time = (stop - start); + Con_Printf( "%f seconds (%f fps)\n", time, 128 / time ); +} diff --git a/engine/client/gl_beams.c b/ref_gl/gl_beams.c similarity index 99% rename from engine/client/gl_beams.c rename to ref_gl/gl_beams.c index a8cd6614..ff2a1f14 100644 --- a/engine/client/gl_beams.c +++ b/ref_gl/gl_beams.c @@ -1398,7 +1398,7 @@ void CL_KillDeadBeams( cl_entity_t *pDeadEntity ) pbeam = cl_active_beams; // old list. pnewlist = NULL; // new list. - + while( pbeam ) { pnext = pbeam->next; @@ -1418,7 +1418,7 @@ void CL_KillDeadBeams( cl_entity_t *pDeadEntity ) if( pbeam->type != TE_BEAMFOLLOW ) { // remove beam - pbeam->die = cl.time - 0.1f; + pbeam->die = cl.time - 0.1f; // kill off particles pHead = pbeam->particles; @@ -1959,7 +1959,7 @@ void CL_ReadLineFile_f( void ) Con_Printf( S_ERROR "couldn't open %s\n", filename ); return; } - + Con_Printf( "Reading %s...\n", filename ); count = 0; @@ -2002,7 +2002,7 @@ void CL_ReadLineFile_f( void ) p2[2] = Q_atof( token ); count++; - + if( !R_BeamPoints( p1, p2, modelIndex, 0, 2, 0, 255, 0, 0, 0, 255.0f, 0.0f, 0.0f )) { if( !model || model->type != mod_sprite ) diff --git a/ref_gl/gl_context.c b/ref_gl/gl_context.c new file mode 100644 index 00000000..c38dc185 --- /dev/null +++ b/ref_gl/gl_context.c @@ -0,0 +1,491 @@ +/* +vid_sdl.c - SDL vid component +Copyright (C) 2018 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 "common.h" +#include "client.h" +#include "gl_local.h" +#include "gl_export.h" + +#define GL_CALL( x ) #x, (void**)&p##x +static dllfunc_t opengl_110funcs[] = +{ + { GL_CALL( glClearColor ) }, + { GL_CALL( glClear ) }, + { GL_CALL( glAlphaFunc ) }, + { GL_CALL( glBlendFunc ) }, + { GL_CALL( glCullFace ) }, + { GL_CALL( glDrawBuffer ) }, + { GL_CALL( glReadBuffer ) }, + { GL_CALL( glAccum ) }, + { GL_CALL( glEnable ) }, + { GL_CALL( glDisable ) }, + { GL_CALL( glEnableClientState ) }, + { GL_CALL( glDisableClientState ) }, + { GL_CALL( glGetBooleanv ) }, + { GL_CALL( glGetDoublev ) }, + { GL_CALL( glGetFloatv ) }, + { GL_CALL( glGetIntegerv ) }, + { GL_CALL( glGetError ) }, + { GL_CALL( glGetString ) }, + { GL_CALL( glFinish ) }, + { GL_CALL( glFlush ) }, + { GL_CALL( glClearDepth ) }, + { GL_CALL( glDepthFunc ) }, + { GL_CALL( glDepthMask ) }, + { GL_CALL( glDepthRange ) }, + { GL_CALL( glFrontFace ) }, + { GL_CALL( glDrawElements ) }, + { GL_CALL( glDrawArrays ) }, + { GL_CALL( glColorMask ) }, + { GL_CALL( glIndexPointer ) }, + { GL_CALL( glVertexPointer ) }, + { GL_CALL( glNormalPointer ) }, + { GL_CALL( glColorPointer ) }, + { GL_CALL( glTexCoordPointer ) }, + { GL_CALL( glArrayElement ) }, + { GL_CALL( glColor3f ) }, + { GL_CALL( glColor3fv ) }, + { GL_CALL( glColor4f ) }, + { GL_CALL( glColor4fv ) }, + { GL_CALL( glColor3ub ) }, + { GL_CALL( glColor4ub ) }, + { GL_CALL( glColor4ubv ) }, + { GL_CALL( glTexCoord1f ) }, + { GL_CALL( glTexCoord2f ) }, + { GL_CALL( glTexCoord3f ) }, + { GL_CALL( glTexCoord4f ) }, + { GL_CALL( glTexCoord1fv ) }, + { GL_CALL( glTexCoord2fv ) }, + { GL_CALL( glTexCoord3fv ) }, + { GL_CALL( glTexCoord4fv ) }, + { GL_CALL( glTexGenf ) }, + { GL_CALL( glTexGenfv ) }, + { GL_CALL( glTexGeni ) }, + { GL_CALL( glVertex2f ) }, + { GL_CALL( glVertex3f ) }, + { GL_CALL( glVertex3fv ) }, + { GL_CALL( glNormal3f ) }, + { GL_CALL( glNormal3fv ) }, + { GL_CALL( glBegin ) }, + { GL_CALL( glEnd ) }, + { GL_CALL( glLineWidth ) }, + { GL_CALL( glPointSize ) }, + { GL_CALL( glMatrixMode ) }, + { GL_CALL( glOrtho ) }, + { GL_CALL( glRasterPos2f ) }, + { GL_CALL( glFrustum ) }, + { GL_CALL( glViewport ) }, + { GL_CALL( glPushMatrix ) }, + { GL_CALL( glPopMatrix ) }, + { GL_CALL( glPushAttrib ) }, + { GL_CALL( glPopAttrib ) }, + { GL_CALL( glLoadIdentity ) }, + { GL_CALL( glLoadMatrixd ) }, + { GL_CALL( glLoadMatrixf ) }, + { GL_CALL( glMultMatrixd ) }, + { GL_CALL( glMultMatrixf ) }, + { GL_CALL( glRotated ) }, + { GL_CALL( glRotatef ) }, + { GL_CALL( glScaled ) }, + { GL_CALL( glScalef ) }, + { GL_CALL( glTranslated ) }, + { GL_CALL( glTranslatef ) }, + { GL_CALL( glReadPixels ) }, + { GL_CALL( glDrawPixels ) }, + { GL_CALL( glStencilFunc ) }, + { GL_CALL( glStencilMask ) }, + { GL_CALL( glStencilOp ) }, + { GL_CALL( glClearStencil ) }, + { GL_CALL( glIsEnabled ) }, + { GL_CALL( glIsList ) }, + { GL_CALL( glIsTexture ) }, + { GL_CALL( glTexEnvf ) }, + { GL_CALL( glTexEnvfv ) }, + { GL_CALL( glTexEnvi ) }, + { GL_CALL( glTexParameterf ) }, + { GL_CALL( glTexParameterfv ) }, + { GL_CALL( glTexParameteri ) }, + { GL_CALL( glHint ) }, + { GL_CALL( glPixelStoref ) }, + { GL_CALL( glPixelStorei ) }, + { GL_CALL( glGenTextures ) }, + { GL_CALL( glDeleteTextures ) }, + { GL_CALL( glBindTexture ) }, + { GL_CALL( glTexImage1D ) }, + { GL_CALL( glTexImage2D ) }, + { GL_CALL( glTexSubImage1D ) }, + { GL_CALL( glTexSubImage2D ) }, + { GL_CALL( glCopyTexImage1D ) }, + { GL_CALL( glCopyTexImage2D ) }, + { GL_CALL( glCopyTexSubImage1D ) }, + { GL_CALL( glCopyTexSubImage2D ) }, + { GL_CALL( glScissor ) }, + { GL_CALL( glGetTexImage ) }, + { GL_CALL( glGetTexEnviv ) }, + { GL_CALL( glPolygonOffset ) }, + { GL_CALL( glPolygonMode ) }, + { GL_CALL( glPolygonStipple ) }, + { GL_CALL( glClipPlane ) }, + { GL_CALL( glGetClipPlane ) }, + { GL_CALL( glShadeModel ) }, + { GL_CALL( glGetTexLevelParameteriv ) }, + { GL_CALL( glGetTexLevelParameterfv ) }, + { GL_CALL( glFogfv ) }, + { GL_CALL( glFogf ) }, + { GL_CALL( glFogi ) }, + { NULL , NULL } +}; + +static dllfunc_t debugoutputfuncs[] = +{ + { GL_CALL( glDebugMessageControlARB ) }, + { GL_CALL( glDebugMessageInsertARB ) }, + { GL_CALL( glDebugMessageCallbackARB ) }, + { GL_CALL( glGetDebugMessageLogARB ) }, + { NULL , NULL } +}; + +static dllfunc_t multitexturefuncs[] = +{ + { GL_CALL( glMultiTexCoord1f ) }, + { GL_CALL( glMultiTexCoord2f ) }, + { GL_CALL( glMultiTexCoord3f ) }, + { GL_CALL( glMultiTexCoord4f ) }, + { GL_CALL( glActiveTexture ) }, + { GL_CALL( glActiveTextureARB ) }, + { GL_CALL( glClientActiveTexture ) }, + { GL_CALL( glClientActiveTextureARB ) }, + { NULL , NULL } +}; + +static dllfunc_t texture3dextfuncs[] = +{ + { GL_CALL( glTexImage3D ) }, + { GL_CALL( glTexSubImage3D ) }, + { GL_CALL( glCopyTexSubImage3D ) }, + { NULL , NULL } +}; + +static dllfunc_t texturecompressionfuncs[] = +{ + { GL_CALL( glCompressedTexImage3DARB ) }, + { GL_CALL( glCompressedTexImage2DARB ) }, + { GL_CALL( glCompressedTexImage1DARB ) }, + { GL_CALL( glCompressedTexSubImage3DARB ) }, + { GL_CALL( glCompressedTexSubImage2DARB ) }, + { GL_CALL( glCompressedTexSubImage1DARB ) }, + { GL_CALL( glGetCompressedTexImage ) }, + { NULL , NULL } +}; + +static dllfunc_t vbofuncs[] = +{ + { GL_CALL( glBindBufferARB ) }, + { GL_CALL( glDeleteBuffersARB ) }, + { GL_CALL( glGenBuffersARB ) }, + { GL_CALL( glIsBufferARB ) }, + { GL_CALL( glMapBufferARB ) }, + { GL_CALL( glUnmapBufferARB ) }, // , + { GL_CALL( glBufferDataARB ) }, + { GL_CALL( glBufferSubDataARB ) }, + { NULL, NULL} +}; + +/* +======================== +DebugCallback + +For ARB_debug_output +======================== +*/ +static void APIENTRY GL_DebugOutput( GLuint source, GLuint type, GLuint id, GLuint severity, GLint length, const GLcharARB *message, GLvoid *userParam ) +{ + switch( type ) + { + case GL_DEBUG_TYPE_ERROR_ARB: + Con_Printf( S_OPENGL_ERROR "%s\n", message ); + break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB: + Con_Printf( S_OPENGL_WARN "%s\n", message ); + break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB: + Con_Printf( S_OPENGL_WARN "%s\n", message ); + break; + case GL_DEBUG_TYPE_PORTABILITY_ARB: + if( host_developer.value < DEV_EXTENDED ) + return; + Con_Printf( S_OPENGL_WARN "%s\n", message ); + break; + case GL_DEBUG_TYPE_PERFORMANCE_ARB: + Con_Printf( S_OPENGL_NOTE "%s\n", message ); + break; + case GL_DEBUG_TYPE_OTHER_ARB: + default: Con_Printf( S_OPENGL_NOTE "%s\n", message ); + break; + } +} + +#ifdef XASH_GLES +void GL_InitExtensionsGLES( void ) +{ + // intialize wrapper type +#ifdef XASH_NANOGL + glConfig.context = CONTEXT_TYPE_GLES_1_X; + glConfig.wrapper = GLES_WRAPPER_NANOGL; +#elif defined( XASH_WES ) + glConfig.context = CONTEXT_TYPE_GLES_2_X; + glConfig.wrapper = GLES_WRAPPER_WES; +#endif + + glConfig.hardware_type = GLHW_GENERIC; + + // initalize until base opengl functions loaded + GL_SetExtension( GL_DRAW_RANGEELEMENTS_EXT, true ); + GL_SetExtension( GL_ARB_MULTITEXTURE, true ); + pglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &glConfig.max_texture_units ); + glConfig.max_texture_coords = glConfig.max_texture_units = 4; + + GL_SetExtension( GL_ENV_COMBINE_EXT, true ); + GL_SetExtension( GL_DOT3_ARB_EXT, true ); + GL_SetExtension( GL_TEXTURE_3D_EXT, false ); + GL_SetExtension( GL_SGIS_MIPMAPS_EXT, true ); // gles specs + GL_SetExtension( GL_ARB_VERTEX_BUFFER_OBJECT_EXT, true ); // gles specs + + // hardware cubemaps + GL_CheckExtension( "GL_OES_texture_cube_map", NULL, "gl_texture_cubemap", GL_TEXTURECUBEMAP_EXT ); + + if( GL_Support( GL_TEXTURECUBEMAP_EXT )) + pglGetIntegerv( GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &glConfig.max_cubemap_size ); + + GL_SetExtension( GL_ARB_SEAMLESS_CUBEMAP, false ); + + GL_SetExtension( GL_EXT_POINTPARAMETERS, false ); + GL_CheckExtension( "GL_OES_texture_npot", NULL, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT ); + + GL_SetExtension( GL_TEXTURE_COMPRESSION_EXT, false ); + GL_SetExtension( GL_CUSTOM_VERTEX_ARRAY_EXT, false ); + GL_SetExtension( GL_CLAMPTOEDGE_EXT, true ); // by gles1 specs + GL_SetExtension( GL_ANISOTROPY_EXT, false ); + GL_SetExtension( GL_TEXTURE_LODBIAS, false ); + GL_SetExtension( GL_CLAMP_TEXBORDER_EXT, false ); + GL_SetExtension( GL_BLEND_MINMAX_EXT, false ); + GL_SetExtension( GL_BLEND_SUBTRACT_EXT, false ); + GL_SetExtension( GL_SEPARATESTENCIL_EXT, false ); + GL_SetExtension( GL_STENCILTWOSIDE_EXT, false ); + GL_SetExtension( GL_TEXTURE_ENV_ADD_EXT,false ); + GL_SetExtension( GL_SHADER_OBJECTS_EXT, false ); + GL_SetExtension( GL_SHADER_GLSL100_EXT, false ); + GL_SetExtension( GL_VERTEX_SHADER_EXT,false ); + GL_SetExtension( GL_FRAGMENT_SHADER_EXT, false ); + GL_SetExtension( GL_SHADOW_EXT, false ); + GL_SetExtension( GL_ARB_DEPTH_FLOAT_EXT, false ); + GL_SetExtension( GL_OCCLUSION_QUERIES_EXT,false ); + GL_CheckExtension( "GL_OES_depth_texture", NULL, "gl_depthtexture", GL_DEPTH_TEXTURE ); + + glConfig.texRectangle = glConfig.max_2d_rectangle_size = 0; // no rectangle + + Cvar_FullSet( "gl_allow_mirrors", "0", CVAR_READ_ONLY); // No support for GLES + +} +#else +void GL_InitExtensionsBigGL() +{ + // intialize wrapper type + glConfig.context = CONTEXT_TYPE_GL; + glConfig.wrapper = GLES_WRAPPER_NONE; + + if( Q_stristr( glConfig.renderer_string, "geforce" )) + glConfig.hardware_type = GLHW_NVIDIA; + else if( Q_stristr( glConfig.renderer_string, "quadro fx" )) + glConfig.hardware_type = GLHW_NVIDIA; + else if( Q_stristr(glConfig.renderer_string, "rv770" )) + glConfig.hardware_type = GLHW_RADEON; + else if( Q_stristr(glConfig.renderer_string, "radeon hd" )) + glConfig.hardware_type = GLHW_RADEON; + else if( Q_stristr( glConfig.renderer_string, "eah4850" ) || Q_stristr( glConfig.renderer_string, "eah4870" )) + glConfig.hardware_type = GLHW_RADEON; + else if( Q_stristr( glConfig.renderer_string, "radeon" )) + glConfig.hardware_type = GLHW_RADEON; + else if( Q_stristr( glConfig.renderer_string, "intel" )) + glConfig.hardware_type = GLHW_INTEL; + else glConfig.hardware_type = GLHW_GENERIC; + + // multitexture + glConfig.max_texture_units = glConfig.max_texture_coords = glConfig.max_teximage_units = 1; + GL_CheckExtension( "GL_ARB_multitexture", multitexturefuncs, "gl_arb_multitexture", GL_ARB_MULTITEXTURE ); + + if( GL_Support( GL_ARB_MULTITEXTURE )) + { + pglGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &glConfig.max_texture_units ); + } + + if( glConfig.max_texture_units == 1 ) + GL_SetExtension( GL_ARB_MULTITEXTURE, false ); + + // 3d texture support + GL_CheckExtension( "GL_EXT_texture3D", texture3dextfuncs, "gl_texture_3d", GL_TEXTURE_3D_EXT ); + + if( GL_Support( GL_TEXTURE_3D_EXT )) + { + pglGetIntegerv( GL_MAX_3D_TEXTURE_SIZE, &glConfig.max_3d_texture_size ); + + if( glConfig.max_3d_texture_size < 32 ) + { + GL_SetExtension( GL_TEXTURE_3D_EXT, false ); + Con_Printf( S_ERROR "GL_EXT_texture3D reported bogus GL_MAX_3D_TEXTURE_SIZE, disabled\n" ); + } + } + + // 2d texture array support + GL_CheckExtension( "GL_EXT_texture_array", texture3dextfuncs, "gl_texture_2d_array", GL_TEXTURE_ARRAY_EXT ); + + if( GL_Support( GL_TEXTURE_ARRAY_EXT )) + pglGetIntegerv( GL_MAX_ARRAY_TEXTURE_LAYERS_EXT, &glConfig.max_2d_texture_layers ); + + // cubemaps support + GL_CheckExtension( "GL_ARB_texture_cube_map", NULL, "gl_texture_cubemap", GL_TEXTURE_CUBEMAP_EXT ); + + if( GL_Support( GL_TEXTURE_CUBEMAP_EXT )) + { + pglGetIntegerv( GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, &glConfig.max_cubemap_size ); + + // check for seamless cubemaps too + GL_CheckExtension( "GL_ARB_seamless_cube_map", NULL, "gl_texture_cubemap_seamless", GL_ARB_SEAMLESS_CUBEMAP ); + } + + GL_CheckExtension( "GL_ARB_texture_non_power_of_two", NULL, "gl_texture_npot", GL_ARB_TEXTURE_NPOT_EXT ); + GL_CheckExtension( "GL_ARB_texture_compression", texturecompressionfuncs, "gl_dds_hardware_support", GL_TEXTURE_COMPRESSION_EXT ); + GL_CheckExtension( "GL_EXT_texture_edge_clamp", NULL, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT ); + if( !GL_Support( GL_CLAMPTOEDGE_EXT )) + GL_CheckExtension( "GL_SGIS_texture_edge_clamp", NULL, "gl_clamp_to_edge", GL_CLAMPTOEDGE_EXT ); + + glConfig.max_texture_anisotropy = 0.0f; + GL_CheckExtension( "GL_EXT_texture_filter_anisotropic", NULL, "gl_ext_anisotropic_filter", GL_ANISOTROPY_EXT ); + if( GL_Support( GL_ANISOTROPY_EXT )) + pglGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &glConfig.max_texture_anisotropy ); + +#ifdef _WIN32 // Win32 only drivers? + // g-cont. because lodbias it too glitchy on Intel's cards + if( glConfig.hardware_type != GLHW_INTEL ) +#endif + GL_CheckExtension( "GL_EXT_texture_lod_bias", NULL, "gl_texture_mipmap_biasing", GL_TEXTURE_LOD_BIAS ); + + if( GL_Support( GL_TEXTURE_LOD_BIAS )) + pglGetFloatv( GL_MAX_TEXTURE_LOD_BIAS_EXT, &glConfig.max_texture_lod_bias ); + + GL_CheckExtension( "GL_ARB_texture_border_clamp", NULL, "gl_ext_texborder_clamp", GL_CLAMP_TEXBORDER_EXT ); + GL_CheckExtension( "GL_ARB_depth_texture", NULL, "gl_depthtexture", GL_DEPTH_TEXTURE ); + GL_CheckExtension( "GL_ARB_texture_float", NULL, "gl_arb_texture_float", GL_ARB_TEXTURE_FLOAT_EXT ); + GL_CheckExtension( "GL_ARB_depth_buffer_float", NULL, "gl_arb_depth_float", GL_ARB_DEPTH_FLOAT_EXT ); + GL_CheckExtension( "GL_EXT_gpu_shader4", NULL, NULL, GL_EXT_GPU_SHADER4 ); // don't confuse users + GL_CheckExtension( "GL_ARB_shading_language_100", NULL, "gl_glslprogram", GL_SHADER_GLSL100_EXT ); + GL_CheckExtension( "GL_ARB_vertex_buffer_object", vbofuncs, "gl_vertex_buffer_object", GL_ARB_VERTEX_BUFFER_OBJECT_EXT ); + + // rectangle textures support + GL_CheckExtension( "GL_ARB_texture_rectangle", NULL, "gl_texture_rectangle", GL_TEXTURE_2D_RECT_EXT ); + + // this won't work without extended context + if( glw_state.extended ) + GL_CheckExtension( "GL_ARB_debug_output", debugoutputfuncs, "gl_debug_output", GL_DEBUG_OUTPUT ); + + if( GL_Support( GL_SHADER_GLSL100_EXT )) + { + pglGetIntegerv( GL_MAX_TEXTURE_COORDS_ARB, &glConfig.max_texture_coords ); + pglGetIntegerv( GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &glConfig.max_teximage_units ); + + // check for hardware skinning + pglGetIntegerv( GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &glConfig.max_vertex_uniforms ); + pglGetIntegerv( GL_MAX_VERTEX_ATTRIBS_ARB, &glConfig.max_vertex_attribs ); + +#ifdef _WIN32 // Win32 only drivers? + if( glConfig.hardware_type == GLHW_RADEON && glConfig.max_vertex_uniforms > 512 ) + glConfig.max_vertex_uniforms /= 4; // radeon returns not correct info +#endif + } + else + { + // just get from multitexturing + glConfig.max_texture_coords = glConfig.max_teximage_units = glConfig.max_texture_units; + } + + pglGetIntegerv( GL_MAX_TEXTURE_SIZE, &glConfig.max_2d_texture_size ); + if( glConfig.max_2d_texture_size <= 0 ) glConfig.max_2d_texture_size = 256; + + if( GL_Support( GL_TEXTURE_2D_RECT_EXT )) + pglGetIntegerv( GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &glConfig.max_2d_rectangle_size ); + +#ifndef XASH_GL_STATIC + // enable gldebug if allowed + if( GL_Support( GL_DEBUG_OUTPUT )) + { + if( host_developer.value ) + { + Con_Reportf( "Installing GL_DebugOutput...\n"); + pglDebugMessageCallbackARB( GL_DebugOutput, NULL ); + + // force everything to happen in the main thread instead of in a separate driver thread + pglEnable( GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB ); + } + + // enable all the low priority messages + pglDebugMessageControlARB( GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW_ARB, 0, NULL, true ); + } +#endif +} +#endif + +void GL_InitExtensions( void ) +{ + // initialize gl extensions + GL_CheckExtension( "OpenGL 1.1.0", opengl_110funcs, NULL, GL_OPENGL_110 ); + + // get our various GL strings + glConfig.vendor_string = pglGetString( GL_VENDOR ); + glConfig.renderer_string = pglGetString( GL_RENDERER ); + glConfig.version_string = pglGetString( GL_VERSION ); + glConfig.extensions_string = pglGetString( GL_EXTENSIONS ); + Con_Reportf( "^3Video^7: %s\n", glConfig.renderer_string ); + +#ifdef XASH_GLES + GL_InitExtensionsGLES(); +#else + GL_InitExtensionsBigGL(); +#endif + + if( GL_Support( GL_TEXTURE_2D_RECT_EXT )) + pglGetIntegerv( GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &glConfig.max_2d_rectangle_size ); + + Cvar_Get( "gl_max_size", va( "%i", glConfig.max_2d_texture_size ), 0, "opengl texture max dims" ); + Cvar_Set( "gl_anisotropy", va( "%f", bound( 0, gl_texture_anisotropy->value, glConfig.max_texture_anisotropy ))); + + if( GL_Support( GL_TEXTURE_COMPRESSION_EXT )) + Image_AddCmdFlags( IL_DDS_HARDWARE ); + + // MCD has buffering issues +#ifdef _WIN32 + if( Q_strstr( glConfig.renderer_string, "gdi" )) + Cvar_SetValue( "gl_finish", 1 ); +#endif + + tr.framecount = tr.visframecount = 1; + glw_state.initialized = true; +} + +void GL_ClearExtensions( void ) +{ + // now all extensions are disabled + memset( glConfig.extension, 0, sizeof( glConfig.extension )); + glw_state.initialized = false; +} + diff --git a/engine/client/gl_cull.c b/ref_gl/gl_cull.c similarity index 100% rename from engine/client/gl_cull.c rename to ref_gl/gl_cull.c diff --git a/ref_gl/gl_dbghulls.c b/ref_gl/gl_dbghulls.c new file mode 100644 index 00000000..662e8cc6 --- /dev/null +++ b/ref_gl/gl_dbghulls.c @@ -0,0 +1,93 @@ +/* +gl_dbghulls.c - loading & handling world and brushmodels +Copyright (C) 2016 Uncle Mike + +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 "mod_local.h" +#include "mathlib.h" +#include "world.h" +#include "gl_local.h" +#include "client.h" + +#define list_entry( ptr, type, member ) \ + ((type *)((char *)(ptr) - (size_t)(&((type *)0)->member))) + +// iterate over each entry in the list +#define list_for_each_entry( pos, head, member ) \ + for( pos = list_entry( (head)->next, winding_t, member ); \ + &pos->member != (head); \ + pos = list_entry( pos->member.next, winding_t, member )) + +void R_DrawWorldHull( void ) +{ + hull_model_t *hull = &world.hull_models[0]; + winding_t *poly; + int i; + + if( FBitSet( r_showhull->flags, FCVAR_CHANGED )) + { + int val = bound( 0, (int)r_showhull->value, 3 ); + if( val ) Mod_CreatePolygonsForHull( val ); + ClearBits( r_showhull->flags, FCVAR_CHANGED ); + } + + if( !CVAR_TO_BOOL( r_showhull )) + return; + pglDisable( GL_TEXTURE_2D ); + + list_for_each_entry( poly, &hull->polys, chain ) + { + srand((unsigned int)poly); + pglColor3f( rand() % 256 / 255.0, rand() % 256 / 255.0, rand() % 256 / 255.0 ); + pglBegin( GL_POLYGON ); + for( i = 0; i < poly->numpoints; i++ ) + pglVertex3fv( poly->p[i] ); + pglEnd(); + } + pglEnable( GL_TEXTURE_2D ); +} + +void R_DrawModelHull( void ) +{ + hull_model_t *hull; + winding_t *poly; + int i; + + if( !CVAR_TO_BOOL( r_showhull )) + return; + + if( !RI.currentmodel || RI.currentmodel->name[0] != '*' ) + return; + + i = atoi( RI.currentmodel->name + 1 ); + if( i < 1 || i >= world.num_hull_models ) + return; + + hull = &world.hull_models[i]; + + pglPolygonOffset( 1.0f, 2.0 ); + pglEnable( GL_POLYGON_OFFSET_FILL ); + pglDisable( GL_TEXTURE_2D ); + list_for_each_entry( poly, &hull->polys, chain ) + { + srand((unsigned int)poly); + pglColor3f( rand() % 256 / 255.0, rand() % 256 / 255.0, rand() % 256 / 255.0 ); + pglBegin( GL_POLYGON ); + for( i = 0; i < poly->numpoints; i++ ) + pglVertex3fv( poly->p[i] ); + pglEnd(); + } + pglEnable( GL_TEXTURE_2D ); + pglDisable( GL_POLYGON_OFFSET_FILL ); +} diff --git a/engine/client/gl_decals.c b/ref_gl/gl_decals.c similarity index 100% rename from engine/client/gl_decals.c rename to ref_gl/gl_decals.c diff --git a/engine/client/gl_draw.c b/ref_gl/gl_draw.c similarity index 100% rename from engine/client/gl_draw.c rename to ref_gl/gl_draw.c diff --git a/engine/client/gl_export.h b/ref_gl/gl_export.h similarity index 100% rename from engine/client/gl_export.h rename to ref_gl/gl_export.h diff --git a/engine/client/gl_frustum.c b/ref_gl/gl_frustum.c similarity index 100% rename from engine/client/gl_frustum.c rename to ref_gl/gl_frustum.c diff --git a/engine/client/gl_frustum.h b/ref_gl/gl_frustum.h similarity index 100% rename from engine/client/gl_frustum.h rename to ref_gl/gl_frustum.h diff --git a/engine/client/gl_image.c b/ref_gl/gl_image.c similarity index 99% rename from engine/client/gl_image.c rename to ref_gl/gl_image.c index 048e9910..63132535 100644 --- a/engine/client/gl_image.c +++ b/ref_gl/gl_image.c @@ -1761,21 +1761,6 @@ int GL_FindTexture( const char *name ) return 0; } -/* -================ -GL_FreeImage - -Frees image by name -================ -*/ -void GL_FreeImage( const char *name ) -{ - int texnum; - - if(( texnum = GL_FindTexture( name )) != 0 ) - GL_FreeTexture( texnum ); -} - /* ================ GL_FreeTexture diff --git a/engine/client/gl_local.h b/ref_gl/gl_local.h similarity index 96% rename from engine/client/gl_local.h rename to ref_gl/gl_local.h index b938295f..2a718bdd 100644 --- a/engine/client/gl_local.h +++ b/ref_gl/gl_local.h @@ -22,6 +22,7 @@ GNU General Public License for more details. #include "protocol.h" #include "dlight.h" #include "gl_frustum.h" +#include "ref_api.h" extern byte *r_temppool; @@ -52,11 +53,6 @@ extern byte *r_temppool; #define RP_LOCALCLIENT( e ) ((e) != NULL && (e)->index == ( cl.playernum + 1 ) && e->player ) #define RP_NORMALPASS() ( FBitSet( RI.params, RP_NONVIEWERREF ) == 0 ) -#define TF_SKY (TF_SKYSIDE|TF_NOMIPMAP) -#define TF_FONT (TF_NOMIPMAP|TF_CLAMP) -#define TF_IMAGE (TF_NOMIPMAP|TF_CLAMP) -#define TF_DECAL (TF_CLAMP) - #define CULL_VISIBLE 0 // not culled #define CULL_BACKSIDE 1 // backside of transparent wall #define CULL_FRUSTUM 2 // culled by frustum @@ -215,7 +211,7 @@ typedef struct // cull info vec3_t modelorg; // relative to viewpoint -} ref_globals_t; +} gl_globals_t; typedef struct { @@ -239,7 +235,7 @@ typedef struct extern ref_speeds_t r_stats; extern ref_instance_t RI; -extern ref_globals_t tr; +extern gl_globals_t tr; extern float gldepthmin, gldepthmax; extern dlight_t cl_dlights[MAX_DLIGHTS]; @@ -323,7 +319,6 @@ void GL_UpdateTexSize( int texnum, int width, int height, int depth ); void GL_ApplyTextureParams( gl_texture_t *tex ); int GL_FindTexture( const char *name ); void GL_FreeTexture( GLenum texnum ); -void GL_FreeImage( const char *name ); const char *GL_Target( GLenum target ); void R_InitDlightTexture( void ); void R_TextureList_f( void ); @@ -369,8 +364,6 @@ void R_DrawFog( void ); // // gl_rmath.c // -float V_CalcFov( float *fov_x, float width, float height ); -void V_AdjustFov( float *fov_x, float *fov_y, float width, float height, qboolean lock_x ); void Matrix4x4_ToArrayFloatGL( const matrix4x4 in, float out[16] ); void Matrix4x4_FromArrayFloatGL( matrix4x4 out, const float in[16] ); void Matrix4x4_Concat( matrix4x4 out, const matrix4x4 in1, const matrix4x4 in2 ); @@ -452,6 +445,23 @@ void R_DrawSkyBox( void ); void R_DrawClouds( void ); void EmitWaterPolys( msurface_t *warp, qboolean reverse ); +// +// 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" // @@ -530,17 +540,6 @@ enum GL_EXTCOUNT, // must be last }; -enum -{ - GL_KEEP_UNIT = -1, - XASH_TEXTURE0 = 0, - XASH_TEXTURE1, - XASH_TEXTURE2, - XASH_TEXTURE3, // g-cont. 4 units should be enough - XASH_TEXTURE4, // mittorn. bump+detail needs 5 for single-pass - MAX_TEXTURE_UNITS = 32 // can't access to all over units without GLSL or cg -}; - typedef enum { GLHW_GENERIC, // where everthing works the way it should @@ -673,7 +672,6 @@ extern convar_t *r_lighting_ambient; extern convar_t *r_studio_lambert; extern convar_t *r_detailtextures; extern convar_t *r_drawentities; -extern convar_t *r_adjust_fov; extern convar_t *r_decals; extern convar_t *r_novis; extern convar_t *r_nocull; @@ -685,14 +683,8 @@ extern convar_t *r_lightmap; extern convar_t *r_vbo; extern convar_t *r_vbo_dlightmode; -extern convar_t *vid_displayfrequency; -extern convar_t *vid_fullscreen; extern convar_t *vid_brightness; extern convar_t *vid_gamma; extern convar_t *vid_highdpi; -extern convar_t *window_xpos; -extern convar_t *window_ypos; -extern convar_t *scr_height; - #endif//GL_LOCAL_H diff --git a/engine/client/gl_refrag.c b/ref_gl/gl_refrag.c similarity index 100% rename from engine/client/gl_refrag.c rename to ref_gl/gl_refrag.c diff --git a/engine/client/gl_rlight.c b/ref_gl/gl_rlight.c similarity index 100% rename from engine/client/gl_rlight.c rename to ref_gl/gl_rlight.c diff --git a/engine/client/gl_rmain.c b/ref_gl/gl_rmain.c similarity index 99% rename from engine/client/gl_rmain.c rename to ref_gl/gl_rmain.c index 46813497..98b25dbe 100644 --- a/engine/client/gl_rmain.c +++ b/ref_gl/gl_rmain.c @@ -1391,7 +1391,7 @@ const byte *GL_TextureData( unsigned int texnum ) if( pic != NULL ) return pic->buffer; - return NULL; + return NULL; } static const ref_overview_t *GL_GetOverviewParms( void ) diff --git a/engine/client/gl_rmath.c b/ref_gl/gl_rmath.c similarity index 89% rename from engine/client/gl_rmath.c rename to ref_gl/gl_rmath.c index 30e591b4..90679250 100644 --- a/engine/client/gl_rmath.c +++ b/ref_gl/gl_rmath.c @@ -18,53 +18,6 @@ GNU General Public License for more details. #include "mathlib.h" #include "client.h" -/* -==================== -V_CalcFov -==================== -*/ -float V_CalcFov( float *fov_x, float width, float height ) -{ - float x, half_fov_y; - - if( *fov_x < 1.0f || *fov_x > 179.0f ) - *fov_x = 90.0f; // default value - - x = width / tan( DEG2RAD( *fov_x ) * 0.5f ); - half_fov_y = atan( height / x ); - - return RAD2DEG( half_fov_y ) * 2; -} - -/* -==================== -V_AdjustFov -==================== -*/ -void V_AdjustFov( float *fov_x, float *fov_y, float width, float height, qboolean lock_x ) -{ - float x, y; - - if( width * 3 == 4 * height || width * 4 == height * 5 ) - { - // 4:3 or 5:4 ratio - return; - } - - if( lock_x ) - { - *fov_y = 2 * atan((width * 3) / (height * 4) * tan( *fov_y * M_PI / 360.0 * 0.5 )) * 360 / M_PI; - return; - } - - y = V_CalcFov( fov_x, 640, 480 ); - x = *fov_x; - - *fov_x = V_CalcFov( &y, height, width ); - if( *fov_x < x ) *fov_x = x; - else *fov_y = y; -} - /* ======================================================================== @@ -313,4 +266,4 @@ void Matrix4x4_ConcatScale3( matrix4x4 out, float x, float y, float z ) Matrix4x4_Copy( base, out ); Matrix4x4_CreateScale3( temp, x, y, z ); Matrix4x4_Concat( out, base, temp ); -} \ No newline at end of file +} diff --git a/engine/client/gl_rmisc.c b/ref_gl/gl_rmisc.c similarity index 91% rename from engine/client/gl_rmisc.c rename to ref_gl/gl_rmisc.c index 87631756..8ac4a638 100644 --- a/engine/client/gl_rmisc.c +++ b/ref_gl/gl_rmisc.c @@ -104,29 +104,6 @@ static void R_ParseDetailTextures( const char *filename ) Mem_Free( afile ); } -/* -======================= -R_ClearStaticEntities - -e.g. by demo request -======================= -*/ -void R_ClearStaticEntities( void ) -{ - int i; - - if( host.type == HOST_DEDICATED ) - return; - - // clear out efrags in case the level hasn't been reloaded - for( i = 0; i < cl.worldmodel->numleafs; i++ ) - cl.worldmodel->leafs[i+1].efrags = NULL; - - clgame.numStatics = 0; - - CL_ClearEfrags (); -} - void R_NewMap( void ) { texture_t *tx; diff --git a/engine/client/gl_rpart.c b/ref_gl/gl_rpart.c similarity index 100% rename from engine/client/gl_rpart.c rename to ref_gl/gl_rpart.c diff --git a/engine/client/gl_rsurf.c b/ref_gl/gl_rsurf.c similarity index 100% rename from engine/client/gl_rsurf.c rename to ref_gl/gl_rsurf.c diff --git a/engine/client/gl_sprite.c b/ref_gl/gl_sprite.c similarity index 100% rename from engine/client/gl_sprite.c rename to ref_gl/gl_sprite.c diff --git a/engine/client/gl_studio.c b/ref_gl/gl_studio.c similarity index 99% rename from engine/client/gl_studio.c rename to ref_gl/gl_studio.c index ed0ceff4..0648ae29 100644 --- a/engine/client/gl_studio.c +++ b/ref_gl/gl_studio.c @@ -663,33 +663,6 @@ float R_StudioEstimateInterpolant( cl_entity_t *e ) return dadt; } -/* -==================== -CL_GetStudioEstimatedFrame - -==================== -*/ -float CL_GetStudioEstimatedFrame( cl_entity_t *ent ) -{ - studiohdr_t *pstudiohdr; - mstudioseqdesc_t *pseqdesc; - int sequence; - - if( ent->model != NULL && ent->model->type == mod_studio ) - { - pstudiohdr = (studiohdr_t *)Mod_StudioExtradata( ent->model ); - - if( pstudiohdr ) - { - sequence = bound( 0, ent->curstate.sequence, pstudiohdr->numseq - 1 ); - pseqdesc = (mstudioseqdesc_t *)((byte *)pstudiohdr + pstudiohdr->seqindex) + sequence; - return R_StudioEstimateFrame( ent, pseqdesc ); - } - } - - return 0; -} - /* ==================== CL_GetSequenceDuration diff --git a/ref_gl/gl_triapi.c b/ref_gl/gl_triapi.c new file mode 100644 index 00000000..7b68cd3f --- /dev/null +++ b/ref_gl/gl_triapi.c @@ -0,0 +1,335 @@ +/* +gl_triapi.c - TriAPI 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" +#include "const.h" + +/* +=============================================================== + + TRIAPI IMPLEMENTATION + +=============================================================== +*/ +/* +============= +TriRenderMode + +set rendermode +============= +*/ +void TriRenderMode( int mode ) +{ + switch( mode ) + { + case kRenderNormal: + pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + pglDisable( GL_BLEND ); + pglDepthMask( GL_TRUE ); + break; + case kRenderTransAlpha: + pglEnable( GL_BLEND ); + pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + pglDepthMask( GL_FALSE ); + break; + case kRenderTransColor: + case kRenderTransTexture: + pglEnable( GL_BLEND ); + pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + break; + case kRenderGlow: + case kRenderTransAdd: + pglBlendFunc( GL_SRC_ALPHA, GL_ONE ); + pglEnable( GL_BLEND ); + pglDepthMask( GL_FALSE ); + break; + } +} + +/* +============= +TriBegin + +begin triangle sequence +============= +*/ +void TriBegin( int mode ) +{ + switch( mode ) + { + case TRI_POINTS: + mode = GL_POINTS; + break; + case TRI_TRIANGLES: + mode = GL_TRIANGLES; + break; + case TRI_TRIANGLE_FAN: + mode = GL_TRIANGLE_FAN; + break; + case TRI_QUADS: + mode = GL_QUADS; + break; + case TRI_LINES: + mode = GL_LINES; + break; + case TRI_TRIANGLE_STRIP: + mode = GL_TRIANGLE_STRIP; + break; + case TRI_QUAD_STRIP: + mode = GL_QUAD_STRIP; + break; + case TRI_POLYGON: + default: + mode = GL_POLYGON; + break; + } + + pglBegin( mode ); +} + +/* +============= +TriEnd + +draw triangle sequence +============= +*/ +void TriEnd( void ) +{ + pglEnd( ); +} + +/* +============= +_TriColor4f + +============= +*/ +void _TriColor4f( float r, float g, float b, float a ) +{ + pglColor4f( r, g, b, a ); +} + +/* +============= +_TriColor4ub + +============= +*/ +void _TriColor4ub( byte r, byte g, byte b, byte a ) +{ + pglColor4ub( r, g, b, a ); +} + +/* +============= +TriColor4f + +============= +*/ +void TriColor4f( float r, float g, float b, float a ) +{ + if( engine.TriGetRenderMode() == kRenderTransAlpha ) + RefTriAPI->Color4ub( r * 255.9f, g * 255.9f, b * 255.9f, a * 255.0f ); + else RefTriAPI->Color4f( r * a, g * a, b * a, 1.0 ); + + clgame.ds.triRGBA[0] = r; + clgame.ds.triRGBA[1] = g; + clgame.ds.triRGBA[2] = b; + clgame.ds.triRGBA[3] = a; +} + +/* +============= +TriColor4ub + +============= +*/ +void TriColor4ub( byte r, byte g, byte b, byte a ) +{ + clgame.ds.triRGBA[0] = r * (1.0f / 255.0f); + clgame.ds.triRGBA[1] = g * (1.0f / 255.0f); + clgame.ds.triRGBA[2] = b * (1.0f / 255.0f); + clgame.ds.triRGBA[3] = a * (1.0f / 255.0f); + + pglColor4f( clgame.ds.triRGBA[0], clgame.ds.triRGBA[1], clgame.ds.triRGBA[2], 1.0f ); +} + +/* +============= +TriTexCoord2f + +============= +*/ +void TriTexCoord2f( float u, float v ) +{ + pglTexCoord2f( u, v ); +} + +/* +============= +TriVertex3fv + +============= +*/ +void TriVertex3fv( const float *v ) +{ + pglVertex3fv( v ); +} + +/* +============= +TriVertex3f + +============= +*/ +void TriVertex3f( float x, float y, float z ) +{ + pglVertex3f( x, y, z ); +} + +/* +============= +TriWorldToScreen + +convert world coordinates (x,y,z) into screen (x, y) +============= +*/ +int TriWorldToScreen( float *world, float *screen ) +{ + int retval; + + retval = R_WorldToScreen( world, screen ); + + screen[0] = 0.5f * screen[0] * (float)clgame.viewport[2]; + screen[1] = -0.5f * screen[1] * (float)clgame.viewport[3]; + screen[0] += 0.5f * (float)clgame.viewport[2]; + screen[1] += 0.5f * (float)clgame.viewport[3]; + + return retval; +} + +/* +============= +TriSpriteTexture + +bind current texture +============= +*/ +int TriSpriteTexture( model_t *pSpriteModel, int frame ) +{ + int gl_texturenum; + + if(( gl_texturenum = R_GetSpriteTexture( pSpriteModel, frame )) == 0 ) + return 0; + + if( gl_texturenum <= 0 || gl_texturenum > MAX_TEXTURES ) + gl_texturenum = tr.defaultTexture; + + GL_Bind( XASH_TEXTURE0, gl_texturenum ); + + return gl_texturenum; // INCOMPATIBILITY +} + +/* +============= +TriFog + +enables global fog on the level +============= +*/ +void TriFog( float flFogColor[3], float flStart, float flEnd, int bOn ) +{ + // overrided by internal fog + if( RI.fogEnabled ) return; + RI.fogCustom = bOn; + + // check for invalid parms + if( flEnd <= flStart ) + { + RI.fogCustom = false; + pglDisable( GL_FOG ); + return; + } + + if( RI.fogCustom ) + pglEnable( GL_FOG ); + else pglDisable( GL_FOG ); + + // copy fog params + RI.fogColor[0] = flFogColor[0] / 255.0f; + RI.fogColor[1] = flFogColor[1] / 255.0f; + RI.fogColor[2] = flFogColor[2] / 255.0f; + RI.fogStart = flStart; + RI.fogColor[3] = 1.0f; + RI.fogDensity = 0.0f; + RI.fogSkybox = true; + RI.fogEnd = flEnd; + + pglFogi( GL_FOG_MODE, GL_LINEAR ); + pglFogfv( GL_FOG_COLOR, RI.fogColor ); + pglFogf( GL_FOG_START, RI.fogStart ); + pglFogf( GL_FOG_END, RI.fogEnd ); + pglHint( GL_FOG_HINT, GL_NICEST ); +} + +/* +============= +TriGetMatrix + +very strange export +============= +*/ +void TriGetMatrix( const int pname, float *matrix ) +{ + pglGetFloatv( pname, matrix ); +} + +/* +============= +TriForParams + +============= +*/ +void TriFogParams( float flDensity, int iFogSkybox ) +{ + RI.fogDensity = flDensity; + RI.fogSkybox = iFogSkybox; +} + +/* +============= +TriCullFace + +============= +*/ +void _TriCullFace( TRICULLSTYLE mode ) +{ + int glMode; + + switch( mode ) + { + case TRI_FRONT: + glMode = GL_FRONT; + break; + default: + glMode = GL_NONE; + break; + } + + GL_Cull( mode ); +} diff --git a/ref_gl/gl_vgui.c b/ref_gl/gl_vgui.c new file mode 100644 index 00000000..aa852b5b --- /dev/null +++ b/ref_gl/gl_vgui.c @@ -0,0 +1,242 @@ +/* +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" + +/* +================ +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 ) + Sys_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 ) + { + 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 ) + { + 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 ) + { + 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 ) +{ + float xscale = glState.width / (float)clgame.scrInfo.iWidth; + float yscale = glState.height / (float)clgame.scrInfo.iHeight; + + 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(); +} diff --git a/engine/client/gl_warp.c b/ref_gl/gl_warp.c similarity index 99% rename from engine/client/gl_warp.c rename to ref_gl/gl_warp.c index a4ea724d..4acc7fe6 100644 --- a/engine/client/gl_warp.c +++ b/ref_gl/gl_warp.c @@ -819,4 +819,4 @@ void EmitWaterPolys( msurface_t *warp, qboolean reverse ) pglEnd(); GL_SetupFogColorForSurfaces(); -} \ No newline at end of file +} diff --git a/ref_gl/wscript b/ref_gl/wscript new file mode 100644 index 00000000..102581cc --- /dev/null +++ b/ref_gl/wscript @@ -0,0 +1,50 @@ +#! /usr/bin/env python +# encoding: utf-8 +# mittorn, 2018 + +from waflib import Logs +import os +from fwgslib import get_subproject_name + +top = '.' + +def options(opt): + # stub + return + +def configure(conf): + # check for dedicated server build + if conf.options.DEDICATED: + return + + if conf.options.SUPPORT_BSP2_FORMAT: + conf.env.append_unique('DEFINES', 'SUPPORT_BSP2_FORMAT') + +def build(bld): + if bld.env.DEDICATED: + return + + bld.load_envs() + name = get_subproject_name(bld) + bld.env = bld.all_envs[name] + + libs = [] + + source = bld.path.ant_glob(['*.c']) + + includes = ['.', + '../engine/common', + '../engine/server', + '../engine/client', + '../common', + '../pm_shared' ] + + bld.shlib( + source = source, + target = name, + features = 'c', + includes = includes, + use = libs, + install_path = bld.env.LIBDIR, + subsystem = bld.env.MSVC_SUBSYSTEM + ) diff --git a/wscript b/wscript index 09070f1b..80534708 100644 --- a/wscript +++ b/wscript @@ -17,7 +17,7 @@ SUBDIRS = [ 'engine', 'game_launch', 'mainui', 'vgui_support' ] top = '.' def options(opt): - opt.load('xcompile compiler_cxx compiler_c') + opt.load('xcompile compiler_cxx compiler_c sdl2') if sys.platform == 'win32': opt.load('msvc msvs') @@ -37,6 +37,10 @@ def options(opt): '--win-style-install', action = 'store_true', dest = 'WIN_INSTALL', default = False, help = 'install like Windows build, ignore prefix, useful for development') + opt.add_option( + '--enable-bsp2', action = 'store_true', dest = 'SUPPORT_BSP2_FORMAT', default = False, + help = 'build engine and renderers with BSP2 map support(recommended for Quake, breaks compability!)') + opt.recurse(SUBDIRS) def configure(conf): @@ -62,7 +66,7 @@ def configure(conf): conf.env.BIT32_MANDATORY = not conf.options.ALLOW64 conf.env.BIT32_ALLOW64 = conf.options.ALLOW64 - conf.load('force_32bit') + conf.load('force_32bit sdl2') if conf.env.DEST_SIZEOF_VOID_P == 4: Logs.info('NOTE: will build engine for 32-bit target')