2011-12-25 22:59:36 +00:00
|
|
|
/*
|
|
|
|
glsl_main.c
|
|
|
|
|
|
|
|
GLSL rendering
|
|
|
|
|
|
|
|
Copyright (C) 2011 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2011/12/23
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
|
|
|
|
2011-12-25 22:59:36 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include "string.h"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include "strings.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
2011-12-31 08:24:20 +00:00
|
|
|
#include "QF/dstring.h"
|
2011-12-25 22:59:36 +00:00
|
|
|
#include "QF/image.h"
|
2011-12-31 08:24:20 +00:00
|
|
|
#include "QF/png.h"
|
|
|
|
#include "QF/quakefs.h"
|
2011-12-25 22:59:36 +00:00
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/skin.h"
|
2011-12-31 08:24:20 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/va.h"
|
2011-12-25 22:59:36 +00:00
|
|
|
|
2011-12-26 07:08:55 +00:00
|
|
|
#include "QF/GLSL/defines.h"
|
|
|
|
#include "QF/GLSL/funcs.h"
|
2012-02-22 12:53:17 +00:00
|
|
|
#include "QF/GLSL/qf_draw.h"
|
2011-12-26 07:08:55 +00:00
|
|
|
#include "QF/GLSL/qf_textures.h"
|
|
|
|
#include "QF/GLSL/qf_vid.h"
|
2011-12-25 22:59:36 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2011-12-25 22:59:36 +00:00
|
|
|
|
2011-12-28 00:05:36 +00:00
|
|
|
/* Unknown renamed to GLErr_Unknown to solve conflict with winioctl.h */
|
2012-02-22 02:09:09 +00:00
|
|
|
static unsigned int GLErr_InvalidEnum;
|
|
|
|
static unsigned int GLErr_InvalidValue;
|
|
|
|
static unsigned int GLErr_InvalidOperation;
|
|
|
|
static unsigned int GLErr_OutOfMemory;
|
|
|
|
static unsigned int GLErr_Unknown;
|
2011-12-28 00:05:36 +00:00
|
|
|
|
|
|
|
extern void (*R_DrawSpriteModel) (struct entity_s *ent);
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
R_TestErrors (unsigned int numerous)
|
|
|
|
{
|
2012-02-22 07:48:57 +00:00
|
|
|
switch (qfeglGetError ()) {
|
2011-12-28 00:05:36 +00:00
|
|
|
case GL_NO_ERROR:
|
|
|
|
return numerous;
|
|
|
|
break;
|
|
|
|
case GL_INVALID_ENUM:
|
|
|
|
GLErr_InvalidEnum++;
|
|
|
|
R_TestErrors (numerous++);
|
|
|
|
break;
|
|
|
|
case GL_INVALID_VALUE:
|
|
|
|
GLErr_InvalidValue++;
|
|
|
|
R_TestErrors (numerous++);
|
|
|
|
break;
|
|
|
|
case GL_INVALID_OPERATION:
|
|
|
|
GLErr_InvalidOperation++;
|
|
|
|
R_TestErrors (numerous++);
|
|
|
|
break;
|
|
|
|
case GL_OUT_OF_MEMORY:
|
|
|
|
GLErr_OutOfMemory++;
|
|
|
|
R_TestErrors (numerous++);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GLErr_Unknown++;
|
|
|
|
R_TestErrors (numerous++);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return numerous;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
R_DisplayErrors (void)
|
|
|
|
{
|
|
|
|
if (GLErr_InvalidEnum)
|
|
|
|
printf ("%d OpenGL errors: Invalid Enum!\n", GLErr_InvalidEnum);
|
|
|
|
if (GLErr_InvalidValue)
|
|
|
|
printf ("%d OpenGL errors: Invalid Value!\n", GLErr_InvalidValue);
|
|
|
|
if (GLErr_InvalidOperation)
|
|
|
|
printf ("%d OpenGL errors: Invalid Operation!\n", GLErr_InvalidOperation);
|
|
|
|
if (GLErr_OutOfMemory)
|
|
|
|
printf ("%d OpenGL errors: Out Of Memory!\n", GLErr_OutOfMemory);
|
|
|
|
if (GLErr_Unknown)
|
|
|
|
printf ("%d Unknown OpenGL errors!\n", GLErr_Unknown);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
R_ClearErrors (void)
|
|
|
|
{
|
|
|
|
GLErr_InvalidEnum = 0;
|
|
|
|
GLErr_InvalidValue = 0;
|
|
|
|
GLErr_InvalidOperation = 0;
|
|
|
|
GLErr_OutOfMemory = 0;
|
|
|
|
GLErr_Unknown = 0;
|
|
|
|
}
|
|
|
|
|
2011-12-25 22:59:36 +00:00
|
|
|
static void
|
|
|
|
SCR_TileClear (void)
|
|
|
|
{
|
|
|
|
if (r_refdef.vrect.x > 0) {
|
|
|
|
// left
|
2012-02-14 08:28:09 +00:00
|
|
|
Draw_TileClear (0, 0, r_refdef.vrect.x, vid.height - vr_data.lineadj);
|
2011-12-25 22:59:36 +00:00
|
|
|
// right
|
|
|
|
Draw_TileClear (r_refdef.vrect.x + r_refdef.vrect.width, 0,
|
|
|
|
vid.width - r_refdef.vrect.x + r_refdef.vrect.width,
|
2012-02-14 08:28:09 +00:00
|
|
|
vid.height - vr_data.lineadj);
|
2011-12-25 22:59:36 +00:00
|
|
|
}
|
|
|
|
if (r_refdef.vrect.y > 0) {
|
|
|
|
// top
|
|
|
|
Draw_TileClear (r_refdef.vrect.x, 0,
|
|
|
|
r_refdef.vrect.x + r_refdef.vrect.width,
|
|
|
|
r_refdef.vrect.y);
|
|
|
|
// bottom
|
|
|
|
Draw_TileClear (r_refdef.vrect.x,
|
|
|
|
r_refdef.vrect.y + r_refdef.vrect.height,
|
|
|
|
r_refdef.vrect.width,
|
2012-02-14 08:28:09 +00:00
|
|
|
vid.height - vr_data.lineadj -
|
2011-12-25 22:59:36 +00:00
|
|
|
(r_refdef.vrect.height + r_refdef.vrect.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_SCR_UpdateScreen (double realtime, SCR_Func scr_3dfunc,
|
|
|
|
SCR_Func *scr_funcs)
|
2011-12-25 22:59:36 +00:00
|
|
|
{
|
|
|
|
static int begun = 0;
|
|
|
|
|
2011-12-28 00:05:36 +00:00
|
|
|
if (R_TestErrors (0))
|
|
|
|
R_DisplayErrors ();
|
|
|
|
R_ClearErrors ();
|
|
|
|
|
2011-12-25 22:59:36 +00:00
|
|
|
if (begun) {
|
|
|
|
begun = 0;
|
2012-02-23 00:15:50 +00:00
|
|
|
vid.end_rendering ();
|
2011-12-25 22:59:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
vr_data.realtime = realtime;
|
2012-04-12 05:40:02 +00:00
|
|
|
//FIXME useless cvar? vid.numpages = 2 + gl_triplebuffer->int_val;
|
2011-12-25 22:59:36 +00:00
|
|
|
|
|
|
|
if (!scr_initialized)
|
|
|
|
return;
|
|
|
|
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2011-12-26 01:16:16 +00:00
|
|
|
|
2011-12-25 22:59:36 +00:00
|
|
|
begun = 1;
|
|
|
|
|
|
|
|
if (oldfov != scr_fov->value) {
|
|
|
|
oldfov = scr_fov->value;
|
|
|
|
vid.recalc_refdef = true;
|
|
|
|
}
|
|
|
|
if (vid.recalc_refdef)
|
|
|
|
SCR_CalcRefdef ();
|
|
|
|
|
2012-01-28 11:45:14 +00:00
|
|
|
scr_3dfunc ();
|
2011-12-25 22:59:36 +00:00
|
|
|
|
|
|
|
SCR_SetUpToDrawConsole ();
|
2012-02-22 12:53:17 +00:00
|
|
|
GLSL_Set2D ();
|
|
|
|
GLSL_DrawReset ();
|
2011-12-25 22:59:36 +00:00
|
|
|
SCR_TileClear ();
|
2012-02-22 12:53:17 +00:00
|
|
|
GLSL_Set2DScaled ();
|
2011-12-25 22:59:36 +00:00
|
|
|
while (*scr_funcs) {
|
|
|
|
(*scr_funcs)();
|
|
|
|
scr_funcs++;
|
2012-02-22 12:53:17 +00:00
|
|
|
GLSL_FlushText ();
|
2011-12-25 22:59:36 +00:00
|
|
|
}
|
2012-07-03 04:38:35 +00:00
|
|
|
GLSL_End2D ();
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglFlush ();
|
2011-12-25 22:59:36 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
tex_t *
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_SCR_CaptureBGR (void)
|
2012-01-05 10:19:37 +00:00
|
|
|
{
|
|
|
|
byte *r, *b;
|
|
|
|
int count, i;
|
|
|
|
tex_t *tex;
|
|
|
|
|
|
|
|
count = vid.width * vid.height;
|
|
|
|
tex = malloc (field_offset (tex_t, data[count * 3]));
|
|
|
|
SYS_CHECKMEM (tex);
|
|
|
|
tex->width = vid.width;
|
|
|
|
tex->height = vid.height;
|
|
|
|
tex->format = tex_rgb;
|
|
|
|
tex->palette = 0;
|
2012-02-22 07:48:57 +00:00
|
|
|
qfeglReadPixels (0, 0, vid.width, vid.height, GL_RGB,
|
2012-01-05 10:19:37 +00:00
|
|
|
GL_UNSIGNED_BYTE, tex->data);
|
|
|
|
for (i = 0, r = tex->data, b = tex->data + 2; i < count;
|
|
|
|
i++, r += 3, b += 3) {
|
|
|
|
byte t = *b;
|
|
|
|
*b = *r;
|
|
|
|
*r = t;
|
|
|
|
}
|
|
|
|
return tex;
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
tex_t *
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_SCR_ScreenShot (int width, int height)
|
2011-12-25 22:59:36 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
glsl_SCR_ScreenShot_f (void)
|
2011-12-25 22:59:36 +00:00
|
|
|
{
|
2011-12-31 08:24:20 +00:00
|
|
|
dstring_t *name = dstring_new ();
|
|
|
|
|
|
|
|
// find a file name to save it to
|
2012-01-05 08:04:23 +00:00
|
|
|
if (!QFS_NextFilename (name,
|
|
|
|
va ("%s/qf", qfs_gamedir->dir.shots), ".png")) {
|
2011-12-31 08:24:20 +00:00
|
|
|
Sys_Printf ("SCR_ScreenShot_f: Couldn't create a PNG file\n");
|
|
|
|
} else {
|
2012-01-05 10:19:37 +00:00
|
|
|
tex_t *tex;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
tex = glsl_SCR_CaptureBGR ();
|
2012-01-05 10:19:37 +00:00
|
|
|
WritePNGqfs (name->str, tex->data, tex->width, tex->height);
|
|
|
|
free (tex);
|
2011-12-31 08:24:20 +00:00
|
|
|
Sys_Printf ("Wrote %s/%s\n", qfs_userpath, name->str);
|
|
|
|
}
|
|
|
|
dstring_delete (name);
|
2011-12-25 22:59:36 +00:00
|
|
|
}
|