[gl] Get fisheye working with frame buffers

Of course, it's not as correct as glsl or sw due to using polygons and
uvs rather than a fragment shader (not that such is out of the question
since GL 3.0 is requested, but I don't feel like getting shaders going
just for a couple of post-processing effects in an obsolete renderer).
This commit is contained in:
Bill Currie 2022-03-26 12:08:06 +09:00
parent aa41259008
commit a0adca011f
10 changed files with 361 additions and 339 deletions

View file

@ -830,4 +830,43 @@
# define GL_OPERAND1_ALPHA 0x8599
# define GL_OPERAND2_ALPHA 0x859A
/* framebuffer */
#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF
#define GL_COLOR_ATTACHMENT0 0x8CE0
#define GL_COLOR_ATTACHMENT1 0x8CE1
#define GL_COLOR_ATTACHMENT2 0x8CE2
#define GL_COLOR_ATTACHMENT3 0x8CE3
#define GL_COLOR_ATTACHMENT4 0x8CE4
#define GL_COLOR_ATTACHMENT5 0x8CE5
#define GL_COLOR_ATTACHMENT6 0x8CE6
#define GL_COLOR_ATTACHMENT7 0x8CE7
#define GL_COLOR_ATTACHMENT8 0x8CE8
#define GL_COLOR_ATTACHMENT9 0x8CE9
#define GL_COLOR_ATTACHMENT10 0x8CEA
#define GL_COLOR_ATTACHMENT11 0x8CEB
#define GL_COLOR_ATTACHMENT12 0x8CEC
#define GL_COLOR_ATTACHMENT13 0x8CED
#define GL_COLOR_ATTACHMENT14 0x8CEE
#define GL_COLOR_ATTACHMENT15 0x8CEF
#define GL_COLOR_ATTACHMENT16 0x8CF0
#define GL_COLOR_ATTACHMENT17 0x8CF1
#define GL_COLOR_ATTACHMENT18 0x8CF2
#define GL_COLOR_ATTACHMENT19 0x8CF3
#define GL_COLOR_ATTACHMENT20 0x8CF4
#define GL_COLOR_ATTACHMENT21 0x8CF5
#define GL_COLOR_ATTACHMENT22 0x8CF6
#define GL_COLOR_ATTACHMENT23 0x8CF7
#define GL_COLOR_ATTACHMENT24 0x8CF8
#define GL_COLOR_ATTACHMENT25 0x8CF9
#define GL_COLOR_ATTACHMENT26 0x8CFA
#define GL_COLOR_ATTACHMENT27 0x8CFB
#define GL_COLOR_ATTACHMENT28 0x8CFC
#define GL_COLOR_ATTACHMENT29 0x8CFD
#define GL_COLOR_ATTACHMENT30 0x8CFE
#define GL_COLOR_ATTACHMENT31 0x8CFF
#define GL_DEPTH_ATTACHMENT 0x8D00
#define GL_STENCIL_ATTACHMENT 0x8D20
#define GL_FRAMEBUFFER 0x8D40
#endif // __gl_defines_h

View file

@ -0,0 +1,37 @@
/*
qf_fisheye.h
GL screen fisheye
Copyright (C) 2022 Bill Currie <bill@taniwha.org>
Author: Bill Currie <bill@taniwha.org>
Date: 2022/3/25
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
*/
#ifndef __QF_GL_qf_fisheye_h
#define __QF_GL_qf_fisheye_h
void gl_InitFisheye (void);
struct framebuffer_s;
void gl_FisheyeScreen (struct framebuffer_s *fb);
#endif//__QF_GL_qf_fisheye_h

View file

@ -418,6 +418,19 @@ QFGL_NEED (void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height))
// ATI Extensions
QFGL_WANT (void, glPNTrianglesiATI, (GLint x, GLint y))
// frame buffers
QFGL_DONT_NEED (GLboolean, glIsFramebuffer, (GLuint framebuffer))
QFGL_NEED (void, glBindFramebuffer, (GLenum target, GLuint framebuffer))
QFGL_DONT_NEED (void, glDeleteFramebuffers, (GLsizei n, const GLuint *framebuffers))
QFGL_NEED (void, glGenFramebuffers, (GLsizei n, GLuint *framebuffers))
QFGL_DONT_NEED (GLenum, glCheckFramebufferStatus, (GLenum target))
QFGL_DONT_NEED (void, glFramebufferTexture1D, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level))
QFGL_NEED (void, glFramebufferTexture2D, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level))
QFGL_DONT_NEED (void, glFramebufferTexture3D, (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLint zoffset))
QFGL_DONT_NEED (void, glFramebufferRenderbuffer, (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer))
QFGL_DONT_NEED (void, glGetFramebufferAttachmentParameteriv, (GLenum target, GLenum attachment, GLenum pname, GLint *params))
#ifdef UNDEF_QFGL_DONT_NEED
#undef QFGL_DONT_NEED
#endif

View file

@ -82,6 +82,7 @@ include_qf_gl = \
include/QF/GL/funcs.h \
include/QF/GL/qf_alias.h \
include/QF/GL/qf_draw.h \
include/QF/GL/qf_fisheye.h \
include/QF/GL/qf_funcs_list.h \
include/QF/GL/qf_iqm.h \
include/QF/GL/qf_lightmap.h \

View file

@ -70,6 +70,7 @@ libs_video_renderer_librender_gl_la_SOURCES = \
libs/video/renderer/gl/gl_dyn_lights.c \
libs/video/renderer/gl/gl_dyn_part.c \
libs/video/renderer/gl/gl_dyn_textures.c \
libs/video/renderer/gl/gl_fisheye.c \
libs/video/renderer/gl/gl_fog.c \
libs/video/renderer/gl/gl_graph.c \
libs/video/renderer/gl/gl_lightmap.c \

View file

@ -0,0 +1,183 @@
/*
gl_fisheye.c
GL fisheye rendering
Copyright (C) 2003 Arkadi Shishlov <arkadi@it.lv>
Copyright (C) 2022 Bill Currie <bill@taniwha.org>
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
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "QF/cvar.h"
#include "QF/mathlib.h"
#include "QF/render.h"
#include "QF/sys.h"
#include "QF/vid.h"
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
#include "QF/GL/qf_draw.h"
#include "QF/GL/qf_fisheye.h"
#include "QF/GL/qf_vid.h"
#include "compat.h"
#include "r_internal.h"
#include "varrays.h"
#include "vid_gl.h"
// Algorithm:
// Draw up to six views, one in each direction.
// Save the picture to cube map texture, use GL_ARB_texture_cube_map.
// Create FPOLYCNTxFPOLYCNT polygons sized flat grid.
// Baseing on field of view, tie cube map texture to grid using
// translation function to map texture coordinates to fixed/regular
// grid vertices coordinates.
// Render view. Fisheye is done.
#define FPOLYCNT 128
struct xyz {
float x, y, z;
};
static struct xyz FisheyeLookupTbl[FPOLYCNT + 1][FPOLYCNT + 1];
//static GLint gl_cube_map_size;
static GLint gl_cube_map_step;
static void
R_BuildFisheyeLookup (int width, int height, float fov)
{
int x, y;
struct xyz *v;
for (y = 0; y <= height; y += gl_cube_map_step) {
for (x = 0; x <= width; x += gl_cube_map_step) {
float dx = x - width / 2;
float dy = y - height / 2;
float yaw = sqrt (dx * dx + dy * dy) * fov / width;
float roll = atan2 (dy, dx);
// X is a first index and Y is a second, because later
// when we draw QUAD_STRIPs we need next Y vertex coordinate.
v = &FisheyeLookupTbl[x / gl_cube_map_step][y / gl_cube_map_step];
v->x = sin (yaw) * cos (roll);
v->y = sin (yaw) * sin (roll);
v->z = cos (yaw);
}
}
}
#define CHKGLERR(s) \
do { \
GLint err = qfglGetError(); \
if (err != GL_NO_ERROR) \
printf ("%s: gl error %d\n", s, (int) err); \
} while (0);
static GLuint fisheye_grid;
void
gl_InitFisheye (void)
{
fisheye_grid = qfglGenLists (1);
}
static void
build_display_list (int width, int height, float fov)
{
int maxd = max (width, height);
gl_cube_map_step = maxd / FPOLYCNT;
R_BuildFisheyeLookup (width, height, fov * M_PI / 180.0);
qfglNewList (fisheye_grid, GL_COMPILE);
qfglDisable (GL_DEPTH_TEST);
qfglFrontFace (GL_CCW);
qfglClear (GL_COLOR_BUFFER_BIT);
for (int y = 0; y < height; y += gl_cube_map_step) {
qfglBegin (GL_QUAD_STRIP);
// quad_strip, so X is inclusive
for (int x = 0; x <= width; x += gl_cube_map_step) {
int xind = x / gl_cube_map_step;
int yind = y / gl_cube_map_step;
struct xyz *v = &FisheyeLookupTbl[xind][yind + 1];
qfglTexCoord3f (v->x, v->y, v->z);
qfglVertex2i (x, y + gl_cube_map_step);
--v;
qfglTexCoord3f (v->x, v->y, v->z);
qfglVertex2i (x, y);
}
qfglEnd ();
}
qfglEnable (GL_DEPTH_TEST);
qfglEndList ();
CHKGLERR("build list");
}
void
gl_FisheyeScreen (framebuffer_t *fb)
{
static int pwidth = -1;
static int pheight = -1;
static float pfov = -1;
if (pwidth != r_refdef.vrect.width || pheight != r_refdef.vrect.height
|| pfov != scr_ffov->value) {
pwidth = r_refdef.vrect.width;
pheight = r_refdef.vrect.height;
pfov = scr_ffov->value;
build_display_list (pwidth, pheight, pfov);
}
gl_framebuffer_t *buffer = fb->buffer;
qfglViewport (r_refdef.vrect.x, r_refdef.vrect.x,
r_refdef.vrect.width, r_refdef.vrect.height);
qfglMatrixMode (GL_PROJECTION);
qfglLoadIdentity ();
qfglOrtho (0, r_refdef.vrect.width, r_refdef.vrect.height, 0, -9999, 9999);
qfglMatrixMode (GL_MODELVIEW);
qfglLoadIdentity ();
qfglColor3ubv (color_white);
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, buffer->color);
qfglCallList (fisheye_grid);
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
CHKGLERR("fisheye");
}

View file

@ -291,27 +291,8 @@ R_SetupGL (void)
qfglShadeModel (GL_FLAT);
}
static void
R_RenderScene (void)
{
R_SetupGL ();
gl_Fog_EnableGFog ();
gl_R_DrawWorld (); // adds static entities to the list
S_ExtraUpdate (); // don't let sound get messed up if going slow
gl_R_RenderDlights ();
R_DrawViewModel ();
gl_Fog_DisableGFog ();
}
/*
R_RenderView_
r_refdef must be set before the first call
*/
static void
R_RenderView_ (void)
void
gl_R_RenderView (void)
{
if (r_norefresh->int_val) {
return;
@ -320,317 +301,15 @@ R_RenderView_ (void)
return;
}
// render normal view
R_RenderScene ();
}
R_SetupGL ();
gl_Fog_EnableGFog ();
static void R_RenderViewFishEye (void);
gl_R_DrawWorld ();
S_ExtraUpdate (); // don't let sound get messed up if going slow
gl_R_RenderDlights ();
R_DrawViewModel ();
void
gl_R_RenderView (void)
{
if(!scr_fisheye->int_val)
R_RenderView_ ();
else
R_RenderViewFishEye ();
}
//FIXME
// Algorithm:
// Draw up to six views, one in each direction.
// Save the picture to cube map texture, use GL_ARB_texture_cube_map.
// Create FPOLYCNTxFPOLYCNT polygons sized flat grid.
// Baseing on field of view, tie cube map texture to grid using
// translation function to map texture coordinates to fixed/regular
// grid vertices coordinates.
// Render view. Fisheye is done.
#if 0
#define BOX_FRONT 0
#define BOX_RIGHT 1
#define BOX_BEHIND 2
#define BOX_LEFT 3
#define BOX_TOP 4
#define BOX_BOTTOM 5
#endif
static mat4f_t box_rotations[] = {
{ { 1, 0, 0, 0}, // front
{ 0, 1, 0, 0},
{ 0, 0, 1, 0},
{ 0, 0, 0, 1} },
{ { 0,-1, 0, 0}, // right
{ 1, 0, 0, 0},
{ 0, 0, 1, 0},
{ 0, 0, 0, 1} },
{ {-1, 0, 0, 0}, // back
{ 0,-1, 0, 0},
{ 0, 0, 1, 0},
{ 0, 0, 0, 1} },
{ { 0, 1, 0, 0}, // left
{-1, 0, 0, 0},
{ 0, 0, 1, 0},
{ 0, 0, 0, 1} },
{ { 0, 0, 1, 0}, // top
{ 0, 1, 0, 0},
{-1, 0, 0, 0},
{ 0, 0, 0, 1} },
{ { 0, 0,-1, 0}, // bottom
{ 0, 1, 0, 0},
{ 1, 0, 0, 0},
{ 0, 0, 0, 1} },
};
#define FPOLYCNT 128
struct xyz {
float x, y, z;
};
static struct xyz FisheyeLookupTbl[FPOLYCNT + 1][FPOLYCNT + 1];
static GLuint cube_map_tex;
static GLint gl_cube_map_size;
static GLint gl_cube_map_step;
static const GLenum box2cube_map[] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
};
static void
R_BuildFisheyeLookup (int width, int height, float fov)
{
int x, y;
struct xyz *v;
for (y = 0; y <= height; y += gl_cube_map_step) {
for (x = 0; x <= width; x += gl_cube_map_step) {
float dx = x - width / 2;
float dy = y - height / 2;
float yaw = sqrt (dx * dx + dy * dy) * fov / width;
float roll = atan2 (dy, dx);
// X is a first index and Y is a second, because later
// when we draw QUAD_STRIPs we need next Y vertex coordinate.
v = &FisheyeLookupTbl[x / gl_cube_map_step][y / gl_cube_map_step];
v->x = sin (yaw) * cos (roll);
v->y = -sin (yaw) * sin (roll);
v->z = cos (yaw);
}
}
}
#define CHKGLERR(s) \
do { \
GLint err = qfglGetError(); \
if (err != GL_NO_ERROR) \
printf ("%s: gl error %d\n", s, (int) err); \
} while (0);
static void
R_RenderCubeSide (int side)
{
mat4f_t camera;
mat4f_t camera_inverse;
mat4f_t rotinv;
memcpy (camera, r_refdef.camera, sizeof (camera));
memcpy (camera_inverse, r_refdef.camera_inverse, sizeof (camera_inverse));
mmulf (r_refdef.camera, camera, box_rotations[side]);
mat4ftranspose (rotinv, box_rotations[side]);
mmulf (r_refdef.camera_inverse, rotinv, camera_inverse);
//FIXME see fixme in r_screen.c
r_refdef.frame.mat[0] = -r_refdef.camera[1];
r_refdef.frame.mat[1] = r_refdef.camera[0];
r_refdef.frame.mat[2] = r_refdef.camera[2];
r_refdef.frame.mat[3] = r_refdef.camera[3];
#if 0
printf ("side: %d\n", side);
printf ("c: " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera, 0));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera, 1));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera, 2));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera, 3));
printf ("i: " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera_inverse, 0));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera_inverse, 1));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera_inverse, 2));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.camera_inverse, 3));
printf ("f: " VEC4F_FMT "\n", MAT4_ROW(r_refdef.frame.mat, 0));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.frame.mat, 1));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.frame.mat, 2));
printf (" " VEC4F_FMT "\n", MAT4_ROW(r_refdef.frame.mat, 3));
#endif
qfglClear (GL_DEPTH_BUFFER_BIT);
R_RenderView_ ();
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
qfglCopyTexSubImage2D (box2cube_map[side], 0, 0, 0, 0, 0,
gl_cube_map_size, gl_cube_map_size);
CHKGLERR ("qfglCopyTexSubImage2D");
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
memcpy (r_refdef.camera, camera, sizeof (camera));
memcpy (r_refdef.camera_inverse, camera_inverse, sizeof (camera_inverse));
}
static qboolean gl_cube_map_capable = false;
static GLint gl_cube_map_maxtex;
static GLuint fisheye_grid;
static int
R_InitFishEyeOnce (void)
{
static qboolean fisheye_init_once_completed = false;
if (fisheye_init_once_completed)
return 1;
Sys_MaskPrintf (SYS_dev, "GL_ARB_texture_cube_map ");
if (QFGL_ExtensionPresent ("GL_ARB_texture_cube_map")) {
qfglGetIntegerv (GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB,
&gl_cube_map_maxtex);
Sys_MaskPrintf (SYS_dev, "present, max texture size %d.\n",
(int) gl_cube_map_maxtex);
gl_cube_map_capable = true;
} else {
Sys_MaskPrintf (SYS_dev, "not found.\n");
gl_cube_map_capable = false;
}
fisheye_init_once_completed = true;
return 1;
}
static int
R_InitFishEye (void)
{
int width = vid.width;
int height = vid.height;
int fov = scr_ffov->int_val;
int views = scr_fviews->int_val;
static int pwidth = -1;
static int pheight = -1;
static int pfov = -1;
static int pviews = -1;
int i, x, y, min_wh, wh_changed = 0;
if (!R_InitFishEyeOnce())
return 0;
if (!gl_cube_map_capable)
return 0;
// There is a problem when max texture size is bigger than
// min(width, height), it shows up as black fat stripes at the edges
// of box polygons, probably due to missing texture fragment. Try
// to play in 640x480 with gl_cube_map_size == 512.
if (pwidth != width || pheight != height) {
wh_changed = 1;
min_wh = (height < width) ? height : width;
gl_cube_map_size = gl_cube_map_maxtex;
while (gl_cube_map_size > min_wh)
gl_cube_map_size /= 2;
gl_cube_map_step = gl_cube_map_size / FPOLYCNT;
}
if (pviews != views) {
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
if (pviews != -1)
qfglDeleteTextures (1, &cube_map_tex);
pviews = views;
qfglGenTextures (1, &cube_map_tex);
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
for (i = 0; i < 6; ++i) {
qfglTexImage2D (box2cube_map[i], 0, 3, gl_cube_map_size,
gl_cube_map_size, 0, GL_RGB, GL_UNSIGNED_SHORT,
NULL);
}
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
}
if (wh_changed || pfov != fov) {
if (pfov != -1)
qfglDeleteLists (fisheye_grid, 1);
pwidth = width;
pheight = height;
pfov = fov;
R_BuildFisheyeLookup (gl_cube_map_size, gl_cube_map_size,
((float) fov) * M_PI / 180.0);
fisheye_grid = qfglGenLists (1);
qfglNewList (fisheye_grid, GL_COMPILE);
qfglLoadIdentity ();
qfglTranslatef (-gl_cube_map_size / 2, -gl_cube_map_size / 2,
-gl_cube_map_size / 2);
qfglDisable (GL_DEPTH_TEST);
qfglFrontFace (GL_CCW);
qfglClear (GL_COLOR_BUFFER_BIT);
qfglEnable (GL_TEXTURE_CUBE_MAP_ARB);
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, cube_map_tex);
for (y = 0; y < gl_cube_map_size; y += gl_cube_map_step) {
qfglBegin (GL_QUAD_STRIP);
for (x = 0; x <= gl_cube_map_size; x += gl_cube_map_step) { // quad_strip, X should be inclusive
struct xyz *v = &FisheyeLookupTbl[x / gl_cube_map_step]
[y / gl_cube_map_step + 1];
qfglTexCoord3f (v->x, v->y, v->z);
qfglVertex2i (x, y + gl_cube_map_step);
--v;
qfglTexCoord3f (v->x, v->y, v->z);
qfglVertex2i (x, y);
}
qfglEnd ();
}
qfglDisable (GL_TEXTURE_CUBE_MAP_ARB);
qfglEnable (GL_DEPTH_TEST);
qfglEndList ();
}
return 1;
}
static void
R_RenderViewFishEye (void)
{
float s_fov_x, s_fov_y;
int s_vid_w, s_vid_h, s_rect_w, s_rect_h;
if (!R_InitFishEye()) return;
// save values
s_fov_x = r_refdef.fov_x;
s_fov_y = r_refdef.fov_y;
s_vid_w = vid.width;
s_vid_h = vid.height;
s_rect_w = r_refdef.vrect.width;
s_rect_h = r_refdef.vrect.height;
// the view should be square
r_refdef.fov_x = r_refdef.fov_y = 90;
vid.width = vid.height =
r_refdef.vrect.height = r_refdef.vrect.width =
gl_cube_map_size;
switch (scr_fviews->int_val) {
case 6: R_RenderCubeSide (BOX_BEHIND);
case 5: R_RenderCubeSide (BOX_BOTTOM);
case 4: R_RenderCubeSide (BOX_TOP);
case 3: R_RenderCubeSide (BOX_LEFT);
case 2: R_RenderCubeSide (BOX_RIGHT);
default: R_RenderCubeSide (BOX_FRONT);
}
// restore
r_refdef.fov_x = s_fov_x;
r_refdef.fov_y = s_fov_y;
vid.width = s_vid_w;
vid.height = s_vid_h;
r_refdef.vrect.width = s_rect_w;
r_refdef.vrect.height = s_rect_h;
R_SetupGL_Viewport_and_Perspective ();
qfglMatrixMode (GL_MODELVIEW);
qfglCallList (fisheye_grid);
gl_Fog_DisableGFog ();
}
void

View file

@ -54,6 +54,7 @@
#include "QF/GL/defines.h"
#include "QF/GL/funcs.h"
#include "QF/GL/qf_draw.h"
#include "QF/GL/qf_fisheye.h"
#include "QF/GL/qf_lightmap.h"
#include "QF/GL/qf_particles.h"
#include "QF/GL/qf_rlight.h"
@ -135,6 +136,7 @@ gl_R_Init (void)
gl_R_InitParticles ();
gl_R_InitSprites ();
Skin_Init ();
gl_InitFisheye ();
}
static void

View file

@ -35,6 +35,7 @@
#include "QF/GL/funcs.h"
#include "QF/GL/qf_draw.h"
#include "QF/GL/qf_fisheye.h"
#include "QF/GL/qf_rmain.h"
#include "QF/GL/qf_rsurf.h"
#include "QF/GL/qf_particles.h"
@ -259,6 +260,7 @@ static void
gl_render_view (void)
{
// do 3D refresh drawing, and then update the screen
qfglClear (GL_DEPTH_BUFFER_BIT);
gl_R_RenderView ();
}
@ -271,6 +273,11 @@ gl_draw_transparent (void)
static void
gl_post_process (framebuffer_t *src)
{
if (scr_fisheye->int_val) {
gl_FisheyeScreen (src);
} else if (r_dowarp) {
//gl_WarpScreen (src);
}
}
static void
@ -306,9 +313,55 @@ gl_end_frame (void)
}
static framebuffer_t *
gl_create_cube_map (int size)
gl_create_cube_map (int side)
{
Sys_Error ("not implemented");
GLuint tex[2];
qfglGenTextures (2, tex);
qfglBindTexture (GL_TEXTURE_CUBE_MAP_ARB, tex[0]);
for (int i = 0; i < 6; i++) {
qfglTexImage2D (GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + i, 0, GL_RGBA,
side, side, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
}
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S,
GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
qfglTexParameteri (GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
qfglBindTexture (GL_TEXTURE_2D, tex[1]);
qfglTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, side, side, 0,
GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, 0);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
qfglTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
size_t size = sizeof (framebuffer_t) * 6;
size += sizeof (gl_framebuffer_t) * 6;
framebuffer_t *cube = malloc (size);
__auto_type buffer_base = (gl_framebuffer_t *) &cube[6];
for (int i = 0; i < 6; i++) {
cube[i].width = side;
cube[i].height = side;
__auto_type buffer = buffer_base + i;
cube[i].buffer = buffer;
buffer->color = tex[0];
buffer->depth = tex[1];
qfglGenFramebuffers (1, &buffer->handle);
qfglBindFramebuffer (GL_FRAMEBUFFER, buffer->handle);
qfglFramebufferTexture2D (GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + i,
buffer->color, 0);
qfglFramebufferTexture2D (GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
GL_TEXTURE_2D, buffer->depth, 0);
}
qfglBindFramebuffer (GL_FRAMEBUFFER, 0);
return cube;
}
static framebuffer_t *
@ -320,16 +373,31 @@ gl_create_frame_buffer (int width, int height)
static void
gl_bind_framebuffer (framebuffer_t *framebuffer)
{
unsigned width = vr_data.vid->width;
unsigned height = vr_data.vid->height;
if (!framebuffer) {
qfglBindFramebuffer (GL_FRAMEBUFFER, 0);
} else {
gl_framebuffer_t *buffer = framebuffer->buffer;
qfglBindFramebuffer (GL_FRAMEBUFFER, buffer->handle);
width = framebuffer->width;
height = framebuffer->height;
}
vrect_t r = { 0, 0, width, height };
R_SetVrect (&r, &r_refdef.vrect, 0);
gl_R_ViewChanged ();
}
static void
gl_set_viewport (const vrect_t *view)
{
int x = r_refdef.vrect.x;
int y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height));
int w = r_refdef.vrect.width;
int h = r_refdef.vrect.height;
qfglViewport (x, y2, w, h);
int x = view->x;
int y = vid.height - (view->y + view->height);//FIXME vid.height
int w = view->width;
int h = view->height;
qfglViewport (x, y, w, h);
}
vid_render_funcs_t gl_vid_render_funcs = {

View file

@ -236,7 +236,6 @@ static void glsl_bind_framebuffer (framebuffer_t *fb);
static void
glsl_post_process (framebuffer_t *src)
{
glsl_bind_framebuffer (0);
if (scr_fisheye->int_val) {
glsl_FisheyeScreen (src);
} else if (r_dowarp) {
@ -376,7 +375,7 @@ static void
glsl_set_viewport (const vrect_t *view)
{
int x = view->x;
int y = vid.height - (view->y + view->height);
int y = vid.height - (view->y + view->height);//FIXME vid.height
int w = view->width;
int h = view->height;
qfeglViewport (x, y, w, h);