diff --git a/Makefile b/Makefile index 68bccf67..ded6db2d 100755 --- a/Makefile +++ b/Makefile @@ -161,7 +161,9 @@ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ -Wall -pipe -g -fwrapv CFLAGS += $(OSX_ARCH) else -CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ +#CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \ + -Wall -pipe -g -ggdb -MMD -fwrapv +CFLAGS := -O0 -fno-strict-aliasing \ -Wall -pipe -g -ggdb -MMD -fwrapv endif @@ -841,10 +843,14 @@ endif # ---------- REFGL3_OBJS_ := \ - src/client/refresh/gl3/gl3_main.o \ - src/client/refresh/gl3/gl3_sdl.o \ src/client/refresh/gl3/gl3_draw.o \ + src/client/refresh/gl3/gl3_image.o \ + src/client/refresh/gl3/gl3_main.o \ + src/client/refresh/gl3/gl3_misc.o \ + src/client/refresh/gl3/gl3_model.o \ + src/client/refresh/gl3/gl3_sdl.o \ src/client/refresh/files/pcx.o \ + src/client/refresh/files/stb.o \ src/common/shared/flash.o \ src/common/shared/rand.o \ src/common/shared/shared.o @@ -854,7 +860,6 @@ REFGL3_TODO_ := \ src/client/refresh/files/md2.o \ src/client/refresh/files/pcx.o \ src/client/refresh/files/sp2.o \ - src/client/refresh/files/stb.o \ src/client/refresh/files/wal.o # TODO: glad_dbg support diff --git a/src/client/refresh/files/pcx.c b/src/client/refresh/files/pcx.c index f0527072..02a25936 100644 --- a/src/client/refresh/files/pcx.c +++ b/src/client/refresh/files/pcx.c @@ -24,7 +24,7 @@ * ======================================================================= */ -#include "../gl/header/local.h" +#include "../ref_shared.h" void LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height) diff --git a/src/client/refresh/gl/header/local.h b/src/client/refresh/gl/header/local.h index 58df1d3d..8715a566 100644 --- a/src/client/refresh/gl/header/local.h +++ b/src/client/refresh/gl/header/local.h @@ -31,9 +31,10 @@ #include #include -#include "../../../header/ref.h" +#include "../../ref_shared.h" #include "qgl.h" + #ifndef GL_COLOR_INDEX8_EXT #define GL_COLOR_INDEX8_EXT GL_COLOR_INDEX #endif @@ -81,24 +82,6 @@ extern viddef_t vid; -/* - * skins will be outline flood filled and mip mapped - * pics and sprites with alpha will be outline flood filled - * pic won't be mip mapped - * - * model skin - * sprite frame - * wall texture - * pic - */ -typedef enum -{ - it_skin, - it_sprite, - it_wall, - it_pic, - it_sky -} imagetype_t; enum stereo_modes { STEREO_MODE_NONE, @@ -300,10 +283,8 @@ int Draw_GetPalette(void); void R_ResampleTexture(unsigned *in, int inwidth, int inheight, unsigned *out, int outwidth, int outheight); -void LoadPCX(char *filename, byte **pic, byte **palette, - int *width, int *height); image_t *LoadWal(char *name); -qboolean LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height); + void GetWalInfo(char *name, int *width, int *height); void GetPCXInfo(char *filename, int *width, int *height); image_t *R_LoadPic(char *name, byte *pic, int width, int realwidth, @@ -408,6 +389,4 @@ void RI_ShutdownWindow(qboolean contextOnly); */ void *GLimp_GetProcAddress (const char* proc); -void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 2, 3))); - #endif diff --git a/src/client/refresh/gl/r_image.c b/src/client/refresh/gl/r_image.c index e2733c38..6b9fbd50 100644 --- a/src/client/refresh/gl/r_image.c +++ b/src/client/refresh/gl/r_image.c @@ -880,7 +880,7 @@ R_LoadPic(char *name, byte *pic, int width, int realwidth, qboolean nolerp = false; - cvar_t* nolerp_var = ri.Cvar_Get("gl_nolerp_list", NULL, 0); + cvar_t* nolerp_var = ri.Cvar_Get("gl_nolerp_list", NULL, 0); // FIXME: isn't this cached somewhere?! if(nolerp_var != NULL && nolerp_var->string != NULL) { nolerp = strstr(nolerp_var->string, name) != NULL; @@ -1270,7 +1270,7 @@ R_InitImages(void) gl_state.inverse_intensity = 1 / intensity->value; - Draw_GetPalette(); + Draw_GetPalette(); // FIXME: I think this is redundant - RI_Init() already calls that! if (gl_config.palettedtexture) { diff --git a/src/client/refresh/gl3/gl3_draw.c b/src/client/refresh/gl3/gl3_draw.c index 315a835a..2ee460c8 100644 --- a/src/client/refresh/gl3/gl3_draw.c +++ b/src/client/refresh/gl3/gl3_draw.c @@ -29,6 +29,20 @@ unsigned d_8to24table[256]; +static cvar_t *gl_nolerp_list; + +gl3image_t *draw_chars; + +void +GL3_Draw_InitLocal(void) +{ + /* don't bilerp characters and crosshairs */ + gl_nolerp_list = ri.Cvar_Get("gl_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", 0); + + /* load console characters */ + draw_chars = GL3_FindImage("pics/conchars.pcx", it_pic); +} + int GL3_Draw_GetPalette(void) { @@ -63,3 +77,5 @@ GL3_Draw_GetPalette(void) return 0; } + + diff --git a/src/client/refresh/gl3/gl3_image.c b/src/client/refresh/gl3/gl3_image.c new file mode 100644 index 00000000..3238004f --- /dev/null +++ b/src/client/refresh/gl3/gl3_image.c @@ -0,0 +1,369 @@ +/* + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (C) 2016 Daniel Gibson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Texture handling for OpenGL3 + * + * ======================================================================= + */ + +#include "header/local.h" + +typedef struct +{ + char *name; + int minimize, maximize; +} glmode_t; + +glmode_t modes[] = { + {"GL_NEAREST", GL_NEAREST, GL_NEAREST}, + {"GL_LINEAR", GL_LINEAR, GL_LINEAR}, + {"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST}, + {"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR}, + {"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST}, + {"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR} +}; + +int gl_filter_min = GL_LINEAR_MIPMAP_NEAREST; +int gl_filter_max = GL_LINEAR; + +void +GL3_TextureMode(char *string) +{ + const int num_modes = sizeof(modes)/sizeof(modes[0]); + int i; + + for (i = 0; i < num_modes; i++) + { + if (!Q_stricmp(modes[i].name, string)) + { + break; + } + } + + if (i == num_modes) + { + R_Printf(PRINT_ALL, "bad filter name\n"); + return; + } + + gl_filter_min = modes[i].minimize; + gl_filter_max = modes[i].maximize; + + /* clamp selected anisotropy */ + if (gl3config.anisotropic) + { + if (gl_anisotropic->value > gl3config.max_anisotropy) + { + ri.Cvar_SetValue("gl_anisotropic", gl3config.max_anisotropy); + } + else if (gl_anisotropic->value < 1.0) + { + ri.Cvar_SetValue("gl_anisotropic", 1.0); + } + } + else + { + ri.Cvar_SetValue("gl_anisotropic", 0.0); + } + +#if 0 // TODO! + image_t *glt; + + /* change all the existing mipmap texture objects */ + for (i = 0, glt = gltextures; i < numgltextures; i++, glt++) + { + if ((glt->type != it_pic) && (glt->type != it_sky)) + { + R_Bind(glt->texnum); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + gl_filter_min); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + gl_filter_max); + + /* Set anisotropic filter if supported and enabled */ + if (gl_config.anisotropic && gl_anisotropic->value) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, + gl_anisotropic->value); + } + } + } +#endif // 0 +} + +/* + * Finds or loads the given image + */ +gl3image_t * +GL3_FindImage(char *name, imagetype_t type) +{ +#if 0 + gl3image_t *image; + int i, len; + byte *pic, *palette; + int width, height; + char *ptr; + char namewe[256]; + int realwidth = 0, realheight = 0; + const char* ext; + + if (!name) + { + return NULL; + } + + ext = COM_FileExtension(name); + if(!ext[0]) + { + /* file has no extension */ + return NULL; + } + + len = strlen(name); + + /* Remove the extension */ + memset(namewe, 0, 256); + memcpy(namewe, name, len - 4); + + if (len < 5) + { + return NULL; + } + + /* fix backslashes */ + while ((ptr = strchr(name, '\\'))) + { + *ptr = '/'; + } + + /* look for it */ + for (i = 0, image = gltextures; i < numgltextures; i++, image++) + { + if (!strcmp(name, image->name)) + { + image->registration_sequence = registration_sequence; + return image; + } + } + + /* load the pic from disk */ + pic = NULL; + palette = NULL; + + if (strcmp(ext, "pcx") == 0) + { + if (gl_retexturing->value) + { + GetPCXInfo(name, &realwidth, &realheight); + if(realwidth == 0) + { + /* No texture found */ + return NULL; + } + + /* try to load a tga, png or jpg (in that order/priority) */ + if ( LoadSTB(namewe, "tga", &pic, &width, &height) + || LoadSTB(namewe, "png", &pic, &width, &height) + || LoadSTB(namewe, "jpg", &pic, &width, &height) ) + { + /* upload tga or png or jpg */ + image = R_LoadPic(name, pic, width, realwidth, height, + realheight, type, 32); + } + else + { + /* PCX if no TGA/PNG/JPEG available (exists always) */ + LoadPCX(name, &pic, &palette, &width, &height); + + if (!pic) + { + /* No texture found */ + return NULL; + } + + /* Upload the PCX */ + image = R_LoadPic(name, pic, width, 0, height, 0, type, 8); + } + } + else /* gl_retexture is not set */ + { + LoadPCX(name, &pic, &palette, &width, &height); + + if (!pic) + { + return NULL; + } + + image = R_LoadPic(name, pic, width, 0, height, 0, type, 8); + } + } + else if (strcmp(ext, "wal") == 0) + { + if (gl_retexturing->value) + { + /* Get size of the original texture */ + GetWalInfo(name, &realwidth, &realheight); + if(realwidth == 0) + { + /* No texture found */ + return NULL; + } + + /* try to load a tga, png or jpg (in that order/priority) */ + if ( LoadSTB(namewe, "tga", &pic, &width, &height) + || LoadSTB(namewe, "png", &pic, &width, &height) + || LoadSTB(namewe, "jpg", &pic, &width, &height) ) + { + /* upload tga or png or jpg */ + image = R_LoadPic(name, pic, width, realwidth, height, + realheight, type, 32); + } + else + { + /* WAL if no TGA/PNG/JPEG available (exists always) */ + image = LoadWal(namewe); + } + + if (!image) + { + /* No texture found */ + return NULL; + } + } + else /* gl_retexture is not set */ + { + image = LoadWal(name); + + if (!image) + { + /* No texture found */ + return NULL; + } + } + } + else if (strcmp(ext, "tga") == 0 || strcmp(ext, "png") == 0 || strcmp(ext, "jpg") == 0) + { + char tmp_name[256]; + + realwidth = 0; + realheight = 0; + + strcpy(tmp_name, namewe); + strcat(tmp_name, ".wal"); + GetWalInfo(tmp_name, &realwidth, &realheight); + + if (realwidth == 0 || realheight == 0) { + /* It's a sky or model skin. */ + strcpy(tmp_name, namewe); + strcat(tmp_name, ".pcx"); + GetPCXInfo(tmp_name, &realwidth, &realheight); + } + + /* TODO: not sure if not having realwidth/heigth is bad - a tga/png/jpg + * was requested, after all, so there might be no corresponding wal/pcx? + * if (realwidth == 0 || realheight == 0) return NULL; + */ + + LoadSTB(name, ext, &pic, &width, &height); + image = R_LoadPic(name, pic, width, realwidth, + height, realheight, type, 32); + } + else + { + return NULL; + } + + if (pic) + { + free(pic); + } + + if (palette) + { + free(palette); + } + + return image; +#endif // 0 + return NULL; +} + +gl3image_t * +GL3_RegisterSkin(char *name) +{ + return GL3_FindImage(name, it_skin); +} + + + +void +GL3_ImageList_f(void) +{ + R_Printf(PRINT_ALL, "TODO: Implement R_ImageList_f()\n"); +#if 0 // TODO! + int i; + image_t *image; + int texels; + const char *palstrings[2] = { + "RGB", + "PAL" + }; + + R_Printf(PRINT_ALL, "------------------\n"); + texels = 0; + + for (i = 0, image = gltextures; i < numgltextures; i++, image++) + { + if (image->texnum <= 0) + { + continue; + } + + texels += image->upload_width * image->upload_height; + + switch (image->type) + { + case it_skin: + R_Printf(PRINT_ALL, "M"); + break; + case it_sprite: + R_Printf(PRINT_ALL, "S"); + break; + case it_wall: + R_Printf(PRINT_ALL, "W"); + break; + case it_pic: + R_Printf(PRINT_ALL, "P"); + break; + default: + R_Printf(PRINT_ALL, " "); + break; + } + + R_Printf(PRINT_ALL, " %3i %3i %s: %s\n", + image->upload_width, image->upload_height, + palstrings[image->paletted], image->name); + } + + R_Printf(PRINT_ALL, "Total texel count (not counting mipmaps): %i\n", texels); +#endif +} diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index aa99cb89..3ec07b25 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -27,7 +27,6 @@ #include "../../header/ref.h" #include "header/local.h" -#include "header/qgl.h" // TODO: put this in local.h ? #define REF_VERSION "Yamagi Quake II OpenGL3 Refresher" @@ -47,9 +46,29 @@ cvar_t *gl_mode; cvar_t *gl_customwidth; cvar_t *gl_customheight; cvar_t *vid_gamma; +cvar_t *gl_anisotropic; cvar_t *gl3_debugcontext; +static void +GL3_Strings(void) +{ + GLint i, numExtensions; + R_Printf(PRINT_ALL, "GL_VENDOR: %s\n", gl3config.vendor_string); + R_Printf(PRINT_ALL, "GL_RENDERER: %s\n", gl3config.renderer_string); + R_Printf(PRINT_ALL, "GL_VERSION: %s\n", gl3config.version_string); + R_Printf(PRINT_ALL, "GL_SHADING_LANGUAGE_VERSION: %s\n", gl3config.glsl_version_string); + + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + + R_Printf(PRINT_ALL, "GL_EXTENSIONS:"); + for(i = 0; i < numExtensions; i++) + { + R_Printf(PRINT_ALL, " %s", (const char*)glGetStringi(GL_EXTENSIONS, i)); + } + R_Printf(PRINT_ALL, "\n"); +} + static void GL3_Register(void) { @@ -60,9 +79,12 @@ GL3_Register(void) gl_mode = ri.Cvar_Get("gl_mode", "4", CVAR_ARCHIVE); gl_customwidth = ri.Cvar_Get("gl_customwidth", "1024", CVAR_ARCHIVE); gl_customheight = ri.Cvar_Get("gl_customheight", "768", CVAR_ARCHIVE); + gl_anisotropic = ri.Cvar_Get("gl_anisotropic", "0", CVAR_ARCHIVE); + vid_fullscreen = ri.Cvar_Get("vid_fullscreen", "0", CVAR_ARCHIVE); vid_gamma = ri.Cvar_Get("vid_gamma", "1.0", CVAR_ARCHIVE); + #if 0 // TODO! gl_lefthand = ri.Cvar_Get("hand", "0", CVAR_USERINFO | CVAR_ARCHIVE); gl_farsee = ri.Cvar_Get("gl_farsee", "0", CVAR_LATCH | CVAR_ARCHIVE); @@ -105,7 +127,7 @@ GL3_Register(void) gl_texturemode = ri.Cvar_Get("gl_texturemode", "GL_LINEAR_MIPMAP_NEAREST", CVAR_ARCHIVE); gl_texturealphamode = ri.Cvar_Get("gl_texturealphamode", "default", CVAR_ARCHIVE); gl_texturesolidmode = ri.Cvar_Get("gl_texturesolidmode", "default", CVAR_ARCHIVE); - gl_anisotropic = ri.Cvar_Get("gl_anisotropic", "0", CVAR_ARCHIVE); + //gl_anisotropic = ri.Cvar_Get("gl_anisotropic", "0", CVAR_ARCHIVE); gl_lockpvs = ri.Cvar_Get("gl_lockpvs", "0", 0); gl_palettedtexture = ri.Cvar_Get("gl_palettedtexture", "0", CVAR_ARCHIVE); @@ -130,12 +152,12 @@ GL3_Register(void) gl_stereo_separation = ri.Cvar_Get( "gl_stereo_separation", "-0.4", CVAR_ARCHIVE ); gl_stereo_anaglyph_colors = ri.Cvar_Get( "gl_stereo_anaglyph_colors", "rc", CVAR_ARCHIVE ); gl_stereo_convergence = ri.Cvar_Get( "gl_stereo_convergence", "1", CVAR_ARCHIVE ); - - ri.Cmd_AddCommand("imagelist", R_ImageList_f); - ri.Cmd_AddCommand("screenshot", R_ScreenShot); - ri.Cmd_AddCommand("modellist", Mod_Modellist_f); - ri.Cmd_AddCommand("gl_strings", R_Strings); #endif // 0 + + ri.Cmd_AddCommand("imagelist", GL3_ImageList_f); + ri.Cmd_AddCommand("screenshot", GL3_ScreenShot); + ri.Cmd_AddCommand("modellist", GL3_Mod_Modellist_f); + ri.Cmd_AddCommand("gl_strings", GL3_Strings); } /* @@ -239,17 +261,16 @@ GL3_SetMode(void) static qboolean GL3_Init(void) { + /* TODO! int j; extern float r_turbsin[256]; - - Swap_Init(); // FIXME: for fucks sake, this doesn't have to be done at runtime! - - /* TODO! for (j = 0; j < 256; j++) { r_turbsin[j] *= 0.5; }*/ + Swap_Init(); // FIXME: for fucks sake, this doesn't have to be done at runtime! + /* Options */ R_Printf(PRINT_ALL, "Refresher build options:\n"); @@ -286,33 +307,13 @@ GL3_Init(void) ri.Vid_MenuInit(); /* get our various GL strings */ - R_Printf(PRINT_ALL, "\nOpenGL setting:\n"); - gl3config.vendor_string = (const char*)glGetString(GL_VENDOR); - R_Printf(PRINT_ALL, "GL_VENDOR: %s\n", gl3config.vendor_string); - gl3config.renderer_string = (const char*)glGetString(GL_RENDERER); - R_Printf(PRINT_ALL, "GL_RENDERER: %s\n", gl3config.renderer_string); - gl3config.version_string = (const char*)glGetString(GL_VERSION); - R_Printf(PRINT_ALL, "GL_VERSION: %s\n", gl3config.version_string); + gl3config.glsl_version_string = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); - gl3config.version_string = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION); - R_Printf(PRINT_ALL, "GL_SHADING_LANGUAGE_VERSION: %s\n", gl3config.version_string); - - //gl3config.extensions_string = (const char*)glGetString(GL_EXTENSIONS); - //R_Printf(PRINT_ALL, "GL_EXTENSIONS: %s\n", gl3config.extensions_string); - { - GLint i, numExtensions; - glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); - - R_Printf(PRINT_ALL, "GL_EXTENSIONS:"); - for(i = 0; i < numExtensions; i++) - { - R_Printf(PRINT_ALL, " %s", (const char*)glGetStringi(GL_EXTENSIONS, i)); - } - R_Printf(PRINT_ALL, "\n"); - } + R_Printf(PRINT_ALL, "\nOpenGL setting:\n"); + GL3_Strings(); /* if (gl_config.major_version < 3) @@ -363,18 +364,22 @@ GL3_Init(void) R_Printf(PRINT_ALL, " - OpenGL Debug Output: Not Supported\n"); } -#if 0 - R_SetDefaultState(); - R_InitImages(); + GL3_SetDefaultState(); + + STUB("TODO: Some intensity and gamma stuff that was in R_InitImages()"); + +#if 0 + //R_InitImages(); - most of the things in R_InitImages() shouldn't be needed anymore Mod_Init(); R_InitParticleTexture(); - Draw_InitLocal(); - - return true; // -1 is error, other values don't matter. FIXME: mabe make this return bool.. #endif // 0 + GL3_Draw_InitLocal(); + R_Printf(PRINT_ALL, "\n"); + return true; // -1 is error, other values don't matter. FIXME: mabe make this return bool.. + return false; } @@ -412,7 +417,7 @@ GetRefAPI(refimport_t imp) re.PrepareForWindow = GL3_PrepareForWindow; re.InitContext = GL3_InitContext; re.ShutdownWindow = GL3_ShutdownWindow; - /* TODO! +#if 0 // TODO! re.BeginRegistration = RI_BeginRegistration; re.RegisterModel = RI_RegisterModel; re.RegisterSkin = RI_RegisterSkin; @@ -438,7 +443,7 @@ GetRefAPI(refimport_t imp) re.SetPalette = RI_SetPalette; re.BeginFrame = RI_BeginFrame; - */ +#endif // 0 re.EndFrame = GL3_EndFrame; return re; diff --git a/src/client/refresh/gl3/gl3_misc.c b/src/client/refresh/gl3/gl3_misc.c new file mode 100644 index 00000000..3b5d4471 --- /dev/null +++ b/src/client/refresh/gl3/gl3_misc.c @@ -0,0 +1,174 @@ +/* + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (C) 2016 Daniel Gibson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Misc OpenGL3 refresher functions + * + * ======================================================================= + */ + +#include "header/local.h" + +void +GL3_SetDefaultState(void) +{ + glClearColor(1, 0, 0.5, 0.5); + glDisable(GL_MULTISAMPLE); + glCullFace(GL_FRONT); + glEnable(GL_TEXTURE_2D); + + //glEnable(GL_ALPHA_TEST); + //glAlphaFunc(GL_GREATER, 0.666); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_CULL_FACE); + glDisable(GL_BLEND); + + //glColor4f(1, 1, 1, 1); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + //glShadeModel(GL_FLAT); + + //GL3_TextureMode(gl_texturemode->string); + STUB("call GL3_TextureMode(gl_texturemode->string);"); + STUB("Use gl_texturealphamode and somehow or only support one mode? => R_TextureAlphaMode(), R_TextureSolidMode()"); + //R_TextureAlphaMode(gl_texturealphamode->string); + //R_TextureSolidMode(gl_texturesolidmode->string); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_min); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + STUB("need replacement for R_TexEnv(GL_REPLACE);"); + + STUB("Apparently the GL_POINT stuff works differently in OpenGL3 core"); +#if 0 + { + // TODO: are we gonna use glPointParameter? + float attenuations[3] = {0.01f, 0.0f, 0.01f}; + /* + attenuations[0] = gl_particle_att_a->value; + attenuations[1] = gl_particle_att_b->value; + attenuations[2] = gl_particle_att_c->value; + */ + STUB("gl_particle_att_[abc], gl_particle_min/max_size ??"); + + /* GL_POINT_SMOOTH is not implemented by some OpenGL + drivers, especially the crappy Mesa3D backends like + i915.so. That the points are squares and not circles + is not a problem by Quake II! */ + glEnable(GL_POINT_SMOOTH); + glPointParameterf(GL_POINT_SIZE_MIN_EXT, 2.0f); // TODO was gl_particle_min_size->value); + glPointParameterf(GL_POINT_SIZE_MAX_EXT, 40.0f); // TODO was gl_particle_max_size->value); + glPointParameterf(GL_DISTANCE_ATTENUATION_EXT, attenuations); + } +#endif // 0 + + if (gl_msaa_samples->value) + { + glEnable(GL_MULTISAMPLE); + // glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST); TODO what is this for? + } +} + +void +GL3_ScreenShot(void) +{ + byte *buffer; + char picname[80]; + char checkname[MAX_OSPATH]; + int i, c; + FILE *f; + + /* FS_InitFilesystem() made sure the screenshots dir exists */ + + /* find a file name to save it to */ + strcpy(picname, "quake00.tga"); + + for (i = 0; i <= 99; i++) + { + picname[5] = i / 10 + '0'; + picname[6] = i % 10 + '0'; + Com_sprintf(checkname, sizeof(checkname), "%s/scrnshot/%s", + ri.FS_Gamedir(), picname); + f = fopen(checkname, "rb"); + + if (!f) + { + break; /* file doesn't exist */ + } + + fclose(f); + } + + if (i == 100) + { + R_Printf(PRINT_ALL, "SCR_ScreenShot_f: Couldn't create a file\n"); + return; + } + + static const int headerLength = 18+4; + + c = headerLength + vid.width * vid.height * 3; + + buffer = malloc(c); + if (!buffer) + { + R_Printf(PRINT_ALL, "SCR_ScreenShot_f: Couldn't malloc %d bytes\n", c); + return; + } + + memset(buffer, 0, headerLength); + buffer[0] = 4; // image ID: "yq2\0" + buffer[2] = 2; /* uncompressed type */ + buffer[12] = vid.width & 255; + buffer[13] = vid.width >> 8; + buffer[14] = vid.height & 255; + buffer[15] = vid.height >> 8; + buffer[16] = 24; /* pixel size */ + buffer[17] = 0; // image descriptor + buffer[18] = 'y'; // following: the 4 image ID fields + buffer[19] = 'q'; + buffer[20] = '2'; + buffer[21] = '\0'; + + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glReadPixels(0, 0, vid.width, vid.height, GL_BGR, + GL_UNSIGNED_BYTE, buffer + headerLength); + + f = fopen(checkname, "wb"); + if (f) + { + fwrite(buffer, 1, c, f); + fclose(f); + R_Printf(PRINT_ALL, "Wrote %s\n", picname); + } + else + { + R_Printf(PRINT_ALL, "SCR_ScreenShot_f: Couldn't write %s\n", picname); + } + + free(buffer); +} diff --git a/src/client/refresh/gl3/gl3_model.c b/src/client/refresh/gl3/gl3_model.c new file mode 100644 index 00000000..b1828315 --- /dev/null +++ b/src/client/refresh/gl3/gl3_model.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 1997-2001 Id Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Model loading and caching for OpenGL3. Includes the .bsp file format + * + * ======================================================================= + */ + +#include "header/local.h" + +void +GL3_Mod_Modellist_f(void) +{ +#if 0 // TODO! + int i; + model_t *mod; + int total; + + total = 0; + R_Printf(PRINT_ALL, "Loaded models:\n"); + + for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++) + { + if (!mod->name[0]) + { + continue; + } + + R_Printf(PRINT_ALL, "%8i : %s\n", mod->extradatasize, mod->name); + total += mod->extradatasize; + } + + R_Printf(PRINT_ALL, "Total resident: %i\n", total); +#endif +} diff --git a/src/client/refresh/gl3/gl3_sdl.c b/src/client/refresh/gl3/gl3_sdl.c index bc624550..e753d6a8 100644 --- a/src/client/refresh/gl3/gl3_sdl.c +++ b/src/client/refresh/gl3/gl3_sdl.c @@ -28,7 +28,6 @@ */ -#include "header/qgl.h" #include "header/local.h" #ifdef SDL2 diff --git a/src/client/refresh/gl3/header/local.h b/src/client/refresh/gl3/header/local.h index 61f56db1..eb684d40 100644 --- a/src/client/refresh/gl3/header/local.h +++ b/src/client/refresh/gl3/header/local.h @@ -29,13 +29,29 @@ #ifndef SRC_CLIENT_REFRESH_GL3_HEADER_LOCAL_H_ #define SRC_CLIENT_REFRESH_GL3_HEADER_LOCAL_H_ -#include "../../../header/ref.h" +#ifdef IN_IDE_PARSER + // this is just a hack to get proper auto-completion in IDEs: + // using system headers for their parsers/indexers but glad for real build + // (in glad glFoo is just a #define to glad_glFoo or sth, which screws up autocompletion) + // (you may have to configure your IDE to #define IN_IDE_PARSER, but not for building!) + #define GL_GLEXT_PROTOTYPES 1 + #include + #include +#else + #include +#endif + +#include "../../ref_shared.h" + +#define STUB(msg) \ + R_Printf(PRINT_ALL, "STUB: %s() %s\n", __FUNCTION__, msg ) typedef struct { const char *renderer_string; const char *vendor_string; const char *version_string; + const char *glsl_version_string; //const char *extensions_string; deprecated in GL3 int major_version; @@ -73,19 +89,48 @@ typedef struct //qboolean hwgamma; } gl3state_t; + +typedef struct gl3image_s +{ + // TODO: what of this is actually needed? + char name[MAX_QPATH]; /* game path, including extension */ + imagetype_t type; + int width, height; /* source image */ + int upload_width, upload_height; /* after power of two and picmip */ + int registration_sequence; /* 0 = free */ + struct msurface_s *texturechain; /* for sort-by-texture world drawing */ + int texnum; /* gl texture binding */ + float sl, tl, sh, th; /* 0,0 - 1,1 unless part of the scrap */ + qboolean scrap; + qboolean has_alpha; + + qboolean paletted; +} gl3image_t; + extern gl3config_t gl3config; extern gl3state_t gl3state; +extern viddef_t vid; + +extern int gl_filter_min; +extern int gl_filter_max; + extern int GL3_PrepareForWindow(void); extern int GL3_InitContext(void* win); extern void GL3_EndFrame(void); extern void GL3_ShutdownWindow(qboolean contextOnly); +extern void GL3_ScreenShot(void); +extern void GL3_SetDefaultState(void); + +extern void GL3_Mod_Modellist_f(void); + +extern void GL3_Draw_InitLocal(void); extern int GL3_Draw_GetPalette(void); -extern void R_Printf(int level, const char* msg, ...) __attribute__((format (printf, 2, 3))); - -extern void LoadPCX(char *filename, byte **pic, byte **palette, int *width, int *height); +extern gl3image_t * GL3_FindImage(char *name, imagetype_t type); +extern void GL3_TextureMode(char *string); +extern void GL3_ImageList_f(void); extern cvar_t *gl_msaa_samples; extern cvar_t *gl_swapinterval; @@ -95,6 +140,7 @@ extern cvar_t *gl_mode; extern cvar_t *gl_customwidth; extern cvar_t *gl_customheight; extern cvar_t *vid_gamma; +extern cvar_t *gl_anisotropic; extern cvar_t *gl3_debugcontext; diff --git a/src/client/refresh/gl3/header/qgl.h b/src/client/refresh/gl3/header/qgl.h deleted file mode 100644 index 87af07b5..00000000 --- a/src/client/refresh/gl3/header/qgl.h +++ /dev/null @@ -1,17 +0,0 @@ - -#ifndef SRC_CLIENT_REFRESH_GL3_HEADER_QGL_H_ -#define SRC_CLIENT_REFRESH_GL3_HEADER_QGL_H_ - -// this is just a hack to get proper auto-completion in IDEs: -// using system headers for their parsers/indexers but glad for real build -// (in glad glFoo is just a #define to glad_glFoo or sth, which screws up autocompletion) -// (you may have to configure your IDE to #define IN_IDE_PARSER, but not for building!) -#ifdef IN_IDE_PARSER - #define GL_GLEXT_PROTOTYPES 1 - #include - #include -#else - #include -#endif - -#endif /* SRC_CLIENT_REFRESH_GL3_HEADER_QGL_H_ */ diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h new file mode 100644 index 00000000..f5324a2a --- /dev/null +++ b/src/client/refresh/ref_shared.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 1997-2001 Id Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Header shared between different refreshers (but not with client) + * + * ======================================================================= + */ + +#ifndef SRC_CLIENT_REFRESH_REF_SHARED_H_ +#define SRC_CLIENT_REFRESH_REF_SHARED_H_ + +#include "../header/ref.h" + +/* + * skins will be outline flood filled and mip mapped + * pics and sprites with alpha will be outline flood filled + * pic won't be mip mapped + * + * model skin + * sprite frame + * wall texture + * pic + */ +typedef enum +{ + it_skin, + it_sprite, + it_wall, + it_pic, + it_sky +} imagetype_t; + +extern void R_Printf(int level, const char* msg, ...) __attribute__ ((format (printf, 2, 3))); + +extern void LoadPCX(char *origname, byte **pic, byte **palette, int *width, int *height); +extern void GetPCXInfo(char *filename, int *width, int *height); + +extern qboolean LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height); + +#endif /* SRC_CLIENT_REFRESH_REF_SHARED_H_ */