GL3: Add remaining stubs, add HandMadeMath, update Copyrights

This commit is contained in:
Daniel Gibson 2017-01-08 17:23:32 +01:00
parent 26904949c2
commit 56661fd43f
15 changed files with 3076 additions and 45 deletions

View File

@ -163,7 +163,7 @@ CFLAGS += $(OSX_ARCH)
else
#CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -ggdb -MMD -fwrapv
CFLAGS := -O0 -fno-strict-aliasing \
CFLAGS := -O2 -fno-strict-aliasing \
-Wall -pipe -g -ggdb -MMD -fwrapv
endif
@ -849,6 +849,7 @@ REFGL3_OBJS_ := \
src/client/refresh/gl3/gl3_misc.o \
src/client/refresh/gl3/gl3_model.o \
src/client/refresh/gl3/gl3_sdl.o \
src/client/refresh/gl3/gl3_warp.o \
src/client/refresh/files/pcx.o \
src/client/refresh/files/stb.o \
src/client/refresh/files/wal.o \
@ -862,6 +863,7 @@ REFGL3_TODO_ := \
src/client/refresh/files/pcx.o \
src/client/refresh/files/sp2.o
# TODO: glad_dbg support
REFGL3_OBJS_ += \
src/client/refresh/gl3/glad/src/glad.o

View File

@ -142,7 +142,7 @@ typedef struct
// called by GLimp_InitGraphics() *after* creating window,
// passing the SDL_Window* (void* so we don't spill SDL.h here)
// returns true (1) on success
int (EXPORT *InitContext)(void* window);
int (EXPORT *InitContext)(void* sdl_window);
// shuts down rendering (OpenGL) context, calls
// VID_ShutdownWindow() to shut down window as well, if !contextOnly

View File

@ -147,7 +147,6 @@ typedef struct mleaf_s
} mleaf_t;
/* Whole model */
typedef enum {mod_bad, mod_brush, mod_sprite, mod_alias} modtype_t;
typedef struct model_s
{

View File

@ -1114,6 +1114,8 @@ R_RenderView(refdef_t *fd)
}
switch (gl_state.stereo_mode) {
case STEREO_MODE_NONE:
break;
case STEREO_MODE_ANAGLYPH:
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
break;
@ -1127,7 +1129,8 @@ R_RenderView(refdef_t *fd)
}
}
enum opengl_special_buffer_modes GL_GetSpecialBufferModeForStereoMode(enum stereo_modes stereo_mode) {
enum opengl_special_buffer_modes
GL_GetSpecialBufferModeForStereoMode(enum stereo_modes stereo_mode) {
switch (stereo_mode) {
case STEREO_MODE_NONE:
case STEREO_SPLIT_HORIZONTAL:

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016 Daniel Gibson
* Copyright (C) 2016-2017 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
@ -38,6 +38,42 @@ GL3_Draw_InitLocal(void)
draw_chars = GL3_FindImage("pics/conchars.pcx", it_pic);
}
gl3image_t *
GL3_Draw_FindPic(char *name)
{
gl3image_t *gl;
char fullname[MAX_QPATH];
if ((name[0] != '/') && (name[0] != '\\'))
{
Com_sprintf(fullname, sizeof(fullname), "pics/%s.pcx", name);
gl = GL3_FindImage(fullname, it_pic);
}
else
{
gl = GL3_FindImage(name + 1, it_pic);
}
return gl;
}
void
GL3_Draw_GetPicSize(int *w, int *h, char *pic)
{
gl3image_t *gl;
gl = GL3Draw_FindPic(pic);
if (!gl)
{
*w = *h = -1;
return;
}
*w = gl->width;
*h = gl->height;
}
int
GL3_Draw_GetPalette(void)
{
@ -72,5 +108,3 @@ GL3_Draw_GetPalette(void)
return 0;
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016 Daniel Gibson
* Copyright (C) 2016-2017 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
@ -318,6 +318,8 @@ GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
glGenTextures(1, &texNum);
image->texnum = texNum;
// glActiveTexture(GL_TEXTURE0); TODO: useful if we need >1 texture in the fragment shader
GL3_Bind(texNum);
if (bits == 8)
@ -681,32 +683,109 @@ GL3_RegisterSkin(char *name)
return GL3_FindImage(name, it_skin);
}
/*
* Any image that was not touched on
* this registration sequence
* will be freed.
*/
void
GL3_FreeUnusedImages(void)
{
int i;
gl3image_t *image;
/* never free r_notexture or particle texture */
gl3_notexture->registration_sequence = registration_sequence;
gl3_particletexture->registration_sequence = registration_sequence;
for (i = 0, image = gl3textures; i < numgl3textures; i++, image++)
{
if (image->registration_sequence == registration_sequence)
{
continue; /* used this sequence */
}
if (!image->registration_sequence)
{
continue; /* free image_t slot */
}
if (image->type == it_pic)
{
continue; /* don't free pics */
}
/* free it */
glDeleteTextures(1, &image->texnum);
memset(image, 0, sizeof(*image));
}
}
void
GL3_ShutdownImages(void)
{
int i;
gl3image_t *image;
for (i = 0, image = gl3textures; i < numgl3textures; i++, image++)
{
if (!image->registration_sequence)
{
continue; /* free image_t slot */
}
/* free it */
glDeleteTextures(1, &image->texnum);
memset(image, 0, sizeof(*image));
}
}
static qboolean IsNPOT(int v)
{
unsigned int uv = v;
// just try all the power of two values between 1 and 1 << 15 (32k)
for(unsigned int i=0; i<16; ++i)
{
unsigned int pot = (1u << i);
if(uv & pot)
{
return uv != pot;
}
}
return true;
}
void
GL3_ImageList_f(void)
{
R_Printf(PRINT_ALL, "TODO: Implement R_ImageList_f()\n");
int i;
int i, texels=0;
gl3image_t *image;
int texels;
const char *formatstrings[2] = {
"RGB ",
"RGBA"
};
const char* potstrings[2] = {
" POT", "NPOT"
};
R_Printf(PRINT_ALL, "------------------\n");
texels = 0;
for (i = 0, image = gl3textures; i < numgl3textures; i++, image++)
{
int w, h;
qboolean isNPOT = false;
if (image->texnum == 0)
{
continue;
}
w = image->upload_width;
h = image->upload_height;
texels += image->upload_width * image->upload_height;
isNPOT = IsNPOT(w) || IsNPOT(h);
texels += w*h;
switch (image->type)
{
@ -727,9 +806,8 @@ GL3_ImageList_f(void)
break;
}
R_Printf(PRINT_ALL, " %3i %3i %s: %s\n",
image->upload_width, image->upload_height,
formatstrings[image->has_alpha], image->name);
R_Printf(PRINT_ALL, " %3i %3i %s %s: %s\n", w, h,
formatstrings[image->has_alpha], potstrings[isNPOT], image->name);
}
R_Printf(PRINT_ALL, "Total texel count (not counting mipmaps): %i\n", texels);

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016 Daniel Gibson
* Copyright (C) 2016-2017 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
@ -25,6 +25,9 @@
* =======================================================================
*/
#define HANDMADE_MATH_IMPLEMENTATION
#include "header/HandmadeMath.h"
#include "../../header/ref.h"
#include "header/local.h"
@ -36,8 +39,13 @@ refimport_t ri;
gl3config_t gl3config;
gl3state_t gl3state;
/* screen size info */
refdef_t gl3_newrefdef;
viddef_t vid;
int gl3_viewcluster, gl3_viewcluster2, gl3_oldviewcluster, gl3_oldviewcluster2;
cvar_t *gl_msaa_samples;
cvar_t *gl_swapinterval;
cvar_t *gl_retexturing;
@ -378,10 +386,8 @@ GL3_Init(void)
STUB("TODO: Some intensity and gamma stuff that was in R_InitImages()");
registration_sequence = 1; // also from R_InitImages()
#if 0
//R_InitImages(); - most of the things in R_InitImages() shouldn't be needed anymore
Mod_Init();
#endif // 0
GL3_Mod_Init();
GL3_InitParticleTexture();
@ -389,28 +395,326 @@ GL3_Init(void)
R_Printf(PRINT_ALL, "\n");
return true;
}
void
GL3_Shutdown(void)
{
ri.Cmd_RemoveCommand("modellist");
ri.Cmd_RemoveCommand("screenshot");
ri.Cmd_RemoveCommand("imagelist");
ri.Cmd_RemoveCommand("gl_strings");
#if 0 // TODO!
Mod_FreeAll();
R_ShutdownImages();
#endif // 0
GL3_Mod_FreeAll();
GL3_ShutdownImages();
/* shutdown OS specific OpenGL stuff like contexts, etc. */
GL3_ShutdownWindow(false);
}
static void
GL3_SetGL2D(void)
{
int x, w, y, h;
#if 0 // TODO: stereo
/* set 2D virtual screen size */
qboolean drawing_left_eye = gl_state.camera_separation < 0;
qboolean stereo_split_tb = ((gl_state.stereo_mode == STEREO_SPLIT_VERTICAL) && gl_state.camera_separation);
qboolean stereo_split_lr = ((gl_state.stereo_mode == STEREO_SPLIT_HORIZONTAL) && gl_state.camera_separation);
#endif // 0
x = 0;
w = vid.width;
y = 0;
h = vid.height;
#if 0 // TODO: stereo
if(stereo_split_lr) {
w = w / 2;
x = drawing_left_eye ? 0 : w;
}
if(stereo_split_tb) {
h = h / 2;
y = drawing_left_eye ? h : 0;
}
#endif // 0
// FIXME: change to GL3 code!
glViewport(x, y, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, vid.width, vid.height, 0, -99999, 99999);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glDisable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glColor4f(1, 1, 1, 1);
}
/*
* r_newrefdef must be set before the first call
*/
static void
GL3_RenderView(refdef_t *fd)
{
#if 0 // TODO: keep stereo stuff?
if ((gl_state.stereo_mode != STEREO_MODE_NONE) && gl_state.camera_separation) {
qboolean drawing_left_eye = gl_state.camera_separation < 0;
switch (gl_state.stereo_mode) {
case STEREO_MODE_ANAGLYPH:
{
// Work out the colour for each eye.
int anaglyph_colours[] = { 0x4, 0x3 }; // Left = red, right = cyan.
if (strlen(gl_stereo_anaglyph_colors->string) == 2) {
int eye, colour, missing_bits;
// Decode the colour name from its character.
for (eye = 0; eye < 2; ++eye) {
colour = 0;
switch (toupper(gl_stereo_anaglyph_colors->string[eye])) {
case 'B': ++colour; // 001 Blue
case 'G': ++colour; // 010 Green
case 'C': ++colour; // 011 Cyan
case 'R': ++colour; // 100 Red
case 'M': ++colour; // 101 Magenta
case 'Y': ++colour; // 110 Yellow
anaglyph_colours[eye] = colour;
break;
}
}
// Fill in any missing bits.
missing_bits = ~(anaglyph_colours[0] | anaglyph_colours[1]) & 0x3;
for (eye = 0; eye < 2; ++eye) {
anaglyph_colours[eye] |= missing_bits;
}
}
// Set the current colour.
glColorMask(
!!(anaglyph_colours[drawing_left_eye] & 0x4),
!!(anaglyph_colours[drawing_left_eye] & 0x2),
!!(anaglyph_colours[drawing_left_eye] & 0x1),
GL_TRUE
);
}
break;
case STEREO_MODE_ROW_INTERLEAVED:
case STEREO_MODE_COLUMN_INTERLEAVED:
case STEREO_MODE_PIXEL_INTERLEAVED:
{
qboolean flip_eyes = true;
int client_x, client_y;
//GLimp_GetClientAreaOffset(&client_x, &client_y);
client_x = 0;
client_y = 0;
GL3_SetGL2D();
glEnable(GL_STENCIL_TEST);
glStencilMask(GL_TRUE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);
glStencilFunc(GL_NEVER, 0, 1);
glBegin(GL_QUADS);
{
glVertex2i(0, 0);
glVertex2i(vid.width, 0);
glVertex2i(vid.width, vid.height);
glVertex2i(0, vid.height);
}
glEnd();
glStencilOp(GL_INVERT, GL_KEEP, GL_KEEP);
glStencilFunc(GL_NEVER, 1, 1);
glBegin(GL_LINES);
{
if (gl_state.stereo_mode == STEREO_MODE_ROW_INTERLEAVED || gl_state.stereo_mode == STEREO_MODE_PIXEL_INTERLEAVED) {
int y;
for (y = 0; y <= vid.height; y += 2) {
glVertex2f(0, y - 0.5f);
glVertex2f(vid.width, y - 0.5f);
}
flip_eyes ^= (client_y & 1);
}
if (gl_state.stereo_mode == STEREO_MODE_COLUMN_INTERLEAVED || gl_state.stereo_mode == STEREO_MODE_PIXEL_INTERLEAVED) {
int x;
for (x = 0; x <= vid.width; x += 2) {
glVertex2f(x - 0.5f, 0);
glVertex2f(x - 0.5f, vid.height);
}
flip_eyes ^= (client_x & 1);
}
}
glEnd();
glStencilMask(GL_FALSE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glStencilFunc(GL_EQUAL, drawing_left_eye ^ flip_eyes, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
}
break;
default:
break;
}
}
#endif // 0 (stereo stuff)
if (gl_norefresh->value)
{
return;
}
gl3_newrefdef = *fd;
STUB_ONCE("TODO: Implement!");
#if 0 // TODO !!
if (!r_worldmodel && !(gl3_newrefdef.rdflags & RDF_NOWORLDMODEL))
{
ri.Sys_Error(ERR_DROP, "R_RenderView: NULL worldmodel");
}
if (gl_speeds->value)
{
c_brush_polys = 0;
c_alias_polys = 0;
}
R_PushDlights();
if (gl_finish->value)
{
glFinish();
}
R_SetupFrame();
R_SetFrustum();
R_SetupGL();
R_MarkLeaves(); /* done here so we know if we're in water */
R_DrawWorld();
R_DrawEntitiesOnList();
R_RenderDlights();
R_DrawParticles();
R_DrawAlphaSurfaces();
R_Flash();
if (gl_speeds->value)
{
R_Printf(PRINT_ALL, "%4i wpoly %4i epoly %i tex %i lmaps\n",
c_brush_polys, c_alias_polys, c_visible_textures,
c_visible_lightmaps);
}
#endif // 0
#if 0 // TODO: stereo stuff
switch (gl_state.stereo_mode) {
case STEREO_MODE_NONE:
break;
case STEREO_MODE_ANAGLYPH:
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
break;
case STEREO_MODE_ROW_INTERLEAVED:
case STEREO_MODE_COLUMN_INTERLEAVED:
case STEREO_MODE_PIXEL_INTERLEAVED:
glDisable(GL_STENCIL_TEST);
break;
default:
break;
}
#endif // 0
}
#if 0 // TODO: stereo
enum opengl_special_buffer_modes
GL3_GetSpecialBufferModeForStereoMode(enum stereo_modes stereo_mode) {
switch (stereo_mode) {
case STEREO_MODE_NONE:
case STEREO_SPLIT_HORIZONTAL:
case STEREO_SPLIT_VERTICAL:
case STEREO_MODE_ANAGLYPH:
return OPENGL_SPECIAL_BUFFER_MODE_NONE;
case STEREO_MODE_OPENGL:
return OPENGL_SPECIAL_BUFFER_MODE_STEREO;
case STEREO_MODE_ROW_INTERLEAVED:
case STEREO_MODE_COLUMN_INTERLEAVED:
case STEREO_MODE_PIXEL_INTERLEAVED:
return OPENGL_SPECIAL_BUFFER_MODE_STENCIL;
}
return OPENGL_SPECIAL_BUFFER_MODE_NONE;
}
#endif // 0
static void
GL3_SetLightLevel(void)
{
vec3_t shadelight = {0};
if (r_newrefdef.rdflags & RDF_NOWORLDMODEL)
{
return;
}
STUB_ONCE("TODO: IMPLEMENT!");
#if 0 // TODO!
/* save off light value for server to look at */
R_LightPoint(r_newrefdef.vieworg, shadelight);
/* pick the greatest component, which should be the
* same as the mono value returned by software */
if (shadelight[0] > shadelight[1])
{
if (shadelight[0] > shadelight[2])
{
gl_lightlevel->value = 150 * shadelight[0];
}
else
{
gl_lightlevel->value = 150 * shadelight[2];
}
}
else
{
if (shadelight[1] > shadelight[2])
{
gl_lightlevel->value = 150 * shadelight[1];
}
else
{
gl_lightlevel->value = 150 * shadelight[2];
}
}
#endif // 0
}
static void
GL3_RenderFrame(refdef_t *fd)
{
GL3_RenderView(fd);
GL3_SetLightLevel();
GL3_SetGL2D();
}
Q2_DLL_EXPORTED refexport_t
GetRefAPI(refimport_t imp)
@ -427,20 +731,19 @@ GetRefAPI(refimport_t imp)
re.InitContext = GL3_InitContext;
re.ShutdownWindow = GL3_ShutdownWindow;
#if 0 // TODO!
re.BeginRegistration = RI_BeginRegistration;
re.RegisterModel = RI_RegisterModel;
re.BeginRegistration = GL3_BeginRegistration;
re.RegisterModel = GL3_RegisterModel;
re.RegisterSkin = GL3_RegisterSkin;
re.SetSky = RI_SetSky;
re.EndRegistration = RI_EndRegistration;
re.SetSky = GL3_SetSky;
re.EndRegistration = GL3_EndRegistration;
re.RenderFrame = RI_RenderFrame;
re.RenderFrame = GL3_RenderFrame;
re.DrawFindPic = RDraw_FindPic;
re.DrawGetPicSize = RDraw_GetPicSize;
re.DrawFindPic = GL3_Draw_FindPic;
re.DrawGetPicSize = GL3_Draw_GetPicSize;
#if 0 // TODO!
re.DrawPicScaled = RDraw_PicScaled;
re.DrawStretchPic = RDraw_StretchPic;
@ -450,8 +753,8 @@ GetRefAPI(refimport_t imp)
re.DrawFadeScreen = RDraw_FadeScreen;
re.DrawStretchRaw = RDraw_StretchRaw;
re.SetPalette = RI_SetPalette;
re.BeginFrame = RI_BeginFrame;
#endif // 0
re.EndFrame = GL3_EndFrame;

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016 Daniel Gibson
* Copyright (C) 2016-2017 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

View File

@ -1,5 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016-2017 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
@ -26,8 +27,13 @@
#include "header/local.h"
enum { MAX_MOD_KNOWN = 512 };
int registration_sequence;
gl3model_t mod_known[MAX_MOD_KNOWN];
int mod_numknown;
void
GL3_Mod_Modellist_f(void)
{
@ -53,3 +59,140 @@ GL3_Mod_Modellist_f(void)
R_Printf(PRINT_ALL, "Total resident: %i\n", total);
#endif
}
void
GL3_Mod_Init(void)
{
STUB("TODO: Implement!");
// memset(mod_novis, 0xff, sizeof(mod_novis));
}
static void
Mod_Free(gl3model_t *mod)
{
Hunk_Free(mod->extradata);
memset(mod, 0, sizeof(*mod));
}
void
GL3_Mod_FreeAll(void)
{
int i;
for (i = 0; i < mod_numknown; i++)
{
if (mod_known[i].extradatasize)
{
Mod_Free(&mod_known[i]);
}
}
}
/*
* Specifies the model that will be used as the world
*/
void
GL3_BeginRegistration(char *model)
{
char fullname[MAX_QPATH];
cvar_t *flushmap;
registration_sequence++;
gl3_oldviewcluster = -1; /* force markleafs */
Com_sprintf(fullname, sizeof(fullname), "maps/%s.bsp", model);
/* explicitly free the old map if different
this guarantees that mod_known[0] is the
world map */
flushmap = ri.Cvar_Get("flushmap", "0", 0);
if (strcmp(mod_known[0].name, fullname) || flushmap->value)
{
Mod_Free(&mod_known[0]);
}
STUB_ONCE("TODO: Implement Mod_ForName()!");
#if 0 // TODO!
r_worldmodel = Mod_ForName(fullname, true);
#endif // 0
gl3_viewcluster = -1;
}
struct model_s *
GL3_RegisterModel(char *name)
{
STUB_ONCE("TODO: Implement!");
return NULL;
#if 0
model_t *mod;
int i;
dsprite_t *sprout;
dmdl_t *pheader;
mod = Mod_ForName(name, false);
if (mod)
{
mod->registration_sequence = registration_sequence;
/* register any images used by the models */
if (mod->type == mod_sprite)
{
sprout = (dsprite_t *)mod->extradata;
for (i = 0; i < sprout->numframes; i++)
{
mod->skins[i] = R_FindImage(sprout->frames[i].name, it_sprite);
}
}
else if (mod->type == mod_alias)
{
pheader = (dmdl_t *)mod->extradata;
for (i = 0; i < pheader->num_skins; i++)
{
mod->skins[i] = R_FindImage((char *)pheader + pheader->ofs_skins +
i * MAX_SKINNAME, it_skin);
}
mod->numframes = pheader->num_frames;
}
else if (mod->type == mod_brush)
{
for (i = 0; i < mod->numtexinfo; i++)
{
mod->texinfo[i].image->registration_sequence =
registration_sequence;
}
}
}
return mod;
#endif // 0
}
void
GL3_EndRegistration(void)
{
int i;
gl3model_t *mod;
for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
{
if (!mod->name[0])
{
continue;
}
if (mod->registration_sequence != registration_sequence)
{
/* don't need this model */
Mod_Free(mod);
}
}
GL3_FreeUnusedImages();
}

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016 Daniel Gibson
* Copyright (C) 2016-2017 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

View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016-2017 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.
*
* =======================================================================
*
* Warps. Used on water surfaces und for skybox rotation.
*
* =======================================================================
*/
#include "header/local.h"
static float skyrotate;
static vec3_t skyaxis;
static gl3image_t* sky_images[6];
static float sky_min, sky_max;
/* 3dstudio environment map names */
static const char* suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
void
GL3_SetSky(char *name, float rotate, vec3_t axis)
{
int i;
char pathname[MAX_QPATH];
char skyname[MAX_QPATH];
Q_strlcpy(skyname, name, sizeof(skyname));
skyrotate = rotate;
VectorCopy(axis, skyaxis);
for (i = 0; i < 6; i++)
{
// NOTE: there might be a paletted .pcx version, which was only used
// if gl_config.palettedtexture
Com_sprintf(pathname, sizeof(pathname), "env/%s%s.tga", skyname, suf[i]);
sky_images[i] = GL3_FindImage(pathname, it_sky);
if (!sky_images[i])
{
sky_images[i] = gl3_notexture;
}
sky_min = 1.0 / 512;
sky_max = 511.0 / 512;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
* Copyright (C) 2016 Daniel Gibson
* Copyright (C) 2016-2017 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
@ -44,16 +44,24 @@
#include "../../ref_shared.h"
#define STUB(msg) \
R_Printf(PRINT_ALL, "STUB: %s() %s\n", __FUNCTION__, msg )
R_Printf(PRINT_ALL, "STUB: %s() %s\n", __FUNCTION__, msg)
#define STUB_ONCE(msg) do {\
#define STUB_ONCE(msg) do { \
static int show=1; \
if(show) { \
show = 0; \
R_Printf(PRINT_ALL, "STUB: %s() %s\n", __FUNCTION__, msg ); \
R_Printf(PRINT_ALL, "STUB: %s() %s\n", __FUNCTION__, msg); \
} \
} while(0);
// a wrapper around glVertexAttribPointer() to stay sane
// (caller doesn't have to cast to GLintptr and then void*)
static inline void
qglVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, GLintptr offset)
{
glVertexAttribPointer(index, size, type, normalized, stride, (const void*)offset);
}
typedef struct
{
const char *renderer_string;
@ -103,6 +111,8 @@ extern gl3state_t gl3state;
extern viddef_t vid;
extern int gl3_viewcluster, gl3_viewcluster2, gl3_oldviewcluster, gl3_oldviewcluster2;
/* NOTE: struct image_s* is what re.RegisterSkin() etc return so no gl3image_s!
* (I think the client only passes the pointer around and doesn't know the
* definition of this struct, so this being different from struct image_s
@ -127,36 +137,54 @@ typedef struct image_s
enum {MAX_GL3TEXTURES = 1024};
// include this down here so it can use gl3image_t
#include "model.h"
extern gl3image_t *gl3_notexture; /* use for bad textures */
extern gl3image_t *gl3_particletexture; /* little dot for particles */
extern int gl_filter_min;
extern int gl_filter_max;
// gl3_sdl.c
extern int GL3_PrepareForWindow(void);
extern int GL3_InitContext(void* win);
extern void GL3_EndFrame(void);
extern void GL3_ShutdownWindow(qboolean contextOnly);
// gl3_misc.c
extern void GL3_InitParticleTexture(void);
extern void GL3_ScreenShot(void);
extern void GL3_SetDefaultState(void);
// gl3_model.c
extern int registration_sequence;
extern void GL3_Mod_Init(void);
extern void GL3_Mod_FreeAll(void);
extern void GL3_BeginRegistration(char *model);
extern struct model_s * GL3_RegisterModel(char *name);
extern void GL3_EndRegistration(void);
extern void GL3_Mod_Modellist_f(void);
// gl3_draw.c
extern void GL3_Draw_InitLocal(void);
extern gl3image_t * GL3_Draw_FindPic(char *name);
extern void GL3_Draw_GetPicSize(int *w, int *h, char *pic);
extern int GL3_Draw_GetPalette(void);
// gl3_image.c
extern void GL3_TextureMode(char *string);
extern void GL3_Bind(int texnum);
extern gl3image_t *GL3_LoadPic(char *name, byte *pic, int width, int realwidth,
int height, int realheight, imagetype_t type, int bits);
extern gl3image_t *GL3_FindImage(char *name, imagetype_t type);
extern gl3image_t *GL3_RegisterSkin(char *name);
extern void GL3_TextureMode(char *string);
extern void GL3_FreeUnusedImages(void);
extern void GL3_ImageList_f(void);
// gl3_warp.c
extern void GL3_SetSky(char *name, float rotate, vec3_t axis);
extern cvar_t *gl_msaa_samples;
extern cvar_t *gl_swapinterval;
extern cvar_t *gl_retexturing;

View File

@ -0,0 +1,226 @@
/*
* 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 for the model stuff.
*
* =======================================================================
*/
#ifndef SRC_CLIENT_REFRESH_GL3_HEADER_MODEL_H_
#define SRC_CLIENT_REFRESH_GL3_HEADER_MODEL_H_
// TODO: maybe lots of these things should get a gl3_ prefix and might
// need to be adapted and so on
enum {
SIDE_FRONT = 0,
SIDE_BACK = 1,
SIDE_ON = 2
};
enum {
SURF_PLANEBACK = 2,
SURF_DRAWSKY = 4,
SURF_DRAWTURB = 0x10,
SURF_DRAWBACKGROUND = 0x40,
SURF_UNDERWATER = 0x80,
VERTEXSIZE = 7
};
/* in memory representation */
typedef struct
{
vec3_t position;
} mvertex_t;
typedef struct
{
vec3_t mins, maxs;
vec3_t origin; /* for sounds or lights */
float radius;
int headnode;
int visleafs; /* not including the solid leaf 0 */
int firstface, numfaces;
} mmodel_t;
typedef struct
{
unsigned short v[2];
unsigned int cachededgeoffset;
} medge_t;
typedef struct mtexinfo_s
{
float vecs[2][4];
int flags;
int numframes;
struct mtexinfo_s *next; /* animation chain */
gl3image_t *image;
} mtexinfo_t;
typedef struct glpoly_s
{
struct glpoly_s *next;
struct glpoly_s *chain;
int numverts;
int flags; /* for SURF_UNDERWATER (not needed anymore?) */
float verts[4][VERTEXSIZE]; /* variable sized (xyz s1t1 s2t2) */
} glpoly_t;
typedef struct msurface_s
{
int visframe; /* should be drawn when node is crossed */
cplane_t *plane;
int flags;
int firstedge; /* look up in model->surfedges[], negative numbers */
int numedges; /* are backwards edges */
short texturemins[2];
short extents[2];
int light_s, light_t; /* gl lightmap coordinates */
int dlight_s, dlight_t; /* gl lightmap coordinates for dynamic lightmaps */
glpoly_t *polys; /* multiple if warped */
struct msurface_s *texturechain;
struct msurface_s *lightmapchain;
mtexinfo_t *texinfo;
/* lighting info */
int dlightframe;
int dlightbits;
int lightmaptexturenum;
byte styles[MAXLIGHTMAPS];
float cached_light[MAXLIGHTMAPS]; /* values currently used in lightmap */
byte *samples; /* [numstyles*surfsize] */
} msurface_t;
typedef struct mnode_s
{
/* common with leaf */
int contents; /* -1, to differentiate from leafs */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* node specific */
cplane_t *plane;
struct mnode_s *children[2];
unsigned short firstsurface;
unsigned short numsurfaces;
} mnode_t;
typedef struct mleaf_s
{
/* common with node */
int contents; /* wil be a negative contents number */
int visframe; /* node needs to be traversed if current */
float minmaxs[6]; /* for bounding box culling */
struct mnode_s *parent;
/* leaf specific */
int cluster;
int area;
msurface_t **firstmarksurface;
int nummarksurfaces;
} mleaf_t;
/* Whole model */
// this, must be struct model_s, not gl3model_s,
// because struct model_s* is returned by re.RegisterModel()
typedef struct model_s
{
char name[MAX_QPATH];
int registration_sequence;
modtype_t type;
int numframes;
int flags;
/* volume occupied by the model graphics */
vec3_t mins, maxs;
float radius;
/* solid volume for clipping */
qboolean clipbox;
vec3_t clipmins, clipmaxs;
/* brush model */
int firstmodelsurface, nummodelsurfaces;
int lightmap; /* only for submodels */
int numsubmodels;
mmodel_t *submodels;
int numplanes;
cplane_t *planes;
int numleafs; /* number of visible leafs, not counting 0 */
mleaf_t *leafs;
int numvertexes;
mvertex_t *vertexes;
int numedges;
medge_t *edges;
int numnodes;
int firstnode;
mnode_t *nodes;
int numtexinfo;
mtexinfo_t *texinfo;
int numsurfaces;
msurface_t *surfaces;
int numsurfedges;
int *surfedges;
int nummarksurfaces;
msurface_t **marksurfaces;
dvis_t *vis;
byte *lightdata;
/* for alias models and skins */
gl3image_t *skins[MAX_MD2SKINS];
int extradatasize;
void *extradata;
} gl3model_t;
#endif /* SRC_CLIENT_REFRESH_GL3_HEADER_MODEL_H_ */

View File

@ -48,6 +48,14 @@ typedef enum
it_sky
} imagetype_t;
typedef enum
{
mod_bad,
mod_brush,
mod_sprite,
mod_alias
} modtype_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);