2004-08-22 22:29:09 +00:00
/*
Copyright ( C ) 1996 - 1997 Id Software , Inc .
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation ; either version 2
of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2005-12-01 11:40:45 +00:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE .
2004-08-22 22:29:09 +00:00
See the GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
// draw.c -- this is the only file outside the refresh that touches the
// vid buffer
# include "quakedef.h"
2009-11-04 21:16:50 +00:00
# ifdef GLQUAKE
2004-08-22 22:29:09 +00:00
# include "glquake.h"
# include "shader.h"
2009-11-04 21:16:50 +00:00
# include "gl_draw.h"
2004-08-22 22:29:09 +00:00
2005-12-01 11:40:45 +00:00
2004-08-22 22:29:09 +00:00
extern cvar_t gl_max_size ;
extern cvar_t gl_picmip ;
2005-01-28 04:28:07 +00:00
extern cvar_t gl_lerpimages ;
2004-11-13 17:31:04 +00:00
extern cvar_t gl_picmip2d ;
2004-08-22 22:29:09 +00:00
extern cvar_t gl_compress ;
2010-07-11 02:22:39 +00:00
extern cvar_t gl_smoothcrosshair ;
2006-06-04 02:25:10 +00:00
extern cvar_t gl_texturemode , gl_texture_anisotropic_filtering ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
float gl_anisotropy_factor ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
static int gl_filter_pic [ 3 ] ; //ui elements
static int gl_filter_mip [ 3 ] ; //everything else
2012-01-01 02:26:42 +00:00
int gl_mipcap_min = 0 ;
int gl_mipcap_max = 1000 ;
2004-08-22 22:29:09 +00:00
2011-10-27 16:16:29 +00:00
void GL_DestroyTexture ( texid_t tex )
{
2014-10-05 20:04:11 +00:00
if ( ! tex )
2007-06-10 05:14:38 +00:00
return ;
2014-10-05 20:04:11 +00:00
if ( tex - > num )
qglDeleteTextures ( 1 , & tex - > num ) ;
tex - > num = 0 ;
2007-06-10 05:14:38 +00:00
}
2011-10-27 16:16:29 +00:00
2004-08-22 22:29:09 +00:00
/*
= = = = = = = = = = = = = = =
Draw_Init
= = = = = = = = = = = = = = =
*/
2011-10-27 16:16:29 +00:00
void GLDraw_Init ( void )
2004-08-22 22:29:09 +00:00
{
2009-11-04 21:16:50 +00:00
R2D_Init ( ) ;
2004-10-10 06:32:29 +00:00
TRACE ( ( " dbg: GLDraw_ReInit: GL_BeginRendering \n " ) ) ;
2009-11-04 21:16:50 +00:00
GL_BeginRendering ( ) ;
2004-10-10 06:32:29 +00:00
TRACE ( ( " dbg: GLDraw_ReInit: SCR_DrawLoading \n " ) ) ;
2014-03-30 08:55:06 +00:00
qglDisable ( GL_SCISSOR_TEST ) ;
2012-01-17 07:57:46 +00:00
GL_Set2D ( false ) ;
2004-10-10 06:32:29 +00:00
2014-03-30 08:55:06 +00:00
qglClearColor ( 0 , 0 , 0 , 1 ) ;
2005-01-07 02:59:56 +00:00
qglClear ( GL_COLOR_BUFFER_BIT ) ;
2004-10-10 06:32:29 +00:00
{
2011-03-31 01:14:01 +00:00
mpic_t * pic = R2D_SafeCachePic ( " gfx/loading.lmp " ) ;
2004-10-10 06:32:29 +00:00
if ( pic )
2011-03-31 01:14:01 +00:00
R2D_ScalePic ( ( ( int ) vid . width - pic - > width ) / 2 ,
2009-11-04 21:16:50 +00:00
( ( int ) vid . height - 48 - pic - > height ) / 2 , pic - > width , pic - > height , pic ) ;
2004-10-10 06:32:29 +00:00
}
TRACE ( ( " dbg: GLDraw_ReInit: GL_EndRendering \n " ) ) ;
2005-12-01 11:40:45 +00:00
GL_EndRendering ( ) ;
2014-03-30 00:39:37 +00:00
VID_SwapBuffers ( ) ;
2004-08-22 22:29:09 +00:00
2005-01-17 18:06:45 +00:00
GL_SetupSceneProcessingTextures ( ) ;
2005-01-12 22:15:50 +00:00
2004-08-22 22:29:09 +00:00
//
// get the other pics we need
//
2011-03-31 01:14:01 +00:00
TRACE ( ( " dbg: GLDraw_ReInit: R2D_SafePicFromWad \n " ) ) ;
draw_disc = R2D_SafePicFromWad ( " disc " ) ;
2004-08-22 22:29:09 +00:00
2010-07-11 02:22:39 +00:00
# ifdef GL_USE8BITTEX
2004-08-22 22:29:09 +00:00
inited15to8 = false ;
2010-07-11 02:22:39 +00:00
# endif
2004-09-13 03:20:04 +00:00
2014-03-30 08:55:06 +00:00
qglClearColor ( 1 , 0 , 0 , 1 ) ;
2004-09-13 03:20:04 +00:00
2004-10-10 06:32:29 +00:00
TRACE ( ( " dbg: GLDraw_ReInit: PPL_LoadSpecularFragmentProgram \n " ) ) ;
2010-03-25 22:56:11 +00:00
GL_InitSceneProcessingShaders ( ) ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
// Cmd_AddCommandD ("r_imagelist", GLDraw_ImageList_f, "Debug command. Reveals current list of loaded images.");
2004-08-22 22:29:09 +00:00
}
2011-10-27 16:16:29 +00:00
2004-08-22 22:29:09 +00:00
void GLDraw_DeInit ( void )
{
2011-10-27 16:16:29 +00:00
Cmd_RemoveCommand ( " r_imagelist " ) ;
2009-11-04 21:16:50 +00:00
2012-07-05 19:42:36 +00:00
R2D_Shutdown ( ) ;
2014-09-08 23:47:19 +00:00
R_GAliasFlushSkinCache ( true ) ;
2005-12-01 11:40:45 +00:00
2004-08-22 22:29:09 +00:00
draw_disc = NULL ;
2014-05-30 03:57:30 +00:00
GL_ShutdownPostProcessing ( ) ;
2004-08-22 22:29:09 +00:00
2010-07-11 02:22:39 +00:00
# ifdef RTLIGHTS
Sh_Shutdown ( ) ;
2004-10-19 16:10:14 +00:00
# endif
2009-11-04 21:16:50 +00:00
Shader_Shutdown ( ) ;
2004-08-22 22:29:09 +00:00
}
//=============================================================================
/*
= = = = = = = = = = = = = = = =
GL_Set2D
Setup as if the screen was 320 * 200
= = = = = = = = = = = = = = = =
*/
2012-01-17 07:57:46 +00:00
void GL_Set2D ( qboolean flipped )
2004-08-22 22:29:09 +00:00
{
2011-02-25 04:22:14 +00:00
extern cvar_t gl_screenangle ;
float rad , ang ;
float tmp [ 16 ] , tmp2 [ 16 ] ;
float w = vid . width , h = vid . height ;
2014-08-03 14:47:47 +00:00
qboolean fbo = ! ! * r_refdef . rt_destcolour [ 0 ] . texname ;
2014-02-07 08:38:40 +00:00
if ( fbo )
{
2014-08-03 14:47:47 +00:00
R2D_RT_GetTexture ( r_refdef . rt_destcolour [ 0 ] . texname , & vid . fbpwidth , & vid . fbpheight ) ;
2014-02-07 08:38:40 +00:00
vid . fbvwidth = vid . fbpwidth ;
vid . fbvheight = vid . fbpheight ;
2014-10-14 16:42:48 +00:00
2015-02-02 08:01:53 +00:00
if ( strcmp ( r_refdef . rt_destcolour [ 0 ] . texname , " megascreeny " ) )
flipped ^ = true ;
2014-02-07 08:38:40 +00:00
}
else
{
vid . fbvwidth = vid . width ;
vid . fbvheight = vid . height ;
vid . fbpwidth = vid . pixelwidth ;
vid . fbpheight = vid . pixelheight ;
}
2011-02-25 04:22:14 +00:00
ang = ( gl_screenangle . value > 0 ? ( gl_screenangle . value + 45 ) : ( gl_screenangle . value - 45 ) ) / 90 ;
ang = ( int ) ang * 90 ;
2014-02-07 08:38:40 +00:00
if ( ang & & ! fbo )
2011-02-25 04:22:14 +00:00
{ /*more expensive maths*/
rad = ( ang * M_PI ) / 180 ;
w = fabs ( cos ( rad ) ) * ( vid . width ) + fabs ( sin ( rad ) ) * ( vid . height ) ;
h = fabs ( sin ( rad ) ) * ( vid . width ) + fabs ( cos ( rad ) ) * ( vid . height ) ;
2011-07-30 14:14:56 +00:00
Matrix4x4_CM_Orthographic ( r_refdef . m_projection , w / - 2.0f , w / 2.0f , h / 2.0f , h / - 2.0f , - 99999 , 99999 ) ;
2011-02-25 04:22:14 +00:00
2011-07-30 14:14:56 +00:00
Matrix4x4_Identity ( tmp ) ;
Matrix4_Multiply ( Matrix4x4_CM_NewTranslation ( ( vid . width / - 2.0f ) , ( vid . height / - 2.0f ) , 0 ) , tmp , tmp2 ) ;
Matrix4_Multiply ( Matrix4x4_CM_NewRotation ( - ang , 0 , 0 , 1 ) , tmp2 , r_refdef . m_view ) ;
2011-02-25 04:22:14 +00:00
}
else
{
2014-02-07 08:38:40 +00:00
w = vid . fbvwidth ;
h = vid . fbvheight ;
2012-01-17 07:57:46 +00:00
if ( flipped )
2014-02-07 08:38:40 +00:00
Matrix4x4_CM_Orthographic ( r_refdef . m_projection , 0 , w , 0 , h , - 99999 , 99999 ) ;
2012-01-17 07:57:46 +00:00
else
2014-02-07 08:38:40 +00:00
Matrix4x4_CM_Orthographic ( r_refdef . m_projection , 0 , w , h , 0 , - 99999 , 99999 ) ;
2011-07-30 14:14:56 +00:00
Matrix4x4_Identity ( r_refdef . m_view ) ;
2011-02-25 04:22:14 +00:00
}
2014-02-07 08:38:40 +00:00
//current physical position on the current render target.
------------------------------------------------------------------------
r4169 | acceptthis | 2013-01-17 08:55:12 +0000 (Thu, 17 Jan 2013) | 31 lines
removed MAX_VISEDICTS limit.
PEXT2_REPLACEMENTDELTAS tweaked, now has 4 million entity limit. still not enabled by default.
TE_BEAM now maps to a separate TEQW_BEAM to avoid conflicts with QW.
added android multitouch emulation for windows/rawinput (in_simulatemultitouch).
split topcolor/bottomcolor from scoreboard, for dp's colormap|1024 feature.
now using utf-8 for windows consoles.
qcc warnings/errors now give clickable console links for quick+easy editing.
disabled menutint when the currently active item changes contrast or gamma (for OneManClan).
Added support for drawfont/drawfontscale.
tweaked the qcvm a little to reduce the number of pointers.
.doll file loading. still experimental and will likely crash. requires csqc active, even if its a dummy progs. this will be fixed in time. Still other things that need cleaning up.
windows: gl_font "?" shows the standard windows font-selection dialog, and can be used to select windows fonts. not all work. and you probably don't want to use windings.
fixed splitscreen support when playing mvds. added mini-scoreboards to splitscreen.
editor/debugger now shows asm if there's no linenumber info. also, pressing f1 for help shows the shortcuts.
Added support for .framegroups files for psk(psa) and iqm formats.
True support for ezquake's colour codes. Mutually exclusive with background colours.
path command output slightly more readable.
added support for digest_hex (MD4, SHA1, CRC16).
skingroups now colourmap correctly.
Fix terrain colour hints, and litdata from the wrong bsp.
fix ftp dual-homed issue. support epsv command, and enable ipv6 (eprt still not supported).
remove d3d11 compilation from the makefile. the required headers are not provided by mingw, and are not available to the build bot, so don't bother.
fix v *= v.x and similar opcodes.
fteqcc: fixed support for áéÃóú type chars in names. utf-8 files now properly supported (even with the utf-8 bom/identifier). utf-16 also supported.
fteqcc: fixed '#if 1 == 3 && 4' parsing.
fteqcc: -Werror acts on the warning, rather than as a separate error. Line numbers are thus more readable.
fteqcc: copyright message now includes compile date instead.
fteqccgui: the treeview control is now coloured depending on whether there were warnings/errors in the last compile.
fteqccgui: the output window is now focused and scrolls down as compilation progresses.
pr_dumpplatform command dumps out some pragmas to convert more serious warnings to errors. This is to avoid the infamous 'fteqcc sucks cos my code sucks' issue.
rewrote prespawn/modelist/soundlist code. server tracks progress now.
------------------------------------------------------------------------
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4167 fc73d0e0-1445-4013-8a0c-d673dee63da5
2013-03-12 22:29:40 +00:00
r_refdef . pxrect . x = 0 ;
2013-11-21 23:02:28 +00:00
r_refdef . pxrect . y = 0 ;
2014-02-07 08:38:40 +00:00
r_refdef . pxrect . width = vid . fbpwidth ;
r_refdef . pxrect . height = vid . fbpheight ;
r_refdef . pxrect . maxheight = vid . fbpheight ;
2011-02-25 04:22:14 +00:00
r_refdef . time = realtime ;
2011-01-23 03:44:49 +00:00
/*flush that gl state*/
2013-11-21 23:02:28 +00:00
GL_ViewportUpdate ( ) ;
2004-08-22 22:29:09 +00:00
2011-01-23 03:44:49 +00:00
if ( qglLoadMatrixf )
{
qglMatrixMode ( GL_PROJECTION ) ;
qglLoadMatrixf ( r_refdef . m_projection ) ;
2004-08-22 22:29:09 +00:00
2011-01-23 03:44:49 +00:00
qglMatrixMode ( GL_MODELVIEW ) ;
qglLoadMatrixf ( r_refdef . m_view ) ;
}
2011-06-05 23:53:33 +00:00
GL_SetShaderState2D ( true ) ;
2004-08-22 22:29:09 +00:00
}
//====================================================================
2014-10-05 20:04:11 +00:00
# ifndef GL_COMPRESSED_RGB_S3TC_DXT1_EXT
# define GL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0
# define GL_COMPRESSED_RGBA_S3TC_DXT1_EXT 0x83F1
# define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
# define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
# endif
//note: needs to be bound first, so the 'targ' argument shouldn't be a problem.
static void GL_Texturemode_Apply ( GLenum targ , unsigned int flags )
2004-08-22 22:29:09 +00:00
{
2014-10-05 20:04:11 +00:00
int min , mag ;
int * filter = ( flags & IF_UIPIC ) ? gl_filter_pic : gl_filter_mip ;
if ( targ = = GL_TEXTURE_CUBE_MAP_ARB )
flags | = IF_NOMIPMAP ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
if ( ( filter [ 2 ] & & ! ( flags & IF_NEAREST ) ) | | ( flags & IF_LINEAR ) )
mag = GL_LINEAR ;
else
mag = GL_NEAREST ;
if ( filter [ 1 ] = = - 1 | | ( flags & IF_NOMIPMAP ) )
{
if ( ( filter [ 0 ] & & ! ( flags & IF_NEAREST ) ) | | ( flags & IF_LINEAR ) )
min = GL_LINEAR ;
else
min = GL_NEAREST ;
}
else
2009-11-04 21:16:50 +00:00
{
2015-04-14 23:12:17 +00:00
if ( ( filter [ 1 ] & & ! ( flags & IF_NEAREST ) ) | | ( flags & IF_LINEAR ) )
2012-07-20 01:46:05 +00:00
{
2015-02-07 22:34:22 +00:00
if ( filter [ 0 ] & & ! ( flags & IF_NEAREST ) | | ( flags & IF_LINEAR ) )
2014-10-05 20:04:11 +00:00
min = GL_LINEAR_MIPMAP_LINEAR ;
else
min = GL_NEAREST_MIPMAP_LINEAR ;
}
else
{
2015-04-14 23:12:17 +00:00
if ( ( filter [ 0 ] & & ! ( flags & IF_NEAREST ) ) | | ( flags & IF_LINEAR ) )
2014-10-05 20:04:11 +00:00
min = GL_LINEAR_MIPMAP_NEAREST ;
else
min = GL_NEAREST_MIPMAP_NEAREST ;
2012-07-20 01:46:05 +00:00
}
2009-11-04 21:16:50 +00:00
}
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
qglTexParameteri ( targ , GL_TEXTURE_MIN_FILTER , min ) ;
qglTexParameteri ( targ , GL_TEXTURE_MAG_FILTER , mag ) ;
if ( gl_anisotropy_factor ) //0 means driver doesn't support
{
//only use anisotrophy when using linear any linear, because of drivers that forces linear sampling when anis is active (annoyingly this is allowed by the spec).
2015-05-03 19:57:46 +00:00
if ( ( min = = GL_LINEAR_MIPMAP_LINEAR | | min = = GL_LINEAR_MIPMAP_NEAREST ) & & mag = = GL_LINEAR )
2014-10-05 20:04:11 +00:00
qglTexParameterf ( targ , GL_TEXTURE_MAX_ANISOTROPY_EXT , gl_anisotropy_factor ) ;
else
qglTexParameterf ( targ , GL_TEXTURE_MAX_ANISOTROPY_EXT , 1 ) ;
}
2004-08-22 22:29:09 +00:00
}
2014-10-05 20:04:11 +00:00
qboolean GL_LoadTextureMips ( texid_t tex , struct pendingtextureinfo * mips )
2004-08-22 22:29:09 +00:00
{
2014-10-05 20:04:11 +00:00
static int cubeface [ ] =
2004-08-22 22:29:09 +00:00
{
2014-10-05 20:04:11 +00:00
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB ,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB ,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB ,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB ,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB ,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
} ;
int targ , targface ;
int i , j ;
2004-08-22 22:29:09 +00:00
2014-10-11 19:39:45 +00:00
if ( gl_config . gles )
{
//gles requires that the internal format must match format
//this means we can't specify 24.0 modes with a 24.8 datatype.
//arguably we shouldn't do this anyway, but there are differences that q3 shaders can notice.
//fixme: move elsewhere?
if ( mips - > encoding = = PTI_RGBX8 )
mips - > encoding = PTI_RGBA8 ;
if ( mips - > encoding = = PTI_BGRX8 )
mips - > encoding = PTI_BGRA8 ;
}
2014-10-05 20:04:11 +00:00
if ( ! tex - > num )
qglGenTextures ( 1 , & tex - > num ) ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
switch ( ( tex - > flags & IF_TEXTYPE ) > > IF_TEXTYPESHIFT )
{
default :
case 0 :
targ = GL_TEXTURE_2D ;
break ;
case 1 :
targ = GL_TEXTURE_3D ;
break ;
case 2 :
targ = GL_TEXTURE_CUBE_MAP_ARB ;
break ;
}
2005-01-28 04:28:07 +00:00
2014-10-05 20:04:11 +00:00
GL_MTBind ( 0 , targ , tex ) ;
2005-01-28 04:28:07 +00:00
2014-10-05 20:04:11 +00:00
if ( tex - > flags & IF_CLAMP )
2005-01-28 04:28:07 +00:00
{
2014-10-05 20:04:11 +00:00
qglTexParameteri ( targ , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ;
qglTexParameteri ( targ , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ;
if ( targ ! = GL_TEXTURE_2D )
qglTexParameteri ( targ , GL_TEXTURE_WRAP_R , GL_CLAMP_TO_EDGE ) ;
}
else
{
qglTexParameteri ( targ , GL_TEXTURE_WRAP_S , GL_REPEAT ) ;
qglTexParameteri ( targ , GL_TEXTURE_WRAP_T , GL_REPEAT ) ;
if ( targ ! = GL_TEXTURE_2D )
qglTexParameteri ( targ , GL_TEXTURE_WRAP_R , GL_REPEAT ) ;
2005-01-28 04:28:07 +00:00
}
2015-03-03 00:14:43 +00:00
//make sure the texture is complete even if the mips are not.
//note that some drivers will just ignore levels that are not valid.
//this means that we can't make this setting dynamic, so we might as well let the drivers know BEFORE we do the uploads, to be kind to those that are buggy..
2015-04-14 23:12:17 +00:00
//this is available in gles3
2015-03-03 00:14:43 +00:00
if ( ! gl_config . gles )
{
2015-05-03 19:57:46 +00:00
if ( targ ! = GL_TEXTURE_CUBE_MAP_ARB )
2015-03-03 00:14:43 +00:00
{
2015-05-03 19:57:46 +00:00
if ( tex - > flags & IF_MIPCAP )
{
qglTexParameteri ( targ , GL_TEXTURE_BASE_LEVEL , min ( mips - > mipcount - 1 , gl_mipcap_min ) ) ;
qglTexParameteri ( targ , GL_TEXTURE_MAX_LEVEL , min ( mips - > mipcount - 1 , gl_mipcap_max ) ) ;
}
else
{
qglTexParameteri ( targ , GL_TEXTURE_BASE_LEVEL , 0 ) ;
qglTexParameteri ( targ , GL_TEXTURE_MAX_LEVEL , mips - > mipcount - 1 ) ;
}
2015-03-03 00:14:43 +00:00
}
}
2014-10-05 20:04:11 +00:00
tex - > width = mips - > mip [ 0 ] . width ;
tex - > height = mips - > mip [ 0 ] . height ;
GL_Texturemode_Apply ( targ , tex - > flags ) ;
if ( targ = = GL_TEXTURE_3D )
2005-01-28 04:28:07 +00:00
{
2014-10-05 20:04:11 +00:00
targface = targ ;
for ( i = 0 ; i < mips - > mipcount ; i + + )
2005-01-28 04:28:07 +00:00
{
2014-10-05 20:04:11 +00:00
int size = mips - > mip [ i ] . height ;
switch ( mips - > encoding )
2005-01-28 04:28:07 +00:00
{
2014-10-05 20:04:11 +00:00
case PTI_RGBX8 :
qglTexImage3D ( targface , i , GL_RGB , size , size , size , 0 , GL_RGBA , GL_UNSIGNED_BYTE , mips - > mip [ i ] . data ) ;
break ;
case PTI_RGBA8 :
qglTexImage3D ( targface , i , GL_RGBA , size , size , size , 0 , GL_RGBA , GL_UNSIGNED_BYTE , mips - > mip [ i ] . data ) ;
break ;
case PTI_BGRX8 :
qglTexImage3D ( targface , i , GL_RGB , size , size , size , 0 , GL_BGRA_EXT , GL_UNSIGNED_INT_8_8_8_8_REV , mips - > mip [ i ] . data ) ;
break ;
case PTI_BGRA8 :
default :
qglTexImage3D ( targface , i , GL_RGBA , size , size , size , 0 , GL_BGRA_EXT , GL_UNSIGNED_INT_8_8_8_8_REV , mips - > mip [ i ] . data ) ;
break ;
2014-10-11 19:39:45 +00:00
case PTI_RGBA4444 :
qglTexImage3D ( targface , i , GL_RGBA , size , size , size , 0 , GL_RGBA , GL_UNSIGNED_SHORT_4_4_4_4 , mips - > mip [ i ] . data ) ;
break ;
case PTI_RGBA5551 :
qglTexImage3D ( targface , i , GL_RGBA , size , size , size , 0 , GL_RGBA , GL_UNSIGNED_SHORT_5_5_5_1 , mips - > mip [ i ] . data ) ;
break ;
case PTI_RGB565 :
qglTexImage3D ( targface , i , GL_RGB , size , size , size , 0 , GL_RGB , GL_UNSIGNED_SHORT_5_6_5 , mips - > mip [ i ] . data ) ;
break ;
2005-01-28 04:28:07 +00:00
}
2014-10-05 20:04:11 +00:00
}
}
else
{
//2d or cubemaps
for ( i = 0 ; i < mips - > mipcount ; i + + )
{
if ( tex - > flags & IF_TEXTYPE )
2005-01-28 04:28:07 +00:00
{
2014-10-05 20:04:11 +00:00
targface = cubeface [ i ] ;
j = 0 ;
2005-01-28 04:28:07 +00:00
}
2014-10-05 20:04:11 +00:00
else
2005-01-28 04:28:07 +00:00
{
2014-10-05 20:04:11 +00:00
targface = targ ;
j = i ;
2005-01-28 04:28:07 +00:00
}
2014-10-05 20:04:11 +00:00
switch ( mips - > encoding )
2005-01-28 04:28:07 +00:00
{
2015-04-21 04:12:00 +00:00
# ifdef FTE_TARGET_WEB
case PTI_WHOLEFILE :
if ( ! i )
emscriptenfte_gl_loadtexturefile ( tex - > num , & tex - > width , & tex - > height , mips - > mip [ i ] . data , mips - > mip [ i ] . datasize ) ;
break ;
# endif
2015-02-02 08:01:53 +00:00
case PTI_DEPTH16 :
qglTexImage2D ( targface , j , gl_config . gles ? GL_DEPTH_COMPONENT : GL_DEPTH_COMPONENT16_ARB , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_DEPTH_COMPONENT , GL_UNSIGNED_SHORT , mips - > mip [ i ] . data ) ;
break ;
case PTI_DEPTH24 :
qglTexImage2D ( targface , j , gl_config . gles ? GL_DEPTH_COMPONENT : GL_DEPTH_COMPONENT24_ARB , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_DEPTH_COMPONENT , GL_UNSIGNED_SHORT , mips - > mip [ i ] . data ) ;
break ;
case PTI_DEPTH32 :
qglTexImage2D ( targface , j , gl_config . gles ? GL_DEPTH_COMPONENT : GL_DEPTH_COMPONENT32_ARB , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_DEPTH_COMPONENT , GL_UNSIGNED_INT , mips - > mip [ i ] . data ) ;
break ;
case PTI_DEPTH24_8 :
qglTexImage2D ( targface , j , GL_DEPTH24_STENCIL8_EXT , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_DEPTH_STENCIL_EXT , GL_UNSIGNED_INT_24_8_EXT , mips - > mip [ i ] . data ) ;
break ;
2014-10-11 19:39:45 +00:00
//32bit formats
2014-10-05 20:04:11 +00:00
case PTI_RGBX8 :
qglTexImage2D ( targface , j , GL_RGB , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , mips - > mip [ i ] . data ) ;
break ;
case PTI_RGBA8 :
qglTexImage2D ( targface , j , GL_RGBA , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , mips - > mip [ i ] . data ) ;
break ;
case PTI_BGRX8 :
qglTexImage2D ( targface , j , GL_RGB , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_BGRA_EXT , GL_UNSIGNED_INT_8_8_8_8_REV , mips - > mip [ i ] . data ) ;
break ;
case PTI_BGRA8 :
default :
qglTexImage2D ( targface , j , GL_RGBA , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_BGRA_EXT , GL_UNSIGNED_INT_8_8_8_8_REV , mips - > mip [ i ] . data ) ;
break ;
2014-11-01 09:09:58 +00:00
case PTI_RGBA16F :
qglTexImage2D ( targface , j , GL_RGBA16F_ARB , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , mips - > mip [ i ] . data ) ;
break ;
case PTI_RGBA32F :
qglTexImage2D ( targface , j , GL_RGBA32F_ARB , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , mips - > mip [ i ] . data ) ;
break ;
2014-10-11 19:39:45 +00:00
//16bit formats
case PTI_RGBA4444 :
qglTexImage2D ( targface , j , GL_RGBA , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_RGBA , GL_UNSIGNED_SHORT_4_4_4_4 , mips - > mip [ i ] . data ) ;
break ;
case PTI_RGBA5551 :
qglTexImage2D ( targface , j , GL_RGBA , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_RGBA , GL_UNSIGNED_SHORT_5_5_5_1 , mips - > mip [ i ] . data ) ;
break ;
case PTI_ARGB4444 :
qglTexImage2D ( targface , j , GL_RGBA , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_BGRA_EXT , GL_UNSIGNED_SHORT_4_4_4_4_REV , mips - > mip [ i ] . data ) ;
break ;
case PTI_ARGB1555 :
qglTexImage2D ( targface , j , GL_RGBA , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_BGRA_EXT , GL_UNSIGNED_SHORT_1_5_5_5_REV , mips - > mip [ i ] . data ) ;
break ;
case PTI_RGB565 :
qglTexImage2D ( targface , j , GL_RGB , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , GL_RGB , GL_UNSIGNED_SHORT_5_6_5 , mips - > mip [ i ] . data ) ;
break ;
//compressed formats
2014-10-05 20:04:11 +00:00
case PTI_S3RGB1 :
qglCompressedTexImage2DARB ( targface , j , GL_COMPRESSED_RGB_S3TC_DXT1_EXT , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , mips - > mip [ i ] . datasize , mips - > mip [ i ] . data ) ;
break ;
case PTI_S3RGBA1 :
qglCompressedTexImage2DARB ( targface , j , GL_COMPRESSED_RGBA_S3TC_DXT1_EXT , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , mips - > mip [ i ] . datasize , mips - > mip [ i ] . data ) ;
break ;
case PTI_S3RGBA3 :
qglCompressedTexImage2DARB ( targface , j , GL_COMPRESSED_RGBA_S3TC_DXT3_EXT , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , mips - > mip [ i ] . datasize , mips - > mip [ i ] . data ) ;
break ;
case PTI_S3RGBA5 :
qglCompressedTexImage2DARB ( targface , j , GL_COMPRESSED_RGBA_S3TC_DXT5_EXT , mips - > mip [ i ] . width , mips - > mip [ i ] . height , 0 , mips - > mip [ i ] . datasize , mips - > mip [ i ] . data ) ;
break ;
2005-01-28 04:28:07 +00:00
}
}
2014-10-05 20:04:11 +00:00
}
2005-01-28 04:28:07 +00:00
2014-10-05 20:04:11 +00:00
return true ;
}
2005-01-28 04:28:07 +00:00
2014-10-05 20:04:11 +00:00
void GL_UpdateFiltering ( image_t * imagelist , int filtermip [ 3 ] , int filterpic [ 3 ] , int mipcap [ 2 ] , float anis )
2004-08-22 22:29:09 +00:00
{
2014-10-05 20:04:11 +00:00
int targ ;
image_t * img ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
gl_mipcap_min = mipcap [ 0 ] ;
gl_mipcap_max = mipcap [ 1 ] ;
2005-01-28 04:28:07 +00:00
2014-10-05 20:04:11 +00:00
VectorCopy ( filterpic , gl_filter_pic ) ;
VectorCopy ( filtermip , gl_filter_mip ) ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
//bound carefully, so that we get 0 if anisrophy is not supported at all (1 is fine). we can then test against 0 (which is an otherwise-invalid value) avoiding gl errors.
if ( anis > gl_config . ext_texture_filter_anisotropic )
gl_anisotropy_factor = gl_config . ext_texture_filter_anisotropic ;
else if ( anis < 1 )
gl_anisotropy_factor = 1 ;
2004-08-22 22:29:09 +00:00
else
2014-10-05 20:04:11 +00:00
gl_anisotropy_factor = anis ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
// change all the existing mipmap texture objects
for ( img = imagelist ; img ; img = img - > next )
2004-08-22 22:29:09 +00:00
{
2015-02-02 08:01:53 +00:00
if ( img - > status ! = TEX_LOADED )
continue ;
2014-10-05 20:04:11 +00:00
switch ( ( img - > flags & IF_TEXTYPE ) > > IF_TEXTYPESHIFT )
2004-08-22 22:29:09 +00:00
{
2014-10-05 20:04:11 +00:00
case 0 :
targ = GL_TEXTURE_2D ;
2004-08-22 22:29:09 +00:00
break ;
2014-10-05 20:04:11 +00:00
case 1 :
targ = GL_TEXTURE_3D ;
2004-08-22 22:29:09 +00:00
break ;
2014-10-05 20:04:11 +00:00
default :
targ = GL_TEXTURE_CUBE_MAP_ARB ;
2004-08-22 22:29:09 +00:00
break ;
}
2014-10-05 20:04:11 +00:00
GL_MTBind ( 0 , targ , img ) ;
GL_Texturemode_Apply ( targ , img - > flags ) ;
2004-08-22 22:29:09 +00:00
2014-10-05 20:04:11 +00:00
//should we do dynamic mipcap settings? this bugs out ATI.
/*
if ( ! gl_config . gles & & ( tex - > flags & IF_MIPCAP ) )
2004-10-10 06:32:29 +00:00
{
2014-10-05 20:04:11 +00:00
qglTexParameteri ( targ , GL_TEXTURE_BASE_LEVEL , gl_mipcap_min ) ;
qglTexParameteri ( targ , GL_TEXTURE_MAX_LEVEL , gl_mipcap_max ) ;
2004-10-10 06:32:29 +00:00
}
2014-10-05 20:04:11 +00:00
*/
2004-08-22 22:29:09 +00:00
}
}
2005-01-12 08:38:31 +00:00
# endif