2006-08-29 01:58:59 +00:00
|
|
|
// blah
|
2010-03-07 01:09:39 +00:00
|
|
|
|
2015-05-16 20:16:27 +00:00
|
|
|
#if defined USE_OPENGL && defined POLYMER
|
2008-04-02 09:29:58 +00:00
|
|
|
|
2012-09-02 14:05:23 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2008-04-02 09:29:58 +00:00
|
|
|
#define POLYMER_C
|
2006-08-31 01:56:43 +00:00
|
|
|
#include "polymer.h"
|
2009-04-11 18:01:39 +00:00
|
|
|
#include "engine_priv.h"
|
2014-03-22 09:26:39 +00:00
|
|
|
#include "xxhash.h"
|
2013-05-15 02:17:17 +00:00
|
|
|
#include "texcache.h"
|
2006-08-29 01:58:59 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
// CVARS
|
2009-04-12 17:14:18 +00:00
|
|
|
int32_t pr_lighting = 1;
|
|
|
|
int32_t pr_normalmapping = 1;
|
|
|
|
int32_t pr_specularmapping = 1;
|
|
|
|
int32_t pr_shadows = 1;
|
|
|
|
int32_t pr_shadowcount = 5;
|
2009-04-28 22:56:43 +00:00
|
|
|
int32_t pr_shadowdetail = 4;
|
2009-06-06 16:00:48 +00:00
|
|
|
int32_t pr_shadowfiltering = 1;
|
2009-07-09 02:29:48 +00:00
|
|
|
int32_t pr_maxlightpasses = 10;
|
2009-04-12 16:28:20 +00:00
|
|
|
int32_t pr_maxlightpriority = PR_MAXLIGHTPRIORITY;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t pr_fov = 426; // appears to be the classic setting.
|
2013-05-15 14:53:54 +00:00
|
|
|
double pr_customaspect = 0.0f;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t pr_billboardingmode = 1;
|
|
|
|
int32_t pr_verbosity = 1; // 0: silent, 1: errors and one-times, 2: multiple-times, 3: flood
|
|
|
|
int32_t pr_wireframe = 0;
|
|
|
|
int32_t pr_vbos = 2;
|
2015-07-14 07:08:44 +00:00
|
|
|
int32_t pr_buckets = 0;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t pr_gpusmoothing = 1;
|
2009-03-29 15:16:33 +00:00
|
|
|
int32_t pr_overrideparallax = 0;
|
2009-03-29 17:14:41 +00:00
|
|
|
float pr_parallaxscale = 0.1f;
|
|
|
|
float pr_parallaxbias = 0.0f;
|
|
|
|
int32_t pr_overridespecular = 0;
|
|
|
|
float pr_specularpower = 15.0f;
|
|
|
|
float pr_specularfactor = 1.0f;
|
2010-12-30 08:13:37 +00:00
|
|
|
int32_t pr_highpalookups = 1;
|
2013-05-07 07:48:08 +00:00
|
|
|
int32_t pr_artmapping = 1;
|
2011-03-01 05:52:33 +00:00
|
|
|
int32_t pr_overridehud = 0;
|
|
|
|
float pr_hudxadd = 0.0f;
|
|
|
|
float pr_hudyadd = 0.0f;
|
|
|
|
float pr_hudzadd = 0.0f;
|
|
|
|
int32_t pr_hudangadd = 0;
|
|
|
|
int32_t pr_hudfov = 426;
|
2011-03-04 05:33:35 +00:00
|
|
|
float pr_overridemodelscale = 0.0f;
|
2009-06-28 21:03:50 +00:00
|
|
|
int32_t pr_ati_fboworkaround = 0;
|
2009-06-28 21:16:11 +00:00
|
|
|
int32_t pr_ati_nodepthoffset = 0;
|
2011-02-06 22:57:32 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
int32_t pr_ati_textureformat_one = 0;
|
|
|
|
#endif
|
2015-06-14 23:42:31 +00:00
|
|
|
int32_t pr_nullrender = 0; // 1: no draw, 2: no draw or updates
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
int32_t r_pr_maxlightpasses = 5; // value of the cvar (not live value), used to detect changes
|
|
|
|
|
2008-05-24 09:37:09 +00:00
|
|
|
GLenum mapvbousage = GL_STREAM_DRAW_ARB;
|
2008-06-01 08:58:06 +00:00
|
|
|
GLenum modelvbousage = GL_STATIC_DRAW_ARB;
|
2008-05-24 09:37:09 +00:00
|
|
|
|
2008-11-25 10:42:22 +00:00
|
|
|
// BUILD DATA
|
2006-09-29 21:36:12 +00:00
|
|
|
_prsector *prsectors[MAXSECTORS];
|
|
|
|
_prwall *prwalls[MAXWALLS];
|
2010-07-26 22:36:45 +00:00
|
|
|
_prsprite *prsprites[MAXSPRITES];
|
2008-11-26 19:31:26 +00:00
|
|
|
_prmaterial mdspritematerial;
|
2011-01-27 07:05:12 +00:00
|
|
|
_prhighpalookup prhighpalookups[MAXBASEPALS][MAXPALOOKUPS];
|
2008-05-18 07:35:35 +00:00
|
|
|
|
2013-05-06 03:12:38 +00:00
|
|
|
// One U8 texture per tile
|
|
|
|
GLuint prartmaps[MAXTILES];
|
|
|
|
// 256 U8U8U8 values per basepal
|
|
|
|
GLuint prbasepalmaps[MAXBASEPALS];
|
|
|
|
// numshades full indirections (32*256) per lookup
|
|
|
|
GLuint prlookups[MAXPALOOKUPS];
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
GLuint prmapvbo;
|
|
|
|
const GLsizeiptrARB proneplanesize = sizeof(_prvert) * 4;
|
|
|
|
const GLintptrARB prwalldatasize = sizeof(_prvert)* 4 * 3; // wall, over and mask planes for every wall
|
|
|
|
GLintptrARB prwalldataoffset;
|
|
|
|
|
2015-07-15 08:23:00 +00:00
|
|
|
GLuint prindexringvbo;
|
|
|
|
GLuint *prindexring;
|
|
|
|
const GLsizeiptrARB prindexringsize = 65535;
|
|
|
|
GLintptrARB prindexringoffset;
|
|
|
|
|
|
|
|
const GLbitfield prindexringmapflags = GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT;
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
_prbucket *prbuckethead;
|
|
|
|
int32_t prcanbucket;
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
static const _prvert vertsprite[4] =
|
2008-05-10 01:29:37 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
{
|
|
|
|
-0.5f, 0.0f, 0.0f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0.5f, 0.0f, 0.0f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0.5f, 1.0f, 0.0f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
-0.5f, 1.0f, 0.0f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
2008-04-02 06:01:12 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
static const _prvert horizsprite[4] =
|
2008-05-10 01:29:37 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
{
|
|
|
|
-0.5f, 0.0f, 0.5f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0.5f, 0.0f, 0.5f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0.5f, 0.0f, -0.5f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
-0.5f, 0.0f, -0.5f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
2008-04-02 06:01:12 +00:00
|
|
|
};
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
static const GLfloat skyboxdata[4 * 5 * 6] =
|
2008-06-09 09:25:47 +00:00
|
|
|
{
|
|
|
|
// -ZY
|
|
|
|
-0.5f, -0.5f, 0.5f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
-0.5f, -0.5f, -0.5f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
-0.5f, 0.5f, -0.5f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
-0.5f, 0.5f, 0.5f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
|
|
|
|
// XY
|
|
|
|
-0.5f, -0.5f, -0.5f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
0.5f, -0.5f, -0.5f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
0.5f, 0.5f, -0.5f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
-0.5f, 0.5f, -0.5f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
|
|
|
|
// ZY
|
|
|
|
0.5f, -0.5f, -0.5f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
0.5f, -0.5f, 0.5f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
0.5f, 0.5f, 0.5f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
0.5f, 0.5f, -0.5f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
|
|
|
|
// -XY
|
|
|
|
0.5f, -0.5f, 0.5f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
-0.5f, -0.5f, 0.5f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
-0.5f, 0.5f, 0.5f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
0.5f, 0.5f, 0.5f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
|
|
|
|
// XZ
|
|
|
|
-0.5f, 0.5f, -0.5f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
0.5f, 0.5f, -0.5f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
0.5f, 0.5f, 0.5f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
-0.5f, 0.5f, 0.5f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
|
|
|
|
// X-Z
|
|
|
|
-0.5f, -0.5f, 0.5f,
|
|
|
|
0.0f, 0.0f,
|
|
|
|
0.5f, -0.5f, 0.5f,
|
|
|
|
0.0f, 1.0f,
|
|
|
|
0.5f, -0.5f, -0.5f,
|
|
|
|
1.0f, 1.0f,
|
|
|
|
-0.5f, -0.5f, -0.5f,
|
|
|
|
1.0f, 0.0f,
|
|
|
|
};
|
|
|
|
|
2008-06-09 09:43:12 +00:00
|
|
|
GLuint skyboxdatavbo;
|
|
|
|
|
2008-06-09 09:25:47 +00:00
|
|
|
GLfloat artskydata[16];
|
|
|
|
|
2008-11-25 10:42:22 +00:00
|
|
|
// LIGHTS
|
2014-09-30 04:04:30 +00:00
|
|
|
static _prplanelist *plpool;
|
2009-07-12 01:55:34 +00:00
|
|
|
#pragma pack(push,1)
|
2008-11-25 09:07:38 +00:00
|
|
|
_prlight prlights[PR_MAXLIGHTS];
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t lightcount;
|
2009-03-12 13:51:30 +00:00
|
|
|
int32_t curlight;
|
2009-07-12 01:55:34 +00:00
|
|
|
#pragma pack(pop)
|
2009-04-12 13:02:36 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
static const GLfloat shadowBias[] =
|
2009-03-26 16:32:00 +00:00
|
|
|
{
|
|
|
|
0.5, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 0.5, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 0.5, 0.0,
|
|
|
|
0.5, 0.5, 0.5, 1.0
|
|
|
|
};
|
|
|
|
|
2008-11-26 14:22:07 +00:00
|
|
|
// MATERIALS
|
2014-09-30 04:04:30 +00:00
|
|
|
static const _prprogrambit prprogrambits[PR_BIT_COUNT] = {
|
2009-02-05 08:56:59 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_HEADER,
|
|
|
|
// vert_def
|
|
|
|
"#version 120\n"
|
2009-03-23 14:18:20 +00:00
|
|
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
2009-02-05 08:56:59 +00:00
|
|
|
"\n",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
|
|
|
"#version 120\n"
|
2009-03-23 14:18:20 +00:00
|
|
|
"#extension GL_ARB_texture_rectangle : enable\n"
|
2009-02-05 08:56:59 +00:00
|
|
|
"\n",
|
|
|
|
// frag_prog
|
|
|
|
"",
|
|
|
|
},
|
2008-11-27 16:19:24 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_ANIM_INTERPOLATION,
|
|
|
|
// vert_def
|
|
|
|
"attribute vec4 nextFrameData;\n"
|
2009-03-10 14:30:34 +00:00
|
|
|
"attribute vec4 nextFrameNormal;\n"
|
2008-11-27 16:19:24 +00:00
|
|
|
"uniform float frameProgress;\n"
|
|
|
|
"\n",
|
|
|
|
// vert_prog
|
|
|
|
" vec4 currentFramePosition;\n"
|
|
|
|
" vec4 nextFramePosition;\n"
|
2008-11-27 23:00:57 +00:00
|
|
|
"\n"
|
2009-03-10 14:30:34 +00:00
|
|
|
" currentFramePosition = curVertex * (1.0 - frameProgress);\n"
|
2008-11-27 16:19:24 +00:00
|
|
|
" nextFramePosition = nextFrameData * frameProgress;\n"
|
2009-03-10 14:30:34 +00:00
|
|
|
" curVertex = currentFramePosition + nextFramePosition;\n"
|
|
|
|
"\n"
|
|
|
|
" currentFramePosition = vec4(curNormal, 1.0) * (1.0 - frameProgress);\n"
|
|
|
|
" nextFramePosition = nextFrameNormal * frameProgress;\n"
|
|
|
|
" curNormal = vec3(currentFramePosition + nextFramePosition);\n"
|
2008-11-27 16:19:24 +00:00
|
|
|
"\n",
|
|
|
|
// frag_def
|
|
|
|
"",
|
|
|
|
// frag_prog
|
|
|
|
"",
|
|
|
|
},
|
2009-03-12 13:51:30 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_LIGHTING_PASS,
|
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
|
|
|
"",
|
|
|
|
// frag_prog
|
|
|
|
" isLightingPass = 1;\n"
|
|
|
|
" result = vec4(0.0, 0.0, 0.0, 1.0);\n"
|
|
|
|
"\n",
|
|
|
|
},
|
2009-03-13 15:18:46 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_NORMAL_MAP,
|
|
|
|
// vert_def
|
|
|
|
"attribute vec3 T;\n"
|
|
|
|
"attribute vec3 B;\n"
|
|
|
|
"attribute vec3 N;\n"
|
2009-03-28 18:25:30 +00:00
|
|
|
"uniform vec3 eyePosition;\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
"varying vec3 tangentSpaceEyeVec;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
"\n",
|
|
|
|
// vert_prog
|
2010-01-21 05:52:19 +00:00
|
|
|
" TBN = mat3(T, B, N);\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
" tangentSpaceEyeVec = eyePosition - vec3(curVertex);\n"
|
|
|
|
" tangentSpaceEyeVec = TBN * tangentSpaceEyeVec;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
"\n"
|
|
|
|
" isNormalMapped = 1;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_def
|
|
|
|
"uniform sampler2D normalMap;\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
"uniform vec2 normalBias;\n"
|
|
|
|
"varying vec3 tangentSpaceEyeVec;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
"\n",
|
|
|
|
// frag_prog
|
2009-03-29 15:16:33 +00:00
|
|
|
" vec4 normalStep;\n"
|
|
|
|
" float biasedHeight;\n"
|
|
|
|
"\n"
|
|
|
|
" eyeVec = normalize(tangentSpaceEyeVec);\n"
|
|
|
|
"\n"
|
|
|
|
" for (int i = 0; i < 4; i++) {\n"
|
|
|
|
" normalStep = texture2D(normalMap, commonTexCoord.st);\n"
|
|
|
|
" biasedHeight = normalStep.a * normalBias.x - normalBias.y;\n"
|
|
|
|
" commonTexCoord += (biasedHeight - commonTexCoord.z) * normalStep.z * eyeVec;\n"
|
|
|
|
" }\n"
|
|
|
|
"\n"
|
|
|
|
" normalTexel = texture2D(normalMap, commonTexCoord.st);\n"
|
2009-03-28 18:25:30 +00:00
|
|
|
"\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
" isNormalMapped = 1;\n"
|
|
|
|
"\n",
|
|
|
|
},
|
2013-05-06 03:12:38 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_ART_MAP,
|
|
|
|
// vert_def
|
2013-05-08 05:03:36 +00:00
|
|
|
"varying vec3 horizDistance;\n"
|
2013-05-06 03:12:38 +00:00
|
|
|
"\n",
|
|
|
|
// vert_prog
|
2013-05-07 07:48:08 +00:00
|
|
|
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
|
2013-05-08 05:03:36 +00:00
|
|
|
" horizDistance = vec3(gl_ModelViewMatrix * curVertex);\n"
|
2013-05-06 03:12:38 +00:00
|
|
|
"\n",
|
|
|
|
// frag_def
|
|
|
|
"uniform sampler2D artMap;\n"
|
|
|
|
"uniform sampler2D basePalMap;\n"
|
2013-05-08 06:18:31 +00:00
|
|
|
"uniform sampler2DRect lookupMap;\n"
|
2013-05-07 07:48:08 +00:00
|
|
|
"uniform float shadeOffset;\n"
|
|
|
|
"uniform float visibility;\n"
|
2013-05-08 05:03:36 +00:00
|
|
|
"varying vec3 horizDistance;\n"
|
2013-05-06 03:12:38 +00:00
|
|
|
"\n",
|
|
|
|
// frag_prog
|
2013-07-18 18:08:15 +00:00
|
|
|
|
|
|
|
// NOTE: the denominator was 1.024, but we increase it towards a bit
|
|
|
|
// farther far clipoff distance to account for the fact that the
|
|
|
|
// distance to the fragment is the common Euclidean one, as opposed to
|
|
|
|
// the "ortho" distance of Build.
|
|
|
|
" float shadeLookup = length(horizDistance) / 1.07 * visibility;\n"
|
2013-05-08 06:18:31 +00:00
|
|
|
" shadeLookup = shadeLookup + shadeOffset;\n"
|
2013-05-07 07:48:08 +00:00
|
|
|
"\n"
|
2013-05-08 06:18:31 +00:00
|
|
|
" float colorIndex = texture2D(artMap, commonTexCoord.st).r * 256.0;\n"
|
|
|
|
" float colorIndexNear = texture2DRect(lookupMap, vec2(colorIndex, floor(shadeLookup))).r;\n"
|
|
|
|
" float colorIndexFar = texture2DRect(lookupMap, vec2(colorIndex, floor(shadeLookup + 1.0))).r;\n"
|
|
|
|
" float colorIndexFullbright = texture2DRect(lookupMap, vec2(colorIndex, 0.0)).r;\n"
|
2013-05-06 03:12:38 +00:00
|
|
|
"\n"
|
2013-05-07 07:48:08 +00:00
|
|
|
" vec3 texelNear = texture2D(basePalMap, vec2(colorIndexNear, 0.5)).rgb;\n"
|
|
|
|
" vec3 texelFar = texture2D(basePalMap, vec2(colorIndexFar, 0.5)).rgb;\n"
|
2015-09-23 17:55:11 +00:00
|
|
|
" diffuseTexel.rgb = texture2D(basePalMap, vec2(colorIndexFullbright, 0.5)).rgb;\n"
|
2013-05-08 05:03:29 +00:00
|
|
|
"\n"
|
|
|
|
" if (isLightingPass == 0) {\n"
|
2015-09-23 17:55:11 +00:00
|
|
|
" result.rgb = mix(texelNear, texelFar, fract(shadeLookup));\n"
|
2013-05-08 05:03:29 +00:00
|
|
|
" result.a = 1.0;\n"
|
2013-05-08 06:18:31 +00:00
|
|
|
" if (colorIndex == 256.0)\n"
|
2013-05-08 05:03:29 +00:00
|
|
|
" result.a = 0.0;\n"
|
|
|
|
" }\n"
|
2013-05-06 03:12:38 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2008-11-26 08:37:14 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_DIFFUSE_MAP,
|
|
|
|
// vert_def
|
2008-11-27 22:26:46 +00:00
|
|
|
"uniform vec2 diffuseScale;\n"
|
|
|
|
"\n",
|
2008-11-26 08:37:14 +00:00
|
|
|
// vert_prog
|
2009-03-28 15:54:25 +00:00
|
|
|
" gl_TexCoord[0] = vec4(diffuseScale, 1.0, 1.0) * gl_MultiTexCoord0;\n"
|
2008-11-26 08:37:14 +00:00
|
|
|
"\n",
|
|
|
|
// frag_def
|
|
|
|
"uniform sampler2D diffuseMap;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_prog
|
2009-03-29 15:16:33 +00:00
|
|
|
" diffuseTexel = texture2D(diffuseMap, commonTexCoord.st);\n"
|
2010-12-29 06:23:49 +00:00
|
|
|
"\n",
|
|
|
|
},
|
|
|
|
{
|
2011-01-12 02:31:50 +00:00
|
|
|
1 << PR_BIT_DIFFUSE_DETAIL_MAP,
|
2010-12-29 06:23:49 +00:00
|
|
|
// vert_def
|
2011-01-12 02:31:50 +00:00
|
|
|
"uniform vec2 detailScale;\n"
|
|
|
|
"varying vec2 fragDetailScale;\n"
|
|
|
|
"\n",
|
2010-12-29 06:23:49 +00:00
|
|
|
// vert_prog
|
2011-01-12 02:31:50 +00:00
|
|
|
" fragDetailScale = detailScale;\n"
|
|
|
|
" if (isNormalMapped == 0)\n"
|
|
|
|
" gl_TexCoord[1] = vec4(detailScale, 1.0, 1.0) * gl_MultiTexCoord0;\n"
|
|
|
|
"\n",
|
2010-12-29 06:23:49 +00:00
|
|
|
// frag_def
|
2011-01-12 02:31:50 +00:00
|
|
|
"uniform sampler2D detailMap;\n"
|
|
|
|
"varying vec2 fragDetailScale;\n"
|
2010-12-29 06:23:49 +00:00
|
|
|
"\n",
|
|
|
|
// frag_prog
|
2011-01-12 02:31:50 +00:00
|
|
|
" if (isNormalMapped == 0)\n"
|
|
|
|
" diffuseTexel *= texture2D(detailMap, gl_TexCoord[1].st);\n"
|
|
|
|
" else\n"
|
|
|
|
" diffuseTexel *= texture2D(detailMap, commonTexCoord.st * fragDetailScale);\n"
|
|
|
|
" diffuseTexel.rgb *= 2.0;\n"
|
2010-12-29 06:23:49 +00:00
|
|
|
"\n",
|
|
|
|
},
|
|
|
|
{
|
2011-01-12 02:31:50 +00:00
|
|
|
1 << PR_BIT_DIFFUSE_MODULATION,
|
2010-12-29 06:23:49 +00:00
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
2011-01-12 02:31:50 +00:00
|
|
|
" gl_FrontColor = gl_Color;\n"
|
|
|
|
"\n",
|
2010-12-29 06:23:49 +00:00
|
|
|
// frag_def
|
|
|
|
"",
|
|
|
|
// frag_prog
|
2009-03-12 13:51:30 +00:00
|
|
|
" if (isLightingPass == 0)\n"
|
2011-01-18 01:34:39 +00:00
|
|
|
" result *= vec4(gl_Color);\n"
|
2008-11-26 08:37:14 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2008-11-27 22:26:46 +00:00
|
|
|
{
|
2011-01-18 01:34:39 +00:00
|
|
|
1 << PR_BIT_DIFFUSE_MAP2,
|
2008-11-27 22:26:46 +00:00
|
|
|
// vert_def
|
2011-01-12 02:31:50 +00:00
|
|
|
"",
|
2008-11-27 22:26:46 +00:00
|
|
|
// vert_prog
|
2011-01-12 02:31:50 +00:00
|
|
|
"",
|
2008-11-27 22:26:46 +00:00
|
|
|
// frag_def
|
2011-01-18 01:34:39 +00:00
|
|
|
"",
|
2008-11-27 22:26:46 +00:00
|
|
|
// frag_prog
|
2011-01-18 01:34:39 +00:00
|
|
|
" if (isLightingPass == 0)\n"
|
|
|
|
" result *= diffuseTexel;\n"
|
2008-11-27 22:26:46 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2008-11-25 11:32:49 +00:00
|
|
|
{
|
2011-01-18 01:34:39 +00:00
|
|
|
1 << PR_BIT_HIGHPALOOKUP_MAP,
|
2008-11-26 07:48:24 +00:00
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
2011-01-12 02:31:50 +00:00
|
|
|
"",
|
2008-11-26 07:48:24 +00:00
|
|
|
// frag_def
|
2011-01-18 01:34:39 +00:00
|
|
|
"uniform sampler3D highPalookupMap;\n"
|
|
|
|
"\n",
|
2008-11-26 07:48:24 +00:00
|
|
|
// frag_prog
|
2011-01-27 07:57:52 +00:00
|
|
|
" float highPalScale = 0.9921875; // for 6 bits\n"
|
|
|
|
" float highPalBias = 0.00390625;\n"
|
|
|
|
"\n"
|
2009-03-12 13:51:30 +00:00
|
|
|
" if (isLightingPass == 0)\n"
|
2011-01-27 07:57:52 +00:00
|
|
|
" result.rgb = texture3D(highPalookupMap, result.rgb * highPalScale + highPalBias).rgb;\n"
|
|
|
|
" diffuseTexel.rgb = texture3D(highPalookupMap, diffuseTexel.rgb * highPalScale + highPalBias).rgb;\n"
|
2009-03-12 13:51:30 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2009-03-28 16:14:10 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_SPECULAR_MAP,
|
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
|
|
|
"uniform sampler2D specMap;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_prog
|
2009-03-29 15:16:33 +00:00
|
|
|
" specTexel = texture2D(specMap, commonTexCoord.st);\n"
|
2009-05-16 01:28:42 +00:00
|
|
|
"\n"
|
|
|
|
" isSpecularMapped = 1;\n"
|
2009-03-28 16:14:10 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2009-03-28 12:14:37 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_SPECULAR_MATERIAL,
|
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
|
|
|
"uniform vec2 specMaterial;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_prog
|
|
|
|
" specularMaterial = specMaterial;\n"
|
|
|
|
"\n",
|
|
|
|
},
|
2009-03-23 14:18:20 +00:00
|
|
|
{
|
2009-03-28 11:43:16 +00:00
|
|
|
1 << PR_BIT_MIRROR_MAP,
|
2009-03-23 14:18:20 +00:00
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
|
|
|
"uniform sampler2DRect mirrorMap;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_prog
|
|
|
|
" vec4 mirrorTexel;\n"
|
|
|
|
" vec2 mirrorCoords;\n"
|
|
|
|
"\n"
|
|
|
|
" mirrorCoords = gl_FragCoord.st;\n"
|
|
|
|
" if (isNormalMapped == 1) {\n"
|
|
|
|
" mirrorCoords += 100.0 * (normalTexel.rg - 0.5);\n"
|
|
|
|
" }\n"
|
|
|
|
" mirrorTexel = texture2DRect(mirrorMap, mirrorCoords);\n"
|
2009-03-28 16:50:46 +00:00
|
|
|
" result = vec4((result.rgb * (1.0 - specTexel.a)) + (mirrorTexel.rgb * specTexel.rgb * specTexel.a), result.a);\n"
|
2009-03-23 14:18:20 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2009-04-11 18:01:39 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_FOG,
|
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
2012-12-16 19:18:10 +00:00
|
|
|
#ifdef PR_LINEAR_FOG
|
|
|
|
"uniform bool linearFog;\n"
|
|
|
|
#endif
|
2009-04-11 18:01:39 +00:00
|
|
|
"",
|
|
|
|
// frag_prog
|
|
|
|
" float fragDepth;\n"
|
|
|
|
" float fogFactor;\n"
|
|
|
|
"\n"
|
2009-04-14 12:37:44 +00:00
|
|
|
" fragDepth = gl_FragCoord.z / gl_FragCoord.w / 35.0;\n"
|
2012-12-16 19:18:10 +00:00
|
|
|
#ifdef PR_LINEAR_FOG
|
|
|
|
" if (!linearFog) {\n"
|
|
|
|
#endif
|
|
|
|
" fragDepth *= fragDepth;\n"
|
|
|
|
" fogFactor = exp2(-gl_Fog.density * gl_Fog.density * fragDepth * 1.442695);\n"
|
|
|
|
#ifdef PR_LINEAR_FOG
|
|
|
|
/* 0.65127==150/230, another constant found out by experiment. :/
|
2012-12-20 12:04:34 +00:00
|
|
|
* (150 is Polymost's old FOGDISTCONST.) */
|
2012-12-16 19:18:10 +00:00
|
|
|
" } else {\n"
|
|
|
|
" fogFactor = gl_Fog.scale * (gl_Fog.end - fragDepth*0.65217);\n"
|
|
|
|
" fogFactor = clamp(fogFactor, 0.0, 1.0);"
|
|
|
|
" }\n"
|
|
|
|
#endif
|
2009-04-11 18:01:39 +00:00
|
|
|
" result.rgb = mix(gl_Fog.color.rgb, result.rgb, fogFactor);\n"
|
|
|
|
"\n",
|
|
|
|
},
|
2009-03-12 13:51:30 +00:00
|
|
|
{
|
2009-03-28 11:43:16 +00:00
|
|
|
1 << PR_BIT_GLOW_MAP,
|
2009-03-12 13:51:30 +00:00
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
2009-03-28 15:54:25 +00:00
|
|
|
"",
|
2009-03-12 13:51:30 +00:00
|
|
|
// frag_def
|
|
|
|
"uniform sampler2D glowMap;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_prog
|
|
|
|
" vec4 glowTexel;\n"
|
|
|
|
"\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
" glowTexel = texture2D(glowMap, commonTexCoord.st);\n"
|
2009-03-12 13:51:30 +00:00
|
|
|
" result = vec4((result.rgb * (1.0 - glowTexel.a)) + (glowTexel.rgb * glowTexel.a), result.a);\n"
|
2008-11-26 07:48:24 +00:00
|
|
|
"\n",
|
2008-11-25 11:32:49 +00:00
|
|
|
},
|
2009-03-26 16:32:00 +00:00
|
|
|
{
|
2010-07-25 02:16:22 +00:00
|
|
|
1 << PR_BIT_PROJECTION_MAP,
|
2009-03-26 16:32:00 +00:00
|
|
|
// vert_def
|
|
|
|
"uniform mat4 shadowProjMatrix;\n"
|
|
|
|
"\n",
|
|
|
|
// vert_prog
|
2009-04-14 12:37:44 +00:00
|
|
|
" gl_TexCoord[2] = shadowProjMatrix * curVertex;\n"
|
2009-03-26 16:32:00 +00:00
|
|
|
"\n",
|
|
|
|
// frag_def
|
2010-07-25 02:16:22 +00:00
|
|
|
"",
|
|
|
|
// frag_prog
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
1 << PR_BIT_SHADOW_MAP,
|
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
2009-03-26 16:32:00 +00:00
|
|
|
"uniform sampler2DShadow shadowMap;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_prog
|
2009-04-14 12:37:44 +00:00
|
|
|
" shadowResult = shadow2DProj(shadowMap, gl_TexCoord[2]).a;\n"
|
2009-03-26 16:32:00 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2009-05-12 20:08:38 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_LIGHT_MAP,
|
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
|
|
|
"uniform sampler2D lightMap;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_prog
|
2011-10-02 03:09:20 +00:00
|
|
|
" lightTexel = texture2D(lightMap, vec2(gl_TexCoord[2].s, -gl_TexCoord[2].t) / gl_TexCoord[2].q).rgb;\n"
|
2009-05-12 20:08:38 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2009-03-25 19:48:27 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_SPOT_LIGHT,
|
|
|
|
// vert_def
|
|
|
|
"",
|
|
|
|
// vert_prog
|
|
|
|
"",
|
|
|
|
// frag_def
|
|
|
|
"uniform vec3 spotDir;\n"
|
|
|
|
"uniform vec2 spotRadius;\n"
|
|
|
|
"\n",
|
|
|
|
// frag_prog
|
|
|
|
" spotVector = spotDir;\n"
|
|
|
|
" spotCosRadius = spotRadius;\n"
|
|
|
|
" isSpotLight = 1;\n"
|
|
|
|
"\n",
|
|
|
|
},
|
2008-11-29 20:16:19 +00:00
|
|
|
{
|
|
|
|
1 << PR_BIT_POINT_LIGHT,
|
|
|
|
// vert_def
|
|
|
|
"varying vec3 vertexNormal;\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
"varying vec3 eyeVector;\n"
|
|
|
|
"varying vec3 lightVector;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
"varying vec3 tangentSpaceLightVector;\n"
|
2008-11-29 20:16:19 +00:00
|
|
|
"\n",
|
|
|
|
// vert_prog
|
2009-03-12 21:20:01 +00:00
|
|
|
" vec3 vertexPos;\n"
|
|
|
|
"\n"
|
2009-03-10 14:30:34 +00:00
|
|
|
" vertexPos = vec3(gl_ModelViewMatrix * curVertex);\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
" eyeVector = -vertexPos;\n"
|
|
|
|
" lightVector = gl_LightSource[0].ambient.rgb - vertexPos;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
"\n"
|
|
|
|
" if (isNormalMapped == 1) {\n"
|
2009-03-28 18:25:30 +00:00
|
|
|
" tangentSpaceLightVector = gl_LightSource[0].specular.rgb - vec3(curVertex);\n"
|
|
|
|
" tangentSpaceLightVector = TBN * tangentSpaceLightVector;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
" } else\n"
|
|
|
|
" vertexNormal = normalize(gl_NormalMatrix * curNormal);\n"
|
2008-11-29 20:16:19 +00:00
|
|
|
"\n",
|
|
|
|
// frag_def
|
|
|
|
"varying vec3 vertexNormal;\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
"varying vec3 eyeVector;\n"
|
|
|
|
"varying vec3 lightVector;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
"varying vec3 tangentSpaceLightVector;\n"
|
2008-11-29 20:16:19 +00:00
|
|
|
"\n",
|
|
|
|
// frag_prog
|
|
|
|
" float pointLightDistance;\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
" float lightAttenuation;\n"
|
2009-03-25 19:48:27 +00:00
|
|
|
" float spotAttenuation;\n"
|
|
|
|
" vec3 N, L, E, R, D;\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
" vec3 lightDiffuse;\n"
|
|
|
|
" float lightSpecular;\n"
|
|
|
|
" float NdotL;\n"
|
2009-03-25 19:48:27 +00:00
|
|
|
" float spotCosAngle;\n"
|
2008-11-29 20:16:19 +00:00
|
|
|
"\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
" L = normalize(lightVector);\n"
|
2009-01-14 14:13:51 +00:00
|
|
|
"\n"
|
2009-06-06 13:48:52 +00:00
|
|
|
" pointLightDistance = dot(lightVector,lightVector);\n"
|
|
|
|
" lightAttenuation = clamp(1.0 - pointLightDistance * gl_LightSource[0].linearAttenuation, 0.0, 1.0);\n"
|
2009-03-25 19:48:27 +00:00
|
|
|
" spotAttenuation = 1.0;\n"
|
|
|
|
"\n"
|
|
|
|
" if (isSpotLight == 1) {\n"
|
|
|
|
" D = normalize(spotVector);\n"
|
|
|
|
" spotCosAngle = dot(-L, D);\n"
|
|
|
|
" spotAttenuation = clamp((spotCosAngle - spotCosRadius.x) * spotCosRadius.y, 0.0, 1.0);\n"
|
|
|
|
" }\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
"\n"
|
2009-03-25 13:23:35 +00:00
|
|
|
" if (isNormalMapped == 1) {\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
" E = eyeVec;\n"
|
2009-03-28 18:25:30 +00:00
|
|
|
" N = normalize(2.0 * (normalTexel.rgb - 0.5));\n"
|
|
|
|
" L = normalize(tangentSpaceLightVector);\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
" } else {\n"
|
|
|
|
" E = normalize(eyeVector);\n"
|
2009-03-25 13:23:35 +00:00
|
|
|
" N = normalize(vertexNormal);\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
" }\n"
|
2009-03-25 13:23:35 +00:00
|
|
|
" NdotL = max(dot(N, L), 0.0);\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
"\n"
|
2009-03-25 13:23:35 +00:00
|
|
|
" R = reflect(-L, N);\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
"\n"
|
2009-05-16 00:50:30 +00:00
|
|
|
" lightDiffuse = gl_Color.a * shadowResult * lightTexel *\n"
|
2009-03-25 19:48:27 +00:00
|
|
|
" gl_LightSource[0].diffuse.rgb * lightAttenuation * spotAttenuation;\n"
|
2009-05-16 00:50:30 +00:00
|
|
|
" result += vec4(lightDiffuse * diffuseTexel.a * diffuseTexel.rgb * NdotL, 0.0);\n"
|
2009-03-12 21:20:01 +00:00
|
|
|
"\n"
|
2009-05-16 01:33:04 +00:00
|
|
|
" if (isSpecularMapped == 0)\n"
|
2009-05-16 01:28:42 +00:00
|
|
|
" specTexel.rgb = diffuseTexel.rgb * diffuseTexel.a;\n"
|
|
|
|
"\n"
|
2009-03-28 16:14:10 +00:00
|
|
|
" lightSpecular = pow( max(dot(R, E), 0.0), specularMaterial.x * specTexel.a) * specularMaterial.y;\n"
|
2009-05-15 14:23:08 +00:00
|
|
|
" result += vec4(lightDiffuse * specTexel.rgb * lightSpecular, 0.0);\n"
|
2008-11-27 23:00:57 +00:00
|
|
|
"\n",
|
|
|
|
},
|
2008-11-25 09:07:38 +00:00
|
|
|
{
|
2009-02-05 08:56:59 +00:00
|
|
|
1 << PR_BIT_FOOTER,
|
2008-11-26 07:48:24 +00:00
|
|
|
// vert_def
|
|
|
|
"void main(void)\n"
|
2008-11-27 16:19:24 +00:00
|
|
|
"{\n"
|
2009-03-10 14:30:34 +00:00
|
|
|
" vec4 curVertex = gl_Vertex;\n"
|
|
|
|
" vec3 curNormal = gl_Normal;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
" int isNormalMapped = 0;\n"
|
|
|
|
" mat3 TBN;\n"
|
2009-03-28 15:54:25 +00:00
|
|
|
"\n"
|
|
|
|
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
|
2008-11-27 16:19:24 +00:00
|
|
|
"\n",
|
2008-11-26 07:48:24 +00:00
|
|
|
// vert_prog
|
2009-03-10 14:30:34 +00:00
|
|
|
" gl_Position = gl_ModelViewProjectionMatrix * curVertex;\n"
|
2008-11-26 07:48:24 +00:00
|
|
|
"}\n",
|
|
|
|
// frag_def
|
|
|
|
"void main(void)\n"
|
|
|
|
"{\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
" vec3 commonTexCoord = vec3(gl_TexCoord[0].st, 0.0);\n"
|
2008-11-26 07:48:24 +00:00
|
|
|
" vec4 result = vec4(1.0, 1.0, 1.0, 1.0);\n"
|
2009-03-08 20:38:51 +00:00
|
|
|
" vec4 diffuseTexel = vec4(1.0, 1.0, 1.0, 1.0);\n"
|
2009-03-28 16:14:10 +00:00
|
|
|
" vec4 specTexel = vec4(1.0, 1.0, 1.0, 1.0);\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
" vec4 normalTexel;\n"
|
2009-03-12 13:51:30 +00:00
|
|
|
" int isLightingPass = 0;\n"
|
2009-03-13 15:18:46 +00:00
|
|
|
" int isNormalMapped = 0;\n"
|
2009-05-16 01:28:42 +00:00
|
|
|
" int isSpecularMapped = 0;\n"
|
2009-03-29 15:16:33 +00:00
|
|
|
" vec3 eyeVec;\n"
|
2009-03-25 19:48:27 +00:00
|
|
|
" int isSpotLight = 0;\n"
|
|
|
|
" vec3 spotVector;\n"
|
|
|
|
" vec2 spotCosRadius;\n"
|
2009-04-14 12:37:44 +00:00
|
|
|
" float shadowResult = 1.0;\n"
|
2009-03-29 17:14:41 +00:00
|
|
|
" vec2 specularMaterial = vec2(15.0, 1.0);\n"
|
2009-05-12 20:08:38 +00:00
|
|
|
" vec3 lightTexel = vec3(1.0, 1.0, 1.0);\n"
|
2008-11-26 07:48:24 +00:00
|
|
|
"\n",
|
|
|
|
// frag_prog
|
|
|
|
" gl_FragColor = result;\n"
|
|
|
|
"}\n",
|
2008-11-25 09:07:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-11-26 08:37:14 +00:00
|
|
|
_prprograminfo prprograms[1 << PR_BIT_COUNT];
|
2008-11-25 09:07:38 +00:00
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
int32_t overridematerial;
|
2009-12-07 07:01:44 +00:00
|
|
|
int32_t globaloldoverridematerial;
|
2009-03-18 15:05:58 +00:00
|
|
|
|
2011-02-28 03:56:37 +00:00
|
|
|
int32_t rotatespritematerialbits;
|
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
// RENDER TARGETS
|
|
|
|
_prrt *prrts;
|
|
|
|
|
2006-10-15 18:51:41 +00:00
|
|
|
// CONTROL
|
2009-01-14 14:13:51 +00:00
|
|
|
GLfloat spritemodelview[16];
|
2010-01-24 05:57:43 +00:00
|
|
|
GLfloat mdspritespace[4][4];
|
2009-01-14 14:13:51 +00:00
|
|
|
GLfloat rootmodelviewmatrix[16];
|
|
|
|
GLfloat *curmodelviewmatrix;
|
2009-05-09 10:42:57 +00:00
|
|
|
GLfloat rootskymodelviewmatrix[16];
|
|
|
|
GLfloat *curskymodelviewmatrix;
|
2006-10-15 18:51:41 +00:00
|
|
|
|
2009-04-12 22:23:47 +00:00
|
|
|
static int16_t sectorqueue[MAXSECTORS];
|
|
|
|
static int16_t querydelay[MAXSECTORS];
|
|
|
|
static GLuint queryid[MAXWALLS];
|
|
|
|
static int16_t drawingstate[MAXSECTORS];
|
|
|
|
|
2011-08-20 21:05:38 +00:00
|
|
|
int16_t *cursectormasks;
|
|
|
|
int16_t *cursectormaskcount;
|
|
|
|
|
2009-03-08 22:59:54 +00:00
|
|
|
float horizang;
|
2009-04-12 16:39:54 +00:00
|
|
|
int16_t viewangle;
|
2008-04-09 07:27:17 +00:00
|
|
|
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t depth;
|
2009-03-23 14:18:20 +00:00
|
|
|
_prmirror mirrors[10];
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2014-10-16 21:03:24 +00:00
|
|
|
#if defined __clang__ && defined __APPLE__
|
|
|
|
// XXX: OS X 10.9 deprecated GLUtesselator.
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
|
|
#endif
|
2006-08-30 23:32:39 +00:00
|
|
|
GLUtesselator* prtess;
|
2014-10-16 21:03:24 +00:00
|
|
|
#if defined __clang__ && defined __APPLE__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2013-08-04 20:37:49 +00:00
|
|
|
static int16_t cursky;
|
|
|
|
static char curskypal;
|
|
|
|
static int8_t curskyshade;
|
|
|
|
static float curskyangmul = 1;
|
2007-07-01 06:32:03 +00:00
|
|
|
|
2008-04-06 23:35:48 +00:00
|
|
|
_pranimatespritesinfo asi;
|
|
|
|
|
2009-12-07 07:01:44 +00:00
|
|
|
int32_t polymersearching;
|
2009-07-11 22:20:15 +00:00
|
|
|
|
2011-09-18 07:18:50 +00:00
|
|
|
int32_t culledface;
|
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
// EXTERNAL FUNCTIONS
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t polymer_init(void)
|
2006-08-29 01:58:59 +00:00
|
|
|
{
|
2011-09-28 20:30:24 +00:00
|
|
|
int32_t i, j, t = getticks();
|
2006-08-29 01:58:59 +00:00
|
|
|
|
2009-05-05 16:21:33 +00:00
|
|
|
if (pr_verbosity >= 1) OSD_Printf("Initializing Polymer subsystem...\n");
|
2006-08-29 01:58:59 +00:00
|
|
|
|
2009-09-30 01:26:13 +00:00
|
|
|
if (!glinfo.texnpot ||
|
|
|
|
!glinfo.depthtex ||
|
|
|
|
!glinfo.shadow ||
|
|
|
|
!glinfo.fbos ||
|
|
|
|
!glinfo.rect ||
|
|
|
|
!glinfo.multitex ||
|
|
|
|
!glinfo.vbos ||
|
|
|
|
!glinfo.occlusionqueries ||
|
|
|
|
!glinfo.glsl)
|
|
|
|
{
|
|
|
|
OSD_Printf("PR : Your video card driver/combo doesn't support the necessary features!\n");
|
|
|
|
OSD_Printf("PR : Disabling Polymer...\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2011-07-24 15:15:57 +00:00
|
|
|
// clean up existing stuff since it will be initialized again if we're re-entering here
|
|
|
|
polymer_uninit();
|
2011-07-22 22:00:53 +00:00
|
|
|
|
2009-04-16 06:49:29 +00:00
|
|
|
Bmemset(&prsectors[0], 0, sizeof(prsectors[0]) * MAXSECTORS);
|
|
|
|
Bmemset(&prwalls[0], 0, sizeof(prwalls[0]) * MAXWALLS);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2007-01-16 03:19:04 +00:00
|
|
|
prtess = bgluNewTess();
|
2006-08-30 23:32:39 +00:00
|
|
|
if (prtess == 0)
|
|
|
|
{
|
2009-05-05 16:21:33 +00:00
|
|
|
OSD_Printf("PR : Tessellation object initialization failed!\n");
|
2006-08-30 23:32:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
polymer_loadboard();
|
|
|
|
|
2008-06-09 09:25:47 +00:00
|
|
|
polymer_initartsky();
|
2009-04-12 09:57:25 +00:00
|
|
|
skyboxdatavbo = 0;
|
2006-10-18 03:59:28 +00:00
|
|
|
|
2009-04-12 10:46:31 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < nextmodelid)
|
|
|
|
{
|
|
|
|
if (models[i])
|
|
|
|
{
|
|
|
|
md3model_t* m;
|
|
|
|
|
|
|
|
m = (md3model_t*)models[i];
|
|
|
|
m->indices = NULL;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2009-04-12 09:57:25 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < (1 << PR_BIT_COUNT))
|
|
|
|
{
|
|
|
|
prprograms[i].handle = 0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
overridematerial = 0xFFFFFFFF;
|
|
|
|
|
2009-12-07 07:01:44 +00:00
|
|
|
polymersearching = FALSE;
|
|
|
|
|
2009-04-12 17:14:18 +00:00
|
|
|
polymer_initrendertargets(pr_shadowcount + 1);
|
2011-07-24 15:15:57 +00:00
|
|
|
|
2010-12-30 08:13:37 +00:00
|
|
|
// Prime highpalookup maps
|
|
|
|
i = 0;
|
2011-01-27 07:05:12 +00:00
|
|
|
while (i < MAXBASEPALS)
|
2010-12-30 08:13:37 +00:00
|
|
|
{
|
2011-01-27 07:05:12 +00:00
|
|
|
j = 0;
|
|
|
|
while (j < MAXPALOOKUPS)
|
2010-12-30 08:13:37 +00:00
|
|
|
{
|
2011-01-27 07:05:12 +00:00
|
|
|
if (prhighpalookups[i][j].data)
|
|
|
|
{
|
|
|
|
bglGenTextures(1, &prhighpalookups[i][j].map);
|
|
|
|
bglBindTexture(GL_TEXTURE_3D, prhighpalookups[i][j].map);
|
|
|
|
bglTexImage3D(GL_TEXTURE_3D, // target
|
|
|
|
0, // mip level
|
|
|
|
GL_RGBA, // internalFormat
|
|
|
|
PR_HIGHPALOOKUP_DIM, // width
|
|
|
|
PR_HIGHPALOOKUP_DIM, // height
|
|
|
|
PR_HIGHPALOOKUP_DIM, // depth
|
|
|
|
0, // border
|
|
|
|
GL_BGRA, // upload format
|
|
|
|
GL_UNSIGNED_BYTE, // upload component type
|
|
|
|
prhighpalookups[i][j].data); // data pointer
|
|
|
|
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
|
|
|
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
|
|
|
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
|
|
|
bglBindTexture(GL_TEXTURE_3D, 0);
|
|
|
|
}
|
|
|
|
j++;
|
2010-12-29 06:23:49 +00:00
|
|
|
}
|
2010-12-30 08:13:37 +00:00
|
|
|
i++;
|
2010-12-29 06:23:49 +00:00
|
|
|
}
|
|
|
|
|
2011-10-11 16:52:53 +00:00
|
|
|
#ifndef __APPLE__
|
2011-10-02 05:56:35 +00:00
|
|
|
if (glinfo.debugoutput) {
|
|
|
|
// Enable everything.
|
|
|
|
bglDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
|
2015-07-15 08:23:00 +00:00
|
|
|
bglDebugMessageCallbackARB((GLDEBUGPROCARB)polymer_debugoutputcallback, NULL);
|
2015-07-13 03:46:35 +00:00
|
|
|
bglEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
|
2011-10-02 05:56:35 +00:00
|
|
|
}
|
2011-10-11 16:52:53 +00:00
|
|
|
#endif
|
2011-10-02 05:56:35 +00:00
|
|
|
|
2011-09-28 20:30:24 +00:00
|
|
|
if (pr_verbosity >= 1) OSD_Printf("PR : Initialization complete in %d ms.\n", getticks()-t);
|
2009-12-07 07:01:44 +00:00
|
|
|
|
2006-08-30 23:32:39 +00:00
|
|
|
return (1);
|
2006-08-29 01:58:59 +00:00
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2009-05-22 23:49:25 +00:00
|
|
|
void polymer_uninit(void)
|
|
|
|
{
|
2011-01-27 07:05:12 +00:00
|
|
|
int32_t i, j;
|
2010-12-30 08:13:37 +00:00
|
|
|
|
2011-07-24 15:15:57 +00:00
|
|
|
if (prtess)
|
|
|
|
{
|
|
|
|
bgluDeleteTess(prtess);
|
|
|
|
prtess = NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-22 23:49:25 +00:00
|
|
|
polymer_freeboard();
|
2011-07-24 15:15:57 +00:00
|
|
|
|
|
|
|
polymer_initrendertargets(0);
|
|
|
|
|
2010-12-30 08:13:37 +00:00
|
|
|
i = 0;
|
2011-01-27 07:05:12 +00:00
|
|
|
while (i < MAXBASEPALS)
|
2010-12-30 08:13:37 +00:00
|
|
|
{
|
2011-01-27 07:05:12 +00:00
|
|
|
j = 0;
|
|
|
|
while (j < MAXPALOOKUPS)
|
|
|
|
{
|
2011-08-17 18:52:54 +00:00
|
|
|
// if (prhighpalookups[i][j].data) {
|
2015-09-23 17:55:31 +00:00
|
|
|
// DO_FREE_AND_NULL(prhighpalookups[i][j].data);
|
2011-08-17 18:52:54 +00:00
|
|
|
// }
|
2011-01-27 07:05:12 +00:00
|
|
|
if (prhighpalookups[i][j].map) {
|
|
|
|
bglDeleteTextures(1, &prhighpalookups[i][j].map);
|
2011-09-28 20:30:24 +00:00
|
|
|
prhighpalookups[i][j].map = 0;
|
2011-01-27 07:05:12 +00:00
|
|
|
}
|
|
|
|
j++;
|
2016-06-05 04:46:28 +00:00
|
|
|
}
|
2010-12-30 08:13:37 +00:00
|
|
|
i++;
|
|
|
|
}
|
2014-09-30 04:04:30 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (plpool)
|
|
|
|
{
|
|
|
|
_prplanelist* next = plpool->n;
|
|
|
|
|
|
|
|
Bfree(plpool);
|
|
|
|
plpool = next;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pr_verbosity >= 3)
|
|
|
|
OSD_Printf("PR: freed %d planelists\n", i);
|
2009-05-22 23:49:25 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 05:52:33 +00:00
|
|
|
void polymer_setaspect(int32_t ang)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2009-09-30 14:32:11 +00:00
|
|
|
float aspect;
|
2012-11-15 14:28:44 +00:00
|
|
|
float fang = (float)ang * atanf((float)viewingrange/65536.0f)/(PI/4);
|
2009-09-30 14:32:11 +00:00
|
|
|
|
2011-03-01 05:52:33 +00:00
|
|
|
if (pr_customaspect != 0.0f)
|
|
|
|
aspect = pr_customaspect;
|
|
|
|
else
|
|
|
|
aspect = (float)(windowx2-windowx1+1) /
|
|
|
|
(float)(windowy2-windowy1+1);
|
|
|
|
|
|
|
|
bglMatrixMode(GL_PROJECTION);
|
|
|
|
bglLoadIdentity();
|
2011-10-17 18:41:38 +00:00
|
|
|
bgluPerspective(fang / (2048.0f / 360.0f), aspect, 0.01f, 100.0f);
|
2011-03-01 05:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void polymer_glinit(void)
|
|
|
|
{
|
2006-04-23 06:44:19 +00:00
|
|
|
bglClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
2006-10-04 09:54:25 +00:00
|
|
|
bglClearStencil(0);
|
|
|
|
bglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2009-09-30 00:51:45 +00:00
|
|
|
bglViewport(windowx1, yres-(windowy2+1),windowx2-windowx1+1, windowy2-windowy1+1);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
|
|
|
// texturing
|
2006-09-27 17:55:49 +00:00
|
|
|
bglEnable(GL_TEXTURE_2D);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2006-04-23 06:44:19 +00:00
|
|
|
bglEnable(GL_DEPTH_TEST);
|
2006-10-19 23:51:44 +00:00
|
|
|
bglDepthFunc(GL_LEQUAL);
|
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
bglDisable(GL_BLEND);
|
|
|
|
bglDisable(GL_ALPHA_TEST);
|
|
|
|
|
2006-08-30 23:32:39 +00:00
|
|
|
if (pr_wireframe)
|
|
|
|
bglPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
|
|
|
else
|
|
|
|
bglPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
2011-09-18 07:18:50 +00:00
|
|
|
|
2011-03-01 05:52:33 +00:00
|
|
|
polymer_setaspect(pr_fov);
|
2006-10-14 23:33:10 +00:00
|
|
|
|
2006-04-23 06:44:19 +00:00
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglLoadIdentity();
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
bglEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
bglEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
|
2006-10-18 03:59:28 +00:00
|
|
|
bglDisable(GL_FOG);
|
|
|
|
|
2011-09-18 07:18:50 +00:00
|
|
|
culledface = GL_BACK;
|
2006-10-04 09:54:25 +00:00
|
|
|
bglCullFace(GL_BACK);
|
2015-02-18 01:47:06 +00:00
|
|
|
bglFrontFace(GL_CCW);
|
2011-09-18 07:18:50 +00:00
|
|
|
|
|
|
|
bglEnable(GL_CULL_FACE);
|
2006-09-29 21:36:12 +00:00
|
|
|
}
|
|
|
|
|
2010-01-25 01:11:34 +00:00
|
|
|
void polymer_resetlights(void)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
_prsector *s;
|
|
|
|
_prwall *w;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < numsectors)
|
|
|
|
{
|
|
|
|
s = prsectors[i];
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
polymer_resetplanelights(&s->floor);
|
|
|
|
polymer_resetplanelights(&s->ceil);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < numwalls)
|
|
|
|
{
|
|
|
|
w = prwalls[i];
|
|
|
|
|
|
|
|
if (!w) {
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
polymer_resetplanelights(&w->wall);
|
|
|
|
polymer_resetplanelights(&w->over);
|
|
|
|
polymer_resetplanelights(&w->mask);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < PR_MAXLIGHTS)
|
|
|
|
{
|
|
|
|
prlights[i].flags.active = 0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
lightcount = 0;
|
2010-05-25 10:56:00 +00:00
|
|
|
|
2012-01-05 21:58:23 +00:00
|
|
|
if (!loadmaphack(NULL))
|
|
|
|
OSD_Printf("polymer_resetlights: reloaded maphack\n");
|
2010-01-25 01:11:34 +00:00
|
|
|
}
|
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
void polymer_loadboard(void)
|
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2009-05-22 23:49:25 +00:00
|
|
|
polymer_freeboard();
|
2009-05-16 22:26:40 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
// in the big map buffer, sectors have floor and ceiling vertices for each wall first, then walls
|
|
|
|
prwalldataoffset = numwalls * 2 * sizeof(_prvert);
|
|
|
|
|
|
|
|
bglGenBuffersARB(1, &prmapvbo);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, prmapvbo);
|
2015-07-14 07:08:44 +00:00
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, prwalldataoffset + (numwalls * prwalldatasize), NULL, mapvbousage);
|
2015-07-13 03:46:35 +00:00
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
|
2015-07-15 08:23:00 +00:00
|
|
|
bglGenBuffersARB(1, &prindexringvbo);
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, prindexringvbo);
|
|
|
|
|
2015-09-11 21:36:57 +00:00
|
|
|
if (pr_buckets)
|
|
|
|
{
|
|
|
|
bglBufferStorage(GL_ELEMENT_ARRAY_BUFFER, prindexringsize * sizeof(GLuint), NULL, prindexringmapflags | GL_DYNAMIC_STORAGE_BIT);
|
|
|
|
prindexring = (GLuint*)bglMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, prindexringsize * sizeof(GLuint), prindexringmapflags);
|
|
|
|
}
|
2015-07-15 08:23:00 +00:00
|
|
|
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < numsectors)
|
|
|
|
{
|
|
|
|
polymer_initsector(i);
|
|
|
|
polymer_updatesector(i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < numwalls)
|
|
|
|
{
|
|
|
|
polymer_initwall(i);
|
|
|
|
polymer_updatewall(i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2006-10-19 23:51:44 +00:00
|
|
|
polymer_getsky();
|
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_resetlights();
|
|
|
|
|
2010-05-19 10:02:35 +00:00
|
|
|
if (pr_verbosity >= 1 && numsectors) OSD_Printf("PR : Board loaded.\n");
|
2006-09-29 21:36:12 +00:00
|
|
|
}
|
2008-03-26 09:24:25 +00:00
|
|
|
|
2013-08-04 20:37:49 +00:00
|
|
|
// The parallaxed ART sky angle divisor corresponding to a horizfrac of 32768.
|
|
|
|
#define DEFAULT_ARTSKY_ANGDIV 4.3027f
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void polymer_drawrooms(int32_t daposx, int32_t daposy, int32_t daposz, int16_t daang, int32_t dahoriz, int16_t dacursectnum)
|
2006-09-29 21:36:12 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int16_t cursectnum;
|
2009-04-01 18:11:01 +00:00
|
|
|
int32_t i, cursectflorz, cursectceilz;
|
2009-05-09 11:04:10 +00:00
|
|
|
float skyhoriz, ang, tiltang;
|
2008-04-06 03:00:39 +00:00
|
|
|
float pos[3];
|
2009-05-09 11:04:10 +00:00
|
|
|
pthtyp* pth;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2013-05-17 03:44:09 +00:00
|
|
|
if (getrendermode() == REND_CLASSIC) return;
|
2009-04-23 09:09:41 +00:00
|
|
|
|
|
|
|
begindrawing();
|
2009-04-23 09:30:10 +00:00
|
|
|
|
|
|
|
// TODO: support for screen resizing
|
|
|
|
// frameoffset = frameplace + windowy1*bytesperline + windowx1;
|
2009-04-23 09:09:41 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Drawing rooms...\n");
|
|
|
|
|
2009-04-11 18:01:39 +00:00
|
|
|
// fogcalc needs this
|
|
|
|
gvisibility = ((float)globalvisibility)*FOGSCALE;
|
|
|
|
|
2006-10-14 23:33:10 +00:00
|
|
|
ang = (float)(daang) / (2048.0f / 360.0f);
|
2009-02-13 12:16:21 +00:00
|
|
|
horizang = (float)(-getangle(128, dahoriz-100)) / (2048.0f / 360.0f);
|
2006-10-14 23:33:10 +00:00
|
|
|
tiltang = (gtang * 90.0f);
|
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
pos[0] = (float)daposy;
|
2008-04-06 23:35:48 +00:00
|
|
|
pos[1] = -(float)(daposz) / 16.0f;
|
2009-07-12 01:55:34 +00:00
|
|
|
pos[2] = -(float)daposx;
|
2006-10-14 23:33:10 +00:00
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_updatelights();
|
|
|
|
|
|
|
|
// polymer_resetlights();
|
|
|
|
// if (pr_lighting)
|
|
|
|
// polymer_applylights();
|
2009-04-12 13:51:43 +00:00
|
|
|
|
2009-03-26 16:32:00 +00:00
|
|
|
depth = 0;
|
2009-04-12 17:14:18 +00:00
|
|
|
|
2009-04-19 09:49:27 +00:00
|
|
|
if (pr_shadows && lightcount && (pr_shadowcount > 0))
|
2009-04-12 17:14:18 +00:00
|
|
|
polymer_prepareshadows();
|
2009-03-26 16:32:00 +00:00
|
|
|
|
2009-05-09 11:04:10 +00:00
|
|
|
// hack for parallax skies
|
|
|
|
skyhoriz = horizang;
|
|
|
|
if (skyhoriz < -180.0f)
|
|
|
|
skyhoriz += 360.0f;
|
|
|
|
|
|
|
|
drawingskybox = 1;
|
2015-12-04 11:52:54 +00:00
|
|
|
pth = texcache_fetch(cursky, 0, 0, DAMETH_NOMASK);
|
2009-05-09 11:04:10 +00:00
|
|
|
drawingskybox = 0;
|
|
|
|
|
|
|
|
// if it's not a skybox, make the sky parallax
|
2013-08-04 20:37:49 +00:00
|
|
|
// DEFAULT_ARTSKY_ANGDIV is computed from eyeballed values
|
2009-05-09 11:04:10 +00:00
|
|
|
// need to recompute it if we ever change the max horiz amplitude
|
2014-05-28 22:40:16 +00:00
|
|
|
if (!pth || !(pth->flags & PTH_SKYBOX))
|
2013-08-04 20:37:49 +00:00
|
|
|
skyhoriz *= curskyangmul;
|
2009-05-09 11:04:10 +00:00
|
|
|
|
2006-10-14 23:33:10 +00:00
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglLoadIdentity();
|
|
|
|
|
2006-10-15 18:51:41 +00:00
|
|
|
bglRotatef(tiltang, 0.0f, 0.0f, -1.0f);
|
2009-05-09 11:04:10 +00:00
|
|
|
bglRotatef(skyhoriz, 1.0f, 0.0f, 0.0f);
|
2006-10-14 23:33:10 +00:00
|
|
|
bglRotatef(ang, 0.0f, 1.0f, 0.0f);
|
|
|
|
|
2009-05-09 10:42:57 +00:00
|
|
|
bglScalef(1.0f / 1000.0f, 1.0f / 1000.0f, 1.0f / 1000.0f);
|
|
|
|
bglTranslatef(-pos[0], -pos[1], -pos[2]);
|
|
|
|
|
|
|
|
bglGetFloatv(GL_MODELVIEW_MATRIX, rootskymodelviewmatrix);
|
2014-09-30 04:04:30 +00:00
|
|
|
|
2009-05-09 10:42:57 +00:00
|
|
|
curskymodelviewmatrix = rootskymodelviewmatrix;
|
|
|
|
|
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglLoadIdentity();
|
|
|
|
|
|
|
|
bglRotatef(tiltang, 0.0f, 0.0f, -1.0f);
|
|
|
|
bglRotatef(horizang, 1.0f, 0.0f, 0.0f);
|
|
|
|
bglRotatef(ang, 0.0f, 1.0f, 0.0f);
|
2006-10-18 03:59:28 +00:00
|
|
|
|
2008-04-06 23:35:48 +00:00
|
|
|
bglScalef(1.0f / 1000.0f, 1.0f / 1000.0f, 1.0f / 1000.0f);
|
2008-01-05 08:58:15 +00:00
|
|
|
bglTranslatef(-pos[0], -pos[1], -pos[2]);
|
2006-10-14 23:33:10 +00:00
|
|
|
|
2009-01-14 14:13:51 +00:00
|
|
|
bglGetFloatv(GL_MODELVIEW_MATRIX, rootmodelviewmatrix);
|
2006-10-15 18:51:41 +00:00
|
|
|
|
2008-04-04 07:28:25 +00:00
|
|
|
cursectnum = dacursectnum;
|
2012-10-01 17:52:09 +00:00
|
|
|
updatesectorbreadth(daposx, daposy, &cursectnum);
|
|
|
|
|
|
|
|
if (cursectnum >= 0 && cursectnum < numsectors)
|
2008-04-04 07:28:25 +00:00
|
|
|
dacursectnum = cursectnum;
|
2012-01-14 14:48:30 +00:00
|
|
|
else if (pr_verbosity>=2)
|
|
|
|
OSD_Printf("PR : got sector %d after update!\n", cursectnum);
|
2008-04-04 07:28:25 +00:00
|
|
|
|
2008-04-27 22:47:47 +00:00
|
|
|
// unflag all sectors
|
2009-06-09 06:19:58 +00:00
|
|
|
i = numsectors-1;
|
|
|
|
while (i >= 0)
|
2008-04-27 22:47:47 +00:00
|
|
|
{
|
2009-06-09 09:32:23 +00:00
|
|
|
prsectors[i]->flags.uptodate = 0;
|
2008-04-27 22:47:47 +00:00
|
|
|
prsectors[i]->wallsproffset = 0.0f;
|
|
|
|
prsectors[i]->floorsproffset = 0.0f;
|
2009-06-09 06:19:58 +00:00
|
|
|
i--;
|
2008-04-27 22:47:47 +00:00
|
|
|
}
|
2009-06-09 06:19:58 +00:00
|
|
|
i = numwalls-1;
|
|
|
|
while (i >= 0)
|
2008-04-27 22:47:47 +00:00
|
|
|
{
|
2009-06-09 09:32:23 +00:00
|
|
|
prwalls[i]->flags.uptodate = 0;
|
2009-06-09 06:19:58 +00:00
|
|
|
i--;
|
2008-04-27 22:47:47 +00:00
|
|
|
}
|
|
|
|
|
2009-12-07 07:01:44 +00:00
|
|
|
if (searchit == 2 && !polymersearching)
|
|
|
|
{
|
|
|
|
globaloldoverridematerial = overridematerial;
|
|
|
|
overridematerial = prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit;
|
2011-01-12 17:10:41 +00:00
|
|
|
overridematerial |= prprogrambits[PR_BIT_DIFFUSE_MAP2].bit;
|
2009-12-07 07:01:44 +00:00
|
|
|
polymersearching = TRUE;
|
|
|
|
}
|
|
|
|
if (!searchit && polymersearching) {
|
|
|
|
overridematerial = globaloldoverridematerial;
|
|
|
|
polymersearching = FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:03:16 +00:00
|
|
|
if (dacursectnum > -1 && dacursectnum < numsectors)
|
|
|
|
getzsofslope(dacursectnum, daposx, daposy, &cursectceilz, &cursectflorz);
|
2009-04-01 18:11:01 +00:00
|
|
|
|
2008-04-04 07:28:25 +00:00
|
|
|
// external view (editor)
|
2008-04-27 22:47:47 +00:00
|
|
|
if ((dacursectnum < 0) || (dacursectnum >= numsectors) ||
|
2009-04-01 18:11:01 +00:00
|
|
|
(daposz > cursectflorz) ||
|
|
|
|
(daposz < cursectceilz))
|
2006-09-29 21:36:12 +00:00
|
|
|
{
|
2015-07-14 07:08:44 +00:00
|
|
|
prcanbucket = 1;
|
|
|
|
|
2012-01-14 14:48:30 +00:00
|
|
|
if (!editstatus && pr_verbosity>=1)
|
2012-03-28 19:45:05 +00:00
|
|
|
{
|
|
|
|
if ((unsigned)dacursectnum < (unsigned)numsectors)
|
|
|
|
OSD_Printf("PR : EXT sec=%d z=%d (%d, %d)\n", dacursectnum, daposz, cursectflorz, cursectceilz);
|
|
|
|
else
|
2012-03-28 19:45:25 +00:00
|
|
|
OSD_Printf("PR : EXT sec=%d z=%d\n", dacursectnum, daposz);
|
2012-03-28 19:45:05 +00:00
|
|
|
}
|
2012-01-14 14:48:30 +00:00
|
|
|
|
2009-12-14 07:08:21 +00:00
|
|
|
curmodelviewmatrix = rootmodelviewmatrix;
|
2009-06-09 06:19:58 +00:00
|
|
|
i = numsectors-1;
|
|
|
|
while (i >= 0)
|
2006-10-14 23:33:10 +00:00
|
|
|
{
|
2006-10-15 18:51:41 +00:00
|
|
|
polymer_updatesector(i);
|
2011-08-20 21:05:38 +00:00
|
|
|
polymer_drawsector(i, FALSE);
|
2008-04-06 23:35:48 +00:00
|
|
|
polymer_scansprites(i, tsprite, &spritesortcnt);
|
2009-06-09 06:19:58 +00:00
|
|
|
i--;
|
2006-10-19 23:51:44 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
i = numwalls-1;
|
|
|
|
while (i >= 0)
|
2006-10-19 23:51:44 +00:00
|
|
|
{
|
2008-04-06 03:00:39 +00:00
|
|
|
polymer_updatewall(i);
|
2008-04-09 07:27:17 +00:00
|
|
|
polymer_drawwall(sectorofwall(i), i);
|
2009-06-09 06:19:58 +00:00
|
|
|
i--;
|
2006-10-19 23:51:44 +00:00
|
|
|
}
|
2015-07-14 07:08:44 +00:00
|
|
|
|
|
|
|
polymer_emptybuckets();
|
|
|
|
|
2008-04-06 03:00:39 +00:00
|
|
|
viewangle = daang;
|
2009-04-23 09:09:41 +00:00
|
|
|
enddrawing();
|
2006-10-19 23:51:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-11-13 23:12:47 +00:00
|
|
|
|
2008-04-06 03:00:39 +00:00
|
|
|
// GO!
|
|
|
|
polymer_displayrooms(dacursectnum);
|
2008-03-30 09:16:39 +00:00
|
|
|
|
2008-04-06 03:00:39 +00:00
|
|
|
curmodelviewmatrix = rootmodelviewmatrix;
|
2009-02-13 12:30:08 +00:00
|
|
|
|
|
|
|
// build globals used by rotatesprite
|
|
|
|
viewangle = daang;
|
2013-02-10 16:24:11 +00:00
|
|
|
set_globalang(daang);
|
2007-03-22 18:28:41 +00:00
|
|
|
|
2009-02-13 12:30:08 +00:00
|
|
|
// polymost globals used by polymost_dorotatesprite
|
2014-09-30 04:04:30 +00:00
|
|
|
gcosang = ((float)cosglobalang)/262144.f;
|
|
|
|
gsinang = ((float)singlobalang)/262144.f;
|
|
|
|
gcosang2 = gcosang*((float)viewingrange)/65536.f;
|
|
|
|
gsinang2 = gsinang*((float)viewingrange)/65536.f;
|
2009-02-13 12:30:08 +00:00
|
|
|
|
2007-07-01 06:32:03 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Rooms drawn.\n");
|
2009-04-23 09:09:41 +00:00
|
|
|
enddrawing();
|
2007-03-22 18:28:41 +00:00
|
|
|
}
|
|
|
|
|
2008-03-30 09:16:39 +00:00
|
|
|
void polymer_drawmasks(void)
|
|
|
|
{
|
2008-03-30 14:22:03 +00:00
|
|
|
bglEnable(GL_ALPHA_TEST);
|
|
|
|
bglEnable(GL_BLEND);
|
2011-08-20 21:05:38 +00:00
|
|
|
// bglEnable(GL_POLYGON_OFFSET_FILL);
|
2008-03-30 14:22:03 +00:00
|
|
|
|
2011-08-20 21:05:38 +00:00
|
|
|
// while (--spritesortcnt)
|
|
|
|
// {
|
|
|
|
// tspriteptr[spritesortcnt] = &tsprite[spritesortcnt];
|
|
|
|
// polymer_drawsprite(spritesortcnt);
|
|
|
|
// }
|
|
|
|
|
2011-08-21 19:41:22 +00:00
|
|
|
bglEnable(GL_CULL_FACE);
|
|
|
|
|
2011-08-20 21:06:00 +00:00
|
|
|
if (cursectormaskcount) {
|
|
|
|
// We (kind of) queue sector masks near to far, so drawing them in reverse
|
|
|
|
// order is the sane approach here. Of course impossible cases will arise.
|
|
|
|
while (*cursectormaskcount) {
|
|
|
|
polymer_drawsector(cursectormasks[--(*cursectormaskcount)], TRUE);
|
|
|
|
}
|
2008-03-30 14:22:03 +00:00
|
|
|
|
2011-08-20 21:06:00 +00:00
|
|
|
// This should _always_ be called after a corresponding pr_displayrooms()
|
|
|
|
// unless we're in "external view" mode, which was checked above.
|
|
|
|
// Both the top-level game drawrooms and the recursive internal passes
|
|
|
|
// should be accounted for here. If these free cause corruption, there's
|
|
|
|
// an accounting bug somewhere.
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(cursectormaskcount);
|
|
|
|
DO_FREE_AND_NULL(cursectormasks);
|
2011-08-20 21:06:00 +00:00
|
|
|
}
|
2011-08-20 21:05:38 +00:00
|
|
|
|
2011-08-21 19:41:22 +00:00
|
|
|
bglDisable(GL_CULL_FACE);
|
|
|
|
|
2011-08-20 21:05:38 +00:00
|
|
|
// bglDisable(GL_POLYGON_OFFSET_FILL);
|
2008-03-30 14:22:03 +00:00
|
|
|
bglDisable(GL_BLEND);
|
|
|
|
bglDisable(GL_ALPHA_TEST);
|
2008-03-30 09:16:39 +00:00
|
|
|
}
|
|
|
|
|
2009-12-07 07:01:44 +00:00
|
|
|
void polymer_editorpick(void)
|
|
|
|
{
|
|
|
|
GLubyte picked[3];
|
|
|
|
int16_t num;
|
|
|
|
|
|
|
|
bglReadPixels(searchx, ydim - searchy, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, picked);
|
|
|
|
|
2015-05-03 07:03:48 +00:00
|
|
|
num = B_UNBUF16(&picked[1]);
|
2009-12-07 07:01:44 +00:00
|
|
|
|
|
|
|
searchstat = picked[0];
|
|
|
|
|
|
|
|
switch (searchstat) {
|
|
|
|
case 0: // wall
|
2011-02-13 23:16:56 +00:00
|
|
|
case 5: // botomwall
|
2009-12-07 07:01:44 +00:00
|
|
|
case 4: // 1-way/masked wall
|
2009-12-31 10:00:21 +00:00
|
|
|
searchsector = sectorofwall(num);
|
2009-12-07 07:01:44 +00:00
|
|
|
searchbottomwall = searchwall = num;
|
2011-03-17 23:37:38 +00:00
|
|
|
searchisbottom = (searchstat==5);
|
2011-02-13 23:16:56 +00:00
|
|
|
if (searchstat == 5) {
|
|
|
|
searchstat = 0;
|
|
|
|
if (wall[num].nextwall >= 0 && (wall[num].cstat & 2)) {
|
|
|
|
searchbottomwall = wall[num].nextwall;
|
|
|
|
}
|
|
|
|
}
|
2009-12-07 07:01:44 +00:00
|
|
|
break;
|
|
|
|
case 1: // floor
|
|
|
|
case 2: // ceiling
|
|
|
|
searchsector = num;
|
2010-09-30 23:05:40 +00:00
|
|
|
|
|
|
|
// Apologies to Plagman for littering here, but this feature is quite essential
|
|
|
|
{
|
|
|
|
GLdouble model[16];
|
|
|
|
GLdouble proj[16];
|
|
|
|
GLint view[4];
|
|
|
|
|
|
|
|
GLdouble x,y,z;
|
|
|
|
GLfloat scr[3], scrv[3];
|
|
|
|
GLdouble scrx,scry,scrz;
|
|
|
|
GLfloat dadepth;
|
|
|
|
|
|
|
|
int16_t k, bestk=0;
|
2012-11-15 14:28:41 +00:00
|
|
|
GLfloat bestwdistsq = (GLfloat)3.4e38, wdistsq;
|
2010-09-30 23:05:40 +00:00
|
|
|
GLfloat w1[2], w2[2], w21[2], pw1[2], pw2[2];
|
|
|
|
GLfloat ptonline[2];
|
|
|
|
GLfloat scrvxz[2];
|
|
|
|
GLfloat scrvxznorm, scrvxzn[2], scrpxz[2];
|
|
|
|
GLfloat w1d, w2d;
|
|
|
|
walltype *wal = &wall[sector[searchsector].wallptr];
|
|
|
|
|
|
|
|
GLfloat t, svcoeff, p[2];
|
|
|
|
GLfloat *pl;
|
|
|
|
|
|
|
|
bglGetDoublev(GL_MODELVIEW_MATRIX, model);
|
|
|
|
bglGetDoublev(GL_PROJECTION_MATRIX, proj);
|
|
|
|
bglGetIntegerv(GL_VIEWPORT, view);
|
|
|
|
|
|
|
|
bglReadPixels(searchx, ydim-searchy, 1,1, GL_DEPTH_COMPONENT, GL_FLOAT, &dadepth);
|
|
|
|
bgluUnProject(searchx, ydim-searchy, dadepth, model, proj, view, &x, &y, &z);
|
|
|
|
bgluUnProject(searchx, ydim-searchy, 0.0, model, proj, view, &scrx, &scry, &scrz);
|
|
|
|
|
|
|
|
scr[0]=scrx, scr[1]=scry, scr[2]=scrz;
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
scrv[0] = x-scrx;
|
|
|
|
scrv[1] = y-scry;
|
|
|
|
scrv[2] = z-scrz;
|
2010-09-30 23:05:40 +00:00
|
|
|
|
|
|
|
scrvxz[0] = x-scrx;
|
|
|
|
scrvxz[1] = z-scrz;
|
|
|
|
|
2011-03-13 11:59:32 +00:00
|
|
|
if (prsectors[searchsector]==NULL)
|
|
|
|
{
|
|
|
|
//OSD_Printf("polymer_editorpick: prsectors[searchsector]==NULL !!!\n");
|
|
|
|
searchwall = sector[num].wallptr;
|
|
|
|
}
|
2010-09-30 23:05:40 +00:00
|
|
|
else
|
2011-03-13 11:59:32 +00:00
|
|
|
{
|
|
|
|
if (searchstat==1)
|
2012-04-14 13:04:31 +00:00
|
|
|
pl = prsectors[searchsector]->ceil.plane;
|
2011-03-13 11:59:32 +00:00
|
|
|
else
|
2012-04-14 13:04:31 +00:00
|
|
|
pl = prsectors[searchsector]->floor.plane;
|
|
|
|
|
|
|
|
if (pl == NULL)
|
|
|
|
{
|
|
|
|
searchwall = sector[num].wallptr;
|
|
|
|
return;
|
|
|
|
}
|
2010-09-30 23:05:40 +00:00
|
|
|
|
2011-03-13 11:59:32 +00:00
|
|
|
t = dot3f(pl,scrv);
|
|
|
|
svcoeff = -(dot3f(pl,scr)+pl[3])/t;
|
2010-09-30 23:05:40 +00:00
|
|
|
|
2011-03-13 11:59:32 +00:00
|
|
|
// point on plane (x and z)
|
|
|
|
p[0] = scrx + svcoeff*scrv[0];
|
|
|
|
p[1] = scrz + svcoeff*scrv[2];
|
2010-09-30 23:05:40 +00:00
|
|
|
|
2011-03-13 11:59:32 +00:00
|
|
|
for (k=0; k<sector[searchsector].wallnum; k++)
|
2010-09-30 23:05:40 +00:00
|
|
|
{
|
2011-03-13 11:59:32 +00:00
|
|
|
w1[1] = -(float)wal[k].x;
|
|
|
|
w1[0] = (float)wal[k].y;
|
|
|
|
w2[1] = -(float)wall[wal[k].point2].x;
|
|
|
|
w2[0] = (float)wall[wal[k].point2].y;
|
|
|
|
|
|
|
|
scrvxznorm = sqrt(dot2f(scrvxz,scrvxz));
|
|
|
|
scrvxzn[0] = scrvxz[1]/scrvxznorm;
|
|
|
|
scrvxzn[1] = -scrvxz[0]/scrvxznorm;
|
|
|
|
|
|
|
|
relvec2f(p,w1, pw1);
|
|
|
|
relvec2f(p,w2, pw2);
|
|
|
|
relvec2f(w2,w1, w21);
|
|
|
|
|
|
|
|
w1d = dot2f(scrvxzn,pw1);
|
|
|
|
w2d = dot2f(scrvxzn,pw2);
|
|
|
|
w2d = -w2d;
|
|
|
|
if (w1d <= 0 || w2d <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ptonline[0] = w2[0]+(w2d/(w1d+w2d))*w21[0];
|
|
|
|
ptonline[1] = w2[1]+(w2d/(w1d+w2d))*w21[1];
|
|
|
|
relvec2f(p,ptonline, scrpxz);
|
|
|
|
if (dot2f(scrvxz,scrpxz)<0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wdistsq = dot2f(scrpxz,scrpxz);
|
|
|
|
if (wdistsq < bestwdistsq)
|
|
|
|
{
|
|
|
|
bestk = k;
|
|
|
|
bestwdistsq = wdistsq;
|
|
|
|
}
|
2010-09-30 23:05:40 +00:00
|
|
|
}
|
|
|
|
|
2011-03-13 11:59:32 +00:00
|
|
|
searchwall = sector[searchsector].wallptr + bestk;
|
|
|
|
}
|
2010-09-30 23:05:40 +00:00
|
|
|
}
|
|
|
|
// :P
|
|
|
|
|
|
|
|
// searchwall = sector[num].wallptr;
|
2009-12-07 07:01:44 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
// sprite
|
2009-12-31 10:00:21 +00:00
|
|
|
searchsector = sprite[num].sectnum;
|
2009-12-07 07:01:44 +00:00
|
|
|
searchwall = num;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
searchit = 0;
|
|
|
|
}
|
|
|
|
|
2015-12-04 11:52:58 +00:00
|
|
|
void polymer_inb4rotatesprite(int16_t tilenum, char pal, int8_t shade, int32_t method)
|
2011-02-28 03:56:37 +00:00
|
|
|
{
|
|
|
|
_prmaterial rotatespritematerial;
|
|
|
|
|
2015-12-04 11:52:58 +00:00
|
|
|
polymer_getbuildmaterial(&rotatespritematerial, tilenum, pal, shade, 0, method);
|
2011-02-28 03:56:37 +00:00
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
rotatespritematerialbits = polymer_bindmaterial(&rotatespritematerial, NULL, 0);
|
2011-02-28 03:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void polymer_postrotatesprite(void)
|
2006-10-14 23:33:10 +00:00
|
|
|
{
|
2011-02-28 03:56:37 +00:00
|
|
|
polymer_unbindmaterial(rotatespritematerialbits);
|
2006-10-14 23:33:10 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
static void polymer_drawsearchplane(_prplane *plane, GLubyte *oldcolor, GLubyte modulation, GLubyte *data)
|
|
|
|
{
|
|
|
|
if (oldcolor)
|
|
|
|
Bmemcpy(oldcolor, plane->material.diffusemodulation, sizeof(GLubyte) * 4);
|
|
|
|
|
|
|
|
plane->material.diffusemodulation[0] = modulation;
|
|
|
|
plane->material.diffusemodulation[1] = ((GLubyte *) data)[0];
|
|
|
|
plane->material.diffusemodulation[2] = ((GLubyte *) data)[1];
|
|
|
|
plane->material.diffusemodulation[3] = 0xFF;
|
|
|
|
|
|
|
|
polymer_drawplane(plane);
|
|
|
|
|
|
|
|
if (oldcolor)
|
|
|
|
Bmemcpy(plane->material.diffusemodulation, oldcolor, sizeof(GLubyte) * 4);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void polymer_drawmaskwall(int32_t damaskwallcnt)
|
2006-10-14 23:33:10 +00:00
|
|
|
{
|
2015-03-24 00:40:21 +00:00
|
|
|
tsectortype *sec;
|
2009-04-11 18:01:39 +00:00
|
|
|
walltype *wal;
|
2008-04-03 06:58:36 +00:00
|
|
|
_prwall *w;
|
2009-12-07 07:01:44 +00:00
|
|
|
GLubyte oldcolor[4];
|
2008-04-03 06:58:36 +00:00
|
|
|
|
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Masked wall %i...\n", damaskwallcnt);
|
|
|
|
|
2015-03-24 00:40:21 +00:00
|
|
|
sec = (tsectortype *)§or[sectorofwall(maskwall[damaskwallcnt])];
|
2009-04-11 18:01:39 +00:00
|
|
|
wal = &wall[maskwall[damaskwallcnt]];
|
2008-04-03 06:58:36 +00:00
|
|
|
w = prwalls[maskwall[damaskwallcnt]];
|
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
bglEnable(GL_CULL_FACE);
|
|
|
|
|
2009-12-07 07:01:44 +00:00
|
|
|
if (searchit == 2) {
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawsearchplane(&w->mask, oldcolor, 0x04, (GLubyte *)&maskwall[damaskwallcnt]);
|
2011-08-20 21:05:14 +00:00
|
|
|
} else {
|
2014-05-01 22:02:21 +00:00
|
|
|
calc_and_apply_fog(wal->picnum, fogpal_shade(sec, wal->shade), sec->visibility, get_floor_fogpal(sec));
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawplane(&w->mask);
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
bglDisable(GL_CULL_FACE);
|
2006-10-14 23:33:10 +00:00
|
|
|
}
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
void polymer_drawsprite(int32_t snum)
|
|
|
|
{
|
|
|
|
int32_t i, j, cs;
|
|
|
|
_prsprite *s;
|
2009-03-08 22:59:54 +00:00
|
|
|
|
2015-01-11 04:55:07 +00:00
|
|
|
tspritetype *const tspr = tspriteptr[snum];
|
2015-03-24 00:40:21 +00:00
|
|
|
const tsectortype *sec;
|
2009-06-01 20:55:36 +00:00
|
|
|
|
2013-05-01 17:42:07 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Sprite %i...\n", snum);
|
2009-06-01 20:55:36 +00:00
|
|
|
|
2013-04-29 19:24:19 +00:00
|
|
|
if (bad_tspr(tspr))
|
|
|
|
return;
|
2010-07-26 22:36:45 +00:00
|
|
|
|
|
|
|
if ((tspr->cstat & 8192) && (depth && !mirrors[depth-1].plane))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((tspr->cstat & 16384) && (!depth || mirrors[depth-1].plane))
|
|
|
|
return;
|
|
|
|
|
2013-03-19 06:23:38 +00:00
|
|
|
DO_TILE_ANIM(tspr->picnum, tspr->owner+32768);
|
|
|
|
|
2015-03-24 00:40:21 +00:00
|
|
|
sec = (tsectortype *)§or[tspr->sectnum];
|
2014-05-01 22:02:21 +00:00
|
|
|
calc_and_apply_fog(tspr->picnum, fogpal_shade(sec, tspr->shade), sec->visibility,
|
2015-03-24 00:40:21 +00:00
|
|
|
get_floor_fogpal((tsectortype *)§or[tspr->sectnum]));
|
2010-07-26 22:36:45 +00:00
|
|
|
|
2010-08-03 15:06:24 +00:00
|
|
|
if (usemodels && tile2model[Ptile2tile(tspr->picnum,tspr->pal)].modelid >= 0 &&
|
|
|
|
tile2model[Ptile2tile(tspr->picnum,tspr->pal)].framenum >= 0 &&
|
2010-08-21 19:04:37 +00:00
|
|
|
!(spriteext[tspr->owner].flags & SPREXT_NOTMD))
|
2009-06-06 13:40:15 +00:00
|
|
|
{
|
2011-09-18 07:18:50 +00:00
|
|
|
bglEnable(GL_CULL_FACE);
|
|
|
|
SWITCH_CULL_DIRECTION;
|
2010-07-26 22:36:45 +00:00
|
|
|
polymer_drawmdsprite(tspr);
|
2011-09-18 07:18:50 +00:00
|
|
|
SWITCH_CULL_DIRECTION;
|
|
|
|
bglDisable(GL_CULL_FACE);
|
2010-07-26 22:36:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-06-06 13:40:15 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
cs = tspr->cstat;
|
|
|
|
|
2010-08-03 15:19:01 +00:00
|
|
|
// I think messing with the tspr is safe at this point?
|
|
|
|
// If not, change that to modify a temp position in updatesprite itself.
|
|
|
|
// I don't think this flags are meant to change on the fly so it'd possibly
|
|
|
|
// be safe to cache a plane that has them applied.
|
|
|
|
if (spriteext[tspr->owner].flags & SPREXT_AWAY1)
|
|
|
|
{
|
|
|
|
tspr->x += sintable[(tspr->ang + 512) & 2047] >> 13;
|
|
|
|
tspr->y += sintable[tspr->ang & 2047] >> 13;
|
|
|
|
}
|
|
|
|
else if (spriteext[tspr->owner].flags & SPREXT_AWAY2)
|
|
|
|
{
|
|
|
|
tspr->x -= sintable[(tspr->ang + 512) & 2047] >> 13;
|
|
|
|
tspr->y -= sintable[tspr->ang & 2047] >> 13;
|
|
|
|
}
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
polymer_updatesprite(snum);
|
|
|
|
|
2013-05-01 17:42:07 +00:00
|
|
|
Bassert(tspr->owner < MAXSPRITES);
|
2010-07-26 22:36:45 +00:00
|
|
|
s = prsprites[tspr->owner];
|
|
|
|
|
2013-05-01 17:42:07 +00:00
|
|
|
if (s == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
switch ((tspr->cstat>>4) & 3)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
prsectors[tspr->sectnum]->wallsproffset += 0.5f;
|
|
|
|
if (!depth || mirrors[depth-1].plane)
|
|
|
|
bglPolygonOffset(-1.0f, -1.0f);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
prsectors[tspr->sectnum]->floorsproffset += 0.5f;
|
|
|
|
if (!depth || mirrors[depth-1].plane)
|
|
|
|
bglPolygonOffset(-1.0f, -1.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cs & 48) == 0)
|
|
|
|
{
|
|
|
|
int32_t curpriority = 0;
|
|
|
|
|
|
|
|
s->plane.lightcount = 0;
|
|
|
|
|
|
|
|
while ((curpriority < pr_maxlightpriority) && (!depth || mirrors[depth-1].plane))
|
|
|
|
{
|
|
|
|
i = j = 0;
|
|
|
|
while (j < lightcount)
|
2009-06-06 13:40:15 +00:00
|
|
|
{
|
2010-08-03 15:06:24 +00:00
|
|
|
while (!prlights[i].flags.active)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (prlights[i].priority != curpriority)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
|
|
|
|
if (polymer_planeinlight(&s->plane, &prlights[i]))
|
2010-08-03 15:06:24 +00:00
|
|
|
s->plane.lights[s->plane.lightcount++] = i;
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
i++;
|
|
|
|
j++;
|
2009-06-06 13:40:15 +00:00
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
curpriority++;
|
2009-03-08 22:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 20:03:39 +00:00
|
|
|
if ((tspr->cstat & 64) && (tspr->cstat & SPR_ALIGN_MASK))
|
|
|
|
{
|
|
|
|
if ((tspr->cstat & SPR_ALIGN_MASK)==SPR_FLOOR && (tspr->cstat & SPR_YFLIP))
|
|
|
|
SWITCH_CULL_DIRECTION;
|
2008-04-04 07:40:15 +00:00
|
|
|
bglEnable(GL_CULL_FACE);
|
2013-06-11 20:03:39 +00:00
|
|
|
}
|
2008-04-04 07:40:15 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
if ((!depth || mirrors[depth-1].plane) && !pr_ati_nodepthoffset)
|
2009-03-27 13:46:40 +00:00
|
|
|
bglEnable(GL_POLYGON_OFFSET_FILL);
|
2008-06-06 11:35:24 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
polymer_drawplane(&s->plane);
|
2008-03-30 09:16:39 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
if ((!depth || mirrors[depth-1].plane) && !pr_ati_nodepthoffset)
|
2009-03-27 13:46:40 +00:00
|
|
|
bglDisable(GL_POLYGON_OFFSET_FILL);
|
2008-06-06 11:35:24 +00:00
|
|
|
|
2013-06-11 20:03:39 +00:00
|
|
|
if ((tspr->cstat & 64) && (tspr->cstat & SPR_ALIGN_MASK))
|
|
|
|
{
|
|
|
|
if ((tspr->cstat & SPR_ALIGN_MASK)==SPR_FLOOR && (tspr->cstat & SPR_YFLIP))
|
|
|
|
SWITCH_CULL_DIRECTION;
|
2008-04-04 07:40:15 +00:00
|
|
|
bglDisable(GL_CULL_FACE);
|
2013-06-11 20:03:39 +00:00
|
|
|
}
|
2006-10-14 23:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void polymer_setanimatesprites(animatespritesptr animatesprites, int32_t x, int32_t y, int32_t a, int32_t smoothratio)
|
2008-04-06 23:35:48 +00:00
|
|
|
{
|
|
|
|
asi.animatesprites = animatesprites;
|
|
|
|
asi.x = x;
|
|
|
|
asi.y = y;
|
|
|
|
asi.a = a;
|
|
|
|
asi.smoothratio = smoothratio;
|
|
|
|
}
|
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
int16_t polymer_addlight(_prlight* light)
|
|
|
|
{
|
2009-07-12 01:55:34 +00:00
|
|
|
int32_t lighti;
|
2009-06-01 20:55:36 +00:00
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
if (lightcount >= PR_MAXLIGHTS || light->priority > pr_maxlightpriority || !pr_lighting)
|
2009-06-07 13:17:55 +00:00
|
|
|
return (-1);
|
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
if ((light->sector == -1) || (light->sector >= numsectors))
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
lighti = 0;
|
2010-07-26 22:36:45 +00:00
|
|
|
while ((lighti < PR_MAXLIGHTS) && (prlights[lighti].flags.active))
|
2009-06-01 20:55:36 +00:00
|
|
|
lighti++;
|
|
|
|
|
|
|
|
if (lighti == PR_MAXLIGHTS)
|
|
|
|
return (-1);
|
2013-01-06 18:56:50 +00:00
|
|
|
#if 0
|
2012-09-24 21:09:37 +00:00
|
|
|
// Spot lights disabled on ATI cards because they cause crashes with
|
|
|
|
// Catalyst 12.8 drivers.
|
|
|
|
// See: http://forums.duke4.net/topic/5723-hrp-polymer-crash/
|
|
|
|
if (pr_ati_fboworkaround && light->radius)
|
|
|
|
return (-1);
|
2013-01-06 18:56:50 +00:00
|
|
|
#endif
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(&prlights[lighti], light, sizeof(_prlight));
|
2009-06-01 20:55:36 +00:00
|
|
|
|
2012-10-21 18:41:09 +00:00
|
|
|
if (light->radius) {
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_processspotlight(&prlights[lighti]);
|
|
|
|
|
2011-10-02 07:09:15 +00:00
|
|
|
// get the texture handle for the lightmap
|
|
|
|
if (light->tilenum > 0) {
|
|
|
|
int16_t picnum = light->tilenum;
|
|
|
|
pthtyp* pth;
|
|
|
|
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(picnum, 0);
|
2011-10-02 07:09:15 +00:00
|
|
|
|
|
|
|
if (!waloff[picnum])
|
|
|
|
loadtile(picnum);
|
|
|
|
|
|
|
|
pth = NULL;
|
2015-12-04 11:52:54 +00:00
|
|
|
pth = texcache_fetch(picnum, 0, 0, DAMETH_NOMASK);
|
2011-10-02 07:09:15 +00:00
|
|
|
|
|
|
|
if (pth)
|
|
|
|
light->lightmap = pth->glpic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
prlights[lighti].flags.isinview = 0;
|
|
|
|
prlights[lighti].flags.active = 1;
|
|
|
|
|
2011-10-03 17:43:36 +00:00
|
|
|
prlights[lighti].flags.invalidate = 0;
|
|
|
|
|
2009-06-07 12:51:00 +00:00
|
|
|
prlights[lighti].planecount = 0;
|
|
|
|
prlights[lighti].planelist = NULL;
|
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_culllight(lighti);
|
|
|
|
|
|
|
|
lightcount++;
|
|
|
|
|
|
|
|
return (lighti);
|
|
|
|
}
|
|
|
|
|
|
|
|
void polymer_deletelight(int16_t lighti)
|
|
|
|
{
|
2009-06-06 13:12:29 +00:00
|
|
|
if (!prlights[lighti].flags.active)
|
2012-01-05 21:58:23 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUGGINGAIDS
|
2012-01-12 20:48:17 +00:00
|
|
|
if (pr_verbosity >= 2)
|
2012-01-05 21:58:23 +00:00
|
|
|
OSD_Printf("PR : Called polymer_deletelight on inactive light\n");
|
|
|
|
// currently known cases: when reloading maphack lights (didn't set maphacklightcnt=0
|
|
|
|
// but did loadmaphack()->delete_maphack_lights() after polymer_resetlights())
|
|
|
|
#endif
|
2009-06-06 13:12:29 +00:00
|
|
|
return;
|
2012-01-05 21:58:23 +00:00
|
|
|
}
|
2009-06-06 13:12:29 +00:00
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_removelight(lighti);
|
|
|
|
|
|
|
|
prlights[lighti].flags.active = 0;
|
|
|
|
|
|
|
|
lightcount--;
|
|
|
|
}
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
void polymer_invalidatelights(void)
|
|
|
|
{
|
|
|
|
int32_t i = PR_MAXLIGHTS-1;
|
|
|
|
|
|
|
|
do
|
2010-07-26 22:36:45 +00:00
|
|
|
prlights[i].flags.invalidate = prlights[i].flags.active;
|
2009-06-09 06:19:58 +00:00
|
|
|
while (i--);
|
|
|
|
}
|
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
void polymer_texinvalidate(void)
|
|
|
|
{
|
2011-10-02 01:00:14 +00:00
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
while (i < MAXSPRITES) {
|
2014-02-08 14:37:52 +00:00
|
|
|
polymer_invalidatesprite(i);
|
2011-10-02 01:00:14 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = numsectors - 1;
|
2009-06-09 09:32:23 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
if (!numsectors || !prsectors[i])
|
2009-06-13 21:06:45 +00:00
|
|
|
return;
|
2011-10-02 01:00:14 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
do
|
|
|
|
prsectors[i--]->flags.invalidtex = 1;
|
|
|
|
while (i >= 0);
|
2009-06-13 21:06:45 +00:00
|
|
|
|
2011-10-02 01:00:14 +00:00
|
|
|
i = numwalls - 1;
|
2010-07-26 22:36:45 +00:00
|
|
|
do
|
|
|
|
prwalls[i--]->flags.invalidtex = 1;
|
|
|
|
while (i >= 0);
|
2009-06-09 09:32:23 +00:00
|
|
|
}
|
|
|
|
|
2011-01-27 07:05:12 +00:00
|
|
|
void polymer_definehighpalookup(char basepalnum, char palnum, char *data)
|
2010-12-30 08:13:37 +00:00
|
|
|
{
|
2014-05-30 00:02:19 +00:00
|
|
|
prhighpalookups[basepalnum][palnum].data = (char *)Xmalloc(PR_HIGHPALOOKUP_DATA_SIZE);
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2011-01-27 07:05:12 +00:00
|
|
|
Bmemcpy(prhighpalookups[basepalnum][palnum].data, data, PR_HIGHPALOOKUP_DATA_SIZE);
|
2010-12-30 08:13:37 +00:00
|
|
|
}
|
|
|
|
|
2011-10-02 05:56:35 +00:00
|
|
|
int32_t polymer_havehighpalookup(int32_t basepalnum, int32_t palnum)
|
2011-09-28 20:30:24 +00:00
|
|
|
{
|
|
|
|
if ((uint32_t)basepalnum >= MAXBASEPALS || (uint32_t)palnum >= MAXPALOOKUPS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (prhighpalookups[basepalnum][palnum].data != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-06 03:00:39 +00:00
|
|
|
// CORE
|
2014-09-30 04:04:30 +00:00
|
|
|
static void polymer_displayrooms(const int16_t dacursectnum)
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2015-03-24 00:40:21 +00:00
|
|
|
tsectortype *sec;
|
2009-03-18 15:05:58 +00:00
|
|
|
int32_t i;
|
2011-08-20 21:04:42 +00:00
|
|
|
int16_t bunchnum;
|
|
|
|
int16_t ns;
|
2008-04-06 03:00:39 +00:00
|
|
|
GLint result;
|
2009-03-18 15:05:58 +00:00
|
|
|
int16_t doquery;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t front;
|
|
|
|
int32_t back;
|
2009-05-09 10:42:57 +00:00
|
|
|
GLfloat localskymodelviewmatrix[16];
|
2009-01-14 14:13:51 +00:00
|
|
|
GLfloat localmodelviewmatrix[16];
|
2009-03-26 16:32:00 +00:00
|
|
|
GLfloat localprojectionmatrix[16];
|
2008-04-06 03:00:39 +00:00
|
|
|
float frustum[5 * 4];
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t localspritesortcnt;
|
2015-01-11 04:55:07 +00:00
|
|
|
tspritetype localtsprite[MAXSPRITESONSCREEN];
|
2009-04-12 22:23:47 +00:00
|
|
|
int16_t localmaskwall[MAXWALLSB];
|
2009-04-12 21:52:49 +00:00
|
|
|
int16_t localmaskwallcnt;
|
2009-03-23 14:18:20 +00:00
|
|
|
_prmirror mirrorlist[10];
|
|
|
|
int mirrorcount;
|
2011-08-20 21:05:38 +00:00
|
|
|
int16_t *localsectormasks;
|
|
|
|
int16_t *localsectormaskcount;
|
2009-03-23 14:18:20 +00:00
|
|
|
int32_t gx, gy, gz, px, py, pz;
|
|
|
|
GLdouble plane[4];
|
|
|
|
float coeff;
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-03-26 16:32:00 +00:00
|
|
|
curmodelviewmatrix = localmodelviewmatrix;
|
|
|
|
bglGetFloatv(GL_MODELVIEW_MATRIX, localmodelviewmatrix);
|
|
|
|
bglGetFloatv(GL_PROJECTION_MATRIX, localprojectionmatrix);
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-03-26 16:32:00 +00:00
|
|
|
polymer_extractfrustum(localmodelviewmatrix, localprojectionmatrix, frustum);
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-04-19 09:49:27 +00:00
|
|
|
Bmemset(querydelay, 0, sizeof(int16_t) * numsectors);
|
|
|
|
Bmemset(queryid, 0, sizeof(GLuint) * numwalls);
|
|
|
|
Bmemset(drawingstate, 0, sizeof(int16_t) * numsectors);
|
2008-04-06 03:00:39 +00:00
|
|
|
|
|
|
|
front = 0;
|
2009-03-18 15:05:58 +00:00
|
|
|
back = 1;
|
|
|
|
sectorqueue[0] = dacursectnum;
|
2008-04-06 03:00:39 +00:00
|
|
|
drawingstate[dacursectnum] = 1;
|
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
localspritesortcnt = localmaskwallcnt = 0;
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
mirrorcount = 0;
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
localsectormasks = (int16_t *)Xmalloc(sizeof(int16_t) * numsectors);
|
|
|
|
localsectormaskcount = (int16_t *)Xcalloc(sizeof(int16_t), 1);
|
2011-08-20 21:05:38 +00:00
|
|
|
cursectormasks = localsectormasks;
|
|
|
|
cursectormaskcount = localsectormaskcount;
|
|
|
|
|
2009-05-09 10:42:57 +00:00
|
|
|
bglDisable(GL_DEPTH_TEST);
|
|
|
|
bglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
2009-06-07 18:38:13 +00:00
|
|
|
polymer_drawsky(cursky, curskypal, curskyshade);
|
2009-05-09 10:42:57 +00:00
|
|
|
bglEnable(GL_DEPTH_TEST);
|
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
// depth-only occlusion testing pass
|
2009-03-23 14:18:20 +00:00
|
|
|
// overridematerial = 0;
|
2009-03-18 15:05:58 +00:00
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
prcanbucket = 1;
|
|
|
|
|
2009-04-19 09:49:27 +00:00
|
|
|
while (front != back)
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2015-03-24 00:40:21 +00:00
|
|
|
sec = (tsectortype *)§or[sectorqueue[front]];
|
2009-03-18 15:05:58 +00:00
|
|
|
|
|
|
|
polymer_pokesector(sectorqueue[front]);
|
2011-08-20 21:05:38 +00:00
|
|
|
polymer_drawsector(sectorqueue[front], FALSE);
|
2009-03-18 15:05:58 +00:00
|
|
|
polymer_scansprites(sectorqueue[front], localtsprite, &localspritesortcnt);
|
|
|
|
|
|
|
|
doquery = 0;
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
i = sec->wallnum-1;
|
2009-06-07 07:36:15 +00:00
|
|
|
do
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2009-06-07 12:51:00 +00:00
|
|
|
// if we have a level boundary somewhere in the sector,
|
|
|
|
// consider these walls as visportals
|
2015-07-15 08:23:00 +00:00
|
|
|
if (wall[sec->wallptr + i].nextsector < 0 && pr_buckets == 0)
|
2009-06-07 12:51:00 +00:00
|
|
|
doquery = 1;
|
2008-04-06 03:00:39 +00:00
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
while (--i >= 0);
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
i = sec->wallnum-1;
|
|
|
|
while (i >= 0)
|
2009-03-18 15:05:58 +00:00
|
|
|
{
|
2009-12-03 06:21:39 +00:00
|
|
|
if ((wall[sec->wallptr + i].nextsector >= 0) &&
|
2009-05-31 18:10:09 +00:00
|
|
|
(wallvisible(globalposx, globalposy, sec->wallptr + i)) &&
|
2009-03-25 21:14:51 +00:00
|
|
|
(polymer_planeinfrustum(&prwalls[sec->wallptr + i]->mask, frustum)))
|
2009-03-18 15:05:58 +00:00
|
|
|
{
|
2009-04-16 06:31:19 +00:00
|
|
|
if ((prwalls[sec->wallptr + i]->mask.vertcount == 4) &&
|
|
|
|
!(prwalls[sec->wallptr + i]->underover & 4) &&
|
|
|
|
!(prwalls[sec->wallptr + i]->underover & 8))
|
2009-04-14 07:38:45 +00:00
|
|
|
{
|
2009-04-16 06:31:19 +00:00
|
|
|
// early exit for closed sectors
|
2009-04-14 07:38:45 +00:00
|
|
|
_prwall *w;
|
|
|
|
|
|
|
|
w = prwalls[sec->wallptr + i];
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if ((w->mask.buffer[0].y >= w->mask.buffer[3].y) &&
|
|
|
|
(w->mask.buffer[1].y >= w->mask.buffer[2].y))
|
2009-04-14 07:38:45 +00:00
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
i--;
|
2009-04-14 07:38:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-20 21:05:24 +00:00
|
|
|
if ((wall[sec->wallptr + i].cstat & 48) == 16)
|
2014-12-20 13:36:40 +00:00
|
|
|
{
|
|
|
|
int pic = wall[sec->wallptr + i].overpicnum;
|
|
|
|
|
|
|
|
if (tilesiz[pic].x > 0 && tilesiz[pic].y > 0)
|
|
|
|
localmaskwall[localmaskwallcnt++] = sec->wallptr + i;
|
|
|
|
}
|
2009-03-23 14:18:20 +00:00
|
|
|
|
2009-03-28 11:43:16 +00:00
|
|
|
if (!depth && (overridematerial & prprogrambits[PR_BIT_MIRROR_MAP].bit) &&
|
2009-03-23 14:18:20 +00:00
|
|
|
wall[sec->wallptr + i].overpicnum == 560 &&
|
2009-03-29 21:08:52 +00:00
|
|
|
wall[sec->wallptr + i].cstat & 32)
|
2009-03-23 14:18:20 +00:00
|
|
|
{
|
2009-03-29 21:08:52 +00:00
|
|
|
mirrorlist[mirrorcount].plane = &prwalls[sec->wallptr + i]->mask;
|
2009-03-23 14:18:20 +00:00
|
|
|
mirrorlist[mirrorcount].sectnum = sectorqueue[front];
|
|
|
|
mirrorlist[mirrorcount].wallnum = sec->wallptr + i;
|
|
|
|
mirrorcount++;
|
|
|
|
}
|
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
if (!(wall[sec->wallptr + i].cstat & 32)) {
|
|
|
|
if (doquery && (!drawingstate[wall[sec->wallptr + i].nextsector]))
|
|
|
|
{
|
|
|
|
float pos[3], sqdist;
|
|
|
|
int32_t oldoverridematerial;
|
2008-04-09 07:27:17 +00:00
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
pos[0] = (float)globalposy;
|
2009-04-16 06:31:19 +00:00
|
|
|
pos[1] = -(float)(globalposz) / 16.0f;
|
2009-07-12 01:55:34 +00:00
|
|
|
pos[2] = -(float)globalposx;
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
sqdist = prwalls[sec->wallptr + i]->mask.plane[0] * pos[0] +
|
|
|
|
prwalls[sec->wallptr + i]->mask.plane[1] * pos[1] +
|
|
|
|
prwalls[sec->wallptr + i]->mask.plane[2] * pos[2] +
|
|
|
|
prwalls[sec->wallptr + i]->mask.plane[3];
|
2009-03-23 14:18:20 +00:00
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
// hack to avoid occlusion querying portals that are too close to the viewpoint
|
|
|
|
// this is needed because of the near z-clipping plane;
|
|
|
|
if (sqdist < 100)
|
|
|
|
queryid[sec->wallptr + i] = 0xFFFFFFFF;
|
|
|
|
else {
|
|
|
|
_prwall *w;
|
2009-03-23 14:18:20 +00:00
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
w = prwalls[sec->wallptr + i];
|
2009-03-18 15:05:58 +00:00
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
bglColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
|
|
|
bglDepthMask(GL_FALSE);
|
2009-03-18 15:05:58 +00:00
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
bglGenQueriesARB(1, &queryid[sec->wallptr + i]);
|
|
|
|
bglBeginQueryARB(GL_SAMPLES_PASSED_ARB, queryid[sec->wallptr + i]);
|
2009-03-26 17:45:12 +00:00
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
oldoverridematerial = overridematerial;
|
|
|
|
overridematerial = 0;
|
2009-03-26 17:45:12 +00:00
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
if ((w->underover & 4) && (w->underover & 1))
|
|
|
|
polymer_drawplane(&w->wall);
|
|
|
|
polymer_drawplane(&w->mask);
|
|
|
|
if ((w->underover & 8) && (w->underover & 2))
|
|
|
|
polymer_drawplane(&w->over);
|
2009-03-26 17:45:12 +00:00
|
|
|
|
2009-04-16 06:31:19 +00:00
|
|
|
overridematerial = oldoverridematerial;
|
|
|
|
|
|
|
|
bglEndQueryARB(GL_SAMPLES_PASSED_ARB);
|
|
|
|
|
|
|
|
bglDepthMask(GL_TRUE);
|
|
|
|
bglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
}
|
|
|
|
} else
|
2011-08-28 04:42:27 +00:00
|
|
|
queryid[sec->wallptr + i] = 0xFFFFFFFF;
|
2009-04-16 06:31:19 +00:00
|
|
|
}
|
2009-03-18 15:05:58 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
i--;
|
2009-03-18 15:05:58 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 21:04:53 +00:00
|
|
|
// Cram as much CPU or GPU work as we can between queuing the
|
|
|
|
// occlusion queries and reaping them.
|
|
|
|
i = sec->wallnum-1;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (wallvisible(globalposx, globalposy, sec->wallptr + i))
|
|
|
|
polymer_drawwall(sectorqueue[front], sec->wallptr + i);
|
|
|
|
}
|
|
|
|
while (--i >= 0);
|
2011-12-25 15:33:02 +00:00
|
|
|
#ifdef YAX_ENABLE
|
2011-08-20 21:04:42 +00:00
|
|
|
// queue ROR neighbors
|
2013-04-09 17:35:11 +00:00
|
|
|
if ((bunchnum = yax_getbunch(sectorqueue[front], YAX_FLOOR)) >= 0) {
|
2011-08-20 21:04:42 +00:00
|
|
|
|
|
|
|
for (SECTORS_OF_BUNCH(bunchnum, YAX_CEILING, ns)) {
|
|
|
|
|
|
|
|
if (ns >= 0 && !drawingstate[ns] &&
|
|
|
|
polymer_planeinfrustum(&prsectors[ns]->ceil, frustum)) {
|
|
|
|
|
|
|
|
sectorqueue[back++] = ns;
|
|
|
|
drawingstate[ns] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-09 17:35:11 +00:00
|
|
|
if ((bunchnum = yax_getbunch(sectorqueue[front], YAX_CEILING)) >= 0) {
|
2011-08-20 21:04:42 +00:00
|
|
|
|
|
|
|
for (SECTORS_OF_BUNCH(bunchnum, YAX_FLOOR, ns)) {
|
|
|
|
|
|
|
|
if (ns >= 0 && !drawingstate[ns] &&
|
|
|
|
polymer_planeinfrustum(&prsectors[ns]->floor, frustum)) {
|
|
|
|
|
|
|
|
sectorqueue[back++] = ns;
|
|
|
|
drawingstate[ns] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-25 15:33:02 +00:00
|
|
|
#endif
|
2009-06-09 06:19:58 +00:00
|
|
|
i = sec->wallnum-1;
|
2009-06-07 07:36:15 +00:00
|
|
|
do
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2009-03-18 15:05:58 +00:00
|
|
|
if ((queryid[sec->wallptr + i]) &&
|
|
|
|
(!drawingstate[wall[sec->wallptr + i].nextsector]))
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2009-03-18 15:05:58 +00:00
|
|
|
// REAP
|
|
|
|
result = 0;
|
2009-04-12 10:46:31 +00:00
|
|
|
if (doquery && (queryid[sec->wallptr + i] != 0xFFFFFFFF))
|
2008-04-13 00:29:13 +00:00
|
|
|
{
|
2009-03-18 15:05:58 +00:00
|
|
|
bglGetQueryObjectivARB(queryid[sec->wallptr + i],
|
|
|
|
GL_QUERY_RESULT_ARB,
|
|
|
|
&result);
|
|
|
|
bglDeleteQueriesARB(1, &queryid[sec->wallptr + i]);
|
2009-04-12 10:46:31 +00:00
|
|
|
} else if (queryid[sec->wallptr + i] == 0xFFFFFFFF)
|
2009-03-26 17:45:12 +00:00
|
|
|
result = 1;
|
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
queryid[sec->wallptr + i] = 0;
|
|
|
|
|
|
|
|
if (result || !doquery)
|
|
|
|
{
|
|
|
|
sectorqueue[back++] = wall[sec->wallptr + i].nextsector;
|
|
|
|
drawingstate[wall[sec->wallptr + i].nextsector] = 1;
|
2008-04-13 00:29:13 +00:00
|
|
|
}
|
2011-08-28 04:42:27 +00:00
|
|
|
} else if (queryid[sec->wallptr + i] &&
|
|
|
|
queryid[sec->wallptr + i] != 0xFFFFFFFF)
|
|
|
|
{
|
|
|
|
bglDeleteQueriesARB(1, &queryid[sec->wallptr + i]);
|
|
|
|
queryid[sec->wallptr + i] = 0;
|
2008-04-06 03:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
while (--i >= 0);
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
front++;
|
|
|
|
}
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
polymer_emptybuckets();
|
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
// do the actual shaded drawing
|
2009-03-23 14:18:20 +00:00
|
|
|
// overridematerial = 0xFFFFFFFF;
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
// go through the sector queue again
|
2009-03-23 14:18:20 +00:00
|
|
|
// front = 0;
|
|
|
|
// while (front < back)
|
|
|
|
// {
|
|
|
|
// sec = §or[sectorqueue[front]];
|
2016-06-05 04:46:28 +00:00
|
|
|
//
|
2009-03-23 14:18:20 +00:00
|
|
|
// polymer_drawsector(sectorqueue[front]);
|
2016-06-05 04:46:28 +00:00
|
|
|
//
|
2009-03-23 14:18:20 +00:00
|
|
|
// i = 0;
|
|
|
|
// while (i < sec->wallnum)
|
|
|
|
// {
|
|
|
|
// polymer_drawwall(sectorqueue[front], sec->wallptr + i);
|
2016-06-05 04:46:28 +00:00
|
|
|
//
|
2009-03-23 14:18:20 +00:00
|
|
|
// i++;
|
|
|
|
// }
|
2016-06-05 04:46:28 +00:00
|
|
|
//
|
2009-03-23 14:18:20 +00:00
|
|
|
// front++;
|
|
|
|
// }
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
i = mirrorcount-1;
|
|
|
|
while (i >= 0)
|
2009-03-18 15:05:58 +00:00
|
|
|
{
|
2009-03-23 14:18:20 +00:00
|
|
|
bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, prrts[0].fbo);
|
|
|
|
bglPushAttrib(GL_VIEWPORT_BIT);
|
2009-09-30 01:00:49 +00:00
|
|
|
bglViewport(windowx1, yres-(windowy2+1),windowx2-windowx1+1, windowy2-windowy1+1);
|
2009-03-18 15:05:58 +00:00
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
bglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-05-09 10:42:57 +00:00
|
|
|
Bmemcpy(localskymodelviewmatrix, curskymodelviewmatrix, sizeof(GLfloat) * 16);
|
|
|
|
curskymodelviewmatrix = localskymodelviewmatrix;
|
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglPushMatrix();
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
plane[0] = mirrorlist[i].plane->plane[0];
|
|
|
|
plane[1] = mirrorlist[i].plane->plane[1];
|
|
|
|
plane[2] = mirrorlist[i].plane->plane[2];
|
|
|
|
plane[3] = mirrorlist[i].plane->plane[3];
|
2009-03-18 15:05:58 +00:00
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
bglClipPlane(GL_CLIP_PLANE0, plane);
|
|
|
|
polymer_inb4mirror(mirrorlist[i].plane->buffer, mirrorlist[i].plane->plane);
|
2011-09-18 07:18:50 +00:00
|
|
|
SWITCH_CULL_DIRECTION;
|
2009-05-09 10:42:57 +00:00
|
|
|
//bglEnable(GL_CLIP_PLANE0);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
if (mirrorlist[i].wallnum >= 0)
|
2013-05-01 17:41:59 +00:00
|
|
|
preparemirror(globalposx, globalposy, globalang,
|
|
|
|
mirrorlist[i].wallnum, &gx, &gy, &viewangle);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
gx = globalposx;
|
|
|
|
gy = globalposy;
|
|
|
|
gz = globalposz;
|
|
|
|
|
|
|
|
// map the player pos from build to polymer
|
|
|
|
px = globalposy;
|
|
|
|
py = -globalposz / 16;
|
|
|
|
pz = -globalposx;
|
|
|
|
|
|
|
|
// calculate new player position on the other side of the mirror
|
|
|
|
// this way the basic build visibility shit can be used (wallvisible)
|
|
|
|
coeff = mirrorlist[i].plane->plane[0] * px +
|
|
|
|
mirrorlist[i].plane->plane[1] * py +
|
|
|
|
mirrorlist[i].plane->plane[2] * pz +
|
|
|
|
mirrorlist[i].plane->plane[3];
|
|
|
|
|
|
|
|
coeff /= (float)(mirrorlist[i].plane->plane[0] * mirrorlist[i].plane->plane[0] +
|
|
|
|
mirrorlist[i].plane->plane[1] * mirrorlist[i].plane->plane[1] +
|
|
|
|
mirrorlist[i].plane->plane[2] * mirrorlist[i].plane->plane[2]);
|
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
px = (int32_t)(-coeff*mirrorlist[i].plane->plane[0]*2 + px);
|
|
|
|
py = (int32_t)(-coeff*mirrorlist[i].plane->plane[1]*2 + py);
|
|
|
|
pz = (int32_t)(-coeff*mirrorlist[i].plane->plane[2]*2 + pz);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
// map back from polymer to build
|
2014-10-25 03:32:26 +00:00
|
|
|
set_globalpos(-pz, px, -py * 16);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
mirrors[depth++] = mirrorlist[i];
|
|
|
|
polymer_displayrooms(mirrorlist[i].sectnum);
|
|
|
|
depth--;
|
|
|
|
|
2011-08-20 21:05:38 +00:00
|
|
|
cursectormasks = localsectormasks;
|
|
|
|
cursectormaskcount = localsectormaskcount;
|
|
|
|
|
2014-10-25 03:32:26 +00:00
|
|
|
set_globalpos(gx, gy, gz);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
bglDisable(GL_CLIP_PLANE0);
|
2011-09-18 07:18:50 +00:00
|
|
|
SWITCH_CULL_DIRECTION;
|
2009-03-23 14:18:20 +00:00
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglPopMatrix();
|
|
|
|
|
|
|
|
bglPopAttrib();
|
|
|
|
bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
|
|
|
|
mirrorlist[i].plane->material.mirrormap = prrts[0].color;
|
|
|
|
polymer_drawplane(mirrorlist[i].plane);
|
|
|
|
mirrorlist[i].plane->material.mirrormap = 0;
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
i--;
|
2008-04-06 03:00:39 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 23:35:48 +00:00
|
|
|
spritesortcnt = localspritesortcnt;
|
2009-04-19 09:49:27 +00:00
|
|
|
Bmemcpy(tsprite, localtsprite, sizeof(spritetype) * spritesortcnt);
|
2008-04-06 23:35:48 +00:00
|
|
|
maskwallcnt = localmaskwallcnt;
|
2009-04-19 09:49:27 +00:00
|
|
|
Bmemcpy(maskwall, localmaskwall, sizeof(int16_t) * maskwallcnt);
|
2008-04-06 23:35:48 +00:00
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
if (depth)
|
|
|
|
{
|
2013-02-10 16:24:11 +00:00
|
|
|
set_globalang(viewangle);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
2009-03-27 11:39:10 +00:00
|
|
|
if (mirrors[depth - 1].plane)
|
|
|
|
display_mirror = 1;
|
2009-03-23 14:18:20 +00:00
|
|
|
polymer_animatesprites();
|
2009-03-27 11:39:10 +00:00
|
|
|
if (mirrors[depth - 1].plane)
|
|
|
|
display_mirror = 0;
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
bglDisable(GL_CULL_FACE);
|
|
|
|
drawmasks();
|
|
|
|
bglEnable(GL_CULL_FACE);
|
|
|
|
}
|
2009-03-18 15:05:58 +00:00
|
|
|
return;
|
2008-04-06 03:00:39 +00:00
|
|
|
}
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
static void polymer_emptybuckets(void)
|
|
|
|
{
|
|
|
|
_prbucket *bucket = prbuckethead;
|
|
|
|
|
2015-09-11 21:36:57 +00:00
|
|
|
if (pr_buckets == 0)
|
|
|
|
return;
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, prmapvbo);
|
|
|
|
bglVertexPointer(3, GL_FLOAT, sizeof(_prvert), NULL);
|
|
|
|
bglTexCoordPointer(2, GL_FLOAT, sizeof(_prvert), (GLvoid *)(3 * sizeof(GLfloat)));
|
|
|
|
|
2015-07-15 08:23:00 +00:00
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, prindexringvbo);
|
|
|
|
|
|
|
|
uint32_t indexcount = 0;
|
|
|
|
while (bucket != NULL)
|
|
|
|
{
|
|
|
|
indexcount += bucket->count;
|
|
|
|
|
|
|
|
bucket = bucket->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure space in index ring, wrap otherwise
|
2015-11-28 09:06:22 +00:00
|
|
|
if (indexcount + prindexringoffset >= (unsigned)prindexringsize)
|
2015-07-15 08:23:00 +00:00
|
|
|
{
|
|
|
|
bglUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER);
|
|
|
|
prindexring = (GLuint *)bglMapBufferRange(GL_ELEMENT_ARRAY_BUFFER, 0, prindexringsize * sizeof(GLuint), GL_MAP_INVALIDATE_BUFFER_BIT | prindexringmapflags);
|
|
|
|
prindexringoffset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// put indices in the ring, all at once
|
|
|
|
bucket = prbuckethead;
|
|
|
|
|
|
|
|
while (bucket != NULL)
|
|
|
|
{
|
|
|
|
if (bucket->count == 0)
|
|
|
|
{
|
|
|
|
bucket = bucket->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&prindexring[prindexringoffset], bucket->indices, bucket->count * sizeof(GLuint));
|
|
|
|
|
|
|
|
bucket->indiceoffset = (GLuint*)(prindexringoffset * sizeof(GLuint));
|
|
|
|
|
|
|
|
prindexringoffset += bucket->count;
|
|
|
|
|
|
|
|
bucket = bucket->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket = prbuckethead;
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
while (bucket != NULL)
|
|
|
|
{
|
|
|
|
if (bucket->count == 0)
|
|
|
|
{
|
|
|
|
bucket = bucket->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t materialbits = polymer_bindmaterial(&bucket->material, NULL, 0);
|
|
|
|
|
2015-07-15 08:23:00 +00:00
|
|
|
bglDrawElements(GL_TRIANGLES, bucket->count, GL_UNSIGNED_INT, bucket->indiceoffset);
|
2015-07-14 07:08:44 +00:00
|
|
|
|
|
|
|
polymer_unbindmaterial(materialbits);
|
|
|
|
|
|
|
|
bucket->count = 0;
|
|
|
|
|
|
|
|
bucket = bucket->next;
|
|
|
|
}
|
|
|
|
|
2015-07-15 08:23:00 +00:00
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 0);
|
2015-07-14 07:08:44 +00:00
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
|
|
|
|
prcanbucket = 0;
|
|
|
|
}
|
|
|
|
|
2015-12-23 04:05:39 +00:00
|
|
|
static hashtable_t h_buckets ={ 2048, NULL };
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
static _prbucket* polymer_findbucket(int16_t tilenum, char pal)
|
|
|
|
{
|
2015-12-23 04:05:39 +00:00
|
|
|
char propstr[16];
|
2015-07-14 07:08:44 +00:00
|
|
|
|
2015-12-23 04:05:39 +00:00
|
|
|
Bsprintf(propstr, "%d_%d", tilenum, pal);
|
2015-07-14 07:08:44 +00:00
|
|
|
|
2015-12-23 04:05:39 +00:00
|
|
|
_prbucket *bucketptr = prbuckethead ? (_prbucket *)hash_find(&h_buckets, propstr) : NULL;
|
|
|
|
|
|
|
|
// find bucket
|
2015-07-14 07:08:44 +00:00
|
|
|
|
|
|
|
// no buckets or no bucket found, create one
|
2015-12-23 04:05:39 +00:00
|
|
|
if (bucketptr == NULL || (intptr_t)bucketptr == -1)
|
2015-07-14 07:08:44 +00:00
|
|
|
{
|
|
|
|
bucketptr = (_prbucket *)Xmalloc(sizeof (_prbucket));
|
|
|
|
|
2015-12-23 04:05:39 +00:00
|
|
|
if (h_buckets.items == NULL)
|
|
|
|
hash_init(&h_buckets);
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
// insert, since most likely to use same pattern next frame
|
|
|
|
// will need to reorder by MRU first every once in a while
|
|
|
|
// or move to hashing lookup
|
|
|
|
bucketptr->next = prbuckethead;
|
|
|
|
prbuckethead = bucketptr;
|
|
|
|
|
|
|
|
bucketptr->tilenum = tilenum;
|
|
|
|
bucketptr->pal = pal;
|
|
|
|
|
|
|
|
bucketptr->invalidmaterial = 1;
|
|
|
|
|
|
|
|
bucketptr->count = 0;
|
|
|
|
bucketptr->buffersize = 1024;
|
|
|
|
bucketptr->indices = (GLuint *)Xmalloc(bucketptr->buffersize * sizeof(GLuint));
|
2015-12-23 04:05:39 +00:00
|
|
|
|
|
|
|
hash_add(&h_buckets, propstr, (intptr_t)bucketptr, 1);
|
2015-07-14 07:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bucketptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void polymer_bucketplane(_prplane* plane)
|
|
|
|
{
|
|
|
|
_prbucket *bucketptr = plane->bucket;
|
|
|
|
uint32_t neededindicecount;
|
2015-09-11 21:36:57 +00:00
|
|
|
int32_t i;
|
2015-07-14 07:08:44 +00:00
|
|
|
|
|
|
|
// we don't keep buffers for quads
|
|
|
|
neededindicecount = (plane->indicescount == 0) ? 6 : plane->indicescount;
|
|
|
|
|
|
|
|
// ensure size
|
|
|
|
while (bucketptr->count + neededindicecount >= bucketptr->buffersize)
|
|
|
|
{
|
|
|
|
bucketptr->buffersize *= 2;
|
|
|
|
bucketptr->indices = (GLuint *)Xrealloc(bucketptr->indices, bucketptr->buffersize * sizeof(GLuint));
|
|
|
|
}
|
|
|
|
|
|
|
|
// queue indices
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
if (plane->indicescount > 0)
|
|
|
|
{
|
|
|
|
while (i < plane->indicescount)
|
|
|
|
{
|
|
|
|
bucketptr->indices[bucketptr->count] = plane->indices[i] + plane->mapvbo_vertoffset;
|
|
|
|
bucketptr->count++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const uint32_t quadindices[6] = { 0, 1, 2, 0, 2, 3 };
|
|
|
|
|
|
|
|
while (i < 6)
|
|
|
|
{
|
|
|
|
bucketptr->indices[bucketptr->count] = quadindices[i] + plane->mapvbo_vertoffset;
|
|
|
|
bucketptr->count++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
static void polymer_drawplane(_prplane* plane)
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t materialbits;
|
2008-04-06 03:00:39 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_nullrender >= 1) return;
|
2015-06-14 23:42:31 +00:00
|
|
|
|
2009-03-11 13:23:05 +00:00
|
|
|
// debug code for drawing plane inverse TBN
|
|
|
|
// bglDisable(GL_TEXTURE_2D);
|
|
|
|
// bglBegin(GL_LINES);
|
|
|
|
// bglColor4f(1.0, 0.0, 0.0, 1.0);
|
|
|
|
// bglVertex3f(plane->buffer[0],
|
|
|
|
// plane->buffer[1],
|
|
|
|
// plane->buffer[2]);
|
|
|
|
// bglVertex3f(plane->buffer[0] + plane->t[0] * 50,
|
|
|
|
// plane->buffer[1] + plane->t[1] * 50,
|
|
|
|
// plane->buffer[2] + plane->t[2] * 50);
|
|
|
|
// bglColor4f(0.0, 1.0, 0.0, 1.0);
|
|
|
|
// bglVertex3f(plane->buffer[0],
|
|
|
|
// plane->buffer[1],
|
|
|
|
// plane->buffer[2]);
|
|
|
|
// bglVertex3f(plane->buffer[0] + plane->b[0] * 50,
|
|
|
|
// plane->buffer[1] + plane->b[1] * 50,
|
|
|
|
// plane->buffer[2] + plane->b[2] * 50);
|
|
|
|
// bglColor4f(0.0, 0.0, 1.0, 1.0);
|
|
|
|
// bglVertex3f(plane->buffer[0],
|
|
|
|
// plane->buffer[1],
|
|
|
|
// plane->buffer[2]);
|
|
|
|
// bglVertex3f(plane->buffer[0] + plane->n[0] * 50,
|
|
|
|
// plane->buffer[1] + plane->n[1] * 50,
|
|
|
|
// plane->buffer[2] + plane->n[2] * 50);
|
|
|
|
// bglEnd();
|
|
|
|
// bglEnable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
// debug code for drawing plane normals
|
|
|
|
// bglDisable(GL_TEXTURE_2D);
|
|
|
|
// bglBegin(GL_LINES);
|
|
|
|
// bglColor4f(1.0, 1.0, 1.0, 1.0);
|
|
|
|
// bglVertex3f(plane->buffer[0],
|
|
|
|
// plane->buffer[1],
|
|
|
|
// plane->buffer[2]);
|
|
|
|
// bglVertex3f(plane->buffer[0] + plane->plane[0] * 50,
|
|
|
|
// plane->buffer[1] + plane->plane[1] * 50,
|
|
|
|
// plane->buffer[2] + plane->plane[2] * 50);
|
|
|
|
// bglEnd();
|
|
|
|
// bglEnable(GL_TEXTURE_2D);
|
2008-11-29 20:16:19 +00:00
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
if (pr_buckets && pr_vbos > 0 && prcanbucket && plane->bucket)
|
|
|
|
{
|
|
|
|
polymer_bucketplane(plane);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-12 13:51:30 +00:00
|
|
|
bglNormal3f((float)(plane->plane[0]), (float)(plane->plane[1]), (float)(plane->plane[2]));
|
2008-04-09 07:27:17 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
GLuint planevbo;
|
|
|
|
GLintptrARB geomfbooffset;
|
|
|
|
|
2015-09-11 21:36:57 +00:00
|
|
|
if (plane->mapvbo_vertoffset != (uint32_t)-1)
|
2009-03-24 10:24:33 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
planevbo = prmapvbo;
|
2015-07-14 07:08:44 +00:00
|
|
|
geomfbooffset = plane->mapvbo_vertoffset * sizeof(_prvert);
|
2015-07-13 03:46:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
planevbo = plane->vbo;
|
2015-07-13 16:01:18 +00:00
|
|
|
geomfbooffset = 0;
|
2015-07-13 03:46:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (planevbo && (pr_vbos > 0))
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, planevbo);
|
|
|
|
bglVertexPointer(3, GL_FLOAT, sizeof(_prvert), (GLvoid *)(geomfbooffset));
|
|
|
|
bglTexCoordPointer(2, GL_FLOAT, sizeof(_prvert), (GLvoid *)(geomfbooffset + (3 * sizeof(GLfloat))));
|
2009-03-24 10:24:33 +00:00
|
|
|
if (plane->indices)
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, plane->ivbo);
|
|
|
|
} else {
|
2015-07-13 03:46:35 +00:00
|
|
|
bglVertexPointer(3, GL_FLOAT, sizeof(_prvert), &plane->buffer->x);
|
|
|
|
bglTexCoordPointer(2, GL_FLOAT, sizeof(_prvert), &plane->buffer->u);
|
2009-03-24 10:24:33 +00:00
|
|
|
}
|
|
|
|
|
2009-06-07 12:51:00 +00:00
|
|
|
curlight = 0;
|
|
|
|
do {
|
2014-09-30 04:04:30 +00:00
|
|
|
materialbits = polymer_bindmaterial(&plane->material, plane->lights, plane->lightcount);
|
2008-04-09 07:27:17 +00:00
|
|
|
|
2009-03-13 15:18:46 +00:00
|
|
|
if (materialbits & prprogrambits[PR_BIT_NORMAL_MAP].bit)
|
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
bglVertexAttrib3fvARB(prprograms[materialbits].attrib_T, &plane->tbn[0][0]);
|
|
|
|
bglVertexAttrib3fvARB(prprograms[materialbits].attrib_B, &plane->tbn[1][0]);
|
|
|
|
bglVertexAttrib3fvARB(prprograms[materialbits].attrib_N, &plane->tbn[2][0]);
|
2009-03-13 15:18:46 +00:00
|
|
|
}
|
|
|
|
|
2009-03-24 10:24:33 +00:00
|
|
|
if (plane->indices)
|
2009-03-12 13:51:30 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
if (planevbo && (pr_vbos > 0))
|
2009-03-24 10:24:33 +00:00
|
|
|
bglDrawElements(GL_TRIANGLES, plane->indicescount, GL_UNSIGNED_SHORT, NULL);
|
|
|
|
else
|
|
|
|
bglDrawElements(GL_TRIANGLES, plane->indicescount, GL_UNSIGNED_SHORT, plane->indices);
|
|
|
|
} else
|
|
|
|
bglDrawArrays(GL_QUADS, 0, 4);
|
2009-03-12 13:51:30 +00:00
|
|
|
|
|
|
|
polymer_unbindmaterial(materialbits);
|
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
if (plane->lightcount && (!depth || mirrors[depth-1].plane))
|
|
|
|
prlights[plane->lights[curlight]].flags.isinview = 1;
|
|
|
|
|
2009-03-12 13:51:30 +00:00
|
|
|
curlight++;
|
2009-06-07 13:07:04 +00:00
|
|
|
} while ((curlight < plane->lightcount) && (curlight < pr_maxlightpasses) && (!depth || mirrors[depth-1].plane));
|
2009-03-24 10:24:33 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (planevbo && (pr_vbos > 0))
|
2009-03-24 10:24:33 +00:00
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
if (plane->indices)
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
2008-04-09 07:27:17 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
static inline void polymer_inb4mirror(_prvert* buffer, GLfloat* plane)
|
2008-04-09 07:27:17 +00:00
|
|
|
{
|
|
|
|
float pv;
|
|
|
|
float reflectionmatrix[16];
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
pv = buffer->x * plane[0] +
|
|
|
|
buffer->y * plane[1] +
|
|
|
|
buffer->z * plane[2];
|
2008-04-09 07:27:17 +00:00
|
|
|
|
|
|
|
reflectionmatrix[0] = 1 - (2 * plane[0] * plane[0]);
|
|
|
|
reflectionmatrix[1] = -2 * plane[0] * plane[1];
|
|
|
|
reflectionmatrix[2] = -2 * plane[0] * plane[2];
|
2008-04-06 03:00:39 +00:00
|
|
|
reflectionmatrix[3] = 0;
|
|
|
|
|
2008-04-09 07:27:17 +00:00
|
|
|
reflectionmatrix[4] = -2 * plane[0] * plane[1];
|
|
|
|
reflectionmatrix[5] = 1 - (2 * plane[1] * plane[1]);
|
|
|
|
reflectionmatrix[6] = -2 * plane[1] * plane[2];
|
2008-04-06 03:00:39 +00:00
|
|
|
reflectionmatrix[7] = 0;
|
|
|
|
|
2008-04-09 07:27:17 +00:00
|
|
|
reflectionmatrix[8] = -2 * plane[0] * plane[2];
|
|
|
|
reflectionmatrix[9] = -2 * plane[1] * plane[2];
|
|
|
|
reflectionmatrix[10] = 1 - (2 * plane[2] * plane[2]);
|
2008-04-06 03:00:39 +00:00
|
|
|
reflectionmatrix[11] = 0;
|
|
|
|
|
2008-04-09 07:27:17 +00:00
|
|
|
reflectionmatrix[12] = 2 * pv * plane[0];
|
|
|
|
reflectionmatrix[13] = 2 * pv * plane[1];
|
|
|
|
reflectionmatrix[14] = 2 * pv * plane[2];
|
2008-04-06 03:00:39 +00:00
|
|
|
reflectionmatrix[15] = 1;
|
|
|
|
|
|
|
|
bglMultMatrixf(reflectionmatrix);
|
2009-05-09 10:42:57 +00:00
|
|
|
|
|
|
|
bglPushMatrix();
|
|
|
|
bglLoadMatrixf(curskymodelviewmatrix);
|
|
|
|
bglMultMatrixf(reflectionmatrix);
|
|
|
|
bglGetFloatv(GL_MODELVIEW_MATRIX, curskymodelviewmatrix);
|
|
|
|
bglPopMatrix();
|
2008-04-06 03:00:39 +00:00
|
|
|
}
|
|
|
|
|
2008-04-06 23:35:48 +00:00
|
|
|
static void polymer_animatesprites(void)
|
|
|
|
{
|
2008-04-28 08:29:40 +00:00
|
|
|
if (asi.animatesprites)
|
|
|
|
asi.animatesprites(globalposx, globalposy, viewangle, asi.smoothratio);
|
2008-04-06 23:35:48 +00:00
|
|
|
}
|
|
|
|
|
2009-05-22 23:49:25 +00:00
|
|
|
static void polymer_freeboard(void)
|
2009-05-17 16:12:53 +00:00
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < MAXSECTORS)
|
|
|
|
{
|
|
|
|
if (prsectors[i])
|
|
|
|
{
|
2015-09-23 17:55:31 +00:00
|
|
|
Bfree(prsectors[i]->verts);
|
|
|
|
Bfree(prsectors[i]->floor.buffer);
|
|
|
|
Bfree(prsectors[i]->ceil.buffer);
|
|
|
|
Bfree(prsectors[i]->floor.indices);
|
|
|
|
Bfree(prsectors[i]->ceil.indices);
|
2009-05-17 16:12:53 +00:00
|
|
|
if (prsectors[i]->ceil.vbo) bglDeleteBuffersARB(1, &prsectors[i]->ceil.vbo);
|
|
|
|
if (prsectors[i]->ceil.ivbo) bglDeleteBuffersARB(1, &prsectors[i]->ceil.ivbo);
|
|
|
|
if (prsectors[i]->floor.vbo) bglDeleteBuffersARB(1, &prsectors[i]->floor.vbo);
|
|
|
|
if (prsectors[i]->floor.ivbo) bglDeleteBuffersARB(1, &prsectors[i]->floor.ivbo);
|
|
|
|
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(prsectors[i]);
|
2009-05-17 16:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < MAXWALLS)
|
|
|
|
{
|
|
|
|
if (prwalls[i])
|
|
|
|
{
|
2015-09-23 17:55:31 +00:00
|
|
|
Bfree(prwalls[i]->bigportal);
|
|
|
|
Bfree(prwalls[i]->mask.buffer);
|
|
|
|
Bfree(prwalls[i]->over.buffer);
|
|
|
|
// Bfree(prwalls[i]->cap);
|
|
|
|
Bfree(prwalls[i]->wall.buffer);
|
2009-05-17 16:12:53 +00:00
|
|
|
if (prwalls[i]->wall.vbo) bglDeleteBuffersARB(1, &prwalls[i]->wall.vbo);
|
|
|
|
if (prwalls[i]->over.vbo) bglDeleteBuffersARB(1, &prwalls[i]->over.vbo);
|
|
|
|
if (prwalls[i]->mask.vbo) bglDeleteBuffersARB(1, &prwalls[i]->mask.vbo);
|
|
|
|
if (prwalls[i]->stuffvbo) bglDeleteBuffersARB(1, &prwalls[i]->stuffvbo);
|
|
|
|
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(prwalls[i]);
|
2009-05-17 16:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < MAXSPRITES)
|
|
|
|
{
|
|
|
|
if (prsprites[i])
|
|
|
|
{
|
2015-09-23 17:55:31 +00:00
|
|
|
Bfree(prsprites[i]->plane.buffer);
|
2010-07-26 22:36:45 +00:00
|
|
|
if (prsprites[i]->plane.vbo) bglDeleteBuffersARB(1, &prsprites[i]->plane.vbo);
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(prsprites[i]);
|
2010-07-26 22:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2013-05-07 07:48:08 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < MAXTILES)
|
|
|
|
{
|
2014-02-08 14:37:53 +00:00
|
|
|
polymer_invalidateartmap(i);
|
2013-05-07 07:48:08 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < MAXBASEPALS)
|
|
|
|
{
|
|
|
|
if (prbasepalmaps[i])
|
|
|
|
{
|
|
|
|
bglDeleteTextures(1, &prbasepalmaps[i]);
|
|
|
|
prbasepalmaps[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < MAXPALOOKUPS)
|
|
|
|
{
|
|
|
|
if (prlookups[i])
|
|
|
|
{
|
|
|
|
bglDeleteTextures(1, &prlookups[i]);
|
|
|
|
prlookups[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2009-05-17 16:12:53 +00:00
|
|
|
}
|
|
|
|
|
2006-10-15 18:51:41 +00:00
|
|
|
// SECTORS
|
2009-01-16 05:03:12 +00:00
|
|
|
static int32_t polymer_initsector(int16_t sectnum)
|
2006-08-31 01:56:43 +00:00
|
|
|
{
|
2015-03-24 00:40:21 +00:00
|
|
|
tsectortype *sec;
|
2006-09-29 21:36:12 +00:00
|
|
|
_prsector* s;
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
if (pr_verbosity >= 2) OSD_Printf("PR : Initializing sector %i...\n", sectnum);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2015-03-24 00:40:21 +00:00
|
|
|
sec = (tsectortype *)§or[sectnum];
|
2014-05-30 00:02:19 +00:00
|
|
|
s = (_prsector *)Xcalloc(1, sizeof(_prsector));
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
s->verts = (GLdouble *)Xcalloc(sec->wallnum, sizeof(GLdouble) * 3);
|
2015-07-13 03:46:35 +00:00
|
|
|
s->floor.buffer = (_prvert *)Xcalloc(sec->wallnum, sizeof(_prvert));
|
2009-03-08 20:38:51 +00:00
|
|
|
s->floor.vertcount = sec->wallnum;
|
2015-07-13 03:46:35 +00:00
|
|
|
s->ceil.buffer = (_prvert *)Xcalloc(sec->wallnum, sizeof(_prvert));
|
2009-03-08 20:38:51 +00:00
|
|
|
s->ceil.vertcount = sec->wallnum;
|
2014-05-30 00:02:19 +00:00
|
|
|
|
2008-05-18 07:35:35 +00:00
|
|
|
bglGenBuffersARB(1, &s->floor.vbo);
|
|
|
|
bglGenBuffersARB(1, &s->ceil.vbo);
|
|
|
|
bglGenBuffersARB(1, &s->floor.ivbo);
|
|
|
|
bglGenBuffersARB(1, &s->ceil.ivbo);
|
2006-11-13 23:12:47 +00:00
|
|
|
|
2008-05-31 08:29:40 +00:00
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, s->floor.vbo);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, sec->wallnum * sizeof(GLfloat) * 5, NULL, mapvbousage);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, s->ceil.vbo);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, sec->wallnum * sizeof(GLfloat) * 5, NULL, mapvbousage);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
s->flags.empty = 1; // let updatesector know that everything needs to go
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2006-10-15 18:51:41 +00:00
|
|
|
prsectors[sectnum] = s;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
if (pr_verbosity >= 2) OSD_Printf("PR : Initialized sector %i.\n", sectnum);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2009-03-24 16:25:20 +00:00
|
|
|
static int32_t polymer_updatesector(int16_t sectnum)
|
|
|
|
{
|
2006-09-29 21:36:12 +00:00
|
|
|
_prsector* s;
|
2015-03-24 00:40:21 +00:00
|
|
|
tsectortype *sec;
|
2006-09-29 21:36:12 +00:00
|
|
|
walltype *wal;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i, j;
|
|
|
|
int32_t ceilz, florz;
|
|
|
|
int32_t tex, tey, heidiff;
|
2008-04-28 08:29:40 +00:00
|
|
|
float secangcos, secangsin, scalecoef, xpancoef, ypancoef;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t ang, needfloor, wallinvalidate;
|
|
|
|
int16_t curstat, curpicnum, floorpicnum, ceilingpicnum;
|
2006-09-29 21:36:12 +00:00
|
|
|
char curxpanning, curypanning;
|
2015-07-13 03:46:35 +00:00
|
|
|
_prvert* curbuffer;
|
2006-08-31 01:56:43 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_nullrender >= 3) return 0;
|
2015-06-14 23:42:31 +00:00
|
|
|
|
2006-08-31 01:56:43 +00:00
|
|
|
s = prsectors[sectnum];
|
2015-03-24 00:40:21 +00:00
|
|
|
sec = (tsectortype *)§or[sectnum];
|
2006-08-31 01:56:43 +00:00
|
|
|
|
2008-04-02 06:58:26 +00:00
|
|
|
secangcos = secangsin = 2;
|
2006-09-27 17:55:49 +00:00
|
|
|
|
2006-08-31 01:56:43 +00:00
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
if (pr_verbosity >= 1) OSD_Printf("PR : Can't update uninitialized sector %i.\n", sectnum);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2008-04-02 06:58:26 +00:00
|
|
|
needfloor = wallinvalidate = 0;
|
2006-09-27 17:55:49 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
// geometry
|
2008-04-02 06:58:26 +00:00
|
|
|
wal = &wall[sec->wallptr];
|
2006-08-31 01:56:43 +00:00
|
|
|
i = 0;
|
2009-04-19 09:49:27 +00:00
|
|
|
while (i < sec->wallnum)
|
2006-08-31 01:56:43 +00:00
|
|
|
{
|
2006-10-17 01:14:20 +00:00
|
|
|
if ((-wal->x != s->verts[(i*3)+2]))
|
2006-10-15 18:51:41 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
s->verts[(i*3)+2] = s->floor.buffer[i].z = s->ceil.buffer[i].z = -(float)wal->x;
|
2008-04-02 06:58:26 +00:00
|
|
|
needfloor = wallinvalidate = 1;
|
2006-10-15 18:51:41 +00:00
|
|
|
}
|
2006-10-17 01:14:20 +00:00
|
|
|
if ((wal->y != s->verts[i*3]))
|
2006-10-15 18:51:41 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
s->verts[i*3] = s->floor.buffer[i].x = s->ceil.buffer[i].x = (float)wal->y;
|
2008-04-02 06:58:26 +00:00
|
|
|
needfloor = wallinvalidate = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
wal = &wall[sec->wallptr + i];
|
|
|
|
}
|
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
if ((s->flags.empty) ||
|
2009-03-24 16:25:20 +00:00
|
|
|
needfloor ||
|
2008-05-10 01:29:37 +00:00
|
|
|
(sec->floorz != s->floorz) ||
|
|
|
|
(sec->ceilingz != s->ceilingz) ||
|
|
|
|
(sec->floorheinum != s->floorheinum) ||
|
|
|
|
(sec->ceilingheinum != s->ceilingheinum))
|
2008-04-02 06:58:26 +00:00
|
|
|
{
|
|
|
|
wallinvalidate = 1;
|
|
|
|
|
|
|
|
wal = &wall[sec->wallptr];
|
|
|
|
i = 0;
|
2009-04-19 09:49:27 +00:00
|
|
|
while (i < sec->wallnum)
|
2008-04-02 06:58:26 +00:00
|
|
|
{
|
|
|
|
getzsofslope(sectnum, wal->x, wal->y, &ceilz, &florz);
|
2015-07-13 03:46:35 +00:00
|
|
|
s->floor.buffer[i].y = -(float)(florz) / 16.0f;
|
|
|
|
s->ceil.buffer[i].y = -(float)(ceilz) / 16.0f;
|
2008-04-02 06:58:26 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
wal = &wall[sec->wallptr + i];
|
2006-10-15 18:51:41 +00:00
|
|
|
}
|
2006-08-31 01:56:43 +00:00
|
|
|
|
2008-04-02 06:58:26 +00:00
|
|
|
s->floorz = sec->floorz;
|
|
|
|
s->ceilingz = sec->ceilingz;
|
|
|
|
s->floorheinum = sec->floorheinum;
|
|
|
|
s->ceilingheinum = sec->ceilingheinum;
|
|
|
|
}
|
2013-12-06 18:56:42 +00:00
|
|
|
else if (sec->visibility != s->visibility)
|
|
|
|
wallinvalidate = 1;
|
2008-04-02 06:58:26 +00:00
|
|
|
|
|
|
|
floorpicnum = sec->floorpicnum;
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(floorpicnum, sectnum);
|
2008-04-02 06:58:26 +00:00
|
|
|
ceilingpicnum = sec->ceilingpicnum;
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(ceilingpicnum, sectnum);
|
2008-04-02 06:58:26 +00:00
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
if ((!s->flags.empty) && (!needfloor) &&
|
2014-09-30 04:04:30 +00:00
|
|
|
(floorpicnum == s->floorpicnum_anim) &&
|
|
|
|
(ceilingpicnum == s->ceilingpicnum_anim) &&
|
2015-12-23 04:05:47 +00:00
|
|
|
#ifndef UNTRACKED_STRUCTS
|
|
|
|
(s->trackedrev == sectorchanged[sectnum]))
|
|
|
|
#else
|
2014-09-30 04:04:30 +00:00
|
|
|
!Bmemcmp(&s->ceilingstat, &sec->ceilingstat, offsetof(sectortype, visibility) - offsetof(sectortype, ceilingstat)))
|
2015-12-23 04:05:47 +00:00
|
|
|
#endif
|
2008-04-02 06:58:26 +00:00
|
|
|
goto attributes;
|
|
|
|
|
|
|
|
wal = &wall[sec->wallptr];
|
|
|
|
i = 0;
|
2009-04-19 09:49:27 +00:00
|
|
|
while (i < sec->wallnum)
|
2008-04-02 06:58:26 +00:00
|
|
|
{
|
2006-09-27 17:55:49 +00:00
|
|
|
j = 2;
|
|
|
|
curstat = sec->floorstat;
|
2008-05-18 07:35:35 +00:00
|
|
|
curbuffer = s->floor.buffer;
|
2008-04-02 06:58:26 +00:00
|
|
|
curpicnum = floorpicnum;
|
2006-09-29 21:36:12 +00:00
|
|
|
curxpanning = sec->floorxpanning;
|
|
|
|
curypanning = sec->floorypanning;
|
2006-09-27 17:55:49 +00:00
|
|
|
|
2009-04-19 09:49:27 +00:00
|
|
|
while (j)
|
2006-09-27 17:55:49 +00:00
|
|
|
{
|
|
|
|
if (j == 1)
|
|
|
|
{
|
|
|
|
curstat = sec->ceilingstat;
|
2008-05-18 07:35:35 +00:00
|
|
|
curbuffer = s->ceil.buffer;
|
2008-04-02 06:58:26 +00:00
|
|
|
curpicnum = ceilingpicnum;
|
2006-09-29 21:36:12 +00:00
|
|
|
curxpanning = sec->ceilingxpanning;
|
|
|
|
curypanning = sec->ceilingypanning;
|
2006-09-27 17:55:49 +00:00
|
|
|
}
|
|
|
|
|
2006-10-16 22:07:15 +00:00
|
|
|
if (!waloff[curpicnum])
|
|
|
|
loadtile(curpicnum);
|
|
|
|
|
2008-04-02 06:58:26 +00:00
|
|
|
if (((sec->floorstat & 64) || (sec->ceilingstat & 64)) &&
|
2008-05-10 01:29:37 +00:00
|
|
|
((secangcos == 2) && (secangsin == 2)))
|
2008-04-02 06:58:26 +00:00
|
|
|
{
|
|
|
|
ang = (getangle(wall[wal->point2].x - wal->x, wall[wal->point2].y - wal->y) + 512) & 2047;
|
|
|
|
secangcos = (float)(sintable[(ang+512)&2047]) / 16383.0f;
|
|
|
|
secangsin = (float)(sintable[ang&2047]) / 16383.0f;
|
|
|
|
}
|
|
|
|
|
2009-04-19 17:03:18 +00:00
|
|
|
// relative texturing
|
|
|
|
if (curstat & 64)
|
|
|
|
{
|
2009-07-12 01:55:34 +00:00
|
|
|
xpancoef = (float)(wal->x - wall[sec->wallptr].x);
|
|
|
|
ypancoef = (float)(wall[sec->wallptr].y - wal->y);
|
2009-04-19 17:03:18 +00:00
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
tex = (int32_t)(xpancoef * secangsin + ypancoef * secangcos);
|
|
|
|
tey = (int32_t)(xpancoef * secangcos - ypancoef * secangsin);
|
2009-04-19 17:03:18 +00:00
|
|
|
} else {
|
|
|
|
tex = wal->x;
|
|
|
|
tey = -wal->y;
|
|
|
|
}
|
2006-09-27 17:55:49 +00:00
|
|
|
|
2008-04-28 08:29:40 +00:00
|
|
|
if ((curstat & (2+64)) == (2+64))
|
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
heidiff = (int32_t)(curbuffer[i].y - curbuffer[0].y);
|
2009-04-19 18:00:51 +00:00
|
|
|
// don't forget the sign, tey could be negative with concave sectors
|
|
|
|
if (tey >= 0)
|
2012-11-15 14:28:41 +00:00
|
|
|
tey = (int32_t)sqrt((double)((tey * tey) + (heidiff * heidiff)));
|
2009-04-19 18:00:51 +00:00
|
|
|
else
|
2012-11-15 14:28:41 +00:00
|
|
|
tey = -(int32_t)sqrt((double)((tey * tey) + (heidiff * heidiff)));
|
2008-04-28 08:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-09-27 17:55:49 +00:00
|
|
|
if (curstat & 4)
|
|
|
|
swaplong(&tex, &tey);
|
|
|
|
|
|
|
|
if (curstat & 16) tex = -tex;
|
|
|
|
if (curstat & 32) tey = -tey;
|
|
|
|
|
|
|
|
scalecoef = (curstat & 8) ? 8.0f : 16.0f;
|
|
|
|
|
2008-04-28 08:29:40 +00:00
|
|
|
if (curxpanning)
|
|
|
|
{
|
|
|
|
xpancoef = (float)(pow2long[picsiz[curpicnum] & 15]);
|
2014-09-30 04:14:21 +00:00
|
|
|
xpancoef *= (float)(curxpanning) / (256.0f * (float)(tilesiz[curpicnum].x));
|
2008-04-28 08:29:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
xpancoef = 0;
|
|
|
|
|
|
|
|
if (curypanning)
|
|
|
|
{
|
|
|
|
ypancoef = (float)(pow2long[picsiz[curpicnum] >> 4]);
|
2014-09-30 04:14:21 +00:00
|
|
|
ypancoef *= (float)(curypanning) / (256.0f * (float)(tilesiz[curpicnum].y));
|
2008-04-28 08:29:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
ypancoef = 0;
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
curbuffer[i].u = ((float)(tex) / (scalecoef * tilesiz[curpicnum].x)) + xpancoef;
|
|
|
|
curbuffer[i].v = ((float)(tey) / (scalecoef * tilesiz[curpicnum].y)) + ypancoef;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
j--;
|
|
|
|
}
|
2008-04-02 06:58:26 +00:00
|
|
|
i++;
|
|
|
|
wal = &wall[sec->wallptr + i];
|
|
|
|
}
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2008-04-02 06:58:26 +00:00
|
|
|
s->floorxpanning = sec->floorxpanning;
|
|
|
|
s->ceilingxpanning = sec->ceilingxpanning;
|
|
|
|
s->floorypanning = sec->floorypanning;
|
|
|
|
s->ceilingypanning = sec->ceilingypanning;
|
2015-12-23 04:05:47 +00:00
|
|
|
#ifndef UNTRACKED_STRUCTS
|
|
|
|
s->trackedrev = sectorchanged[sectnum];
|
|
|
|
#endif
|
2008-04-02 06:58:26 +00:00
|
|
|
|
2008-05-18 07:35:35 +00:00
|
|
|
i = -1;
|
|
|
|
|
2008-04-02 06:58:26 +00:00
|
|
|
attributes:
|
2008-05-24 09:37:09 +00:00
|
|
|
if ((pr_vbos > 0) && ((i == -1) || (wallinvalidate)))
|
2008-05-18 07:35:35 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_vbos > 0)
|
|
|
|
{
|
|
|
|
if (pr_nullrender < 2)
|
|
|
|
{
|
|
|
|
/*bglBindBufferARB(GL_ARRAY_BUFFER_ARB, s->floor.vbo);
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sec->wallnum * sizeof(GLfloat)* 5, s->floor.buffer);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, s->ceil.vbo);
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, sec->wallnum * sizeof(GLfloat)* 5, s->ceil.buffer);
|
|
|
|
*/
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
s->floor.mapvbo_vertoffset = sec->wallptr * 2;
|
|
|
|
s->ceil.mapvbo_vertoffset = s->floor.mapvbo_vertoffset + sec->wallnum;
|
|
|
|
|
|
|
|
GLintptrARB sector_offset = s->floor.mapvbo_vertoffset * sizeof(_prvert);
|
2015-07-13 03:46:35 +00:00
|
|
|
GLsizeiptrARB cur_sector_size = sec->wallnum * sizeof(_prvert);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, prmapvbo);
|
|
|
|
// floor
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, sector_offset, cur_sector_size, s->floor.buffer);
|
|
|
|
// ceiling
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, sector_offset + cur_sector_size, cur_sector_size, s->ceil.buffer);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s->floor.mapvbo_vertoffset = -1;
|
|
|
|
s->ceil.mapvbo_vertoffset = -1;
|
|
|
|
}
|
2008-05-18 07:35:35 +00:00
|
|
|
}
|
2008-04-02 06:58:26 +00:00
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
if ((!s->flags.empty) && (!s->flags.invalidtex) &&
|
2014-09-30 04:04:30 +00:00
|
|
|
(floorpicnum == s->floorpicnum_anim) &&
|
|
|
|
(ceilingpicnum == s->ceilingpicnum_anim) &&
|
|
|
|
!Bmemcmp(&s->ceilingstat, &sec->ceilingstat, offsetof(sectortype, visibility) - offsetof(sectortype, ceilingstat)))
|
2008-04-02 06:58:26 +00:00
|
|
|
goto finish;
|
|
|
|
|
2015-12-04 11:52:58 +00:00
|
|
|
s->floor.bucket = polymer_getbuildmaterial(&s->floor.material, floorpicnum, sec->floorpal, sec->floorshade, sec->visibility, (sec->floorstat & 384) ? DAMETH_MASK : DAMETH_NOMASK);
|
2011-08-20 21:05:04 +00:00
|
|
|
|
2011-08-21 19:41:34 +00:00
|
|
|
if (sec->floorstat & 256) {
|
|
|
|
if (sec->floorstat & 128) {
|
2011-08-20 21:05:04 +00:00
|
|
|
s->floor.material.diffusemodulation[3] = 0x55;
|
|
|
|
} else {
|
|
|
|
s->floor.material.diffusemodulation[3] = 0xAA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 11:52:58 +00:00
|
|
|
s->ceil.bucket = polymer_getbuildmaterial(&s->ceil.material, ceilingpicnum, sec->ceilingpal, sec->ceilingshade, sec->visibility, (sec->ceilingstat & 384) ? DAMETH_MASK : DAMETH_NOMASK);
|
2006-08-31 01:56:43 +00:00
|
|
|
|
2011-08-21 19:41:34 +00:00
|
|
|
if (sec->ceilingstat & 256) {
|
|
|
|
if (sec->ceilingstat & 128) {
|
2011-08-20 21:05:04 +00:00
|
|
|
s->ceil.material.diffusemodulation[3] = 0x55;
|
|
|
|
} else {
|
|
|
|
s->ceil.material.diffusemodulation[3] = 0xAA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
s->flags.invalidtex = 0;
|
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
// copy ceilingstat through visibility members
|
|
|
|
Bmemcpy(&s->ceilingstat, &sec->ceilingstat, offsetof(sectortype, visibility) - offsetof(sectortype, ceilingstat));
|
|
|
|
s->floorpicnum_anim = floorpicnum;
|
|
|
|
s->ceilingpicnum_anim = ceilingpicnum;
|
2008-04-02 06:58:26 +00:00
|
|
|
|
|
|
|
finish:
|
|
|
|
|
2008-03-30 19:13:24 +00:00
|
|
|
if (needfloor)
|
2008-05-18 07:35:35 +00:00
|
|
|
{
|
2006-10-15 18:51:41 +00:00
|
|
|
polymer_buildfloor(sectnum);
|
2008-06-05 02:29:18 +00:00
|
|
|
if ((pr_vbos > 0))
|
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_nullrender < 2)
|
|
|
|
{
|
|
|
|
if (s->oldindicescount < s->indicescount)
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, s->floor.ivbo);
|
|
|
|
bglBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, s->indicescount * sizeof(GLushort), NULL, mapvbousage);
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, s->ceil.ivbo);
|
|
|
|
bglBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, s->indicescount * sizeof(GLushort), NULL, mapvbousage);
|
|
|
|
s->oldindicescount = s->indicescount;
|
|
|
|
}
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, s->floor.ivbo);
|
|
|
|
bglBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, s->indicescount * sizeof(GLushort), s->floor.indices);
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, s->ceil.ivbo);
|
|
|
|
bglBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, s->indicescount * sizeof(GLushort), s->ceil.indices);
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
2008-05-24 09:37:09 +00:00
|
|
|
}
|
2008-05-18 07:35:35 +00:00
|
|
|
}
|
2008-03-30 19:13:24 +00:00
|
|
|
|
2008-04-02 06:58:26 +00:00
|
|
|
if (wallinvalidate)
|
2008-04-06 23:35:48 +00:00
|
|
|
{
|
2008-04-02 08:49:21 +00:00
|
|
|
s->invalidid++;
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_invalidatesectorlights(sectnum);
|
2009-04-19 17:23:07 +00:00
|
|
|
polymer_computeplane(&s->floor);
|
|
|
|
polymer_computeplane(&s->ceil);
|
2008-04-06 23:35:48 +00:00
|
|
|
}
|
2008-04-02 08:49:21 +00:00
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
s->flags.empty = 0;
|
|
|
|
s->flags.uptodate = 1;
|
2006-10-15 18:51:41 +00:00
|
|
|
|
2006-08-31 01:56:43 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Updated sector %i.\n", sectnum);
|
|
|
|
|
2006-09-27 17:55:49 +00:00
|
|
|
return (0);
|
2006-08-31 01:56:43 +00:00
|
|
|
}
|
|
|
|
|
2006-09-17 20:16:20 +00:00
|
|
|
void PR_CALLBACK polymer_tesserror(GLenum error)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-10-07 06:47:35 +00:00
|
|
|
/* This callback is called by the tesselator whenever it raises an error.
|
|
|
|
GLU_TESS_ERROR6 is the "no error"/"null" error spam in e1l1 and others. */
|
|
|
|
|
|
|
|
if (pr_verbosity >= 1 && error != GLU_TESS_ERROR6) OSD_Printf("PR : Tesselation error number %i reported : %s.\n", error, bgluErrorString(errno));
|
2006-08-31 01:56:43 +00:00
|
|
|
}
|
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
void PR_CALLBACK polymer_tessedgeflag(GLenum error)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
// Passing an edgeflag callback forces the tesselator to output a triangle list
|
2008-03-25 09:21:18 +00:00
|
|
|
UNREFERENCED_PARAMETER(error);
|
2006-09-29 21:36:12 +00:00
|
|
|
return;
|
2006-09-27 17:55:49 +00:00
|
|
|
}
|
|
|
|
|
2006-09-27 02:23:27 +00:00
|
|
|
void PR_CALLBACK polymer_tessvertex(void* vertex, void* sector)
|
|
|
|
{
|
|
|
|
_prsector* s;
|
|
|
|
|
|
|
|
s = (_prsector*)sector;
|
|
|
|
|
2006-09-27 17:55:49 +00:00
|
|
|
if (s->curindice >= s->indicescount)
|
|
|
|
{
|
|
|
|
if (pr_verbosity >= 2) OSD_Printf("PR : Indice overflow, extending the indices list... !\n");
|
|
|
|
s->indicescount++;
|
2014-05-30 00:02:19 +00:00
|
|
|
s->floor.indices = (GLushort *)Xrealloc(s->floor.indices, s->indicescount * sizeof(GLushort));
|
|
|
|
s->ceil.indices = (GLushort *)Xrealloc(s->ceil.indices, s->indicescount * sizeof(GLushort));
|
2006-09-27 17:55:49 +00:00
|
|
|
}
|
2008-06-10 19:23:55 +00:00
|
|
|
s->ceil.indices[s->curindice] = (intptr_t)vertex;
|
2006-09-27 02:23:27 +00:00
|
|
|
s->curindice++;
|
|
|
|
}
|
2008-03-14 12:19:13 +00:00
|
|
|
|
2009-01-16 05:03:12 +00:00
|
|
|
static int32_t polymer_buildfloor(int16_t sectnum)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
// This function tesselates the floor/ceiling of a sector and stores the triangles in a display list.
|
2006-09-29 21:36:12 +00:00
|
|
|
_prsector* s;
|
2015-03-24 00:40:21 +00:00
|
|
|
tsectortype *sec;
|
2009-01-16 05:03:12 +00:00
|
|
|
intptr_t i;
|
2006-08-31 01:56:43 +00:00
|
|
|
|
2008-04-12 08:16:01 +00:00
|
|
|
if (pr_verbosity >= 2) OSD_Printf("PR : Tesselating floor of sector %i...\n", sectnum);
|
2006-08-31 01:56:43 +00:00
|
|
|
|
|
|
|
s = prsectors[sectnum];
|
2015-03-24 00:40:21 +00:00
|
|
|
sec = (tsectortype *)§or[sectnum];
|
2006-08-31 01:56:43 +00:00
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
return (-1);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2008-05-18 07:35:35 +00:00
|
|
|
if (s->floor.indices == NULL)
|
2006-09-29 21:36:12 +00:00
|
|
|
{
|
2011-09-06 17:46:34 +00:00
|
|
|
s->indicescount = (max(3, sec->wallnum) - 2) * 3;
|
2014-05-30 00:02:19 +00:00
|
|
|
s->floor.indices = (GLushort *)Xcalloc(s->indicescount, sizeof(GLushort));
|
|
|
|
s->ceil.indices = (GLushort *)Xcalloc(s->indicescount, sizeof(GLushort));
|
2006-09-29 21:36:12 +00:00
|
|
|
}
|
2006-09-27 02:23:27 +00:00
|
|
|
|
|
|
|
s->curindice = 0;
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2012-11-15 14:28:36 +00:00
|
|
|
bgluTessCallback(prtess, GLU_TESS_VERTEX_DATA, (void (PR_CALLBACK *)(void))polymer_tessvertex);
|
|
|
|
bgluTessCallback(prtess, GLU_TESS_EDGE_FLAG, (void (PR_CALLBACK *)(void))polymer_tessedgeflag);
|
|
|
|
bgluTessCallback(prtess, GLU_TESS_ERROR, (void (PR_CALLBACK *)(void))polymer_tesserror);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2007-01-16 03:19:04 +00:00
|
|
|
bgluTessProperty(prtess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_POSITIVE);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2007-01-16 03:19:04 +00:00
|
|
|
bgluTessBeginPolygon(prtess, s);
|
|
|
|
bgluTessBeginContour(prtess);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < sec->wallnum)
|
|
|
|
{
|
2007-01-16 03:19:04 +00:00
|
|
|
bgluTessVertex(prtess, s->verts + (3 * i), (void *)i);
|
2006-09-27 02:23:27 +00:00
|
|
|
if ((i != (sec->wallnum - 1)) && ((sec->wallptr + i) > wall[sec->wallptr + i].point2))
|
2006-08-30 23:32:39 +00:00
|
|
|
{
|
2007-01-16 03:19:04 +00:00
|
|
|
bgluTessEndContour(prtess);
|
|
|
|
bgluTessBeginContour(prtess);
|
2006-08-30 23:32:39 +00:00
|
|
|
}
|
2006-08-31 01:56:43 +00:00
|
|
|
i++;
|
2006-08-30 23:32:39 +00:00
|
|
|
}
|
2007-01-16 03:19:04 +00:00
|
|
|
bgluTessEndContour(prtess);
|
|
|
|
bgluTessEndPolygon(prtess);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2006-10-04 09:54:25 +00:00
|
|
|
i = 0;
|
|
|
|
while (i < s->indicescount)
|
|
|
|
{
|
2008-05-18 07:35:35 +00:00
|
|
|
s->floor.indices[s->indicescount - i - 1] = s->ceil.indices[i];
|
2006-10-04 09:54:25 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2009-03-23 14:18:20 +00:00
|
|
|
s->floor.indicescount = s->ceil.indicescount = s->indicescount;
|
2006-10-04 09:54:25 +00:00
|
|
|
|
2006-08-31 01:56:43 +00:00
|
|
|
if (pr_verbosity >= 2) OSD_Printf("PR : Tesselated floor of sector %i.\n", sectnum);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
|
|
|
return (1);
|
2006-08-31 01:56:43 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 21:05:38 +00:00
|
|
|
static void polymer_drawsector(int16_t sectnum, int32_t domasks)
|
2006-08-31 01:56:43 +00:00
|
|
|
{
|
2015-03-24 00:40:21 +00:00
|
|
|
tsectortype *sec;
|
2006-09-29 21:36:12 +00:00
|
|
|
_prsector* s;
|
2009-12-07 07:01:44 +00:00
|
|
|
GLubyte oldcolor[4];
|
2011-08-20 21:05:38 +00:00
|
|
|
int32_t draw;
|
|
|
|
int32_t queuedmask;
|
2006-08-31 01:56:43 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Drawing sector %i...\n", sectnum);
|
2006-08-31 01:56:43 +00:00
|
|
|
|
2015-03-24 00:40:21 +00:00
|
|
|
sec = (tsectortype *)§or[sectnum];
|
2006-09-29 21:36:12 +00:00
|
|
|
s = prsectors[sectnum];
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2011-08-20 21:05:38 +00:00
|
|
|
queuedmask = FALSE;
|
|
|
|
|
|
|
|
// If you're thinking of 'optimizing' the following logic, you'd better
|
|
|
|
// provide compelling evidence that the generated code is more efficient
|
|
|
|
// than what GCC can come up with on its own.
|
|
|
|
|
|
|
|
draw = TRUE;
|
|
|
|
// Draw masks regardless; avoid all non-masks TROR links
|
|
|
|
if (sec->floorstat & 384) {
|
|
|
|
draw = domasks;
|
2013-04-09 17:35:11 +00:00
|
|
|
} else if (yax_getbunch(sectnum, YAX_FLOOR) >= 0) {
|
2011-08-20 21:05:38 +00:00
|
|
|
draw = FALSE;
|
|
|
|
}
|
|
|
|
// Parallaxed
|
|
|
|
if (sec->floorstat & 1) {
|
|
|
|
draw = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (draw || (searchit == 2)) {
|
2009-12-07 07:01:44 +00:00
|
|
|
if (searchit == 2) {
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawsearchplane(&s->floor, oldcolor, 0x02, (GLubyte *) §num);
|
|
|
|
}
|
|
|
|
else {
|
2014-05-01 22:02:21 +00:00
|
|
|
calc_and_apply_fog(sec->floorpicnum, fogpal_shade(sec, sec->floorshade),
|
2014-09-30 04:04:30 +00:00
|
|
|
sec->visibility, get_floor_fogpal(sec));
|
|
|
|
polymer_drawplane(&s->floor);
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
2011-08-20 21:06:00 +00:00
|
|
|
} else if (!domasks && cursectormaskcount && sec->floorstat & 384) {
|
2011-08-20 21:05:38 +00:00
|
|
|
// If we just skipped a mask, queue it for later
|
|
|
|
cursectormasks[(*cursectormaskcount)++] = sectnum;
|
|
|
|
// Don't queue it twice if the ceiling is also a mask, though.
|
|
|
|
queuedmask = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
draw = TRUE;
|
|
|
|
// Draw masks regardless; avoid all non-masks TROR links
|
|
|
|
if (sec->ceilingstat & 384) {
|
|
|
|
draw = domasks;
|
2013-04-09 17:35:11 +00:00
|
|
|
} else if (yax_getbunch(sectnum, YAX_CEILING) >= 0) {
|
2011-08-20 21:05:38 +00:00
|
|
|
draw = FALSE;
|
|
|
|
}
|
|
|
|
// Parallaxed
|
|
|
|
if (sec->ceilingstat & 1) {
|
|
|
|
draw = FALSE;
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
|
|
|
|
2011-08-20 21:05:38 +00:00
|
|
|
if (draw || (searchit == 2)) {
|
2009-12-07 07:01:44 +00:00
|
|
|
if (searchit == 2) {
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawsearchplane(&s->ceil, oldcolor, 0x01, (GLubyte *) §num);
|
|
|
|
}
|
|
|
|
else {
|
2014-05-01 22:02:21 +00:00
|
|
|
calc_and_apply_fog(sec->ceilingpicnum, fogpal_shade(sec, sec->ceilingshade),
|
|
|
|
sec->visibility, get_ceiling_fogpal(sec));
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawplane(&s->ceil);
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
2011-08-20 21:06:00 +00:00
|
|
|
} else if (!domasks && !queuedmask && cursectormaskcount &&
|
|
|
|
(sec->ceilingstat & 384)) {
|
2011-08-20 21:05:38 +00:00
|
|
|
// If we just skipped a mask, queue it for later
|
|
|
|
cursectormasks[(*cursectormaskcount)++] = sectnum;
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Finished drawing sector %i...\n", sectnum);
|
|
|
|
}
|
|
|
|
|
2006-10-15 18:51:41 +00:00
|
|
|
// WALLS
|
2009-01-16 05:03:12 +00:00
|
|
|
static int32_t polymer_initwall(int16_t wallnum)
|
2006-09-29 21:36:12 +00:00
|
|
|
{
|
|
|
|
_prwall *w;
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
if (pr_verbosity >= 2) OSD_Printf("PR : Initializing wall %i...\n", wallnum);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
w = (_prwall *)Xcalloc(1, sizeof(_prwall));
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2009-03-08 20:38:51 +00:00
|
|
|
if (w->mask.buffer == NULL) {
|
2015-07-13 03:46:35 +00:00
|
|
|
w->mask.buffer = (_prvert *)Xmalloc(4 * sizeof(_prvert));
|
2009-03-08 20:38:51 +00:00
|
|
|
w->mask.vertcount = 4;
|
|
|
|
}
|
2008-04-04 07:28:25 +00:00
|
|
|
if (w->bigportal == NULL)
|
2014-05-30 00:02:19 +00:00
|
|
|
w->bigportal = (GLfloat *)Xmalloc(4 * sizeof(GLfloat) * 5);
|
2015-07-13 03:46:35 +00:00
|
|
|
//if (w->cap == NULL)
|
|
|
|
// w->cap = (GLfloat *)Xmalloc(4 * sizeof(GLfloat) * 3);
|
2008-04-04 07:28:25 +00:00
|
|
|
|
2008-05-24 09:37:09 +00:00
|
|
|
bglGenBuffersARB(1, &w->wall.vbo);
|
|
|
|
bglGenBuffersARB(1, &w->over.vbo);
|
|
|
|
bglGenBuffersARB(1, &w->mask.vbo);
|
|
|
|
bglGenBuffersARB(1, &w->stuffvbo);
|
|
|
|
|
2008-05-31 08:29:40 +00:00
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, w->wall.vbo);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, 4 * sizeof(GLfloat) * 5, NULL, mapvbousage);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, w->over.vbo);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, 4 * sizeof(GLfloat) * 5, NULL, mapvbousage);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, w->mask.vbo);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, 4 * sizeof(GLfloat) * 5, NULL, mapvbousage);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, w->stuffvbo);
|
2009-03-08 22:59:54 +00:00
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, 8 * sizeof(GLfloat) * 5, NULL, mapvbousage);
|
2008-05-31 08:29:40 +00:00
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
w->flags.empty = 1;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
prwalls[wallnum] = w;
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
if (pr_verbosity >= 2) OSD_Printf("PR : Initialized wall %i.\n", wallnum);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2014-06-01 11:55:19 +00:00
|
|
|
// TODO: r_npotwallmode. Needs polymost_is_npotmode() handling among others.
|
|
|
|
#define DAMETH_WALL 0
|
|
|
|
|
2012-07-09 19:00:14 +00:00
|
|
|
static float calc_ypancoef(char curypanning, int16_t curpicnum, int32_t dopancor)
|
2012-07-06 15:36:50 +00:00
|
|
|
{
|
2013-07-04 19:38:37 +00:00
|
|
|
#ifdef NEW_MAP_FORMAT
|
|
|
|
if (g_loadedMapVersion >= 10)
|
|
|
|
return curypanning / 256.0f;
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
float ypancoef = (float)(pow2long[picsiz[curpicnum] >> 4]);
|
2012-07-06 15:36:50 +00:00
|
|
|
|
2014-09-30 04:14:21 +00:00
|
|
|
if (ypancoef < tilesiz[curpicnum].y)
|
2013-07-04 19:38:37 +00:00
|
|
|
ypancoef *= 2;
|
2012-07-09 19:00:14 +00:00
|
|
|
|
2013-07-04 19:38:37 +00:00
|
|
|
if (dopancor)
|
|
|
|
{
|
2014-10-25 03:29:21 +00:00
|
|
|
int32_t yoffs = Blrintf((ypancoef - tilesiz[curpicnum].y) * (255.0f / ypancoef));
|
2013-07-04 19:38:37 +00:00
|
|
|
if (curypanning > 256 - yoffs)
|
|
|
|
curypanning -= yoffs;
|
|
|
|
}
|
2012-07-06 15:36:50 +00:00
|
|
|
|
2014-09-30 04:14:21 +00:00
|
|
|
ypancoef *= (float)curypanning / (256.0f * (float)tilesiz[curpicnum].y);
|
2012-07-06 15:36:50 +00:00
|
|
|
|
2013-07-04 19:38:37 +00:00
|
|
|
return ypancoef;
|
|
|
|
}
|
2012-07-06 15:36:50 +00:00
|
|
|
}
|
|
|
|
|
2014-12-21 15:51:51 +00:00
|
|
|
#define NBYTES_WALL_CSTAT_THROUGH_YPANNING \
|
|
|
|
(offsetof(walltype, ypanning)+sizeof(wall[0].ypanning) - offsetof(walltype, cstat))
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void polymer_updatewall(int16_t wallnum)
|
2006-09-29 21:36:12 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int16_t nwallnum, nnwallnum, curpicnum, wallpicnum, walloverpicnum, nwallpicnum;
|
2008-04-29 04:46:06 +00:00
|
|
|
char curxpanning, curypanning, underwall, overwall, curpal;
|
2009-01-16 05:03:12 +00:00
|
|
|
int8_t curshade;
|
2006-09-29 21:36:12 +00:00
|
|
|
walltype *wal;
|
|
|
|
sectortype *sec, *nsec;
|
|
|
|
_prwall *w;
|
|
|
|
_prsector *s, *ns;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t xref, yref;
|
2006-10-17 01:14:20 +00:00
|
|
|
float ypancoef, dist;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i;
|
|
|
|
uint32_t invalid;
|
2009-06-07 07:36:15 +00:00
|
|
|
int32_t sectofwall = sectorofwall(wallnum);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_nullrender >= 3) return;
|
2015-06-14 23:42:31 +00:00
|
|
|
|
2008-04-04 07:28:25 +00:00
|
|
|
// yes, this function is messy and unefficient
|
|
|
|
// it also works, bitches
|
2009-10-07 06:47:35 +00:00
|
|
|
sec = §or[sectofwall];
|
2009-06-07 07:36:15 +00:00
|
|
|
|
2011-03-04 08:50:58 +00:00
|
|
|
if (sectofwall < 0 || sectofwall >= numsectors ||
|
2009-12-07 07:01:44 +00:00
|
|
|
wallnum < 0 || wallnum > numwalls ||
|
|
|
|
sec->wallptr > wallnum || wallnum >= (sec->wallptr + sec->wallnum))
|
2009-05-31 18:16:14 +00:00
|
|
|
return; // yay, corrupt map
|
2009-10-01 00:50:20 +00:00
|
|
|
|
2009-10-07 06:47:35 +00:00
|
|
|
wal = &wall[wallnum];
|
|
|
|
nwallnum = wal->nextwall;
|
2009-10-01 00:50:20 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
w = prwalls[wallnum];
|
2009-06-07 07:36:15 +00:00
|
|
|
s = prsectors[sectofwall];
|
2008-04-02 08:49:21 +00:00
|
|
|
invalid = s->invalidid;
|
2014-05-17 12:36:03 +00:00
|
|
|
if (nwallnum >= 0 && nwallnum < numwalls && wal->nextsector >= 0 && wal->nextsector < numsectors)
|
2008-04-02 08:49:21 +00:00
|
|
|
{
|
|
|
|
ns = prsectors[wal->nextsector];
|
|
|
|
invalid += ns->invalidid;
|
2008-04-03 06:58:36 +00:00
|
|
|
nsec = §or[wal->nextsector];
|
2008-04-02 08:49:21 +00:00
|
|
|
}
|
|
|
|
else
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2008-04-02 08:49:21 +00:00
|
|
|
ns = NULL;
|
2008-04-06 03:00:39 +00:00
|
|
|
nsec = NULL;
|
|
|
|
}
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2009-03-08 20:38:51 +00:00
|
|
|
if (w->wall.buffer == NULL) {
|
2015-07-13 03:46:35 +00:00
|
|
|
w->wall.buffer = (_prvert *)Xcalloc(4, sizeof(_prvert)); // XXX
|
2009-03-08 20:38:51 +00:00
|
|
|
w->wall.vertcount = 4;
|
|
|
|
}
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2008-04-02 08:49:21 +00:00
|
|
|
wallpicnum = wal->picnum;
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(wallpicnum, wallnum+16384);
|
|
|
|
|
2008-04-02 08:49:21 +00:00
|
|
|
walloverpicnum = wal->overpicnum;
|
2012-11-15 21:09:53 +00:00
|
|
|
if (walloverpicnum>=0)
|
|
|
|
DO_TILE_ANIM(walloverpicnum, wallnum+16384);
|
|
|
|
|
2009-10-01 00:50:20 +00:00
|
|
|
if (nwallnum >= 0 && nwallnum < numwalls)
|
2008-04-02 08:49:21 +00:00
|
|
|
{
|
|
|
|
nwallpicnum = wall[nwallnum].picnum;
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(nwallpicnum, wallnum+16384);
|
2008-04-02 08:49:21 +00:00
|
|
|
}
|
2008-04-06 03:00:39 +00:00
|
|
|
else
|
|
|
|
nwallpicnum = 0;
|
2008-04-02 08:49:21 +00:00
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
if ((!w->flags.empty) && (!w->flags.invalidtex) &&
|
2008-05-10 01:29:37 +00:00
|
|
|
(w->invalidid == invalid) &&
|
2014-09-30 04:04:30 +00:00
|
|
|
(wallpicnum == w->picnum_anim) &&
|
|
|
|
(walloverpicnum == w->overpicnum_anim) &&
|
2015-12-23 04:05:47 +00:00
|
|
|
#ifndef UNTRACKED_STRUCTS
|
2016-01-27 10:28:00 +00:00
|
|
|
(w->trackedrev == wallchanged[wallnum]) &&
|
2015-12-23 04:05:47 +00:00
|
|
|
#else
|
2014-12-21 15:51:51 +00:00
|
|
|
!Bmemcmp(&wal->cstat, &w->cstat, NBYTES_WALL_CSTAT_THROUGH_YPANNING) &&
|
2015-12-23 04:05:47 +00:00
|
|
|
#endif
|
2009-10-01 00:50:20 +00:00
|
|
|
((nwallnum < 0 || nwallnum > numwalls) ||
|
2008-05-10 01:29:37 +00:00
|
|
|
((nwallpicnum == w->nwallpicnum) &&
|
|
|
|
(wall[nwallnum].xpanning == w->nwallxpanning) &&
|
|
|
|
(wall[nwallnum].ypanning == w->nwallypanning) &&
|
2011-02-13 23:37:35 +00:00
|
|
|
(wall[nwallnum].cstat == w->nwallcstat) &&
|
|
|
|
(wall[nwallnum].shade == w->nwallshade))))
|
2008-04-02 08:49:21 +00:00
|
|
|
{
|
2009-06-09 09:32:23 +00:00
|
|
|
w->flags.uptodate = 1;
|
2008-04-02 08:49:21 +00:00
|
|
|
return; // screw you guys I'm going home
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w->invalidid = invalid;
|
2014-09-30 04:04:30 +00:00
|
|
|
|
2014-12-21 15:51:51 +00:00
|
|
|
Bmemcpy(&w->cstat, &wal->cstat, NBYTES_WALL_CSTAT_THROUGH_YPANNING);
|
2014-09-30 04:04:30 +00:00
|
|
|
|
|
|
|
w->picnum_anim = wallpicnum;
|
|
|
|
w->overpicnum_anim = walloverpicnum;
|
2015-12-23 04:05:47 +00:00
|
|
|
#ifndef UNTRACKED_STRUCTS
|
2016-01-27 10:28:00 +00:00
|
|
|
w->trackedrev = wallchanged[wallnum];
|
2015-12-23 04:05:47 +00:00
|
|
|
#endif
|
2009-10-01 00:50:20 +00:00
|
|
|
if (nwallnum >= 0 && nwallnum < numwalls)
|
2008-04-02 08:49:21 +00:00
|
|
|
{
|
|
|
|
w->nwallpicnum = nwallpicnum;
|
|
|
|
w->nwallxpanning = wall[nwallnum].xpanning;
|
|
|
|
w->nwallypanning = wall[nwallnum].ypanning;
|
|
|
|
w->nwallcstat = wall[nwallnum].cstat;
|
2011-02-13 23:37:35 +00:00
|
|
|
w->nwallshade = wall[nwallnum].shade;
|
2008-04-02 08:49:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-03 06:58:36 +00:00
|
|
|
w->underover = underwall = overwall = 0;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
if (wal->cstat & 8)
|
2006-10-17 01:14:20 +00:00
|
|
|
xref = 1;
|
2006-09-29 21:36:12 +00:00
|
|
|
else
|
2006-10-17 01:14:20 +00:00
|
|
|
xref = 0;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
if ((unsigned)wal->nextsector >= (unsigned)numsectors || !ns)
|
2006-09-29 21:36:12 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(w->wall.buffer, &s->floor.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->wall.buffer[1], &s->floor.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->wall.buffer[2], &s->ceil.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->wall.buffer[3], &s->ceil.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 3);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2009-12-03 06:21:39 +00:00
|
|
|
if (wal->nextsector < 0)
|
2009-03-23 14:18:20 +00:00
|
|
|
curpicnum = wallpicnum;
|
2009-03-24 09:37:30 +00:00
|
|
|
else
|
|
|
|
curpicnum = walloverpicnum;
|
2006-10-16 22:07:15 +00:00
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
w->wall.bucket = polymer_getbuildmaterial(&w->wall.material, curpicnum, wal->pal, wal->shade, sec->visibility, DAMETH_WALL);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
if (wal->cstat & 4)
|
2006-11-13 23:12:47 +00:00
|
|
|
yref = sec->floorz;
|
2006-08-31 01:56:43 +00:00
|
|
|
else
|
2006-09-29 21:36:12 +00:00
|
|
|
yref = sec->ceilingz;
|
|
|
|
|
2009-12-03 06:21:39 +00:00
|
|
|
if ((wal->cstat & 32) && (wal->nextsector >= 0))
|
2008-04-03 06:58:36 +00:00
|
|
|
{
|
|
|
|
if ((!(wal->cstat & 2) && (wal->cstat & 4)) || ((wal->cstat & 2) && (wall[nwallnum].cstat & 4)))
|
|
|
|
yref = sec->ceilingz;
|
|
|
|
else
|
|
|
|
yref = nsec->floorz;
|
|
|
|
}
|
|
|
|
|
2006-10-16 22:07:15 +00:00
|
|
|
if (wal->ypanning)
|
2014-05-28 22:40:14 +00:00
|
|
|
// white (but not 1-way)
|
2012-07-09 19:00:14 +00:00
|
|
|
ypancoef = calc_ypancoef(wal->ypanning, curpicnum, !(wal->cstat & 4));
|
2006-10-16 22:07:15 +00:00
|
|
|
else
|
|
|
|
ypancoef = 0;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 4)
|
|
|
|
{
|
2006-10-17 01:14:20 +00:00
|
|
|
if ((i == 0) || (i == 3))
|
2009-07-12 01:55:34 +00:00
|
|
|
dist = (float)xref;
|
2006-10-17 01:14:20 +00:00
|
|
|
else
|
2009-07-12 01:55:34 +00:00
|
|
|
dist = (float)(xref == 0);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
w->wall.buffer[i].u = ((dist * 8.0f * wal->xrepeat) + wal->xpanning) / (float)(tilesiz[curpicnum].x);
|
|
|
|
w->wall.buffer[i].v = (-(float)(yref + (w->wall.buffer[i].y * 16)) / ((tilesiz[curpicnum].y * 2048.0f) / (float)(wal->yrepeat))) + ypancoef;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2015-07-15 05:14:08 +00:00
|
|
|
if (wal->cstat & 256) w->wall.buffer[i].v = -w->wall.buffer[i].v;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
w->underover |= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nnwallnum = wall[nwallnum].point2;
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if ((s->floor.buffer[wallnum - sec->wallptr].y < ns->floor.buffer[nnwallnum - nsec->wallptr].y) ||
|
|
|
|
(s->floor.buffer[wal->point2 - sec->wallptr].y < ns->floor.buffer[nwallnum - nsec->wallptr].y))
|
2008-04-03 06:58:36 +00:00
|
|
|
underwall = 1;
|
|
|
|
|
2009-03-29 19:31:24 +00:00
|
|
|
if ((underwall) || (wal->cstat & 16) || (wal->cstat & 32))
|
2006-08-31 01:56:43 +00:00
|
|
|
{
|
2012-07-09 19:00:17 +00:00
|
|
|
int32_t refwall;
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (s->floor.buffer[wallnum - sec->wallptr].y < ns->floor.buffer[nnwallnum - nsec->wallptr].y)
|
|
|
|
Bmemcpy(w->wall.buffer, &s->floor.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 3);
|
2009-04-12 19:26:02 +00:00
|
|
|
else
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(w->wall.buffer, &ns->floor.buffer[nnwallnum - nsec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->wall.buffer[1], &s->floor.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->wall.buffer[2], &ns->floor.buffer[nwallnum - nsec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->wall.buffer[3], &ns->floor.buffer[nnwallnum - nsec->wallptr], sizeof(GLfloat) * 3);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2006-10-16 22:07:15 +00:00
|
|
|
if (wal->cstat & 2)
|
2012-07-09 19:00:17 +00:00
|
|
|
refwall = nwallnum;
|
2006-10-16 22:07:15 +00:00
|
|
|
else
|
2012-07-09 19:00:17 +00:00
|
|
|
refwall = wallnum;
|
2012-07-09 19:00:21 +00:00
|
|
|
|
2012-07-15 09:23:58 +00:00
|
|
|
curpicnum = (wal->cstat & 2) ? nwallpicnum : wallpicnum;
|
2012-07-09 19:00:21 +00:00
|
|
|
curpal = wall[refwall].pal;
|
|
|
|
curshade = wall[refwall].shade;
|
|
|
|
curxpanning = wall[refwall].xpanning;
|
|
|
|
curypanning = wall[refwall].ypanning;
|
2006-10-16 22:07:15 +00:00
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
w->wall.bucket = polymer_getbuildmaterial(&w->wall.material, curpicnum, curpal, curshade, sec->visibility, DAMETH_WALL);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2012-07-09 19:00:21 +00:00
|
|
|
if (!(wall[refwall].cstat&4))
|
2006-09-29 21:36:12 +00:00
|
|
|
yref = nsec->floorz;
|
2012-07-09 19:00:21 +00:00
|
|
|
else
|
|
|
|
yref = sec->ceilingz;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2006-10-17 01:14:20 +00:00
|
|
|
if (curypanning)
|
2012-07-09 19:00:14 +00:00
|
|
|
// under
|
2012-07-09 19:00:17 +00:00
|
|
|
ypancoef = calc_ypancoef(curypanning, curpicnum, !(wall[refwall].cstat & 4));
|
2006-10-16 22:07:15 +00:00
|
|
|
else
|
|
|
|
ypancoef = 0;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 4)
|
|
|
|
{
|
2006-10-17 01:14:20 +00:00
|
|
|
if ((i == 0) || (i == 3))
|
2009-07-12 01:55:34 +00:00
|
|
|
dist = (float)xref;
|
2006-10-17 01:14:20 +00:00
|
|
|
else
|
2009-07-12 01:55:34 +00:00
|
|
|
dist = (float)(xref == 0);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
w->wall.buffer[i].u = ((dist * 8.0f * wal->xrepeat) + curxpanning) / (float)(tilesiz[curpicnum].x);
|
|
|
|
w->wall.buffer[i].v = (-(float)(yref + (w->wall.buffer[i].y * 16)) / ((tilesiz[curpicnum].y * 2048.0f) / (float)(wal->yrepeat))) + ypancoef;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2009-06-08 00:29:29 +00:00
|
|
|
if ((!(wal->cstat & 2) && (wal->cstat & 256)) ||
|
|
|
|
((wal->cstat & 2) && (wall[nwallnum].cstat & 256)))
|
2015-07-13 03:46:35 +00:00
|
|
|
w->wall.buffer[i].v = -w->wall.buffer[i].v;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
i++;
|
2006-08-31 01:56:43 +00:00
|
|
|
}
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2008-04-03 06:58:36 +00:00
|
|
|
if (underwall)
|
|
|
|
w->underover |= 1;
|
2009-12-07 07:17:33 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(w->mask.buffer, &w->wall.buffer[3], sizeof(GLfloat) * 5);
|
|
|
|
Bmemcpy(&w->mask.buffer[1], &w->wall.buffer[2], sizeof(GLfloat) * 5);
|
2008-04-04 07:28:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(w->mask.buffer, &s->floor.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 5);
|
|
|
|
Bmemcpy(&w->mask.buffer[1], &s->floor.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 5);
|
2006-08-31 01:56:43 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if ((s->ceil.buffer[wallnum - sec->wallptr].y > ns->ceil.buffer[nnwallnum - nsec->wallptr].y) ||
|
|
|
|
(s->ceil.buffer[wal->point2 - sec->wallptr].y > ns->ceil.buffer[nwallnum - nsec->wallptr].y))
|
2008-04-03 06:58:36 +00:00
|
|
|
overwall = 1;
|
|
|
|
|
2015-12-04 11:52:58 +00:00
|
|
|
if ((overwall) || (wal->cstat & 48))
|
2006-09-29 21:36:12 +00:00
|
|
|
{
|
2009-03-08 20:38:51 +00:00
|
|
|
if (w->over.buffer == NULL) {
|
2015-07-13 03:46:35 +00:00
|
|
|
w->over.buffer = (_prvert *)Xmalloc(4 * sizeof(_prvert));
|
2009-03-08 20:38:51 +00:00
|
|
|
w->over.vertcount = 4;
|
|
|
|
}
|
2006-08-31 01:56:43 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(w->over.buffer, &ns->ceil.buffer[nnwallnum - nsec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->over.buffer[1], &ns->ceil.buffer[nwallnum - nsec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
if (s->ceil.buffer[wal->point2 - sec->wallptr].y > ns->ceil.buffer[nwallnum - nsec->wallptr].y)
|
|
|
|
Bmemcpy(&w->over.buffer[2], &s->ceil.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 3);
|
2009-04-12 19:26:02 +00:00
|
|
|
else
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(&w->over.buffer[2], &ns->ceil.buffer[nwallnum - nsec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->over.buffer[3], &s->ceil.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 3);
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2006-10-16 22:07:15 +00:00
|
|
|
if ((wal->cstat & 16) || (wal->overpicnum == 0))
|
2008-04-02 08:49:21 +00:00
|
|
|
curpicnum = wallpicnum;
|
2006-10-16 22:07:15 +00:00
|
|
|
else
|
2008-04-02 08:49:21 +00:00
|
|
|
curpicnum = wallpicnum;
|
2006-10-16 22:07:15 +00:00
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
w->over.bucket = polymer_getbuildmaterial(&w->over.material, curpicnum, wal->pal, wal->shade, sec->visibility, DAMETH_WALL);
|
2006-10-16 22:07:15 +00:00
|
|
|
|
2015-12-04 11:52:58 +00:00
|
|
|
if (wal->cstat & 48)
|
2008-04-03 06:58:36 +00:00
|
|
|
{
|
2008-11-26 14:22:07 +00:00
|
|
|
// mask
|
2015-12-04 11:52:58 +00:00
|
|
|
w->mask.bucket = polymer_getbuildmaterial(&w->mask.material, walloverpicnum, wal->pal, wal->shade, sec->visibility, DAMETH_WALL | ((wal->cstat & 48) == 48 ? DAMETH_NOMASK : DAMETH_MASK));
|
2009-12-07 07:01:44 +00:00
|
|
|
|
2008-04-04 07:28:25 +00:00
|
|
|
if (wal->cstat & 128)
|
|
|
|
{
|
|
|
|
if (wal->cstat & 512)
|
2009-12-07 07:01:44 +00:00
|
|
|
w->mask.material.diffusemodulation[3] = 0x55;
|
2008-04-04 07:28:25 +00:00
|
|
|
else
|
2009-12-07 07:01:44 +00:00
|
|
|
w->mask.material.diffusemodulation[3] = 0xAA;
|
2008-04-04 07:28:25 +00:00
|
|
|
}
|
2006-09-29 21:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wal->cstat & 4)
|
2006-11-13 23:12:47 +00:00
|
|
|
yref = sec->ceilingz;
|
2006-09-29 21:36:12 +00:00
|
|
|
else
|
|
|
|
yref = nsec->ceilingz;
|
|
|
|
|
2006-10-16 22:07:15 +00:00
|
|
|
if (wal->ypanning)
|
2012-07-09 19:00:14 +00:00
|
|
|
// over
|
|
|
|
ypancoef = calc_ypancoef(wal->ypanning, curpicnum, wal->cstat & 4);
|
2006-10-16 22:07:15 +00:00
|
|
|
else
|
|
|
|
ypancoef = 0;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 4)
|
|
|
|
{
|
2006-10-17 01:14:20 +00:00
|
|
|
if ((i == 0) || (i == 3))
|
2009-07-12 01:55:34 +00:00
|
|
|
dist = (float)xref;
|
2006-10-17 01:14:20 +00:00
|
|
|
else
|
2009-07-12 01:55:34 +00:00
|
|
|
dist = (float)(xref == 0);
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
w->over.buffer[i].u = ((dist * 8.0f * wal->xrepeat) + wal->xpanning) / (float)(tilesiz[curpicnum].x);
|
|
|
|
w->over.buffer[i].v = (-(float)(yref + (w->over.buffer[i].y * 16)) / ((tilesiz[curpicnum].y * 2048.0f) / (float)(wal->yrepeat))) + ypancoef;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (wal->cstat & 256) w->over.buffer[i].v = -w->over.buffer[i].v;
|
2006-09-29 21:36:12 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2008-04-03 06:58:36 +00:00
|
|
|
if (overwall)
|
|
|
|
w->underover |= 2;
|
2009-12-07 07:17:33 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(&w->mask.buffer[2], &w->over.buffer[1], sizeof(GLfloat) * 5);
|
|
|
|
Bmemcpy(&w->mask.buffer[3], &w->over.buffer[0], sizeof(GLfloat) * 5);
|
2008-04-04 07:28:25 +00:00
|
|
|
|
2009-03-29 19:31:24 +00:00
|
|
|
if ((wal->cstat & 16) || (wal->cstat & 32))
|
2008-04-04 07:28:25 +00:00
|
|
|
{
|
2015-05-22 12:43:26 +00:00
|
|
|
const int botSwap = (wal->cstat & 4);
|
2008-04-04 07:28:25 +00:00
|
|
|
|
2009-03-29 19:31:24 +00:00
|
|
|
if (wal->cstat & 32)
|
|
|
|
{
|
2015-05-22 12:43:26 +00:00
|
|
|
// 1-sided wall
|
|
|
|
if (nsec)
|
|
|
|
yref = botSwap ? sec->ceilingz : nsec->ceilingz;
|
|
|
|
else
|
|
|
|
yref = botSwap ? sec->floorz : sec->ceilingz;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// masked wall
|
|
|
|
if (botSwap)
|
|
|
|
yref = min(sec->floorz, nsec->floorz);
|
2009-03-29 19:31:24 +00:00
|
|
|
else
|
2015-05-22 12:43:26 +00:00
|
|
|
yref = max(sec->ceilingz, nsec->ceilingz);
|
2009-03-29 19:31:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
curpicnum = walloverpicnum;
|
2008-04-04 07:28:25 +00:00
|
|
|
|
|
|
|
if (wal->ypanning)
|
2014-05-28 22:40:14 +00:00
|
|
|
// mask / 1-way
|
2012-07-09 19:00:14 +00:00
|
|
|
ypancoef = calc_ypancoef(wal->ypanning, curpicnum, 0);
|
2008-04-04 07:28:25 +00:00
|
|
|
else
|
|
|
|
ypancoef = 0;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < 4)
|
|
|
|
{
|
|
|
|
if ((i == 0) || (i == 3))
|
2009-07-12 01:55:34 +00:00
|
|
|
dist = (float)xref;
|
2008-04-04 07:28:25 +00:00
|
|
|
else
|
2009-07-12 01:55:34 +00:00
|
|
|
dist = (float)(xref == 0);
|
2008-04-04 07:28:25 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
w->mask.buffer[i].u = ((dist * 8.0f * wal->xrepeat) + wal->xpanning) / (float)(tilesiz[curpicnum].x);
|
|
|
|
w->mask.buffer[i].v = (-(float)(yref + (w->mask.buffer[i].y * 16)) / ((tilesiz[curpicnum].y * 2048.0f) / (float)(wal->yrepeat))) + ypancoef;
|
2008-04-04 07:28:25 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (wal->cstat & 256) w->mask.buffer[i].v = -w->mask.buffer[i].v;
|
2008-04-04 07:28:25 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2008-04-03 06:58:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(&w->mask.buffer[2], &s->ceil.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 5);
|
|
|
|
Bmemcpy(&w->mask.buffer[3], &s->ceil.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 5);
|
2008-04-03 06:58:36 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-15 18:51:41 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
// make sure shade color handling is correct below XXX
|
2009-12-03 06:21:39 +00:00
|
|
|
if (wal->nextsector < 0)
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(w->mask.buffer, w->wall.buffer, sizeof(_prvert) * 4);
|
2008-04-04 07:28:25 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(w->bigportal, &s->floor.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->bigportal[5], &s->floor.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->bigportal[10], &s->ceil.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
Bmemcpy(&w->bigportal[15], &s->ceil.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 3);
|
2006-10-15 18:51:41 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
//Bmemcpy(&w->cap[0], &s->ceil.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
//Bmemcpy(&w->cap[3], &s->ceil.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
//Bmemcpy(&w->cap[6], &s->ceil.buffer[wal->point2 - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
//Bmemcpy(&w->cap[9], &s->ceil.buffer[wallnum - sec->wallptr], sizeof(GLfloat) * 3);
|
|
|
|
//w->cap[7] += 1048576; // this number is the result of 1048574 + 2
|
|
|
|
//w->cap[10] += 1048576; // this one is arbitrary
|
2008-04-12 08:16:01 +00:00
|
|
|
|
2009-03-13 15:18:46 +00:00
|
|
|
if (w->underover & 1)
|
2009-04-19 17:23:07 +00:00
|
|
|
polymer_computeplane(&w->wall);
|
2009-03-13 15:18:46 +00:00
|
|
|
if (w->underover & 2)
|
2009-04-19 17:23:07 +00:00
|
|
|
polymer_computeplane(&w->over);
|
|
|
|
polymer_computeplane(&w->mask);
|
2008-04-09 07:59:37 +00:00
|
|
|
|
2008-05-24 09:37:09 +00:00
|
|
|
if ((pr_vbos > 0))
|
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_nullrender < 2)
|
|
|
|
{
|
|
|
|
const GLintptrARB thiswalloffset = prwalldataoffset + (prwalldatasize * wallnum);
|
|
|
|
const GLintptrARB thisoveroffset = thiswalloffset + proneplanesize;
|
|
|
|
const GLintptrARB thismaskoffset = thisoveroffset + proneplanesize;
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, prmapvbo);
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, thiswalloffset, proneplanesize, w->wall.buffer);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, prmapvbo);
|
|
|
|
if (w->over.buffer)
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, thisoveroffset, proneplanesize, w->over.buffer);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, prmapvbo);
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, thismaskoffset, proneplanesize, w->mask.buffer);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, w->stuffvbo);
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, 4 * sizeof(GLfloat)* 5, w->bigportal);
|
|
|
|
//bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 4 * sizeof(GLfloat)* 5, 4 * sizeof(GLfloat)* 3, w->cap);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
w->wall.mapvbo_vertoffset = thiswalloffset / sizeof(_prvert);
|
|
|
|
w->over.mapvbo_vertoffset = thisoveroffset / sizeof(_prvert);
|
|
|
|
w->mask.mapvbo_vertoffset = thismaskoffset / sizeof(_prvert);
|
2015-07-13 03:46:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w->wall.mapvbo_vertoffset = -1;
|
|
|
|
w->over.mapvbo_vertoffset = -1;
|
|
|
|
w->mask.mapvbo_vertoffset = -1;
|
2008-05-24 09:37:09 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
w->flags.empty = 0;
|
|
|
|
w->flags.uptodate = 1;
|
|
|
|
w->flags.invalidtex = 0;
|
2008-03-30 19:13:24 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Updated wall %i.\n", wallnum);
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void polymer_drawwall(int16_t sectnum, int16_t wallnum)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2015-03-24 00:40:21 +00:00
|
|
|
tsectortype *sec;
|
2009-04-11 18:01:39 +00:00
|
|
|
walltype *wal;
|
2006-09-29 21:36:12 +00:00
|
|
|
_prwall *w;
|
2009-12-07 07:01:44 +00:00
|
|
|
GLubyte oldcolor[4];
|
2009-12-07 07:17:33 +00:00
|
|
|
int32_t parallaxedfloor = 0, parallaxedceiling = 0;
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Drawing wall %i...\n", wallnum);
|
2006-08-29 01:58:59 +00:00
|
|
|
|
2015-03-24 00:40:21 +00:00
|
|
|
sec = (tsectortype *)§or[sectnum];
|
2009-04-11 18:01:39 +00:00
|
|
|
wal = &wall[wallnum];
|
2006-09-29 21:36:12 +00:00
|
|
|
w = prwalls[wallnum];
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2009-12-07 07:17:33 +00:00
|
|
|
if ((sec->floorstat & 1) && (wal->nextsector >= 0) &&
|
|
|
|
(sector[wal->nextsector].floorstat & 1))
|
|
|
|
parallaxedfloor = 1;
|
|
|
|
|
|
|
|
if ((sec->ceilingstat & 1) && (wal->nextsector >= 0) &&
|
|
|
|
(sector[wal->nextsector].ceilingstat & 1))
|
|
|
|
parallaxedceiling = 1;
|
|
|
|
|
2014-05-01 22:02:21 +00:00
|
|
|
calc_and_apply_fog(wal->picnum, fogpal_shade(sec, wal->shade), sec->visibility, get_floor_fogpal(sec));
|
2009-04-11 18:01:39 +00:00
|
|
|
|
2009-12-07 07:17:33 +00:00
|
|
|
if ((w->underover & 1) && (!parallaxedfloor || (searchit == 2)))
|
2006-08-29 01:58:59 +00:00
|
|
|
{
|
2009-12-07 07:01:44 +00:00
|
|
|
if (searchit == 2) {
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawsearchplane(&w->wall, oldcolor, 0x05, (GLubyte *) &wallnum);
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
2014-09-30 04:04:30 +00:00
|
|
|
else
|
|
|
|
polymer_drawplane(&w->wall);
|
2006-09-29 21:36:12 +00:00
|
|
|
}
|
2008-03-26 12:04:00 +00:00
|
|
|
|
2009-12-07 07:17:33 +00:00
|
|
|
if ((w->underover & 2) && (!parallaxedceiling || (searchit == 2)))
|
2006-09-29 21:36:12 +00:00
|
|
|
{
|
2009-12-07 07:01:44 +00:00
|
|
|
if (searchit == 2) {
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawsearchplane(&w->over, oldcolor, 0x00, (GLubyte *) &wallnum);
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
2014-09-30 04:04:30 +00:00
|
|
|
else
|
|
|
|
polymer_drawplane(&w->over);
|
2006-08-29 01:58:59 +00:00
|
|
|
}
|
2006-08-30 23:32:39 +00:00
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
if ((wall[wallnum].cstat & 32) && (wall[wallnum].nextsector >= 0))
|
|
|
|
{
|
2009-12-07 07:01:44 +00:00
|
|
|
if (searchit == 2) {
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawsearchplane(&w->mask, oldcolor, 0x04, (GLubyte *) &wallnum);
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
2014-09-30 04:04:30 +00:00
|
|
|
else
|
|
|
|
polymer_drawplane(&w->mask);
|
2009-12-07 07:01:44 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
//if (!searchit && (sector[sectnum].ceilingstat & 1) &&
|
|
|
|
// ((wall[wallnum].nextsector < 0) ||
|
|
|
|
// !(sector[wall[wallnum].nextsector].ceilingstat & 1)))
|
|
|
|
//{
|
|
|
|
// bglColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
|
2008-05-24 09:37:09 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
// if (pr_vbos)
|
|
|
|
// {
|
|
|
|
// bglBindBufferARB(GL_ARRAY_BUFFER_ARB, w->stuffvbo);
|
|
|
|
// bglVertexPointer(3, GL_FLOAT, 0, (const GLvoid*)(4 * sizeof(GLfloat) * 5));
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// bglVertexPointer(3, GL_FLOAT, 0, w->cap);
|
2008-05-24 09:37:09 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
// bglDrawArrays(GL_QUADS, 0, 4);
|
2008-05-24 09:37:09 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
// if (pr_vbos)
|
|
|
|
// bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
2008-05-24 09:37:09 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
// bglColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
|
|
|
//}
|
2008-04-12 08:16:01 +00:00
|
|
|
|
2006-09-29 21:36:12 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Finished drawing wall %i...\n", wallnum);
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
2006-10-14 23:33:10 +00:00
|
|
|
|
|
|
|
// HSR
|
2009-04-19 17:23:07 +00:00
|
|
|
static void polymer_computeplane(_prplane* p)
|
2008-04-06 23:35:48 +00:00
|
|
|
{
|
2009-04-12 10:46:31 +00:00
|
|
|
GLfloat vec1[5], vec2[5], norm, r;// BxN[3], NxT[3], TxB[3];
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i;
|
2015-07-13 03:46:35 +00:00
|
|
|
_prvert* buffer;
|
2009-04-19 17:23:07 +00:00
|
|
|
GLfloat* plane;
|
2008-04-06 23:35:48 +00:00
|
|
|
|
2009-04-19 17:23:07 +00:00
|
|
|
if (p->indices && (p->indicescount < 3))
|
2009-04-12 22:27:49 +00:00
|
|
|
return; // corrupt sector (E3L4, I'm looking at you)
|
|
|
|
|
2009-04-19 17:23:07 +00:00
|
|
|
buffer = p->buffer;
|
|
|
|
plane = p->plane;
|
|
|
|
|
2008-04-06 23:35:48 +00:00
|
|
|
i = 0;
|
2009-04-19 09:49:27 +00:00
|
|
|
do
|
2008-05-10 01:29:37 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
vec1[0] = buffer[(INDICE(1))].x - buffer[(INDICE(0))].x; //x1
|
|
|
|
vec1[1] = buffer[(INDICE(1))].y - buffer[(INDICE(0))].y; //y1
|
|
|
|
vec1[2] = buffer[(INDICE(1))].z - buffer[(INDICE(0))].z; //z1
|
|
|
|
vec1[3] = buffer[(INDICE(1))].u - buffer[(INDICE(0))].u; //s1
|
|
|
|
vec1[4] = buffer[(INDICE(1))].v - buffer[(INDICE(0))].v; //t1
|
2009-03-11 13:23:05 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
vec2[0] = buffer[(INDICE(2))].x - buffer[(INDICE(1))].x; //x2
|
|
|
|
vec2[1] = buffer[(INDICE(2))].y - buffer[(INDICE(1))].y; //y2
|
|
|
|
vec2[2] = buffer[(INDICE(2))].z - buffer[(INDICE(1))].z; //z2
|
|
|
|
vec2[3] = buffer[(INDICE(2))].u - buffer[(INDICE(1))].u; //s2
|
|
|
|
vec2[4] = buffer[(INDICE(2))].v - buffer[(INDICE(1))].v; //t2
|
2008-04-06 23:35:48 +00:00
|
|
|
|
2008-04-09 07:59:37 +00:00
|
|
|
polymer_crossproduct(vec2, vec1, plane);
|
2008-04-06 23:35:48 +00:00
|
|
|
|
2009-03-11 13:23:05 +00:00
|
|
|
norm = plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2];
|
|
|
|
|
2009-04-19 17:23:07 +00:00
|
|
|
// hack to work around a precision issue with slopes
|
2010-01-18 07:07:22 +00:00
|
|
|
if (norm >= 15000)
|
2009-03-11 13:23:05 +00:00
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
float tangent[3][3];
|
|
|
|
double det;
|
2010-01-21 05:52:19 +00:00
|
|
|
|
2009-03-11 13:23:05 +00:00
|
|
|
// normalize the normal/plane equation and calculate its plane norm
|
2009-04-19 09:49:27 +00:00
|
|
|
norm = -sqrt(norm);
|
|
|
|
norm = 1.0 / norm;
|
2009-04-17 18:34:55 +00:00
|
|
|
plane[0] *= norm;
|
|
|
|
plane[1] *= norm;
|
|
|
|
plane[2] *= norm;
|
2015-07-13 03:46:35 +00:00
|
|
|
plane[3] = -(plane[0] * buffer->x + plane[1] * buffer->y + plane[2] * buffer->z);
|
2009-03-11 13:23:05 +00:00
|
|
|
|
|
|
|
// calculate T and B
|
|
|
|
r = 1.0 / (vec1[3] * vec2[4] - vec2[3] * vec1[4]);
|
|
|
|
|
|
|
|
// tangent
|
2010-01-24 05:57:43 +00:00
|
|
|
tangent[0][0] = (vec2[4] * vec1[0] - vec1[4] * vec2[0]) * r;
|
|
|
|
tangent[0][1] = (vec2[4] * vec1[1] - vec1[4] * vec2[1]) * r;
|
|
|
|
tangent[0][2] = (vec2[4] * vec1[2] - vec1[4] * vec2[2]) * r;
|
2010-01-21 05:52:19 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
polymer_normalize(&tangent[0][0]);
|
2009-03-11 13:23:05 +00:00
|
|
|
|
|
|
|
// bitangent
|
2010-01-24 05:57:43 +00:00
|
|
|
tangent[1][0] = (vec1[3] * vec2[0] - vec2[3] * vec1[0]) * r;
|
|
|
|
tangent[1][1] = (vec1[3] * vec2[1] - vec2[3] * vec1[1]) * r;
|
|
|
|
tangent[1][2] = (vec1[3] * vec2[2] - vec2[3] * vec1[2]) * r;
|
2009-03-11 13:23:05 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
polymer_normalize(&tangent[1][0]);
|
2009-03-11 13:23:05 +00:00
|
|
|
|
2010-01-21 05:52:19 +00:00
|
|
|
// normal
|
2010-01-24 05:57:43 +00:00
|
|
|
tangent[2][0] = plane[0];
|
|
|
|
tangent[2][1] = plane[1];
|
|
|
|
tangent[2][2] = plane[2];
|
2009-03-11 13:23:05 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
INVERT_3X3(p->tbn, det, tangent);
|
2009-03-11 13:23:05 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2010-01-18 07:07:22 +00:00
|
|
|
i+= (p->indices) ? 3 : 1;
|
2008-04-06 23:35:48 +00:00
|
|
|
}
|
2016-06-05 04:46:28 +00:00
|
|
|
while ((p->indices && i < p->indicescount) ||
|
2010-01-18 07:07:22 +00:00
|
|
|
(!p->indices && i < p->vertcount));
|
2008-04-06 23:35:48 +00:00
|
|
|
}
|
|
|
|
|
2009-04-12 22:23:47 +00:00
|
|
|
static inline void polymer_crossproduct(GLfloat* in_a, GLfloat* in_b, GLfloat* out)
|
2008-04-06 23:35:48 +00:00
|
|
|
{
|
|
|
|
out[0] = in_a[1] * in_b[2] - in_a[2] * in_b[1];
|
|
|
|
out[1] = in_a[2] * in_b[0] - in_a[0] * in_b[2];
|
|
|
|
out[2] = in_a[0] * in_b[1] - in_a[1] * in_b[0];
|
|
|
|
}
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
static inline void polymer_transformpoint(const float* inpos, float* pos, float* matrix)
|
2009-03-08 22:59:54 +00:00
|
|
|
{
|
|
|
|
pos[0] = inpos[0] * matrix[0] +
|
|
|
|
inpos[1] * matrix[4] +
|
|
|
|
inpos[2] * matrix[8] +
|
|
|
|
+ matrix[12];
|
|
|
|
pos[1] = inpos[0] * matrix[1] +
|
|
|
|
inpos[1] * matrix[5] +
|
|
|
|
inpos[2] * matrix[9] +
|
|
|
|
+ matrix[13];
|
|
|
|
pos[2] = inpos[0] * matrix[2] +
|
|
|
|
inpos[1] * matrix[6] +
|
|
|
|
inpos[2] * matrix[10] +
|
|
|
|
+ matrix[14];
|
|
|
|
}
|
|
|
|
|
2010-01-21 05:52:19 +00:00
|
|
|
static inline void polymer_normalize(float* vec)
|
|
|
|
{
|
|
|
|
double norm;
|
|
|
|
|
|
|
|
norm = vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2];
|
|
|
|
|
|
|
|
norm = sqrt(norm);
|
|
|
|
norm = 1.0 / norm;
|
|
|
|
vec[0] *= norm;
|
|
|
|
vec[1] *= norm;
|
|
|
|
vec[2] *= norm;
|
|
|
|
}
|
|
|
|
|
2009-04-12 22:23:47 +00:00
|
|
|
static inline void polymer_pokesector(int16_t sectnum)
|
2008-04-02 09:29:58 +00:00
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
sectortype *sec = §or[sectnum];
|
|
|
|
_prsector *s = prsectors[sectnum];
|
|
|
|
walltype *wal = &wall[sec->wallptr];
|
|
|
|
int32_t i = 0;
|
2008-04-02 09:29:58 +00:00
|
|
|
|
2009-06-09 09:32:23 +00:00
|
|
|
if (!s->flags.uptodate)
|
2008-04-02 09:29:58 +00:00
|
|
|
polymer_updatesector(sectnum);
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
do
|
2008-04-02 09:29:58 +00:00
|
|
|
{
|
2009-12-03 06:21:39 +00:00
|
|
|
if ((wal->nextsector >= 0) && (!prsectors[wal->nextsector]->flags.uptodate))
|
2008-04-02 09:29:58 +00:00
|
|
|
polymer_updatesector(wal->nextsector);
|
2009-06-09 09:32:23 +00:00
|
|
|
if (!prwalls[sec->wallptr + i]->flags.uptodate)
|
2008-04-02 09:29:58 +00:00
|
|
|
polymer_updatewall(sec->wallptr + i);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
wal = &wall[sec->wallptr + i];
|
|
|
|
}
|
2009-06-09 06:19:58 +00:00
|
|
|
while (i < sec->wallnum);
|
2008-04-02 09:29:58 +00:00
|
|
|
}
|
|
|
|
|
2009-01-14 14:13:51 +00:00
|
|
|
static void polymer_extractfrustum(GLfloat* modelview, GLfloat* projection, float* frustum)
|
2006-10-15 18:51:41 +00:00
|
|
|
{
|
2009-01-14 14:13:51 +00:00
|
|
|
GLfloat matrix[16];
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i;
|
2006-10-15 18:51:41 +00:00
|
|
|
|
|
|
|
bglMatrixMode(GL_TEXTURE);
|
2009-01-14 14:13:51 +00:00
|
|
|
bglLoadMatrixf(projection);
|
|
|
|
bglMultMatrixf(modelview);
|
|
|
|
bglGetFloatv(GL_TEXTURE_MATRIX, matrix);
|
2006-10-15 18:51:41 +00:00
|
|
|
bglLoadIdentity();
|
2008-03-30 09:16:39 +00:00
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
2006-10-15 18:51:41 +00:00
|
|
|
|
|
|
|
i = 0;
|
2009-06-07 07:36:15 +00:00
|
|
|
do
|
2006-10-15 18:51:41 +00:00
|
|
|
{
|
2014-09-30 04:04:30 +00:00
|
|
|
uint32_t ii = i<<2, iii = (i<<2) + 3;
|
|
|
|
|
|
|
|
frustum[i] = matrix[iii] + matrix[ii]; // left
|
|
|
|
frustum[i + 4] = matrix[iii] - matrix[ii]; // right
|
|
|
|
frustum[i + 8] = matrix[iii] - matrix[ii + 1]; // top
|
|
|
|
frustum[i + 12] = matrix[iii] + matrix[ii + 1]; // bottom
|
|
|
|
frustum[i + 16] = matrix[iii] - matrix[ii + 2]; // far
|
2006-10-15 18:51:41 +00:00
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
while (++i < 4);
|
2007-07-01 06:32:03 +00:00
|
|
|
|
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Frustum extracted.\n");
|
2006-10-15 18:51:41 +00:00
|
|
|
}
|
|
|
|
|
2009-06-13 21:06:45 +00:00
|
|
|
static inline int32_t polymer_planeinfrustum(_prplane *plane, float* frustum)
|
2006-10-15 18:51:41 +00:00
|
|
|
{
|
2010-06-22 21:50:01 +00:00
|
|
|
int32_t i, j, k = -1;
|
2009-06-13 21:06:45 +00:00
|
|
|
i = 4;
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
|
2009-06-13 21:06:45 +00:00
|
|
|
do
|
2006-10-15 18:51:41 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
int32_t ii = i * 4;
|
2009-06-13 21:06:45 +00:00
|
|
|
j = k = plane->vertcount - 1;
|
2016-06-05 04:46:28 +00:00
|
|
|
|
2009-06-13 21:06:45 +00:00
|
|
|
do
|
2006-10-15 18:51:41 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
k -= ((frustum[ii + 0] * plane->buffer[j].x +
|
|
|
|
frustum[ii + 1] * plane->buffer[j].y +
|
|
|
|
frustum[ii + 2] * plane->buffer[j].z +
|
2014-09-30 04:04:30 +00:00
|
|
|
frustum[ii + 3]) < 0.f);
|
2006-10-15 18:51:41 +00:00
|
|
|
}
|
2009-06-13 21:06:45 +00:00
|
|
|
while (j--);
|
|
|
|
|
|
|
|
if (k == -1)
|
2014-09-30 04:04:30 +00:00
|
|
|
return 0; // OUT !
|
2007-07-01 06:32:03 +00:00
|
|
|
}
|
2009-06-13 21:06:45 +00:00
|
|
|
while (i--);
|
2007-07-01 06:32:03 +00:00
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
return 1;
|
2006-10-14 23:33:10 +00:00
|
|
|
}
|
2006-10-18 03:59:28 +00:00
|
|
|
|
2015-01-11 04:55:07 +00:00
|
|
|
static inline void polymer_scansprites(int16_t sectnum, tspritetype* localtsprite, int32_t* localspritesortcnt)
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i;
|
2008-04-06 03:00:39 +00:00
|
|
|
spritetype *spr;
|
|
|
|
|
|
|
|
for (i = headspritesect[sectnum];i >=0;i = nextspritesect[i])
|
|
|
|
{
|
|
|
|
spr = &sprite[i];
|
|
|
|
if ((((spr->cstat&0x8000) == 0) || (showinvisibility)) &&
|
2008-05-10 01:29:37 +00:00
|
|
|
(spr->xrepeat > 0) && (spr->yrepeat > 0) &&
|
|
|
|
(*localspritesortcnt < MAXSPRITESONSCREEN))
|
2008-04-06 03:00:39 +00:00
|
|
|
{
|
2012-02-18 22:14:45 +00:00
|
|
|
// this function's localtsprite is either the tsprite global or
|
|
|
|
// polymer_drawroom's locattsprite, so no aliasing
|
|
|
|
Bmemcpy(&localtsprite[*localspritesortcnt], spr, sizeof(spritetype));
|
2016-06-05 04:46:37 +00:00
|
|
|
localtsprite[*localspritesortcnt].extra = 0;
|
2008-04-06 23:35:48 +00:00
|
|
|
localtsprite[(*localspritesortcnt)++].owner = i;
|
2008-04-06 03:00:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-20 21:04:28 +00:00
|
|
|
void polymer_updatesprite(int32_t snum)
|
|
|
|
{
|
2015-12-23 04:05:47 +00:00
|
|
|
int32_t xsize, ysize, i, j;
|
2013-05-16 21:54:58 +00:00
|
|
|
int32_t tilexoff, tileyoff, xoff, yoff, centeryoff=0;
|
2015-01-11 04:55:07 +00:00
|
|
|
tspritetype *tspr = tspriteptr[snum];
|
2015-12-23 04:05:47 +00:00
|
|
|
float xratio, yratio, ang;
|
2011-08-20 21:04:28 +00:00
|
|
|
float spos[3];
|
2015-07-13 03:46:35 +00:00
|
|
|
const _prvert *inbuffer;
|
2011-08-20 21:04:28 +00:00
|
|
|
uint8_t flipu, flipv;
|
|
|
|
_prsprite *s;
|
|
|
|
|
2013-05-16 21:54:56 +00:00
|
|
|
const uint32_t cs = tspr->cstat;
|
|
|
|
const uint32_t alignmask = (cs & SPR_ALIGN_MASK);
|
2013-05-16 21:54:58 +00:00
|
|
|
const uint8_t flooraligned = (alignmask==SPR_FLOOR);
|
2013-05-16 21:54:56 +00:00
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_nullrender >= 3) return;
|
2015-06-14 23:42:31 +00:00
|
|
|
|
2011-08-20 21:04:28 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Updating sprite %i...\n", snum);
|
|
|
|
|
|
|
|
if (tspr->owner < 0 || tspr->picnum < 0) return;
|
|
|
|
|
2015-12-23 04:05:47 +00:00
|
|
|
s = prsprites[tspr->owner];
|
2011-08-20 21:04:28 +00:00
|
|
|
|
2015-12-23 04:05:47 +00:00
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
s = prsprites[tspr->owner] = (_prsprite *)Xcalloc(sizeof(_prsprite), 1);
|
2015-07-13 03:46:35 +00:00
|
|
|
|
2015-12-23 04:05:47 +00:00
|
|
|
s->plane.buffer = (_prvert *)Xcalloc(4, sizeof(_prvert)); // XXX
|
|
|
|
s->plane.vertcount = 4;
|
|
|
|
s->plane.mapvbo_vertoffset = -1;
|
2016-06-10 18:23:22 +00:00
|
|
|
s->hash = 0xDEADBEEF;
|
2011-08-20 21:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 04:05:47 +00:00
|
|
|
if ((tspr->cstat & 48) && (pr_vbos > 0) && !s->plane.vbo)
|
2011-08-20 21:04:28 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_nullrender < 2)
|
|
|
|
{
|
2015-12-23 04:05:47 +00:00
|
|
|
bglGenBuffersARB(1, &s->plane.vbo);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, s->plane.vbo);
|
2015-07-13 03:46:35 +00:00
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, 4 * sizeof(_prvert), NULL, mapvbousage);
|
|
|
|
}
|
2011-08-20 21:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 04:05:47 +00:00
|
|
|
int32_t curpicnum = tspr->picnum;
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(curpicnum, tspr->owner+32768);
|
2011-08-20 21:04:28 +00:00
|
|
|
|
|
|
|
if (tspr->cstat & 48 && searchit != 2)
|
|
|
|
{
|
2015-12-23 04:05:47 +00:00
|
|
|
uint32_t const changed = XXH32((uint8_t *) tspr, offsetof(spritetype, owner), 0xDEADBEEF);
|
2011-08-20 21:04:28 +00:00
|
|
|
|
2016-06-10 18:23:22 +00:00
|
|
|
if (changed == s->hash)
|
2014-09-30 04:04:30 +00:00
|
|
|
return;
|
|
|
|
|
2016-06-10 18:23:22 +00:00
|
|
|
s->hash = changed;
|
2011-08-20 21:04:28 +00:00
|
|
|
}
|
|
|
|
|
2013-05-07 07:48:08 +00:00
|
|
|
polymer_getbuildmaterial(&s->plane.material, curpicnum, tspr->pal, tspr->shade,
|
2015-12-04 11:52:58 +00:00
|
|
|
sector[tspr->sectnum].visibility, DAMETH_MASK | DAMETH_CLAMPED);
|
2011-08-20 21:04:28 +00:00
|
|
|
|
|
|
|
if (tspr->cstat & 2)
|
|
|
|
{
|
|
|
|
if (tspr->cstat & 512)
|
|
|
|
s->plane.material.diffusemodulation[3] = 0x55;
|
|
|
|
else
|
|
|
|
s->plane.material.diffusemodulation[3] = 0xAA;
|
|
|
|
}
|
|
|
|
|
2015-12-23 04:05:47 +00:00
|
|
|
float f = s->plane.material.diffusemodulation[3] * (1.0f - spriteext[tspr->owner].alpha);
|
2012-11-15 14:28:44 +00:00
|
|
|
s->plane.material.diffusemodulation[3] = (GLubyte)f;
|
2011-08-20 21:04:28 +00:00
|
|
|
|
|
|
|
if (searchit == 2)
|
|
|
|
{
|
2014-09-30 04:04:30 +00:00
|
|
|
polymer_drawsearchplane(&s->plane, NULL, 0x03, (GLubyte *) &tspr->owner);
|
2016-06-10 18:23:22 +00:00
|
|
|
s->hash = 0xDEADBEEF;
|
2011-08-20 21:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
curpicnum = tspr->picnum;
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(curpicnum, tspr->owner+32768);
|
2011-08-20 21:04:28 +00:00
|
|
|
|
|
|
|
if (((tspr->cstat>>4) & 3) == 0)
|
|
|
|
xratio = (float)(tspr->xrepeat) * 0.20f; // 32 / 160
|
|
|
|
else
|
|
|
|
xratio = (float)(tspr->xrepeat) * 0.25f;
|
|
|
|
|
|
|
|
yratio = (float)(tspr->yrepeat) * 0.25f;
|
|
|
|
|
2014-09-30 04:14:21 +00:00
|
|
|
xsize = tilesiz[curpicnum].x;
|
|
|
|
ysize = tilesiz[curpicnum].y;
|
2011-08-20 21:04:28 +00:00
|
|
|
|
|
|
|
if (usehightile && h_xsize[curpicnum])
|
|
|
|
{
|
|
|
|
xsize = h_xsize[curpicnum];
|
|
|
|
ysize = h_ysize[curpicnum];
|
|
|
|
}
|
|
|
|
|
|
|
|
xsize = (int32_t)(xsize * xratio);
|
|
|
|
ysize = (int32_t)(ysize * yratio);
|
|
|
|
|
|
|
|
tilexoff = (int32_t)tspr->xoffset;
|
|
|
|
tileyoff = (int32_t)tspr->yoffset;
|
2012-11-17 19:46:28 +00:00
|
|
|
tilexoff += (usehightile && h_xsize[curpicnum]) ? h_xoffs[curpicnum] : picanm[curpicnum].xofs;
|
|
|
|
tileyoff += (usehightile && h_xsize[curpicnum]) ? h_yoffs[curpicnum] : picanm[curpicnum].yofs;
|
2011-08-20 21:04:28 +00:00
|
|
|
|
|
|
|
xoff = (int32_t)(tilexoff * xratio);
|
|
|
|
yoff = (int32_t)(tileyoff * yratio);
|
|
|
|
|
2013-05-16 21:54:58 +00:00
|
|
|
if ((tspr->cstat & 128) && !flooraligned)
|
|
|
|
{
|
|
|
|
if (alignmask == 0)
|
|
|
|
yoff -= ysize / 2;
|
|
|
|
else
|
|
|
|
centeryoff = ysize / 2;
|
|
|
|
}
|
2011-08-20 21:04:28 +00:00
|
|
|
|
|
|
|
spos[0] = (float)tspr->y;
|
|
|
|
spos[1] = -(float)(tspr->z) / 16.0f;
|
|
|
|
spos[2] = -(float)tspr->x;
|
|
|
|
|
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglPushMatrix();
|
|
|
|
bglLoadIdentity();
|
|
|
|
|
|
|
|
inbuffer = vertsprite;
|
|
|
|
|
2013-05-16 21:54:52 +00:00
|
|
|
{
|
2013-05-16 21:54:56 +00:00
|
|
|
const uint8_t xflip = !!(cs & SPR_XFLIP);
|
|
|
|
const uint8_t yflip = !!(cs & SPR_YFLIP);
|
2013-03-31 23:26:40 +00:00
|
|
|
|
2013-05-16 21:54:56 +00:00
|
|
|
// Initially set flipu and flipv.
|
2013-05-16 21:54:52 +00:00
|
|
|
flipu = (xflip ^ flooraligned);
|
|
|
|
flipv = (yflip && !flooraligned);
|
2013-03-31 23:26:40 +00:00
|
|
|
|
2013-05-16 21:54:56 +00:00
|
|
|
if (pr_billboardingmode && alignmask==0)
|
|
|
|
{
|
|
|
|
// do surgery on the face tspr to make it look like a wall sprite
|
|
|
|
tspr->cstat |= 16;
|
|
|
|
tspr->ang = (viewangle + 1024) & 2047;
|
|
|
|
}
|
2011-08-20 21:04:28 +00:00
|
|
|
|
2013-05-16 21:54:56 +00:00
|
|
|
if (flipu)
|
|
|
|
xoff = -xoff;
|
2013-03-31 23:26:40 +00:00
|
|
|
|
2013-05-16 21:54:56 +00:00
|
|
|
if (yflip && alignmask!=0)
|
|
|
|
yoff = -yoff;
|
2013-03-31 23:26:40 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 21:54:52 +00:00
|
|
|
switch (tspr->cstat & SPR_ALIGN_MASK)
|
2011-08-20 21:04:28 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
ang = (float)((viewangle) & 2047) / (2048.0f / 360.0f);
|
|
|
|
|
|
|
|
bglTranslatef(spos[0], spos[1], spos[2]);
|
|
|
|
bglRotatef(-ang, 0.0f, 1.0f, 0.0f);
|
|
|
|
bglRotatef(-horizang, 1.0f, 0.0f, 0.0f);
|
|
|
|
bglTranslatef((float)(-xoff), (float)(yoff), 0.0f);
|
|
|
|
bglScalef((float)(xsize), (float)(ysize), 1.0f);
|
|
|
|
break;
|
2013-05-16 21:54:52 +00:00
|
|
|
case SPR_WALL:
|
2011-08-20 21:04:28 +00:00
|
|
|
ang = (float)((tspr->ang + 1024) & 2047) / (2048.0f / 360.0f);
|
|
|
|
|
|
|
|
bglTranslatef(spos[0], spos[1], spos[2]);
|
|
|
|
bglRotatef(-ang, 0.0f, 1.0f, 0.0f);
|
2013-05-16 21:54:58 +00:00
|
|
|
bglTranslatef((float)(-xoff), (float)(yoff-centeryoff), 0.0f);
|
2011-08-20 21:04:28 +00:00
|
|
|
bglScalef((float)(xsize), (float)(ysize), 1.0f);
|
|
|
|
break;
|
2013-05-16 21:54:52 +00:00
|
|
|
case SPR_FLOOR:
|
2011-08-20 21:04:28 +00:00
|
|
|
ang = (float)((tspr->ang + 1024) & 2047) / (2048.0f / 360.0f);
|
|
|
|
|
|
|
|
bglTranslatef(spos[0], spos[1], spos[2]);
|
|
|
|
bglRotatef(-ang, 0.0f, 1.0f, 0.0f);
|
|
|
|
bglTranslatef((float)(-xoff), 1.0f, (float)(yoff));
|
|
|
|
bglScalef((float)(xsize), 1.0f, (float)(ysize));
|
|
|
|
|
|
|
|
inbuffer = horizsprite;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bglGetFloatv(GL_MODELVIEW_MATRIX, spritemodelview);
|
|
|
|
bglPopMatrix();
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
Bmemcpy(s->plane.buffer, inbuffer, sizeof(_prvert) * 4);
|
2011-08-20 21:04:28 +00:00
|
|
|
|
|
|
|
if (flipu || flipv)
|
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (flipu)
|
2015-07-13 03:46:35 +00:00
|
|
|
s->plane.buffer[i].u =
|
|
|
|
(s->plane.buffer[i].u - 1.0f) * -1.0f;
|
2011-08-20 21:04:28 +00:00
|
|
|
if (flipv)
|
2015-07-13 03:46:35 +00:00
|
|
|
s->plane.buffer[i].v =
|
|
|
|
(s->plane.buffer[i].v - 1.0f) * -1.0f;
|
2011-08-20 21:04:28 +00:00
|
|
|
}
|
|
|
|
while (++i < 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do
|
2015-07-13 03:46:35 +00:00
|
|
|
polymer_transformpoint(&inbuffer[i].x, &s->plane.buffer[i].x, spritemodelview);
|
2011-08-20 21:04:28 +00:00
|
|
|
while (++i < 4);
|
|
|
|
|
|
|
|
polymer_computeplane(&s->plane);
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (pr_nullrender < 2)
|
|
|
|
{
|
|
|
|
if (alignmask && (pr_vbos > 0))
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, s->plane.vbo);
|
|
|
|
bglBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, 4 * sizeof(_prvert), s->plane.buffer);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
|
|
|
else if (s->plane.vbo) // clean up the vbo if a wall/floor sprite becomes a face sprite
|
|
|
|
{
|
|
|
|
bglDeleteBuffersARB(1, &s->plane.vbo);
|
|
|
|
s->plane.vbo = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-03-26 00:55:53 +00:00
|
|
|
|
2013-05-16 21:54:56 +00:00
|
|
|
if (alignmask)
|
2012-03-26 00:55:53 +00:00
|
|
|
{
|
|
|
|
int32_t curpriority = 0;
|
|
|
|
|
|
|
|
polymer_resetplanelights(&s->plane);
|
|
|
|
|
|
|
|
while (curpriority < pr_maxlightpriority)
|
|
|
|
{
|
|
|
|
i = j = 0;
|
|
|
|
while (j < lightcount)
|
|
|
|
{
|
|
|
|
while (!prlights[i].flags.active)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (prlights[i].priority != curpriority)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (polymer_planeinlight(&s->plane, &prlights[i]))
|
|
|
|
polymer_addplanelight(&s->plane, i);
|
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
curpriority++;
|
|
|
|
}
|
|
|
|
}
|
2011-08-20 21:04:28 +00:00
|
|
|
}
|
|
|
|
|
2006-10-18 03:59:28 +00:00
|
|
|
// SKIES
|
2008-04-02 09:29:58 +00:00
|
|
|
static void polymer_getsky(void)
|
2006-10-19 23:51:44 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i;
|
2006-10-19 23:51:44 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < numsectors)
|
|
|
|
{
|
|
|
|
if (sector[i].ceilingstat & 1)
|
|
|
|
{
|
2013-08-04 20:37:49 +00:00
|
|
|
int32_t horizfrac;
|
|
|
|
|
2006-10-19 23:51:44 +00:00
|
|
|
cursky = sector[i].ceilingpicnum;
|
2009-06-07 18:38:13 +00:00
|
|
|
curskypal = sector[i].ceilingpal;
|
|
|
|
curskyshade = sector[i].ceilingshade;
|
2013-08-04 20:37:49 +00:00
|
|
|
|
|
|
|
getpsky(cursky, &horizfrac, NULL);
|
|
|
|
|
|
|
|
switch (horizfrac)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
// psky always at same level wrt screen
|
|
|
|
curskyangmul = 0.f;
|
|
|
|
break;
|
|
|
|
case 65536:
|
|
|
|
// psky horiz follows camera horiz
|
|
|
|
curskyangmul = 1.f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// sky has hard-coded parallax
|
|
|
|
curskyangmul = 1/DEFAULT_ARTSKY_ANGDIV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-10-19 23:51:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2006-10-18 03:59:28 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
void polymer_drawsky(int16_t tilenum, char palnum, int8_t shade)
|
2006-10-18 03:59:28 +00:00
|
|
|
{
|
2009-05-09 10:42:57 +00:00
|
|
|
float pos[3];
|
2008-06-09 09:25:47 +00:00
|
|
|
pthtyp* pth;
|
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
pos[0] = (float)globalposy;
|
2009-05-09 10:42:57 +00:00
|
|
|
pos[1] = -(float)(globalposz) / 16.0f;
|
2009-07-12 01:55:34 +00:00
|
|
|
pos[2] = -(float)globalposx;
|
2009-05-09 10:42:57 +00:00
|
|
|
|
|
|
|
bglPushMatrix();
|
|
|
|
bglLoadIdentity();
|
2014-09-30 04:04:30 +00:00
|
|
|
|
2009-05-09 10:42:57 +00:00
|
|
|
bglLoadMatrixf(curskymodelviewmatrix);
|
|
|
|
|
|
|
|
bglTranslatef(pos[0], pos[1], pos[2]);
|
|
|
|
bglScalef(1000.0f, 1000.0f, 1000.0f);
|
|
|
|
|
2008-06-09 09:25:47 +00:00
|
|
|
drawingskybox = 1;
|
2015-12-04 11:52:54 +00:00
|
|
|
pth = texcache_fetch(tilenum, 0, 0, DAMETH_NOMASK);
|
2008-06-09 09:25:47 +00:00
|
|
|
drawingskybox = 0;
|
|
|
|
|
2014-05-28 22:40:16 +00:00
|
|
|
if (pth && (pth->flags & PTH_SKYBOX))
|
2009-06-07 18:38:13 +00:00
|
|
|
polymer_drawskybox(tilenum, palnum, shade);
|
2008-06-09 09:25:47 +00:00
|
|
|
else
|
2009-06-07 18:38:13 +00:00
|
|
|
polymer_drawartsky(tilenum, palnum, shade);
|
2009-05-09 10:42:57 +00:00
|
|
|
|
|
|
|
bglPopMatrix();
|
2008-06-09 09:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void polymer_initartsky(void)
|
|
|
|
{
|
|
|
|
GLfloat halfsqrt2 = 0.70710678f;
|
|
|
|
|
|
|
|
artskydata[0] = -1.0f; artskydata[1] = 0.0f; // 0
|
|
|
|
artskydata[2] = -halfsqrt2; artskydata[3] = halfsqrt2; // 1
|
|
|
|
artskydata[4] = 0.0f; artskydata[5] = 1.0f; // 2
|
|
|
|
artskydata[6] = halfsqrt2; artskydata[7] = halfsqrt2; // 3
|
|
|
|
artskydata[8] = 1.0f; artskydata[9] = 0.0f; // 4
|
|
|
|
artskydata[10] = halfsqrt2; artskydata[11] = -halfsqrt2; // 5
|
|
|
|
artskydata[12] = 0.0f; artskydata[13] = -1.0f; // 6
|
|
|
|
artskydata[14] = -halfsqrt2; artskydata[15] = -halfsqrt2; // 7
|
2006-10-18 03:59:28 +00:00
|
|
|
}
|
|
|
|
|
2009-06-07 18:38:13 +00:00
|
|
|
static void polymer_drawartsky(int16_t tilenum, char palnum, int8_t shade)
|
2006-10-18 03:59:28 +00:00
|
|
|
{
|
|
|
|
pthtyp* pth;
|
2013-08-04 20:37:45 +00:00
|
|
|
GLuint glpics[PSKYOFF_MAX+1];
|
|
|
|
GLfloat glcolors[PSKYOFF_MAX+1][3];
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i, j;
|
2006-10-18 03:59:28 +00:00
|
|
|
GLfloat height = 2.45f / 2.0f;
|
|
|
|
|
2013-08-04 20:37:49 +00:00
|
|
|
int32_t dapskybits;
|
|
|
|
const int8_t *dapskyoff = getpsky(tilenum, NULL, &dapskybits);
|
|
|
|
const int32_t numskytilesm1 = (1<<dapskybits)-1;
|
|
|
|
|
2006-10-18 03:59:28 +00:00
|
|
|
i = 0;
|
2013-08-04 20:37:45 +00:00
|
|
|
while (i <= PSKYOFF_MAX)
|
2006-10-18 03:59:28 +00:00
|
|
|
{
|
2013-08-04 20:37:45 +00:00
|
|
|
int16_t picnum = tilenum + i;
|
2013-08-04 20:37:49 +00:00
|
|
|
// Prevent oob by bad user input:
|
|
|
|
if (picnum >= MAXTILES)
|
|
|
|
picnum = MAXTILES-1;
|
|
|
|
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(picnum, 0);
|
2009-06-07 18:38:13 +00:00
|
|
|
if (!waloff[picnum])
|
|
|
|
loadtile(picnum);
|
2015-12-04 11:52:54 +00:00
|
|
|
pth = texcache_fetch(picnum, palnum, 0, DAMETH_NOMASK);
|
2006-10-18 03:59:28 +00:00
|
|
|
glpics[i] = pth ? pth->glpic : 0;
|
2009-06-07 18:38:13 +00:00
|
|
|
|
2012-12-14 19:28:01 +00:00
|
|
|
glcolors[i][0] = glcolors[i][1] = glcolors[i][2] = getshadefactor(shade);
|
2009-06-07 18:38:13 +00:00
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
if (pth)
|
2009-06-07 18:38:13 +00:00
|
|
|
{
|
2015-04-14 21:18:08 +00:00
|
|
|
// tinting
|
|
|
|
if (!(hictinting[palnum].f & HICTINT_PRECOMPUTED))
|
|
|
|
{
|
|
|
|
if (pth->flags & PTH_HIGHTILE)
|
|
|
|
{
|
|
|
|
if (pth->palnum != palnum || (pth->effects & HICTINT_IN_MEMORY) || (hictinting[palnum].f & HICTINT_APPLYOVERALTPAL))
|
|
|
|
hictinting_apply(glcolors[i], palnum);
|
|
|
|
}
|
|
|
|
else if (hictinting[palnum].f & HICTINT_USEONART)
|
|
|
|
hictinting_apply(glcolors[i], palnum);
|
|
|
|
}
|
2009-06-07 18:38:13 +00:00
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
// global tinting
|
|
|
|
if ((pth->flags & PTH_HIGHTILE) && have_basepal_tint())
|
2014-05-28 22:40:17 +00:00
|
|
|
hictinting_apply(glcolors[i], MAXPALOOKUPS-1);
|
2009-06-07 18:38:13 +00:00
|
|
|
}
|
|
|
|
|
2006-10-18 03:59:28 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2006-10-19 23:51:44 +00:00
|
|
|
i = 0;
|
2013-08-04 20:37:49 +00:00
|
|
|
j = 8; // In Polymer, an ART sky has always 8 sides...
|
2009-04-19 09:49:27 +00:00
|
|
|
while (i < j)
|
2006-10-19 23:51:44 +00:00
|
|
|
{
|
2012-04-10 20:14:52 +00:00
|
|
|
GLint oldswrap;
|
2013-08-04 20:37:49 +00:00
|
|
|
// ... but in case a multi-psky specifies less than 8, repeat cyclically:
|
|
|
|
const int8_t tileofs = dapskyoff[i&numskytilesm1];
|
2012-04-10 20:14:52 +00:00
|
|
|
|
2013-08-04 20:37:45 +00:00
|
|
|
bglColor4f(glcolors[tileofs][0], glcolors[tileofs][1], glcolors[tileofs][2], 1.0f);
|
|
|
|
bglBindTexture(GL_TEXTURE_2D, glpics[tileofs]);
|
2012-04-10 20:14:52 +00:00
|
|
|
|
|
|
|
bglGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &oldswrap);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
|
|
|
|
2008-06-09 09:25:47 +00:00
|
|
|
polymer_drawartskyquad(i, (i + 1) & (j - 1), height);
|
2012-04-10 20:14:52 +00:00
|
|
|
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, oldswrap);
|
|
|
|
|
2008-06-09 09:25:47 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void polymer_drawartskyquad(int32_t p1, int32_t p2, GLfloat height)
|
2008-06-09 09:25:47 +00:00
|
|
|
{
|
|
|
|
bglBegin(GL_QUADS);
|
|
|
|
bglTexCoord2f(0.0f, 0.0f);
|
|
|
|
//OSD_Printf("PR: drawing %f %f %f\n", skybox[(p1 * 2) + 1], height, skybox[p1 * 2]);
|
|
|
|
bglVertex3f(artskydata[(p1 * 2) + 1], height, artskydata[p1 * 2]);
|
|
|
|
bglTexCoord2f(0.0f, 1.0f);
|
|
|
|
//OSD_Printf("PR: drawing %f %f %f\n", skybox[(p1 * 2) + 1], -height, skybox[p1 * 2]);
|
|
|
|
bglVertex3f(artskydata[(p1 * 2) + 1], -height, artskydata[p1 * 2]);
|
|
|
|
bglTexCoord2f(1.0f, 1.0f);
|
|
|
|
//OSD_Printf("PR: drawing %f %f %f\n", skybox[(p2 * 2) + 1], -height, skybox[p2 * 2]);
|
|
|
|
bglVertex3f(artskydata[(p2 * 2) + 1], -height, artskydata[p2 * 2]);
|
|
|
|
bglTexCoord2f(1.0f, 0.0f);
|
|
|
|
//OSD_Printf("PR: drawing %f %f %f\n", skybox[(p2 * 2) + 1], height, skybox[p2 * 2]);
|
|
|
|
bglVertex3f(artskydata[(p2 * 2) + 1], height, artskydata[p2 * 2]);
|
|
|
|
bglEnd();
|
|
|
|
}
|
|
|
|
|
2009-06-07 18:38:13 +00:00
|
|
|
static void polymer_drawskybox(int16_t tilenum, char palnum, int8_t shade)
|
2008-06-09 09:25:47 +00:00
|
|
|
{
|
|
|
|
pthtyp* pth;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i;
|
2009-06-07 18:38:13 +00:00
|
|
|
GLfloat color[3];
|
2008-06-09 09:25:47 +00:00
|
|
|
|
2008-06-09 09:43:12 +00:00
|
|
|
if ((pr_vbos > 0) && (skyboxdatavbo == 0))
|
|
|
|
{
|
|
|
|
bglGenBuffersARB(1, &skyboxdatavbo);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, skyboxdatavbo);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, 4 * sizeof(GLfloat) * 5 * 6, skyboxdata, modelvbousage);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pr_vbos > 0)
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, skyboxdatavbo);
|
|
|
|
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(tilenum, 0);
|
2009-06-07 18:38:13 +00:00
|
|
|
|
2008-06-09 09:25:47 +00:00
|
|
|
i = 0;
|
2009-04-19 09:49:27 +00:00
|
|
|
while (i < 6)
|
2008-06-09 09:25:47 +00:00
|
|
|
{
|
|
|
|
drawingskybox = i + 1;
|
2014-05-30 00:02:14 +00:00
|
|
|
pth = texcache_fetch(tilenum, palnum, 0, DAMETH_CLAMPED);
|
2009-06-07 18:38:13 +00:00
|
|
|
|
2012-12-14 19:28:01 +00:00
|
|
|
color[0] = color[1] = color[2] = getshadefactor(shade);
|
2009-06-07 18:38:13 +00:00
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
if (pth)
|
2009-06-07 18:38:13 +00:00
|
|
|
{
|
2015-04-14 21:18:08 +00:00
|
|
|
// tinting
|
|
|
|
if (!(hictinting[palnum].f & HICTINT_PRECOMPUTED))
|
|
|
|
{
|
|
|
|
if (pth->flags & PTH_HIGHTILE)
|
|
|
|
{
|
|
|
|
if (pth->palnum != palnum || (pth->effects & HICTINT_IN_MEMORY) || (hictinting[palnum].f & HICTINT_APPLYOVERALTPAL))
|
|
|
|
hictinting_apply(color, palnum);
|
|
|
|
}
|
|
|
|
else if (hictinting[palnum].f & HICTINT_USEONART)
|
|
|
|
hictinting_apply(color, palnum);
|
|
|
|
}
|
2009-06-07 18:38:13 +00:00
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
// global tinting
|
|
|
|
if ((pth->flags & PTH_HIGHTILE) && have_basepal_tint())
|
2014-05-28 22:40:17 +00:00
|
|
|
hictinting_apply(color, MAXPALOOKUPS-1);
|
2009-06-07 18:38:13 +00:00
|
|
|
}
|
2008-06-09 09:25:47 +00:00
|
|
|
|
2009-06-07 18:38:13 +00:00
|
|
|
bglColor4f(color[0], color[1], color[2], 1.0);
|
2008-06-09 09:25:47 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, pth ? pth->glpic : 0);
|
2008-06-09 09:43:12 +00:00
|
|
|
if (pr_vbos > 0)
|
|
|
|
{
|
|
|
|
bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), (GLfloat*)(4 * 5 * i * sizeof(GLfloat)));
|
|
|
|
bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), (GLfloat*)(((4 * 5 * i) + 3) * sizeof(GLfloat)));
|
|
|
|
} else {
|
|
|
|
bglVertexPointer(3, GL_FLOAT, 5 * sizeof(GLfloat), &skyboxdata[4 * 5 * i]);
|
|
|
|
bglTexCoordPointer(2, GL_FLOAT, 5 * sizeof(GLfloat), &skyboxdata[3 + (4 * 5 * i)]);
|
|
|
|
}
|
2008-06-09 09:25:47 +00:00
|
|
|
bglDrawArrays(GL_QUADS, 0, 4);
|
|
|
|
|
2006-10-19 23:51:44 +00:00
|
|
|
i++;
|
|
|
|
}
|
2008-06-09 09:25:47 +00:00
|
|
|
drawingskybox = 0;
|
2008-06-09 09:43:12 +00:00
|
|
|
|
|
|
|
if (pr_vbos > 0)
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
|
2008-06-09 09:25:47 +00:00
|
|
|
return;
|
2006-10-18 03:59:28 +00:00
|
|
|
}
|
2008-06-01 08:58:06 +00:00
|
|
|
|
|
|
|
// MDSPRITES
|
2015-01-11 04:55:07 +00:00
|
|
|
static void polymer_drawmdsprite(tspritetype *tspr)
|
2008-06-01 08:58:06 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
md3model_t* m;
|
2008-11-27 22:26:46 +00:00
|
|
|
mdskinmap_t* sk;
|
2009-03-10 12:08:33 +00:00
|
|
|
float *v0, *v1;
|
2008-11-27 22:26:46 +00:00
|
|
|
md3surf_t *s;
|
2012-01-22 17:18:49 +00:00
|
|
|
char targetpal, usinghighpal, foundpalskin;
|
2010-08-21 07:39:12 +00:00
|
|
|
float spos2[3], spos[3], tspos[3], lpos[3], tlpos[3], vec[3], mat[4][4];
|
2008-06-01 08:58:06 +00:00
|
|
|
float ang;
|
|
|
|
float scale;
|
2010-01-24 05:57:43 +00:00
|
|
|
double det;
|
2009-06-01 20:55:36 +00:00
|
|
|
int32_t surfi, i, j;
|
2009-12-07 07:01:44 +00:00
|
|
|
GLubyte* color;
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t materialbits;
|
2009-03-10 17:49:34 +00:00
|
|
|
float sradius, lradius;
|
2009-06-01 20:55:36 +00:00
|
|
|
int16_t modellights[PR_MAXLIGHTS];
|
2009-03-10 17:49:34 +00:00
|
|
|
char modellightcount;
|
2009-06-06 13:40:15 +00:00
|
|
|
uint8_t curpriority;
|
2008-06-01 08:58:06 +00:00
|
|
|
|
2012-01-22 17:18:49 +00:00
|
|
|
uint8_t lpal = (tspr->owner >= MAXSPRITES) ? tspr->pal : sprite[tspr->owner].pal;
|
2008-06-01 08:58:06 +00:00
|
|
|
|
2012-01-22 17:18:49 +00:00
|
|
|
m = (md3model_t*)models[tile2model[Ptile2tile(tspr->picnum,lpal)].modelid];
|
|
|
|
updateanimation((md2model_t *)m,tspr,lpal);
|
2008-11-27 22:26:46 +00:00
|
|
|
|
2008-06-01 08:58:06 +00:00
|
|
|
if ((pr_vbos > 1) && (m->indices == NULL))
|
|
|
|
polymer_loadmodelvbos(m);
|
|
|
|
|
2010-08-21 07:39:12 +00:00
|
|
|
// Hackish, but that means it's a model drawn by rotatesprite.
|
|
|
|
if (tspriteptr[MAXSPRITESONSCREEN] == tspr) {
|
|
|
|
float x, y, z;
|
|
|
|
|
|
|
|
spos[0] = (float)globalposy;
|
|
|
|
spos[1] = -(float)(globalposz) / 16.0f;
|
|
|
|
spos[2] = -(float)globalposx;
|
|
|
|
|
|
|
|
// The coordinates are actually floats disguised as int in this case
|
|
|
|
memcpy(&x, &tspr->x, sizeof(float));
|
|
|
|
memcpy(&y, &tspr->y, sizeof(float));
|
|
|
|
memcpy(&z, &tspr->z, sizeof(float));
|
|
|
|
|
|
|
|
spos2[0] = (float)y - globalposy;
|
|
|
|
spos2[1] = -(float)(z - globalposz) / 16.0f;
|
|
|
|
spos2[2] = -(float)(x - globalposx);
|
|
|
|
} else {
|
|
|
|
spos[0] = (float)tspr->y;
|
|
|
|
spos[1] = -(float)(tspr->z) / 16.0f;
|
|
|
|
spos[2] = -(float)tspr->x;
|
2011-10-02 00:31:46 +00:00
|
|
|
|
2011-01-16 03:53:27 +00:00
|
|
|
spos2[0] = spos2[1] = spos2[2] = 0.0f;
|
2010-08-21 07:39:12 +00:00
|
|
|
}
|
|
|
|
|
2008-06-06 11:35:24 +00:00
|
|
|
ang = (float)((tspr->ang+spriteext[tspr->owner].angoff) & 2047) / (2048.0f / 360.0f);
|
|
|
|
ang -= 90.0f;
|
|
|
|
if (((tspr->cstat>>4) & 3) == 2)
|
|
|
|
ang -= 90.0f;
|
2008-06-01 08:58:06 +00:00
|
|
|
|
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglPushMatrix();
|
2009-03-27 12:56:42 +00:00
|
|
|
bglLoadIdentity();
|
2008-06-06 11:35:24 +00:00
|
|
|
scale = (1.0/4.0);
|
2008-06-01 08:58:06 +00:00
|
|
|
scale *= m->scale;
|
2011-03-04 05:33:35 +00:00
|
|
|
if (pr_overridemodelscale) {
|
|
|
|
scale *= pr_overridemodelscale;
|
|
|
|
} else {
|
|
|
|
scale *= m->bscale;
|
|
|
|
}
|
2008-06-01 08:58:06 +00:00
|
|
|
|
2010-08-21 07:39:12 +00:00
|
|
|
if (tspriteptr[MAXSPRITESONSCREEN] == tspr) {
|
2010-08-26 15:27:16 +00:00
|
|
|
float playerang, radplayerang, cosminusradplayerang, sinminusradplayerang, hudzoom;
|
2010-08-21 07:39:12 +00:00
|
|
|
|
2010-08-26 15:27:16 +00:00
|
|
|
playerang = (globalang & 2047) / (2048.0f / 360.0f) - 90.0f;
|
2010-08-21 07:39:12 +00:00
|
|
|
radplayerang = (globalang & 2047) * 2.0f * PI / 2048.0f;
|
|
|
|
cosminusradplayerang = cos(-radplayerang);
|
|
|
|
sinminusradplayerang = sin(-radplayerang);
|
2014-10-25 03:36:34 +00:00
|
|
|
hudzoom = 65536.0 / spriteext[tspr->owner].offset.z;
|
2010-08-21 07:39:12 +00:00
|
|
|
|
|
|
|
bglTranslatef(spos[0], spos[1], spos[2]);
|
|
|
|
bglRotatef(horizang, -cosminusradplayerang, 0.0f, sinminusradplayerang);
|
|
|
|
bglRotatef(spriteext[tspr->owner].roll / (2048.0f / 360.0f), sinminusradplayerang, 0.0f, cosminusradplayerang);
|
2010-08-26 15:27:16 +00:00
|
|
|
bglRotatef(-playerang, 0.0f, 1.0f, 0.0f);
|
|
|
|
bglScalef(hudzoom, 1.0f, 1.0f);
|
|
|
|
bglRotatef(playerang, 0.0f, 1.0f, 0.0f);
|
2010-08-21 07:39:12 +00:00
|
|
|
bglTranslatef(spos2[0], spos2[1], spos2[2]);
|
|
|
|
bglRotatef(-ang, 0.0f, 1.0f, 0.0f);
|
|
|
|
} else {
|
|
|
|
bglTranslatef(spos[0], spos[1], spos[2]);
|
|
|
|
bglRotatef(-ang, 0.0f, 1.0f, 0.0f);
|
|
|
|
}
|
2008-06-06 11:35:24 +00:00
|
|
|
if (((tspr->cstat>>4) & 3) == 2)
|
|
|
|
{
|
2014-09-30 04:14:21 +00:00
|
|
|
bglTranslatef(0.0f, 0.0, -(float)(tilesiz[tspr->picnum].y * tspr->yrepeat) / 8.0f);
|
2008-06-06 11:35:24 +00:00
|
|
|
bglRotatef(90.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
bglRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
if ((tspr->cstat & 128) && (((tspr->cstat>>4) & 3) != 2))
|
2014-09-30 04:14:21 +00:00
|
|
|
bglTranslatef(0.0f, 0.0, -(float)(tilesiz[tspr->picnum].y * tspr->yrepeat) / 8.0f);
|
2008-06-06 11:35:24 +00:00
|
|
|
|
2012-01-17 04:31:59 +00:00
|
|
|
// yoffset differs from zadd in that it does not follow cstat&8 y-flipping
|
|
|
|
bglTranslatef(0.0f, 0.0, m->yoffset * 64 * scale * tspr->yrepeat);
|
|
|
|
|
2008-06-06 11:35:24 +00:00
|
|
|
if (tspr->cstat & 8)
|
|
|
|
{
|
2014-09-30 04:14:21 +00:00
|
|
|
bglTranslatef(0.0f, 0.0, (float)(tilesiz[tspr->picnum].y * tspr->yrepeat) / 4.0f);
|
2008-06-06 11:35:24 +00:00
|
|
|
bglScalef(1.0f, 1.0f, -1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tspr->cstat & 4)
|
|
|
|
bglScalef(1.0f, -1.0f, 1.0f);
|
|
|
|
|
2011-10-02 00:32:00 +00:00
|
|
|
if (!(tspr->cstat & 4) != !(tspr->cstat & 8)) {
|
|
|
|
// Only inverting one coordinate will reverse the winding order of
|
|
|
|
// faces, so we need to account for that when culling.
|
|
|
|
SWITCH_CULL_DIRECTION;
|
|
|
|
}
|
|
|
|
|
2008-06-06 11:35:24 +00:00
|
|
|
bglScalef(scale * tspr->xrepeat, scale * tspr->xrepeat, scale * tspr->yrepeat);
|
|
|
|
bglTranslatef(0.0f, 0.0, m->zadd * 64);
|
|
|
|
|
2009-05-10 17:51:00 +00:00
|
|
|
// scripted model rotation
|
2010-08-21 07:39:12 +00:00
|
|
|
if (tspr->owner < MAXSPRITES &&
|
|
|
|
(spriteext[tspr->owner].pitch || spriteext[tspr->owner].roll))
|
2009-05-10 17:51:00 +00:00
|
|
|
{
|
|
|
|
float pitchang, rollang, offsets[3];
|
|
|
|
|
|
|
|
pitchang = (float)(spriteext[tspr->owner].pitch) / (2048.0f / 360.0f);
|
|
|
|
rollang = (float)(spriteext[tspr->owner].roll) / (2048.0f / 360.0f);
|
|
|
|
|
2014-10-25 03:36:34 +00:00
|
|
|
offsets[0] = -spriteext[tspr->owner].offset.x / (scale * tspr->xrepeat);
|
|
|
|
offsets[1] = -spriteext[tspr->owner].offset.y / (scale * tspr->xrepeat);
|
|
|
|
offsets[2] = (float)(spriteext[tspr->owner].offset.z) / 16.0f / (scale * tspr->yrepeat);
|
2009-05-10 17:51:00 +00:00
|
|
|
|
|
|
|
bglTranslatef(-offsets[0], -offsets[1], -offsets[2]);
|
|
|
|
|
|
|
|
bglRotatef(pitchang, 0.0f, 1.0f, 0.0f);
|
|
|
|
bglRotatef(rollang, -1.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
bglTranslatef(offsets[0], offsets[1], offsets[2]);
|
|
|
|
}
|
|
|
|
|
2009-03-10 17:49:34 +00:00
|
|
|
bglGetFloatv(GL_MODELVIEW_MATRIX, spritemodelview);
|
2009-05-10 17:51:00 +00:00
|
|
|
|
2009-03-27 12:56:42 +00:00
|
|
|
bglPopMatrix();
|
|
|
|
bglPushMatrix();
|
|
|
|
bglMultMatrixf(spritemodelview);
|
2009-03-10 17:49:34 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
// invert this matrix to get the polymer -> mdsprite space
|
|
|
|
memcpy(mat, spritemodelview, sizeof(float) * 16);
|
|
|
|
INVERT_4X4(mdspritespace, det, mat);
|
|
|
|
|
2009-03-10 09:26:25 +00:00
|
|
|
// debug code for drawing the model bounding sphere
|
2009-03-10 14:30:34 +00:00
|
|
|
// bglDisable(GL_TEXTURE_2D);
|
|
|
|
// bglBegin(GL_LINES);
|
|
|
|
// bglColor4f(1.0, 0.0, 0.0, 1.0);
|
|
|
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
|
|
|
// m->head.frames[m->cframe].cen.y,
|
|
|
|
// m->head.frames[m->cframe].cen.z);
|
|
|
|
// bglVertex3f(m->head.frames[m->cframe].cen.x + m->head.frames[m->cframe].r,
|
|
|
|
// m->head.frames[m->cframe].cen.y,
|
|
|
|
// m->head.frames[m->cframe].cen.z);
|
|
|
|
// bglColor4f(0.0, 1.0, 0.0, 1.0);
|
|
|
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
|
|
|
// m->head.frames[m->cframe].cen.y,
|
|
|
|
// m->head.frames[m->cframe].cen.z);
|
|
|
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
|
|
|
// m->head.frames[m->cframe].cen.y + m->head.frames[m->cframe].r,
|
|
|
|
// m->head.frames[m->cframe].cen.z);
|
|
|
|
// bglColor4f(0.0, 0.0, 1.0, 1.0);
|
|
|
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
|
|
|
// m->head.frames[m->cframe].cen.y,
|
|
|
|
// m->head.frames[m->cframe].cen.z);
|
|
|
|
// bglVertex3f(m->head.frames[m->cframe].cen.x,
|
|
|
|
// m->head.frames[m->cframe].cen.y,
|
|
|
|
// m->head.frames[m->cframe].cen.z + m->head.frames[m->cframe].r);
|
|
|
|
// bglEnd();
|
|
|
|
// bglEnable(GL_TEXTURE_2D);
|
2009-03-10 09:26:25 +00:00
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
polymer_getscratchmaterial(&mdspritematerial);
|
2008-11-26 19:31:26 +00:00
|
|
|
|
|
|
|
color = mdspritematerial.diffusemodulation;
|
|
|
|
|
2008-06-06 11:35:24 +00:00
|
|
|
color[0] = color[1] = color[2] =
|
2012-11-15 14:28:44 +00:00
|
|
|
(GLubyte)(((float)(numshades-min(max((tspr->shade * shadescale)+m->shadeoff,0),numshades)))/((float)numshades) * 0xFF);
|
2011-10-02 00:31:46 +00:00
|
|
|
|
2011-01-27 07:05:12 +00:00
|
|
|
usinghighpal = (pr_highpalookups &&
|
|
|
|
prhighpalookups[curbasepal][tspr->pal].map);
|
2008-06-06 11:35:24 +00:00
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
// tinting
|
2015-04-14 08:08:02 +00:00
|
|
|
if (!usinghighpal && !(hictinting[tspr->pal].f & HICTINT_PRECOMPUTED))
|
2008-06-06 11:35:24 +00:00
|
|
|
{
|
2015-04-14 08:07:08 +00:00
|
|
|
if (!(m->flags&1))
|
2014-05-28 22:40:17 +00:00
|
|
|
hictinting_apply_ub(color, tspr->pal);
|
2008-11-26 19:31:26 +00:00
|
|
|
else globalnoeffect=1; //mdloadskin reads this
|
2008-06-06 11:35:24 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
// global tinting
|
2014-05-28 22:40:17 +00:00
|
|
|
if (!usinghighpal && have_basepal_tint())
|
|
|
|
hictinting_apply_ub(color, MAXPALOOKUPS-1);
|
2009-06-09 09:32:23 +00:00
|
|
|
|
2008-06-06 11:35:24 +00:00
|
|
|
if (tspr->cstat & 2)
|
|
|
|
{
|
|
|
|
if (!(tspr->cstat&512))
|
2009-12-07 07:01:44 +00:00
|
|
|
color[3] = 0xAA;
|
2008-06-06 11:35:24 +00:00
|
|
|
else
|
2009-12-07 07:01:44 +00:00
|
|
|
color[3] = 0x55;
|
2009-04-19 09:49:27 +00:00
|
|
|
} else
|
2009-12-07 07:01:44 +00:00
|
|
|
color[3] = 0xFF;
|
2008-06-06 11:35:24 +00:00
|
|
|
|
2012-11-15 14:28:44 +00:00
|
|
|
{
|
|
|
|
double f = color[3] * (1.0f - spriteext[tspr->owner].alpha);
|
|
|
|
color[3] = (GLubyte)f;
|
|
|
|
}
|
2009-04-24 02:53:50 +00:00
|
|
|
|
2009-12-07 07:01:44 +00:00
|
|
|
if (searchit == 2)
|
|
|
|
{
|
|
|
|
color[0] = 0x03;
|
|
|
|
color[1] = ((GLubyte *)(&tspr->owner))[0];
|
|
|
|
color[2] = ((GLubyte *)(&tspr->owner))[1];
|
|
|
|
color[3] = 0xFF;
|
|
|
|
}
|
|
|
|
|
2008-06-06 14:00:12 +00:00
|
|
|
if (pr_gpusmoothing)
|
2008-11-27 16:19:24 +00:00
|
|
|
mdspritematerial.frameprogress = m->interpol;
|
2008-06-06 14:00:12 +00:00
|
|
|
|
2009-03-27 12:56:42 +00:00
|
|
|
mdspritematerial.mdspritespace = GL_TRUE;
|
|
|
|
|
2009-03-12 13:51:30 +00:00
|
|
|
modellightcount = 0;
|
2009-06-06 13:40:15 +00:00
|
|
|
curpriority = 0;
|
2009-03-12 13:51:30 +00:00
|
|
|
|
2009-03-10 17:49:34 +00:00
|
|
|
// light culling
|
2009-06-07 13:07:04 +00:00
|
|
|
if (lightcount && (!depth || mirrors[depth-1].plane))
|
2009-03-10 17:49:34 +00:00
|
|
|
{
|
|
|
|
sradius = (m->head.frames[m->cframe].r * (1 - m->interpol)) +
|
|
|
|
(m->head.frames[m->nframe].r * m->interpol);
|
|
|
|
|
|
|
|
sradius *= max(scale * tspr->xrepeat, scale * tspr->yrepeat);
|
|
|
|
sradius /= 1000.0f;
|
|
|
|
|
|
|
|
spos[0] = (m->head.frames[m->cframe].cen.x * (1 - m->interpol)) +
|
|
|
|
(m->head.frames[m->nframe].cen.x * m->interpol);
|
|
|
|
spos[1] = (m->head.frames[m->cframe].cen.y * (1 - m->interpol)) +
|
|
|
|
(m->head.frames[m->nframe].cen.y * m->interpol);
|
|
|
|
spos[2] = (m->head.frames[m->cframe].cen.z * (1 - m->interpol)) +
|
|
|
|
(m->head.frames[m->nframe].cen.z * m->interpol);
|
|
|
|
|
|
|
|
polymer_transformpoint(spos, tspos, spritemodelview);
|
2009-03-27 12:56:42 +00:00
|
|
|
polymer_transformpoint(tspos, spos, rootmodelviewmatrix);
|
2009-03-10 17:49:34 +00:00
|
|
|
|
2009-06-06 13:40:15 +00:00
|
|
|
while (curpriority < pr_maxlightpriority)
|
2009-03-10 17:49:34 +00:00
|
|
|
{
|
2009-06-06 13:40:15 +00:00
|
|
|
i = j = 0;
|
|
|
|
while (j < lightcount)
|
|
|
|
{
|
2010-08-03 15:06:24 +00:00
|
|
|
while (!prlights[i].flags.active)
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (prlights[i].priority != curpriority)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
}
|
2009-06-01 20:55:36 +00:00
|
|
|
|
2009-06-06 13:40:15 +00:00
|
|
|
lradius = prlights[i].range / 1000.0f;
|
2009-03-10 17:49:34 +00:00
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
lpos[0] = (float)prlights[i].y;
|
|
|
|
lpos[1] = -(float)prlights[i].z / 16.0f;
|
|
|
|
lpos[2] = -(float)prlights[i].x;
|
2009-03-10 17:49:34 +00:00
|
|
|
|
2009-06-06 13:40:15 +00:00
|
|
|
polymer_transformpoint(lpos, tlpos, rootmodelviewmatrix);
|
2009-03-10 17:49:34 +00:00
|
|
|
|
2009-06-06 13:40:15 +00:00
|
|
|
vec[0] = tlpos[0] - spos[0];
|
|
|
|
vec[0] *= vec[0];
|
|
|
|
vec[1] = tlpos[1] - spos[1];
|
|
|
|
vec[1] *= vec[1];
|
|
|
|
vec[2] = tlpos[2] - spos[2];
|
|
|
|
vec[2] *= vec[2];
|
2009-03-10 17:49:34 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
if ((vec[0] + vec[1] + vec[2]) <= ((sradius+lradius) * (sradius+lradius)))
|
|
|
|
modellights[modellightcount++] = i;
|
|
|
|
|
2009-06-06 13:40:15 +00:00
|
|
|
i++;
|
|
|
|
j++;
|
2009-03-10 17:49:34 +00:00
|
|
|
}
|
2009-06-06 13:40:15 +00:00
|
|
|
curpriority++;
|
2009-03-10 17:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-01 08:58:06 +00:00
|
|
|
for (surfi=0;surfi<m->head.numsurfs;surfi++)
|
|
|
|
{
|
|
|
|
s = &m->head.surfs[surfi];
|
2010-01-24 05:57:43 +00:00
|
|
|
v0 = &s->geometry[m->cframe*s->numverts*15];
|
|
|
|
v1 = &s->geometry[m->nframe*s->numverts*15];
|
2008-06-01 08:58:06 +00:00
|
|
|
|
2009-03-10 14:30:34 +00:00
|
|
|
// debug code for drawing model normals
|
|
|
|
// bglDisable(GL_TEXTURE_2D);
|
|
|
|
// bglBegin(GL_LINES);
|
|
|
|
// bglColor4f(1.0, 1.0, 1.0, 1.0);
|
2016-06-05 04:46:28 +00:00
|
|
|
//
|
2009-03-10 14:30:34 +00:00
|
|
|
// int i = 0;
|
|
|
|
// while (i < s->numverts)
|
|
|
|
// {
|
|
|
|
// bglVertex3f(v0[(i * 6) + 0],
|
|
|
|
// v0[(i * 6) + 1],
|
|
|
|
// v0[(i * 6) + 2]);
|
|
|
|
// bglVertex3f(v0[(i * 6) + 0] + v0[(i * 6) + 3] * 100,
|
|
|
|
// v0[(i * 6) + 1] + v0[(i * 6) + 4] * 100,
|
|
|
|
// v0[(i * 6) + 2] + v0[(i * 6) + 5] * 100);
|
|
|
|
// i++;
|
|
|
|
// }
|
|
|
|
// bglEnd();
|
|
|
|
// bglEnable(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
|
2011-01-12 02:06:51 +00:00
|
|
|
targetpal = tspr->pal;
|
|
|
|
foundpalskin = 0;
|
|
|
|
|
|
|
|
for (sk = m->skinmap; sk; sk = sk->next)
|
|
|
|
if ((int32_t)sk->palette == tspr->pal &&
|
|
|
|
sk->skinnum == tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum &&
|
|
|
|
sk->surfnum == surfi)
|
|
|
|
{
|
|
|
|
if (sk->specpower != 1.0)
|
|
|
|
mdspritematerial.specmaterial[0] = sk->specpower;
|
|
|
|
mdspritematerial.specmaterial[1] = sk->specfactor;
|
|
|
|
foundpalskin = 1;
|
|
|
|
}
|
2011-10-02 00:31:46 +00:00
|
|
|
|
2011-01-27 07:57:52 +00:00
|
|
|
// If we have a global palette tint, the palskin won't do us any good
|
|
|
|
if (curbasepal)
|
|
|
|
foundpalskin = 0;
|
2011-10-02 00:31:46 +00:00
|
|
|
|
2011-01-14 19:50:01 +00:00
|
|
|
if (!foundpalskin && usinghighpal) {
|
2011-01-12 02:06:51 +00:00
|
|
|
// We don't have a specific skin defined for this palette
|
|
|
|
// Use the base skin instead and plug in our highpalookup map
|
|
|
|
targetpal = 0;
|
2011-01-27 07:05:12 +00:00
|
|
|
mdspritematerial.highpalookupmap = prhighpalookups[curbasepal][tspr->pal].map;
|
2011-01-12 02:06:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
mdspritematerial.diffusemap =
|
2011-01-12 02:06:51 +00:00
|
|
|
mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,targetpal,surfi);
|
2008-11-26 19:31:26 +00:00
|
|
|
if (!mdspritematerial.diffusemap)
|
2008-06-01 08:58:06 +00:00
|
|
|
continue;
|
|
|
|
|
2015-10-21 19:54:14 +00:00
|
|
|
if (!(tspr->extra&TSPR_EXTRA_MDHACK))
|
2008-11-27 23:00:57 +00:00
|
|
|
{
|
|
|
|
mdspritematerial.detailmap =
|
2009-01-10 07:38:50 +00:00
|
|
|
mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,DETAILPAL,surfi);
|
2008-11-27 23:00:57 +00:00
|
|
|
|
|
|
|
for (sk = m->skinmap; sk; sk = sk->next)
|
2009-01-09 09:29:17 +00:00
|
|
|
if ((int32_t)sk->palette == DETAILPAL &&
|
2008-11-27 23:00:57 +00:00
|
|
|
sk->skinnum == tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum &&
|
|
|
|
sk->surfnum == surfi)
|
|
|
|
mdspritematerial.detailscale[0] = mdspritematerial.detailscale[1] = sk->param;
|
2008-11-27 22:26:46 +00:00
|
|
|
|
2010-03-07 01:09:39 +00:00
|
|
|
mdspritematerial.specmap =
|
|
|
|
mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,SPECULARPAL,surfi);
|
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
mdspritematerial.normalmap =
|
|
|
|
mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,NORMALPAL,surfi);
|
|
|
|
|
|
|
|
for (sk = m->skinmap; sk; sk = sk->next)
|
|
|
|
if ((int32_t)sk->palette == NORMALPAL &&
|
|
|
|
sk->skinnum == tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum &&
|
|
|
|
sk->surfnum == surfi) {
|
|
|
|
mdspritematerial.normalbias[0] = sk->specpower;
|
|
|
|
mdspritematerial.normalbias[1] = sk->specfactor;
|
|
|
|
}
|
|
|
|
|
2008-11-27 23:00:57 +00:00
|
|
|
mdspritematerial.glowmap =
|
2009-01-10 07:38:50 +00:00
|
|
|
mdloadskin((md2model_t *)m,tile2model[Ptile2tile(tspr->picnum,lpal)].skinnum,GLOWPAL,surfi);
|
2008-11-27 23:00:57 +00:00
|
|
|
}
|
2008-11-27 22:26:46 +00:00
|
|
|
|
2009-03-10 14:30:34 +00:00
|
|
|
bglEnableClientState(GL_NORMAL_ARRAY);
|
|
|
|
|
2008-06-01 08:58:06 +00:00
|
|
|
if (pr_vbos > 1)
|
|
|
|
{
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, m->texcoords[surfi]);
|
|
|
|
bglTexCoordPointer(2, GL_FLOAT, 0, 0);
|
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, m->geometry[surfi]);
|
2010-01-24 05:57:43 +00:00
|
|
|
bglVertexPointer(3, GL_FLOAT, sizeof(float) * 15, (GLfloat*)(m->cframe * s->numverts * sizeof(float) * 15));
|
|
|
|
bglNormalPointer(GL_FLOAT, sizeof(float) * 15, (GLfloat*)(m->cframe * s->numverts * sizeof(float) * 15) + 3);
|
2008-11-27 16:19:24 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
mdspritematerial.tbn = (GLfloat*)(m->cframe * s->numverts * sizeof(float) * 15) + 6;
|
|
|
|
|
|
|
|
if (pr_gpusmoothing) {
|
|
|
|
mdspritematerial.nextframedata = (GLfloat*)(m->nframe * s->numverts * sizeof(float) * 15);
|
2008-06-06 14:00:12 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 08:58:06 +00:00
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m->indices[surfi]);
|
|
|
|
|
2009-06-07 12:51:00 +00:00
|
|
|
curlight = 0;
|
|
|
|
do {
|
2014-09-30 04:04:30 +00:00
|
|
|
materialbits = polymer_bindmaterial(&mdspritematerial, modellights, modellightcount);
|
2016-06-05 04:46:28 +00:00
|
|
|
bglDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_INT, 0);
|
2009-03-12 13:51:30 +00:00
|
|
|
polymer_unbindmaterial(materialbits);
|
2010-07-26 22:36:45 +00:00
|
|
|
} while ((++curlight < modellightcount) && (curlight < pr_maxlightpasses));
|
2008-11-27 16:19:24 +00:00
|
|
|
|
2008-06-01 08:58:06 +00:00
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
2008-06-05 02:29:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-24 05:57:43 +00:00
|
|
|
bglVertexPointer(3, GL_FLOAT, sizeof(float) * 15, v0);
|
|
|
|
bglNormalPointer(GL_FLOAT, sizeof(float) * 15, v0 + 3);
|
2008-06-01 08:58:06 +00:00
|
|
|
bglTexCoordPointer(2, GL_FLOAT, 0, s->uv);
|
2008-06-06 14:00:12 +00:00
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
mdspritematerial.tbn = v0 + 6;
|
|
|
|
|
|
|
|
if (pr_gpusmoothing) {
|
2008-11-27 16:19:24 +00:00
|
|
|
mdspritematerial.nextframedata = (GLfloat*)(v1);
|
2008-06-06 14:00:12 +00:00
|
|
|
}
|
|
|
|
|
2009-06-07 12:51:00 +00:00
|
|
|
curlight = 0;
|
|
|
|
do {
|
2014-09-30 04:04:30 +00:00
|
|
|
materialbits = polymer_bindmaterial(&mdspritematerial, modellights, modellightcount);
|
2009-03-12 13:51:30 +00:00
|
|
|
bglDrawElements(GL_TRIANGLES, s->numtris * 3, GL_UNSIGNED_INT, s->tris);
|
|
|
|
polymer_unbindmaterial(materialbits);
|
2010-07-26 22:36:45 +00:00
|
|
|
} while ((++curlight < modellightcount) && (curlight < pr_maxlightpasses));
|
2008-06-01 08:58:06 +00:00
|
|
|
}
|
2009-03-10 14:30:34 +00:00
|
|
|
|
|
|
|
bglDisableClientState(GL_NORMAL_ARRAY);
|
2008-06-01 08:58:06 +00:00
|
|
|
}
|
2008-06-06 14:00:12 +00:00
|
|
|
|
2008-06-01 08:58:06 +00:00
|
|
|
bglPopMatrix();
|
2008-06-06 14:00:12 +00:00
|
|
|
|
2011-10-02 00:32:00 +00:00
|
|
|
if (!(tspr->cstat & 4) != !(tspr->cstat & 8)) {
|
|
|
|
SWITCH_CULL_DIRECTION;
|
|
|
|
}
|
|
|
|
|
2009-12-07 07:01:44 +00:00
|
|
|
globalnoeffect = 0;
|
2008-06-01 08:58:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-10 07:38:50 +00:00
|
|
|
static void polymer_loadmodelvbos(md3model_t* m)
|
2008-06-01 08:58:06 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i;
|
2008-06-01 08:58:06 +00:00
|
|
|
md3surf_t *s;
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
m->indices = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint));
|
|
|
|
m->texcoords = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint));
|
|
|
|
m->geometry = (GLuint *)Xmalloc(m->head.numsurfs * sizeof(GLuint));
|
2008-06-01 08:58:06 +00:00
|
|
|
|
|
|
|
bglGenBuffersARB(m->head.numsurfs, m->indices);
|
|
|
|
bglGenBuffersARB(m->head.numsurfs, m->texcoords);
|
|
|
|
bglGenBuffersARB(m->head.numsurfs, m->geometry);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < m->head.numsurfs)
|
|
|
|
{
|
|
|
|
s = &m->head.surfs[i];
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m->indices[i]);
|
|
|
|
bglBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, s->numtris * sizeof(md3tri_t), s->tris, modelvbousage);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, m->texcoords[i]);
|
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, s->numverts * sizeof(md3uv_t), s->uv, modelvbousage);
|
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, m->geometry[i]);
|
2010-01-24 05:57:43 +00:00
|
|
|
bglBufferDataARB(GL_ARRAY_BUFFER_ARB, s->numframes * s->numverts * sizeof(float) * (15), s->geometry, modelvbousage);
|
2008-06-01 08:58:06 +00:00
|
|
|
|
|
|
|
bglBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-26 14:22:07 +00:00
|
|
|
// MATERIALS
|
2008-11-27 16:19:24 +00:00
|
|
|
static void polymer_getscratchmaterial(_prmaterial* material)
|
|
|
|
{
|
|
|
|
// this function returns a material that won't validate any bits
|
|
|
|
// make sure to keep it up to date with the validation logic in bindmaterial
|
|
|
|
|
|
|
|
// PR_BIT_ANIM_INTERPOLATION
|
|
|
|
material->frameprogress = 0.0f;
|
2012-03-11 06:52:41 +00:00
|
|
|
material->nextframedata = (float*)-1;
|
2009-03-13 15:18:46 +00:00
|
|
|
// PR_BIT_NORMAL_MAP
|
|
|
|
material->normalmap = 0;
|
2009-03-29 15:16:33 +00:00
|
|
|
material->normalbias[0] = material->normalbias[1] = 0.0f;
|
2010-01-24 05:57:43 +00:00
|
|
|
material->tbn = NULL;
|
2013-05-06 03:12:38 +00:00
|
|
|
// PR_BIT_ART_MAP
|
|
|
|
material->artmap = 0;
|
|
|
|
material->basepalmap = 0;
|
|
|
|
material->lookupmap = 0;
|
2008-11-27 16:19:24 +00:00
|
|
|
// PR_BIT_DIFFUSE_MAP
|
|
|
|
material->diffusemap = 0;
|
2008-11-27 22:26:46 +00:00
|
|
|
material->diffusescale[0] = material->diffusescale[1] = 1.0f;
|
2010-12-29 06:23:49 +00:00
|
|
|
// PR_BIT_HIGHPALOOKUP_MAP
|
|
|
|
material->highpalookupmap = 0;
|
2008-11-27 22:26:46 +00:00
|
|
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
|
|
|
material->detailmap = 0;
|
|
|
|
material->detailscale[0] = material->detailscale[1] = 1.0f;
|
2008-11-27 16:19:24 +00:00
|
|
|
// PR_BIT_DIFFUSE_MODULATION
|
|
|
|
material->diffusemodulation[0] =
|
|
|
|
material->diffusemodulation[1] =
|
|
|
|
material->diffusemodulation[2] =
|
2009-12-07 07:01:44 +00:00
|
|
|
material->diffusemodulation[3] = 0xFF;
|
2009-03-28 16:14:10 +00:00
|
|
|
// PR_BIT_SPECULAR_MAP
|
|
|
|
material->specmap = 0;
|
2009-03-28 12:14:37 +00:00
|
|
|
// PR_BIT_SPECULAR_MATERIAL
|
2009-03-29 17:14:41 +00:00
|
|
|
material->specmaterial[0] = 15.0f;
|
|
|
|
material->specmaterial[1] = 1.0f;
|
2009-03-28 11:43:16 +00:00
|
|
|
// PR_BIT_MIRROR_MAP
|
2009-03-23 14:18:20 +00:00
|
|
|
material->mirrormap = 0;
|
2009-03-28 11:43:16 +00:00
|
|
|
// PR_BIT_GLOW_MAP
|
2008-11-27 23:00:57 +00:00
|
|
|
material->glowmap = 0;
|
2010-07-25 02:16:22 +00:00
|
|
|
// PR_BIT_PROJECTION_MAP
|
2009-03-27 12:56:42 +00:00
|
|
|
material->mdspritespace = GL_FALSE;
|
2008-11-27 16:19:24 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 04:05:43 +00:00
|
|
|
static void polymer_setupartmap(int16_t tilenum, char pal)
|
2008-11-26 14:22:07 +00:00
|
|
|
{
|
2015-12-23 04:05:43 +00:00
|
|
|
if (!prartmaps[tilenum]) {
|
|
|
|
char *tilebuffer = (char *) waloff[tilenum];
|
|
|
|
char *tempbuffer = (char *) Xmalloc(tilesiz[tilenum].x * tilesiz[tilenum].y);
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
i = k = 0;
|
|
|
|
while (i < tilesiz[tilenum].y) {
|
|
|
|
j = 0;
|
|
|
|
while (j < tilesiz[tilenum].x) {
|
|
|
|
tempbuffer[k] = tilebuffer[(j * tilesiz[tilenum].y) + i];
|
|
|
|
k++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
2015-07-14 07:08:44 +00:00
|
|
|
|
2015-12-23 04:05:43 +00:00
|
|
|
bglGenTextures(1, &prartmaps[tilenum]);
|
|
|
|
bglBindTexture(GL_TEXTURE_2D, prartmaps[tilenum]);
|
|
|
|
bglTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0,
|
|
|
|
GL_R8,
|
|
|
|
tilesiz[tilenum].x,
|
|
|
|
tilesiz[tilenum].y,
|
|
|
|
0,
|
|
|
|
GL_RED,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
tempbuffer);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
|
|
bglBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
Bfree(tempbuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prbasepalmaps[curbasepal]) {
|
|
|
|
bglGenTextures(1, &prbasepalmaps[curbasepal]);
|
|
|
|
bglBindTexture(GL_TEXTURE_2D, prbasepalmaps[curbasepal]);
|
|
|
|
bglTexImage2D(GL_TEXTURE_2D,
|
|
|
|
0,
|
|
|
|
GL_RGB,
|
|
|
|
256,
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
GL_RGB,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
basepaltable[curbasepal]);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glinfo.clamptoedge ? GL_CLAMP_TO_EDGE : GL_CLAMP);
|
|
|
|
bglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glinfo.clamptoedge ? GL_CLAMP_TO_EDGE : GL_CLAMP);
|
|
|
|
bglBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!prlookups[pal]) {
|
|
|
|
bglGenTextures(1, &prlookups[pal]);
|
|
|
|
bglBindTexture(GL_TEXTURE_RECTANGLE, prlookups[pal]);
|
|
|
|
bglTexImage2D(GL_TEXTURE_RECTANGLE,
|
|
|
|
0,
|
|
|
|
GL_R8,
|
|
|
|
256,
|
|
|
|
numshades,
|
|
|
|
0,
|
|
|
|
GL_RED,
|
|
|
|
GL_UNSIGNED_BYTE,
|
|
|
|
palookup[pal]);
|
|
|
|
bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, glinfo.clamptoedge ? GL_CLAMP_TO_EDGE : GL_CLAMP);
|
|
|
|
bglTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, glinfo.clamptoedge ? GL_CLAMP_TO_EDGE : GL_CLAMP);
|
|
|
|
bglBindTexture(GL_TEXTURE_RECTANGLE, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static _prbucket* polymer_getbuildmaterial(_prmaterial* material, int16_t tilenum, char pal, int8_t shade, int8_t vis, int32_t cmeth)
|
|
|
|
{
|
2015-07-14 07:08:44 +00:00
|
|
|
// find corresponding bucket; XXX key that with pr_buckets later, need to be tied to restartvid
|
2015-12-23 04:05:43 +00:00
|
|
|
_prbucket *bucketptr = polymer_findbucket(tilenum, pal);
|
2013-05-07 07:48:08 +00:00
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
polymer_getscratchmaterial(material);
|
2013-05-07 07:48:08 +00:00
|
|
|
|
2008-11-26 14:22:07 +00:00
|
|
|
if (!waloff[tilenum])
|
|
|
|
loadtile(tilenum);
|
2013-05-06 03:12:38 +00:00
|
|
|
|
2013-05-07 07:48:08 +00:00
|
|
|
// PR_BIT_DIFFUSE_MAP
|
2015-12-23 04:05:43 +00:00
|
|
|
pthtyp *pth = texcache_fetch(tilenum, pal, 0, cmeth);
|
2013-05-07 07:48:08 +00:00
|
|
|
|
|
|
|
if (pth)
|
2013-05-22 16:23:14 +00:00
|
|
|
{
|
2013-05-07 07:48:08 +00:00
|
|
|
material->diffusemap = pth->glpic;
|
|
|
|
|
2013-05-22 16:23:14 +00:00
|
|
|
if (pth->hicr)
|
|
|
|
{
|
2014-10-25 03:36:34 +00:00
|
|
|
material->diffusescale[0] = pth->hicr->scale.x;
|
|
|
|
material->diffusescale[1] = pth->hicr->scale.y;
|
2013-05-22 16:23:14 +00:00
|
|
|
}
|
2013-05-07 07:48:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 04:05:35 +00:00
|
|
|
int32_t usinghighpal = 0;
|
|
|
|
|
2013-05-06 03:12:38 +00:00
|
|
|
// Lazily fill in all the textures we need, move this to precaching later
|
2015-12-23 04:05:43 +00:00
|
|
|
if (pr_artmapping && !(globalflags & GLOBAL_NO_GL_TILESHADES) && polymer_eligible_for_artmap(tilenum, pth))
|
|
|
|
{
|
|
|
|
if (!prartmaps[tilenum] || !prbasepalmaps[curbasepal] || !prlookups[pal])
|
|
|
|
polymer_setupartmap(tilenum, pal);
|
2013-05-06 03:12:38 +00:00
|
|
|
|
|
|
|
material->artmap = prartmaps[tilenum];
|
|
|
|
material->basepalmap = prbasepalmaps[curbasepal];
|
|
|
|
material->lookupmap = prlookups[pal];
|
2013-05-07 07:48:08 +00:00
|
|
|
|
|
|
|
if (!material->basepalmap || !material->lookupmap) {
|
|
|
|
material->artmap = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
material->shadeoffset = shade;
|
2015-12-23 04:05:43 +00:00
|
|
|
material->visibility = ((uint8_t) (vis+16) / 16.0f);
|
2013-05-07 07:48:08 +00:00
|
|
|
|
2015-07-14 07:08:44 +00:00
|
|
|
// all the stuff below is mutually exclusive with artmapping
|
|
|
|
goto done;
|
2013-05-06 03:12:38 +00:00
|
|
|
}
|
|
|
|
|
2010-12-30 08:13:37 +00:00
|
|
|
// PR_BIT_HIGHPALOOKUP_MAP
|
2011-01-27 07:05:12 +00:00
|
|
|
if (pr_highpalookups && prhighpalookups[curbasepal][pal].map &&
|
2014-09-30 04:04:30 +00:00
|
|
|
hicfindsubst(tilenum, 0) &&
|
|
|
|
(curbasepal || (hicfindsubst(tilenum, pal)->palnum != pal)))
|
2010-12-30 08:13:37 +00:00
|
|
|
{
|
2011-01-27 07:05:12 +00:00
|
|
|
material->highpalookupmap = prhighpalookups[curbasepal][pal].map;
|
2010-12-30 08:13:37 +00:00
|
|
|
pal = 0;
|
2011-01-27 07:05:12 +00:00
|
|
|
usinghighpal = 1;
|
2010-12-30 08:13:37 +00:00
|
|
|
}
|
2013-05-07 07:48:08 +00:00
|
|
|
|
|
|
|
if (pth)
|
2008-11-26 17:24:08 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
if (pth->hicr)
|
2008-11-27 22:26:46 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
// PR_BIT_SPECULAR_MATERIAL
|
|
|
|
if (pth->hicr->specpower != 1.0f)
|
|
|
|
material->specmaterial[0] = pth->hicr->specpower;
|
|
|
|
material->specmaterial[1] = pth->hicr->specfactor;
|
2008-11-27 22:26:46 +00:00
|
|
|
}
|
2013-05-07 07:48:08 +00:00
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
// PR_BIT_DIFFUSE_MODULATION
|
|
|
|
material->diffusemodulation[0] =
|
2008-11-26 14:22:07 +00:00
|
|
|
material->diffusemodulation[1] =
|
|
|
|
material->diffusemodulation[2] =
|
2012-12-14 19:28:01 +00:00
|
|
|
(GLubyte)(getshadefactor(shade) * 0xFF);
|
2013-05-07 07:48:08 +00:00
|
|
|
|
2015-04-14 21:18:08 +00:00
|
|
|
// tinting
|
|
|
|
if (!(hictinting[pal].f & HICTINT_PRECOMPUTED))
|
2009-06-09 09:32:23 +00:00
|
|
|
{
|
2015-04-14 21:18:08 +00:00
|
|
|
if (pth->flags & PTH_HIGHTILE)
|
|
|
|
{
|
|
|
|
if (pth->palnum != pal || (pth->effects & HICTINT_IN_MEMORY) || (hictinting[pal].f & HICTINT_APPLYOVERALTPAL))
|
|
|
|
hictinting_apply_ub(material->diffusemodulation, pal);
|
|
|
|
}
|
|
|
|
else if (hictinting[pal].f & HICTINT_USEONART)
|
2014-05-28 22:40:17 +00:00
|
|
|
hictinting_apply_ub(material->diffusemodulation, pal);
|
2009-12-05 09:22:43 +00:00
|
|
|
}
|
2015-04-14 21:18:08 +00:00
|
|
|
|
|
|
|
// global tinting
|
|
|
|
if ((pth->flags & PTH_HIGHTILE) && !usinghighpal && have_basepal_tint())
|
|
|
|
hictinting_apply_ub(material->diffusemodulation, MAXPALOOKUPS-1);
|
2013-05-07 07:48:08 +00:00
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
// PR_BIT_GLOW_MAP
|
2014-05-28 22:40:16 +00:00
|
|
|
if (r_fullbrights && pth->flags & PTH_HASFULLBRIGHT)
|
2009-12-05 09:22:43 +00:00
|
|
|
material->glowmap = pth->ofb->glpic;
|
2009-03-28 16:14:10 +00:00
|
|
|
}
|
2013-05-07 07:48:08 +00:00
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
2015-12-04 11:52:54 +00:00
|
|
|
if (hicfindsubst(tilenum, DETAILPAL) && (pth = texcache_fetch(tilenum, DETAILPAL, 0, DAMETH_NOMASK)) &&
|
2009-12-05 09:22:43 +00:00
|
|
|
pth->hicr && (pth->hicr->palnum == DETAILPAL))
|
2009-03-28 12:14:37 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
material->detailmap = pth->glpic;
|
2014-10-25 03:36:34 +00:00
|
|
|
material->detailscale[0] = pth->hicr->scale.x;
|
|
|
|
material->detailscale[1] = pth->hicr->scale.y;
|
2009-03-28 12:14:37 +00:00
|
|
|
}
|
2013-05-07 07:48:08 +00:00
|
|
|
|
|
|
|
// PR_BIT_GLOW_MAP
|
2015-12-04 11:52:58 +00:00
|
|
|
if (hicfindsubst(tilenum, GLOWPAL) && (pth = texcache_fetch(tilenum, GLOWPAL, 0, DAMETH_MASK)) &&
|
2009-12-05 09:22:43 +00:00
|
|
|
pth->hicr && (pth->hicr->palnum == GLOWPAL))
|
|
|
|
material->glowmap = pth->glpic;
|
2013-05-07 07:48:08 +00:00
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
// PR_BIT_SPECULAR_MAP
|
2015-12-04 11:52:54 +00:00
|
|
|
if (hicfindsubst(tilenum, SPECULARPAL) && (pth = texcache_fetch(tilenum, SPECULARPAL, 0, DAMETH_NOMASK)) &&
|
2009-12-05 09:22:43 +00:00
|
|
|
pth->hicr && (pth->hicr->palnum == SPECULARPAL))
|
|
|
|
material->specmap = pth->glpic;
|
2009-03-28 12:14:37 +00:00
|
|
|
|
2009-12-05 09:22:43 +00:00
|
|
|
// PR_BIT_NORMAL_MAP
|
2015-12-04 11:52:54 +00:00
|
|
|
if (hicfindsubst(tilenum, NORMALPAL) && (pth = texcache_fetch(tilenum, NORMALPAL, 0, DAMETH_NOMASK)) &&
|
2009-12-05 09:22:43 +00:00
|
|
|
pth->hicr && (pth->hicr->palnum == NORMALPAL))
|
2008-11-27 23:00:57 +00:00
|
|
|
{
|
2009-12-05 09:22:43 +00:00
|
|
|
material->normalmap = pth->glpic;
|
|
|
|
material->normalbias[0] = pth->hicr->specpower;
|
|
|
|
material->normalbias[1] = pth->hicr->specfactor;
|
2008-11-27 23:00:57 +00:00
|
|
|
}
|
2015-07-14 07:08:44 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (bucketptr->invalidmaterial != 0)
|
|
|
|
{
|
|
|
|
bucketptr->material = *material;
|
|
|
|
bucketptr->invalidmaterial = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bucketptr;
|
2008-11-26 14:22:07 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
static int32_t polymer_bindmaterial(const _prmaterial *material, int16_t* lights, int matlightcount)
|
2008-11-25 11:32:49 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t programbits;
|
|
|
|
int32_t texunit;
|
2008-11-25 11:32:49 +00:00
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
programbits = 0;
|
2008-11-25 11:32:49 +00:00
|
|
|
|
|
|
|
// --------- bit validation
|
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
// PR_BIT_ANIM_INTERPOLATION
|
2014-09-30 04:04:30 +00:00
|
|
|
if (material->nextframedata != ((float*)-1))
|
2008-11-27 16:19:24 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit;
|
|
|
|
|
2009-03-12 13:51:30 +00:00
|
|
|
// PR_BIT_LIGHTING_PASS
|
2009-06-07 12:51:00 +00:00
|
|
|
if (curlight && matlightcount)
|
2009-03-12 13:51:30 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_LIGHTING_PASS].bit;
|
|
|
|
|
2009-03-13 15:18:46 +00:00
|
|
|
// PR_BIT_NORMAL_MAP
|
2014-09-30 04:04:30 +00:00
|
|
|
if (pr_normalmapping && material->normalmap)
|
2009-03-13 15:18:46 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_NORMAL_MAP].bit;
|
|
|
|
|
2013-05-06 03:12:38 +00:00
|
|
|
// PR_BIT_ART_MAP
|
2014-09-30 04:04:30 +00:00
|
|
|
if (pr_artmapping && material->artmap &&
|
2015-03-09 20:32:36 +00:00
|
|
|
!(globalflags & GLOBAL_NO_GL_TILESHADES) &&
|
2013-05-07 07:48:08 +00:00
|
|
|
(overridematerial & prprogrambits[PR_BIT_ART_MAP].bit)) {
|
2013-05-06 03:12:38 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_ART_MAP].bit;
|
|
|
|
} else
|
2008-11-26 08:37:14 +00:00
|
|
|
// PR_BIT_DIFFUSE_MAP
|
2014-09-30 04:04:30 +00:00
|
|
|
if (material->diffusemap) {
|
2008-11-26 08:37:14 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_MAP].bit;
|
2010-12-29 06:23:49 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_MAP2].bit;
|
|
|
|
}
|
2013-05-06 03:12:38 +00:00
|
|
|
|
2010-12-29 06:23:49 +00:00
|
|
|
// PR_BIT_HIGHPALOOKUP_MAP
|
2014-09-30 04:04:30 +00:00
|
|
|
if (material->highpalookupmap)
|
2010-12-29 06:23:49 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_HIGHPALOOKUP_MAP].bit;
|
2008-11-26 08:37:14 +00:00
|
|
|
|
2008-11-27 22:26:46 +00:00
|
|
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
2014-09-30 04:04:30 +00:00
|
|
|
if (r_detailmapping && material->detailmap)
|
2008-11-27 22:26:46 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_DETAIL_MAP].bit;
|
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
// PR_BIT_DIFFUSE_MODULATION
|
2013-05-07 07:48:08 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit;
|
2009-03-12 13:51:30 +00:00
|
|
|
|
2009-03-28 16:14:10 +00:00
|
|
|
// PR_BIT_SPECULAR_MAP
|
2014-09-30 04:04:30 +00:00
|
|
|
if (pr_specularmapping && material->specmap)
|
2009-03-28 16:14:10 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_SPECULAR_MAP].bit;
|
|
|
|
|
2009-03-28 12:14:37 +00:00
|
|
|
// PR_BIT_SPECULAR_MATERIAL
|
2014-09-30 04:04:30 +00:00
|
|
|
if ((material->specmaterial[0] != 15.0) || (material->specmaterial[1] != 1.0) || pr_overridespecular)
|
2009-03-28 12:14:37 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_SPECULAR_MATERIAL].bit;
|
|
|
|
|
2009-03-28 11:43:16 +00:00
|
|
|
// PR_BIT_MIRROR_MAP
|
2014-09-30 04:04:30 +00:00
|
|
|
if (!curlight && material->mirrormap)
|
2009-03-28 11:43:16 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_MIRROR_MAP].bit;
|
2009-03-23 14:18:20 +00:00
|
|
|
|
2009-04-11 18:01:39 +00:00
|
|
|
// PR_BIT_FOG
|
2014-09-30 04:04:30 +00:00
|
|
|
if (!material->artmap && !curlight && !material->mirrormap)
|
2009-06-13 21:06:45 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_FOG].bit;
|
2009-04-11 18:01:39 +00:00
|
|
|
|
2009-03-28 11:43:16 +00:00
|
|
|
// PR_BIT_GLOW_MAP
|
2014-09-30 04:04:30 +00:00
|
|
|
if (!curlight && r_glowmapping && material->glowmap)
|
2009-03-28 11:43:16 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_GLOW_MAP].bit;
|
2008-11-25 11:32:49 +00:00
|
|
|
|
2009-02-05 08:56:59 +00:00
|
|
|
// PR_BIT_POINT_LIGHT
|
2009-06-01 20:55:36 +00:00
|
|
|
if (matlightcount) {
|
2009-02-14 14:31:58 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_POINT_LIGHT].bit;
|
2009-03-25 19:48:27 +00:00
|
|
|
// PR_BIT_SPOT_LIGHT
|
2009-03-26 16:32:00 +00:00
|
|
|
if (prlights[lights[curlight]].radius) {
|
2009-03-25 19:48:27 +00:00
|
|
|
programbits |= prprogrambits[PR_BIT_SPOT_LIGHT].bit;
|
2012-10-21 18:41:09 +00:00
|
|
|
// PR_BIT_SHADOW_MAP
|
|
|
|
if (prlights[lights[curlight]].rtindex != -1) {
|
|
|
|
programbits |= prprogrambits[PR_BIT_SHADOW_MAP].bit;
|
|
|
|
programbits |= prprogrambits[PR_BIT_PROJECTION_MAP].bit;
|
|
|
|
}
|
|
|
|
// PR_BIT_LIGHT_MAP
|
|
|
|
if (prlights[lights[curlight]].lightmap) {
|
|
|
|
programbits |= prprogrambits[PR_BIT_LIGHT_MAP].bit;
|
|
|
|
programbits |= prprogrambits[PR_BIT_PROJECTION_MAP].bit;
|
2009-05-12 20:08:38 +00:00
|
|
|
}
|
2009-03-26 16:32:00 +00:00
|
|
|
}
|
2009-03-25 19:48:27 +00:00
|
|
|
}
|
2009-02-05 08:56:59 +00:00
|
|
|
|
2009-03-18 15:05:58 +00:00
|
|
|
// material override
|
|
|
|
programbits &= overridematerial;
|
|
|
|
|
|
|
|
programbits |= prprogrambits[PR_BIT_HEADER].bit;
|
|
|
|
programbits |= prprogrambits[PR_BIT_FOOTER].bit;
|
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
// --------- program compiling
|
2008-11-26 08:37:14 +00:00
|
|
|
if (!prprograms[programbits].handle)
|
2008-11-25 11:32:49 +00:00
|
|
|
polymer_compileprogram(programbits);
|
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
bglUseProgramObjectARB(prprograms[programbits].handle);
|
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
// --------- bit setup
|
|
|
|
|
2008-11-27 22:26:46 +00:00
|
|
|
texunit = 0;
|
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
// PR_BIT_ANIM_INTERPOLATION
|
|
|
|
if (programbits & prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit)
|
|
|
|
{
|
|
|
|
bglEnableVertexAttribArrayARB(prprograms[programbits].attrib_nextFrameData);
|
2009-04-14 13:58:38 +00:00
|
|
|
if (prprograms[programbits].attrib_nextFrameNormal != -1)
|
|
|
|
bglEnableVertexAttribArrayARB(prprograms[programbits].attrib_nextFrameNormal);
|
2008-11-27 16:19:24 +00:00
|
|
|
bglVertexAttribPointerARB(prprograms[programbits].attrib_nextFrameData,
|
2009-03-10 12:08:33 +00:00
|
|
|
3, GL_FLOAT, GL_FALSE,
|
2010-01-24 05:57:43 +00:00
|
|
|
sizeof(float) * 15,
|
2014-09-30 04:04:30 +00:00
|
|
|
material->nextframedata);
|
2009-04-14 13:58:38 +00:00
|
|
|
if (prprograms[programbits].attrib_nextFrameNormal != -1)
|
|
|
|
bglVertexAttribPointerARB(prprograms[programbits].attrib_nextFrameNormal,
|
|
|
|
3, GL_FLOAT, GL_FALSE,
|
2010-01-24 05:57:43 +00:00
|
|
|
sizeof(float) * 15,
|
2014-09-30 04:04:30 +00:00
|
|
|
material->nextframedata + 3);
|
2008-11-27 16:19:24 +00:00
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
bglUniform1fARB(prprograms[programbits].uniform_frameProgress, material->frameprogress);
|
2008-11-27 16:19:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 13:51:30 +00:00
|
|
|
// PR_BIT_LIGHTING_PASS
|
|
|
|
if (programbits & prprogrambits[PR_BIT_LIGHTING_PASS].bit)
|
|
|
|
{
|
2012-10-21 04:52:43 +00:00
|
|
|
bglPushAttrib(GL_COLOR_BUFFER_BIT);
|
|
|
|
bglEnable(GL_BLEND);
|
2009-03-12 13:51:30 +00:00
|
|
|
bglBlendFunc(GL_ONE, GL_ONE);
|
2012-10-21 04:52:43 +00:00
|
|
|
|
|
|
|
if (prlights[lights[curlight]].publicflags.negative) {
|
|
|
|
bglBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
|
|
|
|
}
|
2009-03-12 13:51:30 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 15:18:46 +00:00
|
|
|
// PR_BIT_NORMAL_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_NORMAL_MAP].bit)
|
|
|
|
{
|
2009-03-29 15:16:33 +00:00
|
|
|
float pos[3], bias[2];
|
2009-03-28 18:25:30 +00:00
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
pos[0] = (float)globalposy;
|
2009-03-28 18:25:30 +00:00
|
|
|
pos[1] = -(float)(globalposz) / 16.0f;
|
2009-07-12 01:55:34 +00:00
|
|
|
pos[2] = -(float)globalposx;
|
2009-03-28 18:25:30 +00:00
|
|
|
|
2009-03-13 15:18:46 +00:00
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, material->normalmap);
|
2009-03-13 15:18:46 +00:00
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
if (material->mdspritespace == GL_TRUE) {
|
2010-01-24 05:57:43 +00:00
|
|
|
float mdspritespacepos[3];
|
|
|
|
polymer_transformpoint(pos, mdspritespacepos, (float *)mdspritespace);
|
|
|
|
bglUniform3fvARB(prprograms[programbits].uniform_eyePosition, 1, mdspritespacepos);
|
|
|
|
} else
|
|
|
|
bglUniform3fvARB(prprograms[programbits].uniform_eyePosition, 1, pos);
|
2009-03-13 15:18:46 +00:00
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_normalMap, texunit);
|
2009-03-29 15:16:33 +00:00
|
|
|
if (pr_overrideparallax) {
|
|
|
|
bias[0] = pr_parallaxscale;
|
|
|
|
bias[1] = pr_parallaxbias;
|
|
|
|
bglUniform2fvARB(prprograms[programbits].uniform_normalBias, 1, bias);
|
|
|
|
} else
|
2014-09-30 04:04:30 +00:00
|
|
|
bglUniform2fvARB(prprograms[programbits].uniform_normalBias, 1, material->normalbias);
|
2009-03-13 15:18:46 +00:00
|
|
|
|
2014-09-30 04:04:30 +00:00
|
|
|
if (material->tbn) {
|
2010-01-24 05:57:43 +00:00
|
|
|
bglEnableVertexAttribArrayARB(prprograms[programbits].attrib_T);
|
|
|
|
bglEnableVertexAttribArrayARB(prprograms[programbits].attrib_B);
|
|
|
|
bglEnableVertexAttribArrayARB(prprograms[programbits].attrib_N);
|
|
|
|
|
|
|
|
bglVertexAttribPointerARB(prprograms[programbits].attrib_T,
|
|
|
|
3, GL_FLOAT, GL_FALSE,
|
|
|
|
sizeof(float) * 15,
|
2014-09-30 04:04:30 +00:00
|
|
|
material->tbn);
|
2010-01-24 05:57:43 +00:00
|
|
|
bglVertexAttribPointerARB(prprograms[programbits].attrib_B,
|
|
|
|
3, GL_FLOAT, GL_FALSE,
|
|
|
|
sizeof(float) * 15,
|
2014-09-30 04:04:30 +00:00
|
|
|
material->tbn + 3);
|
2010-01-24 05:57:43 +00:00
|
|
|
bglVertexAttribPointerARB(prprograms[programbits].attrib_N,
|
|
|
|
3, GL_FLOAT, GL_FALSE,
|
|
|
|
sizeof(float) * 15,
|
2014-09-30 04:04:30 +00:00
|
|
|
material->tbn + 6);
|
2010-01-24 05:57:43 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 15:18:46 +00:00
|
|
|
texunit++;
|
|
|
|
}
|
|
|
|
|
2013-05-06 03:12:38 +00:00
|
|
|
// PR_BIT_ART_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_ART_MAP].bit)
|
|
|
|
{
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, material->artmap);
|
2013-05-06 03:12:38 +00:00
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_artMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, material->basepalmap);
|
2013-05-06 03:12:38 +00:00
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_basePalMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_RECTANGLE, material->lookupmap);
|
2013-05-06 03:12:38 +00:00
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_lookupMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
|
2014-10-29 17:06:20 +00:00
|
|
|
bglUniform1fARB(prprograms[programbits].uniform_shadeOffset, (GLfloat)material->shadeoffset);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglUniform1fARB(prprograms[programbits].uniform_visibility, globalvisibility/2048.0 * material->visibility);
|
2013-05-06 03:12:38 +00:00
|
|
|
}
|
|
|
|
|
2008-11-26 08:37:14 +00:00
|
|
|
// PR_BIT_DIFFUSE_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_MAP].bit)
|
|
|
|
{
|
2008-11-27 22:26:46 +00:00
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, material->diffusemap);
|
2008-11-26 17:24:08 +00:00
|
|
|
|
2008-11-27 22:26:46 +00:00
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_diffuseMap, texunit);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglUniform2fvARB(prprograms[programbits].uniform_diffuseScale, 1, material->diffusescale);
|
2008-11-27 22:26:46 +00:00
|
|
|
|
|
|
|
texunit++;
|
|
|
|
}
|
|
|
|
|
2010-12-29 06:23:49 +00:00
|
|
|
// PR_BIT_HIGHPALOOKUP_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_HIGHPALOOKUP_MAP].bit)
|
|
|
|
{
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_3D, material->highpalookupmap);
|
2010-12-29 06:23:49 +00:00
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_highPalookupMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
}
|
|
|
|
|
2008-11-27 22:26:46 +00:00
|
|
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_DETAIL_MAP].bit)
|
|
|
|
{
|
2009-03-29 15:16:33 +00:00
|
|
|
float scale[2];
|
|
|
|
|
|
|
|
// scale by the diffuse map scale if we're not doing normal mapping
|
|
|
|
if (!(programbits & prprogrambits[PR_BIT_NORMAL_MAP].bit))
|
|
|
|
{
|
2014-09-30 04:04:30 +00:00
|
|
|
scale[0] = material->diffusescale[0] * material->detailscale[0];
|
|
|
|
scale[1] = material->diffusescale[1] * material->detailscale[1];
|
2009-03-29 15:16:33 +00:00
|
|
|
} else {
|
2014-09-30 04:04:30 +00:00
|
|
|
scale[0] = material->detailscale[0];
|
|
|
|
scale[1] = material->detailscale[1];
|
2009-03-29 15:16:33 +00:00
|
|
|
}
|
|
|
|
|
2008-11-27 22:26:46 +00:00
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, material->detailmap);
|
2008-11-27 22:26:46 +00:00
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_detailMap, texunit);
|
2009-03-29 15:16:33 +00:00
|
|
|
bglUniform2fvARB(prprograms[programbits].uniform_detailScale, 1, scale);
|
2008-11-27 22:26:46 +00:00
|
|
|
|
|
|
|
texunit++;
|
2008-11-26 08:37:14 +00:00
|
|
|
}
|
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
// PR_BIT_DIFFUSE_MODULATION
|
|
|
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit)
|
|
|
|
{
|
2014-09-30 04:04:30 +00:00
|
|
|
bglColor4ub(material->diffusemodulation[0],
|
|
|
|
material->diffusemodulation[1],
|
|
|
|
material->diffusemodulation[2],
|
|
|
|
material->diffusemodulation[3]);
|
2008-11-25 11:32:49 +00:00
|
|
|
}
|
|
|
|
|
2009-03-28 16:14:10 +00:00
|
|
|
// PR_BIT_SPECULAR_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_SPECULAR_MAP].bit)
|
|
|
|
{
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, material->specmap);
|
2009-03-28 16:14:10 +00:00
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_specMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
}
|
|
|
|
|
2009-03-28 12:14:37 +00:00
|
|
|
// PR_BIT_SPECULAR_MATERIAL
|
|
|
|
if (programbits & prprogrambits[PR_BIT_SPECULAR_MATERIAL].bit)
|
|
|
|
{
|
2009-03-29 17:14:41 +00:00
|
|
|
float specmaterial[2];
|
|
|
|
|
|
|
|
if (pr_overridespecular) {
|
|
|
|
specmaterial[0] = pr_specularpower;
|
|
|
|
specmaterial[1] = pr_specularfactor;
|
|
|
|
bglUniform2fvARB(prprograms[programbits].uniform_specMaterial, 1, specmaterial);
|
|
|
|
} else
|
2014-09-30 04:04:30 +00:00
|
|
|
bglUniform2fvARB(prprograms[programbits].uniform_specMaterial, 1, material->specmaterial);
|
2009-03-28 12:14:37 +00:00
|
|
|
}
|
|
|
|
|
2009-03-28 11:43:16 +00:00
|
|
|
// PR_BIT_MIRROR_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_MIRROR_MAP].bit)
|
2009-03-23 14:18:20 +00:00
|
|
|
{
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_RECTANGLE, material->mirrormap);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_mirrorMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
}
|
2012-12-16 19:18:10 +00:00
|
|
|
#ifdef PR_LINEAR_FOG
|
|
|
|
if (programbits & prprogrambits[PR_BIT_FOG].bit)
|
|
|
|
{
|
2014-03-23 23:14:48 +00:00
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_linearFog, r_usenewshading >= 2);
|
2012-12-16 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-03-28 11:43:16 +00:00
|
|
|
// PR_BIT_GLOW_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_GLOW_MAP].bit)
|
2009-03-12 13:51:30 +00:00
|
|
|
{
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
2014-09-30 04:04:30 +00:00
|
|
|
bglBindTexture(GL_TEXTURE_2D, material->glowmap);
|
2009-03-12 13:51:30 +00:00
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_glowMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
}
|
|
|
|
|
2008-11-29 20:16:19 +00:00
|
|
|
// PR_BIT_POINT_LIGHT
|
|
|
|
if (programbits & prprogrambits[PR_BIT_POINT_LIGHT].bit)
|
|
|
|
{
|
2009-02-14 14:31:58 +00:00
|
|
|
float inpos[4], pos[4];
|
|
|
|
float range[2];
|
|
|
|
float color[4];
|
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
inpos[0] = (float)prlights[lights[curlight]].y;
|
|
|
|
inpos[1] = -(float)prlights[lights[curlight]].z / 16.0f;
|
|
|
|
inpos[2] = -(float)prlights[lights[curlight]].x;
|
2009-02-14 14:31:58 +00:00
|
|
|
|
2009-03-31 23:23:06 +00:00
|
|
|
polymer_transformpoint(inpos, pos, curmodelviewmatrix);
|
2009-03-25 19:48:27 +00:00
|
|
|
|
|
|
|
// PR_BIT_SPOT_LIGHT
|
|
|
|
if (programbits & prprogrambits[PR_BIT_SPOT_LIGHT].bit)
|
|
|
|
{
|
|
|
|
float sinang, cosang, sinhorizang, coshorizangs;
|
|
|
|
float indir[3], dir[3];
|
|
|
|
|
|
|
|
cosang = (float)(sintable[(-prlights[lights[curlight]].angle+1024)&2047]) / 16383.0f;
|
|
|
|
sinang = (float)(sintable[(-prlights[lights[curlight]].angle+512)&2047]) / 16383.0f;
|
|
|
|
coshorizangs = (float)(sintable[(getangle(128, prlights[lights[curlight]].horiz-100)+1024)&2047]) / 16383.0f;
|
|
|
|
sinhorizang = (float)(sintable[(getangle(128, prlights[lights[curlight]].horiz-100)+512)&2047]) / 16383.0f;
|
|
|
|
|
|
|
|
indir[0] = inpos[0] + sinhorizang * cosang;
|
|
|
|
indir[1] = inpos[1] - coshorizangs;
|
|
|
|
indir[2] = inpos[2] - sinhorizang * sinang;
|
|
|
|
|
2009-03-31 23:23:06 +00:00
|
|
|
polymer_transformpoint(indir, dir, curmodelviewmatrix);
|
2009-03-25 19:48:27 +00:00
|
|
|
|
|
|
|
dir[0] -= pos[0];
|
|
|
|
dir[1] -= pos[1];
|
|
|
|
dir[2] -= pos[2];
|
|
|
|
|
|
|
|
indir[0] = (float)(sintable[(prlights[lights[curlight]].radius+512)&2047]) / 16383.0f;
|
|
|
|
indir[1] = (float)(sintable[(prlights[lights[curlight]].faderadius+512)&2047]) / 16383.0f;
|
|
|
|
indir[1] = 1.0 / (indir[1] - indir[0]);
|
|
|
|
|
|
|
|
bglUniform3fvARB(prprograms[programbits].uniform_spotDir, 1, dir);
|
|
|
|
bglUniform2fvARB(prprograms[programbits].uniform_spotRadius, 1, indir);
|
2009-03-26 16:32:00 +00:00
|
|
|
|
2010-07-25 02:16:22 +00:00
|
|
|
// PR_BIT_PROJECTION_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_PROJECTION_MAP].bit)
|
2009-03-26 16:32:00 +00:00
|
|
|
{
|
|
|
|
GLfloat matrix[16];
|
|
|
|
|
|
|
|
bglMatrixMode(GL_TEXTURE);
|
|
|
|
bglLoadMatrixf(shadowBias);
|
|
|
|
bglMultMatrixf(prlights[lights[curlight]].proj);
|
|
|
|
bglMultMatrixf(prlights[lights[curlight]].transform);
|
2014-09-30 04:04:30 +00:00
|
|
|
if (material->mdspritespace == GL_TRUE)
|
2009-03-27 12:56:42 +00:00
|
|
|
bglMultMatrixf(spritemodelview);
|
2009-03-26 16:32:00 +00:00
|
|
|
bglGetFloatv(GL_TEXTURE_MATRIX, matrix);
|
|
|
|
bglLoadIdentity();
|
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
|
|
bglUniformMatrix4fvARB(prprograms[programbits].uniform_shadowProjMatrix, 1, GL_FALSE, matrix);
|
|
|
|
|
2010-07-25 02:16:22 +00:00
|
|
|
// PR_BIT_SHADOW_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_SHADOW_MAP].bit)
|
|
|
|
{
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
|
|
|
bglBindTexture(prrts[prlights[lights[curlight]].rtindex].target, prrts[prlights[lights[curlight]].rtindex].z);
|
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_shadowMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
}
|
2009-05-12 20:08:38 +00:00
|
|
|
|
|
|
|
// PR_BIT_LIGHT_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_LIGHT_MAP].bit)
|
|
|
|
{
|
|
|
|
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
|
|
|
|
bglBindTexture(GL_TEXTURE_2D, prlights[lights[curlight]].lightmap);
|
|
|
|
|
|
|
|
bglUniform1iARB(prprograms[programbits].uniform_lightMap, texunit);
|
|
|
|
|
|
|
|
texunit++;
|
|
|
|
}
|
2009-03-26 16:32:00 +00:00
|
|
|
}
|
2009-03-25 19:48:27 +00:00
|
|
|
}
|
2009-02-14 14:31:58 +00:00
|
|
|
|
2009-03-25 13:23:35 +00:00
|
|
|
range[0] = prlights[lights[curlight]].range / 1000.0f;
|
2009-06-06 13:48:52 +00:00
|
|
|
range[1] = 1 / (range[0] * range[0]);
|
2009-02-05 08:56:59 +00:00
|
|
|
|
2009-03-12 13:51:30 +00:00
|
|
|
color[0] = prlights[lights[curlight]].color[0] / 255.0f;
|
|
|
|
color[1] = prlights[lights[curlight]].color[1] / 255.0f;
|
|
|
|
color[2] = prlights[lights[curlight]].color[2] / 255.0f;
|
2009-02-14 14:31:58 +00:00
|
|
|
|
2012-10-21 04:52:43 +00:00
|
|
|
// If this isn't a lighting-only pass, just negate the components
|
|
|
|
if (!curlight && prlights[lights[curlight]].publicflags.negative) {
|
|
|
|
color[0] = -color[0];
|
|
|
|
color[1] = -color[1];
|
|
|
|
color[2] = -color[2];
|
|
|
|
}
|
|
|
|
|
2009-03-12 13:51:30 +00:00
|
|
|
bglLightfv(GL_LIGHT0, GL_AMBIENT, pos);
|
|
|
|
bglLightfv(GL_LIGHT0, GL_DIFFUSE, color);
|
2014-09-30 04:04:30 +00:00
|
|
|
if (material->mdspritespace == GL_TRUE) {
|
2010-01-24 05:57:43 +00:00
|
|
|
float mdspritespacepos[3];
|
|
|
|
polymer_transformpoint(inpos, mdspritespacepos, (float *)mdspritespace);
|
|
|
|
bglLightfv(GL_LIGHT0, GL_SPECULAR, mdspritespacepos);
|
|
|
|
} else {
|
|
|
|
bglLightfv(GL_LIGHT0, GL_SPECULAR, inpos);
|
|
|
|
}
|
2009-03-12 13:51:30 +00:00
|
|
|
bglLightfv(GL_LIGHT0, GL_LINEAR_ATTENUATION, &range[1]);
|
2008-11-27 23:00:57 +00:00
|
|
|
}
|
|
|
|
|
2008-11-27 22:26:46 +00:00
|
|
|
bglActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
return (programbits);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void polymer_unbindmaterial(int32_t programbits)
|
2008-11-27 16:19:24 +00:00
|
|
|
{
|
2009-03-12 13:51:30 +00:00
|
|
|
// repair any dirty GL state here
|
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
// PR_BIT_ANIM_INTERPOLATION
|
|
|
|
if (programbits & prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit)
|
|
|
|
{
|
2009-04-14 13:58:38 +00:00
|
|
|
if (prprograms[programbits].attrib_nextFrameNormal != -1)
|
|
|
|
bglDisableVertexAttribArrayARB(prprograms[programbits].attrib_nextFrameNormal);
|
2008-11-27 16:19:24 +00:00
|
|
|
bglDisableVertexAttribArrayARB(prprograms[programbits].attrib_nextFrameData);
|
|
|
|
}
|
|
|
|
|
2009-03-12 13:51:30 +00:00
|
|
|
// PR_BIT_LIGHTING_PASS
|
|
|
|
if (programbits & prprogrambits[PR_BIT_LIGHTING_PASS].bit)
|
|
|
|
{
|
2010-12-17 03:56:25 +00:00
|
|
|
bglPopAttrib();
|
2009-03-12 13:51:30 +00:00
|
|
|
}
|
|
|
|
|
2010-01-24 05:57:43 +00:00
|
|
|
// PR_BIT_NORMAL_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_NORMAL_MAP].bit)
|
|
|
|
{
|
|
|
|
bglDisableVertexAttribArrayARB(prprograms[programbits].attrib_T);
|
|
|
|
bglDisableVertexAttribArrayARB(prprograms[programbits].attrib_B);
|
|
|
|
bglDisableVertexAttribArrayARB(prprograms[programbits].attrib_N);
|
|
|
|
}
|
|
|
|
|
2008-11-27 16:19:24 +00:00
|
|
|
bglUseProgramObjectARB(0);
|
2008-11-25 11:32:49 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void polymer_compileprogram(int32_t programbits)
|
2008-11-25 09:07:38 +00:00
|
|
|
{
|
2009-01-16 05:03:12 +00:00
|
|
|
int32_t i, enabledbits;
|
2008-11-25 09:07:38 +00:00
|
|
|
GLhandleARB vert, frag, program;
|
2012-07-01 22:11:33 +00:00
|
|
|
const GLcharARB* source[PR_BIT_COUNT * 2];
|
2008-11-25 09:07:38 +00:00
|
|
|
GLcharARB infobuffer[PR_INFO_LOG_BUFFER_SIZE];
|
2009-04-14 13:58:38 +00:00
|
|
|
GLint linkstatus;
|
2008-11-25 09:07:38 +00:00
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
// --------- VERTEX
|
2008-11-25 09:07:38 +00:00
|
|
|
vert = bglCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
|
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
enabledbits = i = 0;
|
2008-11-25 09:07:38 +00:00
|
|
|
while (i < PR_BIT_COUNT)
|
|
|
|
{
|
|
|
|
if (programbits & prprogrambits[i].bit)
|
2008-11-25 11:32:49 +00:00
|
|
|
source[enabledbits++] = prprogrambits[i].vert_def;
|
2008-11-25 09:07:38 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
while (i < PR_BIT_COUNT)
|
|
|
|
{
|
|
|
|
if (programbits & prprogrambits[i].bit)
|
2008-11-25 11:32:49 +00:00
|
|
|
source[enabledbits++] = prprogrambits[i].vert_prog;
|
2008-11-25 09:07:38 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2012-07-01 22:11:33 +00:00
|
|
|
bglShaderSourceARB(vert, enabledbits, source, NULL);
|
2008-11-25 09:07:38 +00:00
|
|
|
|
|
|
|
bglCompileShaderARB(vert);
|
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
// --------- FRAGMENT
|
2008-11-25 09:07:38 +00:00
|
|
|
frag = bglCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
|
|
|
|
|
|
|
|
enabledbits = i = 0;
|
|
|
|
while (i < PR_BIT_COUNT)
|
|
|
|
{
|
|
|
|
if (programbits & prprogrambits[i].bit)
|
2008-11-25 11:32:49 +00:00
|
|
|
source[enabledbits++] = prprogrambits[i].frag_def;
|
2008-11-25 09:07:38 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
while (i < PR_BIT_COUNT)
|
|
|
|
{
|
|
|
|
if (programbits & prprogrambits[i].bit)
|
2008-11-25 11:32:49 +00:00
|
|
|
source[enabledbits++] = prprogrambits[i].frag_prog;
|
2008-11-25 09:07:38 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
bglShaderSourceARB(frag, enabledbits, (const GLcharARB**)source, NULL);
|
2008-11-25 09:07:38 +00:00
|
|
|
|
|
|
|
bglCompileShaderARB(frag);
|
|
|
|
|
2008-11-25 11:32:49 +00:00
|
|
|
// --------- PROGRAM
|
2008-11-25 09:07:38 +00:00
|
|
|
program = bglCreateProgramObjectARB();
|
|
|
|
|
|
|
|
bglAttachObjectARB(program, vert);
|
|
|
|
bglAttachObjectARB(program, frag);
|
|
|
|
|
|
|
|
bglLinkProgramARB(program);
|
|
|
|
|
2009-04-14 13:58:38 +00:00
|
|
|
bglGetObjectParameterivARB(program, GL_OBJECT_LINK_STATUS_ARB, &linkstatus);
|
|
|
|
|
2008-11-25 09:07:38 +00:00
|
|
|
bglGetInfoLogARB(program, PR_INFO_LOG_BUFFER_SIZE, NULL, infobuffer);
|
|
|
|
|
2008-11-26 08:37:14 +00:00
|
|
|
prprograms[programbits].handle = program;
|
2008-11-25 09:07:38 +00:00
|
|
|
|
2012-01-12 20:48:17 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
if (pr_verbosity >= 1)
|
|
|
|
#else
|
|
|
|
if (pr_verbosity >= 2)
|
|
|
|
#endif
|
|
|
|
OSD_Printf("PR : Compiling GPU program with bits (octal) %o...\n", (unsigned)programbits);
|
2009-04-14 13:58:38 +00:00
|
|
|
if (!linkstatus) {
|
2012-01-12 20:48:17 +00:00
|
|
|
OSD_Printf("PR : Failed to compile GPU program with bits (octal) %o!\n", (unsigned)programbits);
|
2009-04-14 13:58:38 +00:00
|
|
|
if (pr_verbosity >= 1) OSD_Printf("PR : Compilation log:\n%s\n", infobuffer);
|
2008-11-29 20:16:19 +00:00
|
|
|
bglGetShaderSourceARB(vert, PR_INFO_LOG_BUFFER_SIZE, NULL, infobuffer);
|
2009-04-14 13:58:38 +00:00
|
|
|
if (pr_verbosity >= 1) OSD_Printf("PR : Vertex source dump:\n%s\n", infobuffer);
|
2008-11-29 20:16:19 +00:00
|
|
|
bglGetShaderSourceARB(frag, PR_INFO_LOG_BUFFER_SIZE, NULL, infobuffer);
|
2009-04-14 13:58:38 +00:00
|
|
|
if (pr_verbosity >= 1) OSD_Printf("PR : Fragment source dump:\n%s\n", infobuffer);
|
2008-11-29 20:16:19 +00:00
|
|
|
}
|
2008-11-27 16:19:24 +00:00
|
|
|
|
|
|
|
// --------- ATTRIBUTE/UNIFORM LOCATIONS
|
|
|
|
|
|
|
|
// PR_BIT_ANIM_INTERPOLATION
|
|
|
|
if (programbits & prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].attrib_nextFrameData = bglGetAttribLocationARB(program, "nextFrameData");
|
2009-03-10 14:30:34 +00:00
|
|
|
prprograms[programbits].attrib_nextFrameNormal = bglGetAttribLocationARB(program, "nextFrameNormal");
|
2008-11-27 16:19:24 +00:00
|
|
|
prprograms[programbits].uniform_frameProgress = bglGetUniformLocationARB(program, "frameProgress");
|
|
|
|
}
|
2008-11-27 22:26:46 +00:00
|
|
|
|
2009-03-13 15:18:46 +00:00
|
|
|
// PR_BIT_NORMAL_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_NORMAL_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].attrib_T = bglGetAttribLocationARB(program, "T");
|
|
|
|
prprograms[programbits].attrib_B = bglGetAttribLocationARB(program, "B");
|
|
|
|
prprograms[programbits].attrib_N = bglGetAttribLocationARB(program, "N");
|
2009-03-28 18:25:30 +00:00
|
|
|
prprograms[programbits].uniform_eyePosition = bglGetUniformLocationARB(program, "eyePosition");
|
|
|
|
prprograms[programbits].uniform_normalMap = bglGetUniformLocationARB(program, "normalMap");
|
2009-03-29 15:16:33 +00:00
|
|
|
prprograms[programbits].uniform_normalBias = bglGetUniformLocationARB(program, "normalBias");
|
2009-03-13 15:18:46 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 03:12:38 +00:00
|
|
|
// PR_BIT_ART_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_ART_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_artMap = bglGetUniformLocationARB(program, "artMap");
|
|
|
|
prprograms[programbits].uniform_basePalMap = bglGetUniformLocationARB(program, "basePalMap");
|
|
|
|
prprograms[programbits].uniform_lookupMap = bglGetUniformLocationARB(program, "lookupMap");
|
2013-05-07 07:48:08 +00:00
|
|
|
prprograms[programbits].uniform_shadeOffset = bglGetUniformLocationARB(program, "shadeOffset");
|
|
|
|
prprograms[programbits].uniform_visibility = bglGetUniformLocationARB(program, "visibility");
|
2013-05-06 03:12:38 +00:00
|
|
|
}
|
|
|
|
|
2008-11-27 22:26:46 +00:00
|
|
|
// PR_BIT_DIFFUSE_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_diffuseMap = bglGetUniformLocationARB(program, "diffuseMap");
|
|
|
|
prprograms[programbits].uniform_diffuseScale = bglGetUniformLocationARB(program, "diffuseScale");
|
|
|
|
}
|
|
|
|
|
2010-12-29 06:23:49 +00:00
|
|
|
// PR_BIT_HIGHPALOOKUP_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_HIGHPALOOKUP_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_highPalookupMap = bglGetUniformLocationARB(program, "highPalookupMap");
|
|
|
|
}
|
|
|
|
|
2008-11-27 22:26:46 +00:00
|
|
|
// PR_BIT_DIFFUSE_DETAIL_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_DIFFUSE_DETAIL_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_detailMap = bglGetUniformLocationARB(program, "detailMap");
|
|
|
|
prprograms[programbits].uniform_detailScale = bglGetUniformLocationARB(program, "detailScale");
|
|
|
|
}
|
2009-02-05 08:56:59 +00:00
|
|
|
|
2009-03-28 16:14:10 +00:00
|
|
|
// PR_BIT_SPECULAR_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_SPECULAR_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_specMap = bglGetUniformLocationARB(program, "specMap");
|
|
|
|
}
|
|
|
|
|
2009-03-28 12:14:37 +00:00
|
|
|
// PR_BIT_SPECULAR_MATERIAL
|
|
|
|
if (programbits & prprogrambits[PR_BIT_SPECULAR_MATERIAL].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_specMaterial = bglGetUniformLocationARB(program, "specMaterial");
|
|
|
|
}
|
|
|
|
|
2009-03-28 11:43:16 +00:00
|
|
|
// PR_BIT_MIRROR_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_MIRROR_MAP].bit)
|
2009-03-23 14:18:20 +00:00
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_mirrorMap = bglGetUniformLocationARB(program, "mirrorMap");
|
|
|
|
}
|
2012-12-16 19:18:10 +00:00
|
|
|
#ifdef PR_LINEAR_FOG
|
|
|
|
if (programbits & prprogrambits[PR_BIT_FOG].bit)
|
|
|
|
{
|
2016-06-05 04:46:28 +00:00
|
|
|
prprograms[programbits].uniform_linearFog = bglGetUniformLocationARB(program, "linearFog");
|
2012-12-16 19:18:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-03-28 11:43:16 +00:00
|
|
|
// PR_BIT_GLOW_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_GLOW_MAP].bit)
|
2008-11-27 23:00:57 +00:00
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_glowMap = bglGetUniformLocationARB(program, "glowMap");
|
|
|
|
}
|
2009-03-12 13:51:30 +00:00
|
|
|
|
2010-07-25 02:16:22 +00:00
|
|
|
// PR_BIT_PROJECTION_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_PROJECTION_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_shadowProjMatrix = bglGetUniformLocationARB(program, "shadowProjMatrix");
|
|
|
|
}
|
|
|
|
|
2009-03-26 16:32:00 +00:00
|
|
|
// PR_BIT_SHADOW_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_SHADOW_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_shadowMap = bglGetUniformLocationARB(program, "shadowMap");
|
|
|
|
}
|
|
|
|
|
2009-05-12 20:08:38 +00:00
|
|
|
// PR_BIT_LIGHT_MAP
|
|
|
|
if (programbits & prprogrambits[PR_BIT_LIGHT_MAP].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_lightMap = bglGetUniformLocationARB(program, "lightMap");
|
|
|
|
}
|
|
|
|
|
2009-03-25 19:48:27 +00:00
|
|
|
// PR_BIT_SPOT_LIGHT
|
|
|
|
if (programbits & prprogrambits[PR_BIT_SPOT_LIGHT].bit)
|
|
|
|
{
|
|
|
|
prprograms[programbits].uniform_spotDir = bglGetUniformLocationARB(program, "spotDir");
|
|
|
|
prprograms[programbits].uniform_spotRadius = bglGetUniformLocationARB(program, "spotRadius");
|
|
|
|
}
|
2008-11-25 09:07:38 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 14:31:58 +00:00
|
|
|
// LIGHTS
|
2009-06-07 12:51:00 +00:00
|
|
|
static void polymer_removelight(int16_t lighti)
|
|
|
|
{
|
|
|
|
_prplanelist* oldhead;
|
|
|
|
|
|
|
|
while (prlights[lighti].planelist)
|
|
|
|
{
|
|
|
|
polymer_deleteplanelight(prlights[lighti].planelist->plane, lighti);
|
|
|
|
oldhead = prlights[lighti].planelist;
|
|
|
|
prlights[lighti].planelist = prlights[lighti].planelist->n;
|
2014-09-30 04:04:30 +00:00
|
|
|
oldhead->n = plpool;
|
|
|
|
plpool = oldhead;
|
|
|
|
plpool->plane = NULL;
|
2009-06-07 12:51:00 +00:00
|
|
|
}
|
|
|
|
prlights[lighti].planecount = 0;
|
2009-06-09 06:19:58 +00:00
|
|
|
prlights[lighti].planelist = NULL;
|
2009-06-07 12:51:00 +00:00
|
|
|
}
|
2009-06-06 13:12:29 +00:00
|
|
|
|
|
|
|
static void polymer_updatelights(void)
|
|
|
|
{
|
2009-06-06 22:30:53 +00:00
|
|
|
int32_t i = 0;
|
2009-06-06 13:12:29 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
do
|
2009-06-06 13:12:29 +00:00
|
|
|
{
|
2011-10-02 07:09:15 +00:00
|
|
|
_prlight* light = &prlights[i];
|
|
|
|
|
|
|
|
if (light->flags.active && light->flags.invalidate) {
|
2009-06-06 13:12:29 +00:00
|
|
|
// highly suboptimal
|
|
|
|
polymer_removelight(i);
|
|
|
|
|
2012-10-21 18:41:09 +00:00
|
|
|
if (light->radius)
|
2011-10-02 07:09:15 +00:00
|
|
|
polymer_processspotlight(light);
|
2010-07-26 22:36:45 +00:00
|
|
|
|
2009-06-06 13:12:29 +00:00
|
|
|
polymer_culllight(i);
|
|
|
|
|
2011-10-02 07:09:15 +00:00
|
|
|
light->flags.invalidate = 0;
|
2009-06-06 13:12:29 +00:00
|
|
|
}
|
|
|
|
|
2011-10-02 07:09:15 +00:00
|
|
|
if (light->flags.active) {
|
|
|
|
// get the texture handle for the lightmap
|
|
|
|
if (light->radius && light->tilenum > 0)
|
|
|
|
{
|
|
|
|
int16_t picnum = light->tilenum;
|
|
|
|
pthtyp* pth;
|
|
|
|
|
2012-11-15 21:09:53 +00:00
|
|
|
DO_TILE_ANIM(picnum, 0);
|
2011-10-02 07:09:15 +00:00
|
|
|
|
|
|
|
if (!waloff[picnum])
|
|
|
|
loadtile(picnum);
|
|
|
|
|
|
|
|
pth = NULL;
|
2015-12-04 11:52:54 +00:00
|
|
|
pth = texcache_fetch(picnum, 0, 0, DAMETH_NOMASK);
|
2011-10-02 07:09:15 +00:00
|
|
|
|
|
|
|
if (pth)
|
|
|
|
light->lightmap = pth->glpic;
|
|
|
|
}
|
|
|
|
|
|
|
|
light->rtindex = -1;
|
|
|
|
}
|
2009-06-06 13:12:29 +00:00
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
while (++i < PR_MAXLIGHTS);
|
2009-06-06 13:12:29 +00:00
|
|
|
}
|
|
|
|
|
2009-06-08 00:31:53 +00:00
|
|
|
static inline void polymer_resetplanelights(_prplane* plane)
|
2009-06-06 13:12:29 +00:00
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemset(&plane->lights[0], -1, sizeof(plane->lights[0]) * plane->lightcount);
|
2009-06-06 13:12:29 +00:00
|
|
|
plane->lightcount = 0;
|
|
|
|
}
|
2009-05-12 20:08:38 +00:00
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
static void polymer_addplanelight(_prplane* plane, int16_t lighti)
|
|
|
|
{
|
2009-06-07 12:51:00 +00:00
|
|
|
_prplanelist* oldhead;
|
2010-07-26 22:36:45 +00:00
|
|
|
int32_t i = 0;
|
2009-04-12 13:51:43 +00:00
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
if (plane->lightcount)
|
2009-06-01 20:55:36 +00:00
|
|
|
{
|
2014-09-30 04:04:30 +00:00
|
|
|
if (plane->lightcount == PR_MAXLIGHTS - 1)
|
|
|
|
return;
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (plane->lights[i++] == lighti)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
while (i < plane->lightcount);
|
|
|
|
|
|
|
|
i = 0;
|
2009-06-09 06:19:58 +00:00
|
|
|
while (i < plane->lightcount && prlights[plane->lights[i]].priority < prlights[lighti].priority)
|
2009-06-07 12:51:00 +00:00
|
|
|
i++;
|
2010-07-26 22:36:45 +00:00
|
|
|
Bmemmove(&plane->lights[i+1], &plane->lights[i], sizeof(int16_t) * (plane->lightcount - i));
|
2009-06-09 06:19:58 +00:00
|
|
|
}
|
2009-06-06 13:40:15 +00:00
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
plane->lights[i] = lighti;
|
|
|
|
plane->lightcount++;
|
2009-06-06 22:30:53 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
out:
|
|
|
|
oldhead = prlights[lighti].planelist;
|
|
|
|
while (oldhead != NULL)
|
|
|
|
{
|
|
|
|
if (oldhead->plane == plane) return;
|
|
|
|
oldhead = oldhead->n;
|
|
|
|
}
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
oldhead = prlights[lighti].planelist;
|
2014-09-30 04:04:30 +00:00
|
|
|
if (plpool == NULL)
|
|
|
|
{
|
|
|
|
prlights[lighti].planelist = (_prplanelist *) Xmalloc(sizeof(_prplanelist));
|
|
|
|
prlights[lighti].planelist->n = oldhead;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prlights[lighti].planelist = plpool;
|
|
|
|
plpool = plpool->n;
|
|
|
|
prlights[lighti].planelist->n = oldhead;
|
|
|
|
}
|
2009-06-07 12:51:00 +00:00
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
prlights[lighti].planelist->plane = plane;
|
|
|
|
prlights[lighti].planecount++;
|
2009-06-01 20:55:36 +00:00
|
|
|
}
|
2009-04-12 13:51:43 +00:00
|
|
|
|
2009-06-06 22:30:53 +00:00
|
|
|
static inline void polymer_deleteplanelight(_prplane* plane, int16_t lighti)
|
2009-06-01 20:55:36 +00:00
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
int32_t i = plane->lightcount-1;
|
2009-04-12 13:51:43 +00:00
|
|
|
|
2009-06-08 00:31:53 +00:00
|
|
|
while (i >= 0)
|
2009-06-01 20:55:36 +00:00
|
|
|
{
|
|
|
|
if (plane->lights[i] == lighti)
|
|
|
|
{
|
2010-07-26 22:36:45 +00:00
|
|
|
Bmemmove(&plane->lights[i], &plane->lights[i+1], sizeof(int16_t) * (plane->lightcount - i));
|
2009-06-01 20:55:36 +00:00
|
|
|
plane->lightcount--;
|
|
|
|
return;
|
|
|
|
}
|
2009-06-08 00:31:53 +00:00
|
|
|
i--;
|
2009-04-12 13:51:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-19 09:49:27 +00:00
|
|
|
static int32_t polymer_planeinlight(_prplane* plane, _prlight* light)
|
2009-03-08 20:38:51 +00:00
|
|
|
{
|
|
|
|
float lightpos[3];
|
2009-06-09 06:19:58 +00:00
|
|
|
int32_t i, j, k, l;
|
2009-03-08 20:38:51 +00:00
|
|
|
|
2009-04-19 09:49:27 +00:00
|
|
|
if (!plane->vertcount)
|
|
|
|
return 0;
|
|
|
|
|
2009-03-25 21:14:51 +00:00
|
|
|
if (light->radius)
|
|
|
|
return polymer_planeinfrustum(plane, light->frustum);
|
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
lightpos[0] = (float)light->y;
|
|
|
|
lightpos[1] = -(float)light->z / 16.0f;
|
|
|
|
lightpos[2] = -(float)light->x;
|
2009-03-08 20:38:51 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
2009-06-07 03:13:55 +00:00
|
|
|
do
|
2009-03-08 20:38:51 +00:00
|
|
|
{
|
|
|
|
j = k = l = 0;
|
|
|
|
|
2009-06-07 03:13:55 +00:00
|
|
|
do
|
2009-03-08 20:38:51 +00:00
|
|
|
{
|
2015-07-13 03:46:35 +00:00
|
|
|
if ((&plane->buffer[j].x)[i] > (lightpos[i] + light->range)) k++;
|
|
|
|
if ((&plane->buffer[j].x)[i] < (lightpos[i] - light->range)) l++;
|
2009-03-08 20:38:51 +00:00
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
while (++j < plane->vertcount);
|
2009-03-08 20:38:51 +00:00
|
|
|
|
|
|
|
if ((k == plane->vertcount) || (l == plane->vertcount))
|
|
|
|
return 0;
|
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
while (++i < 3);
|
2009-03-08 20:38:51 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
static void polymer_invalidateplanelights(_prplane* plane)
|
|
|
|
{
|
2010-07-26 22:36:45 +00:00
|
|
|
int32_t i = plane->lightcount;
|
2009-06-01 20:55:36 +00:00
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
while (i--)
|
2009-06-01 20:55:36 +00:00
|
|
|
{
|
2014-09-30 04:04:30 +00:00
|
|
|
if (((unsigned)plane->lights[i] < PR_MAXLIGHTS) && (prlights[plane->lights[i]].flags.active))
|
2009-06-01 20:55:36 +00:00
|
|
|
prlights[plane->lights[i]].flags.invalidate = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void polymer_invalidatesectorlights(int16_t sectnum)
|
|
|
|
{
|
|
|
|
int32_t i;
|
2009-06-09 06:19:58 +00:00
|
|
|
_prsector *s = prsectors[sectnum];
|
|
|
|
sectortype *sec = §or[sectnum];
|
2009-06-01 20:55:36 +00:00
|
|
|
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
|
|
|
|
polymer_invalidateplanelights(&s->floor);
|
|
|
|
polymer_invalidateplanelights(&s->ceil);
|
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
i = sec->wallnum;
|
2009-06-01 20:55:36 +00:00
|
|
|
|
2010-07-03 08:53:57 +00:00
|
|
|
while (i--)
|
|
|
|
{
|
2010-07-26 22:36:45 +00:00
|
|
|
_prwall *w;
|
2010-07-03 08:53:57 +00:00
|
|
|
if (!(w = prwalls[sec->wallptr + i])) continue;
|
2009-06-01 20:55:36 +00:00
|
|
|
|
|
|
|
polymer_invalidateplanelights(&w->wall);
|
|
|
|
polymer_invalidateplanelights(&w->over);
|
|
|
|
polymer_invalidateplanelights(&w->mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void polymer_processspotlight(_prlight* light)
|
|
|
|
{
|
|
|
|
float radius, ang, horizang, lightpos[3];
|
|
|
|
|
|
|
|
// hack to avoid lights beams perpendicular to walls
|
|
|
|
if ((light->horiz <= 100) && (light->horiz > 90))
|
|
|
|
light->horiz = 90;
|
|
|
|
if ((light->horiz > 100) && (light->horiz < 110))
|
|
|
|
light->horiz = 110;
|
|
|
|
|
2009-07-12 01:55:34 +00:00
|
|
|
lightpos[0] = (float)light->y;
|
|
|
|
lightpos[1] = -(float)light->z / 16.0f;
|
|
|
|
lightpos[2] = -(float)light->x;
|
2009-06-01 20:55:36 +00:00
|
|
|
|
2012-10-21 03:41:13 +00:00
|
|
|
// calculate the spot light transformations and matrices
|
2009-06-01 20:55:36 +00:00
|
|
|
radius = (float)(light->radius) / (2048.0f / 360.0f);
|
|
|
|
ang = (float)(light->angle) / (2048.0f / 360.0f);
|
|
|
|
horizang = (float)(-getangle(128, light->horiz-100)) / (2048.0f / 360.0f);
|
|
|
|
|
|
|
|
bglMatrixMode(GL_PROJECTION);
|
|
|
|
bglPushMatrix();
|
|
|
|
bglLoadIdentity();
|
|
|
|
bgluPerspective(radius * 2, 1, 0.1f, light->range / 1000.0f);
|
|
|
|
bglGetFloatv(GL_PROJECTION_MATRIX, light->proj);
|
|
|
|
bglPopMatrix();
|
|
|
|
|
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglPushMatrix();
|
|
|
|
bglLoadIdentity();
|
|
|
|
bglRotatef(horizang, 1.0f, 0.0f, 0.0f);
|
|
|
|
bglRotatef(ang, 0.0f, 1.0f, 0.0f);
|
|
|
|
bglScalef(1.0f / 1000.0f, 1.0f / 1000.0f, 1.0f / 1000.0f);
|
|
|
|
bglTranslatef(-lightpos[0], -lightpos[1], -lightpos[2]);
|
|
|
|
bglGetFloatv(GL_MODELVIEW_MATRIX, light->transform);
|
|
|
|
bglPopMatrix();
|
|
|
|
|
|
|
|
polymer_extractfrustum(light->transform, light->proj, light->frustum);
|
|
|
|
|
|
|
|
light->rtindex = -1;
|
|
|
|
light->lightmap = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void polymer_culllight(int16_t lighti)
|
2009-03-08 20:38:51 +00:00
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
_prlight* light = &prlights[lighti];
|
|
|
|
int32_t front = 0;
|
|
|
|
int32_t back = 1;
|
2009-03-08 20:38:51 +00:00
|
|
|
int32_t i;
|
2009-06-07 03:13:55 +00:00
|
|
|
int32_t j;
|
2009-06-07 20:27:45 +00:00
|
|
|
int32_t zdiff;
|
2011-08-20 21:05:49 +00:00
|
|
|
int32_t checkror;
|
|
|
|
int16_t bunchnum;
|
|
|
|
int16_t ns;
|
2009-03-08 20:38:51 +00:00
|
|
|
_prsector *s;
|
|
|
|
_prwall *w;
|
|
|
|
sectortype *sec;
|
|
|
|
|
2009-04-19 09:49:27 +00:00
|
|
|
Bmemset(drawingstate, 0, sizeof(int16_t) * numsectors);
|
|
|
|
drawingstate[light->sector] = 1;
|
2009-03-08 20:38:51 +00:00
|
|
|
|
|
|
|
sectorqueue[0] = light->sector;
|
|
|
|
|
2010-07-26 22:36:45 +00:00
|
|
|
do
|
2009-03-08 20:38:51 +00:00
|
|
|
{
|
|
|
|
s = prsectors[sectorqueue[front]];
|
|
|
|
sec = §or[sectorqueue[front]];
|
|
|
|
|
2009-04-14 08:39:13 +00:00
|
|
|
polymer_pokesector(sectorqueue[front]);
|
|
|
|
|
2011-08-20 21:05:49 +00:00
|
|
|
checkror = FALSE;
|
|
|
|
|
2009-06-07 20:27:45 +00:00
|
|
|
zdiff = light->z - s->floorz;
|
|
|
|
if (zdiff < 0)
|
|
|
|
zdiff = -zdiff;
|
|
|
|
zdiff >>= 4;
|
|
|
|
|
2009-06-08 00:31:53 +00:00
|
|
|
if (!light->radius && !(sec->floorstat & 1)) {
|
2011-08-20 21:05:49 +00:00
|
|
|
if (zdiff < light->range) {
|
2009-06-07 20:27:45 +00:00
|
|
|
polymer_addplanelight(&s->floor, lighti);
|
2011-08-20 21:05:49 +00:00
|
|
|
checkror = TRUE;
|
|
|
|
}
|
|
|
|
} else if (polymer_planeinlight(&s->floor, light)) {
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_addplanelight(&s->floor, lighti);
|
2011-08-20 21:05:49 +00:00
|
|
|
checkror = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-25 15:33:02 +00:00
|
|
|
#ifdef YAX_ENABLE
|
2011-08-20 21:05:49 +00:00
|
|
|
// queue ROR neighbors
|
2013-04-09 17:35:11 +00:00
|
|
|
if (checkror &&
|
2011-08-20 21:05:49 +00:00
|
|
|
(bunchnum = yax_getbunch(sectorqueue[front], YAX_FLOOR)) >= 0) {
|
|
|
|
|
|
|
|
for (SECTORS_OF_BUNCH(bunchnum, YAX_CEILING, ns)) {
|
|
|
|
|
|
|
|
if (ns >= 0 && !drawingstate[ns] &&
|
|
|
|
polymer_planeinlight(&prsectors[ns]->ceil, light)) {
|
|
|
|
|
|
|
|
sectorqueue[back++] = ns;
|
|
|
|
drawingstate[ns] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-25 15:33:02 +00:00
|
|
|
#endif
|
2011-08-20 21:05:49 +00:00
|
|
|
checkror = FALSE;
|
2009-06-07 03:13:55 +00:00
|
|
|
|
2009-06-07 20:27:45 +00:00
|
|
|
zdiff = light->z - s->ceilingz;
|
|
|
|
if (zdiff < 0)
|
|
|
|
zdiff = -zdiff;
|
|
|
|
zdiff >>= 4;
|
|
|
|
|
2009-06-08 00:31:53 +00:00
|
|
|
if (!light->radius && !(sec->ceilingstat & 1)) {
|
2011-08-20 21:05:49 +00:00
|
|
|
if (zdiff < light->range) {
|
2009-06-07 20:27:45 +00:00
|
|
|
polymer_addplanelight(&s->ceil, lighti);
|
2011-08-20 21:05:49 +00:00
|
|
|
checkror = TRUE;
|
|
|
|
}
|
|
|
|
} else if (polymer_planeinlight(&s->ceil, light)) {
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_addplanelight(&s->ceil, lighti);
|
2011-08-20 21:05:49 +00:00
|
|
|
checkror = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-12-25 15:33:02 +00:00
|
|
|
#ifdef YAX_ENABLE
|
2011-08-20 21:05:49 +00:00
|
|
|
// queue ROR neighbors
|
2013-04-09 17:35:11 +00:00
|
|
|
if (checkror &&
|
2011-08-20 21:05:49 +00:00
|
|
|
(bunchnum = yax_getbunch(sectorqueue[front], YAX_CEILING)) >= 0) {
|
|
|
|
|
|
|
|
for (SECTORS_OF_BUNCH(bunchnum, YAX_FLOOR, ns)) {
|
|
|
|
|
|
|
|
if (ns >= 0 && !drawingstate[ns] &&
|
|
|
|
polymer_planeinlight(&prsectors[ns]->floor, light)) {
|
|
|
|
|
|
|
|
sectorqueue[back++] = ns;
|
|
|
|
drawingstate[ns] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-25 15:33:02 +00:00
|
|
|
#endif
|
2009-03-08 20:38:51 +00:00
|
|
|
i = 0;
|
2009-04-19 09:49:27 +00:00
|
|
|
while (i < sec->wallnum)
|
2009-03-08 20:38:51 +00:00
|
|
|
{
|
|
|
|
w = prwalls[sec->wallptr + i];
|
|
|
|
|
2009-06-07 03:13:55 +00:00
|
|
|
j = 0;
|
|
|
|
|
2009-03-08 20:38:51 +00:00
|
|
|
if (polymer_planeinlight(&w->wall, light)) {
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_addplanelight(&w->wall, lighti);
|
2009-06-07 03:13:55 +00:00
|
|
|
j++;
|
2009-03-08 20:38:51 +00:00
|
|
|
}
|
2009-06-07 03:13:55 +00:00
|
|
|
|
2009-03-08 20:38:51 +00:00
|
|
|
if (polymer_planeinlight(&w->over, light)) {
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_addplanelight(&w->over, lighti);
|
2009-06-07 03:13:55 +00:00
|
|
|
j++;
|
2009-03-08 20:38:51 +00:00
|
|
|
}
|
2009-06-07 03:13:55 +00:00
|
|
|
|
|
|
|
// assume the light hits the middle section if it hits the top and bottom
|
2009-05-31 18:10:09 +00:00
|
|
|
if (wallvisible(light->x, light->y, sec->wallptr + i) &&
|
2009-06-07 03:13:55 +00:00
|
|
|
(j == 2 || polymer_planeinlight(&w->mask, light))) {
|
2009-04-14 07:01:55 +00:00
|
|
|
if ((w->mask.vertcount == 4) &&
|
2015-07-13 03:46:35 +00:00
|
|
|
(w->mask.buffer[0].y >= w->mask.buffer[3].y) &&
|
|
|
|
(w->mask.buffer[1].y >= w->mask.buffer[2].y))
|
2009-04-14 07:01:55 +00:00
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-06-01 20:55:36 +00:00
|
|
|
polymer_addplanelight(&w->mask, lighti);
|
2009-03-08 20:38:51 +00:00
|
|
|
|
2009-12-03 06:21:39 +00:00
|
|
|
if ((wall[sec->wallptr + i].nextsector >= 0) &&
|
2009-04-19 09:49:27 +00:00
|
|
|
(!drawingstate[wall[sec->wallptr + i].nextsector])) {
|
|
|
|
drawingstate[wall[sec->wallptr + i].nextsector] = 1;
|
2009-03-08 20:38:51 +00:00
|
|
|
sectorqueue[back] = wall[sec->wallptr + i].nextsector;
|
|
|
|
back++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
front++;
|
|
|
|
}
|
2010-07-26 22:36:45 +00:00
|
|
|
while (front != back);
|
|
|
|
|
|
|
|
i = MAXSPRITES-1;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
_prsprite *s = prsprites[i];
|
|
|
|
|
|
|
|
if ((sprite[i].cstat & 48) == 0 || s == NULL || sprite[i].statnum == MAXSTATUS || sprite[i].sectnum == MAXSECTORS)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (polymer_planeinlight(&s->plane, light))
|
|
|
|
polymer_addplanelight(&s->plane, lighti);
|
|
|
|
}
|
|
|
|
while (i--);
|
2009-03-08 20:38:51 +00:00
|
|
|
}
|
|
|
|
|
2009-03-26 16:32:00 +00:00
|
|
|
static void polymer_prepareshadows(void)
|
|
|
|
{
|
2009-04-01 17:58:22 +00:00
|
|
|
int16_t oviewangle, oglobalang;
|
2009-06-06 13:12:29 +00:00
|
|
|
int32_t i, j, k;
|
2009-03-26 17:45:12 +00:00
|
|
|
int32_t gx, gy, gz;
|
2009-03-27 10:39:18 +00:00
|
|
|
int32_t oldoverridematerial;
|
2009-03-26 16:32:00 +00:00
|
|
|
|
2009-04-01 17:58:22 +00:00
|
|
|
// for wallvisible()
|
|
|
|
gx = globalposx;
|
|
|
|
gy = globalposy;
|
|
|
|
gz = globalposz;
|
|
|
|
// build globals used by drawmasks
|
|
|
|
oviewangle = viewangle;
|
|
|
|
oglobalang = globalang;
|
|
|
|
|
2009-06-06 13:12:29 +00:00
|
|
|
i = j = k = 0;
|
2009-03-26 16:32:00 +00:00
|
|
|
|
2009-06-06 13:12:29 +00:00
|
|
|
while ((k < lightcount) && (j < pr_shadowcount))
|
2009-03-26 16:32:00 +00:00
|
|
|
{
|
2010-07-26 22:36:45 +00:00
|
|
|
while (!prlights[i].flags.active)
|
2009-06-01 20:55:36 +00:00
|
|
|
i++;
|
|
|
|
|
2012-10-21 03:41:13 +00:00
|
|
|
if (prlights[i].radius && prlights[i].publicflags.emitshadow &&
|
|
|
|
prlights[i].flags.isinview)
|
2009-03-26 16:32:00 +00:00
|
|
|
{
|
2009-06-01 20:55:36 +00:00
|
|
|
prlights[i].flags.isinview = 0;
|
2009-03-26 16:32:00 +00:00
|
|
|
prlights[i].rtindex = j + 1;
|
2009-06-01 21:11:26 +00:00
|
|
|
if (pr_verbosity >= 3) OSD_Printf("PR : Drawing shadow %i...\n", i);
|
2009-03-26 16:32:00 +00:00
|
|
|
|
|
|
|
bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, prrts[prlights[i].rtindex].fbo);
|
|
|
|
bglPushAttrib(GL_VIEWPORT_BIT);
|
|
|
|
bglViewport(0, 0, prrts[prlights[i].rtindex].xdim, prrts[prlights[i].rtindex].ydim);
|
|
|
|
|
|
|
|
bglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
bglMatrixMode(GL_PROJECTION);
|
|
|
|
bglPushMatrix();
|
|
|
|
bglLoadMatrixf(prlights[i].proj);
|
|
|
|
bglMatrixMode(GL_MODELVIEW);
|
|
|
|
bglLoadMatrixf(prlights[i].transform);
|
|
|
|
|
|
|
|
bglEnable(GL_POLYGON_OFFSET_FILL);
|
2009-03-27 13:46:40 +00:00
|
|
|
bglPolygonOffset(5, SHADOW_DEPTH_OFFSET);
|
2009-03-26 16:32:00 +00:00
|
|
|
|
2014-10-25 03:32:26 +00:00
|
|
|
set_globalpos(prlights[i].x, prlights[i].y, prlights[i].z);
|
2009-04-01 17:58:22 +00:00
|
|
|
|
|
|
|
// build globals used by rotatesprite
|
|
|
|
viewangle = prlights[i].angle;
|
2013-02-10 16:24:11 +00:00
|
|
|
set_globalang(prlights[i].angle);
|
2009-03-26 16:41:06 +00:00
|
|
|
|
2009-03-27 10:39:18 +00:00
|
|
|
oldoverridematerial = overridematerial;
|
|
|
|
// smooth model shadows
|
|
|
|
overridematerial = prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit;
|
|
|
|
// used by alpha-testing for sprite silhouette
|
|
|
|
overridematerial |= prprogrambits[PR_BIT_DIFFUSE_MAP].bit;
|
2010-12-29 06:23:49 +00:00
|
|
|
overridematerial |= prprogrambits[PR_BIT_DIFFUSE_MAP2].bit;
|
2009-03-27 10:39:18 +00:00
|
|
|
|
|
|
|
// to force sprite drawing
|
2009-03-27 11:39:10 +00:00
|
|
|
mirrors[depth++].plane = NULL;
|
2009-03-26 16:32:00 +00:00
|
|
|
polymer_displayrooms(prlights[i].sector);
|
2009-03-27 10:39:18 +00:00
|
|
|
depth--;
|
|
|
|
|
|
|
|
overridematerial = oldoverridematerial;
|
2009-03-26 16:32:00 +00:00
|
|
|
|
|
|
|
bglDisable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
|
|
|
|
bglMatrixMode(GL_PROJECTION);
|
|
|
|
bglPopMatrix();
|
|
|
|
|
|
|
|
bglPopAttrib();
|
|
|
|
bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
i++;
|
2009-06-06 13:12:29 +00:00
|
|
|
k++;
|
2009-03-26 16:32:00 +00:00
|
|
|
}
|
2009-04-01 17:58:22 +00:00
|
|
|
|
2014-10-25 03:32:26 +00:00
|
|
|
set_globalpos(gx, gy, gz);
|
2009-04-01 17:58:22 +00:00
|
|
|
|
|
|
|
viewangle = oviewangle;
|
2013-02-10 16:24:11 +00:00
|
|
|
set_globalang(oglobalang);
|
2009-03-26 16:32:00 +00:00
|
|
|
}
|
|
|
|
|
2009-03-23 14:18:20 +00:00
|
|
|
// RENDER TARGETS
|
|
|
|
static void polymer_initrendertargets(int32_t count)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
|
2011-07-22 22:00:53 +00:00
|
|
|
static int32_t ocount;
|
2011-07-24 15:15:57 +00:00
|
|
|
|
|
|
|
if (count == 0) // uninit
|
2011-07-22 22:00:53 +00:00
|
|
|
{
|
2011-07-24 15:15:57 +00:00
|
|
|
if (prrts)
|
2011-07-22 22:00:53 +00:00
|
|
|
{
|
2011-07-24 15:15:57 +00:00
|
|
|
for (i=0; i<ocount; i++)
|
|
|
|
{
|
|
|
|
if (prrts[i].color)
|
|
|
|
{
|
|
|
|
bglDeleteTextures(1, &prrts[i].color);
|
|
|
|
prrts[i].color = 0;
|
|
|
|
}
|
|
|
|
bglDeleteTextures(1, &prrts[i].z);
|
|
|
|
prrts[i].z = 0;
|
|
|
|
|
|
|
|
bglDeleteFramebuffersEXT(1, &prrts[i].fbo);
|
|
|
|
prrts[i].fbo = 0;
|
|
|
|
}
|
2015-09-23 17:55:31 +00:00
|
|
|
DO_FREE_AND_NULL(prrts);
|
2011-07-22 22:00:53 +00:00
|
|
|
}
|
|
|
|
|
2011-07-24 15:15:57 +00:00
|
|
|
ocount = 0;
|
|
|
|
return;
|
2011-07-22 22:00:53 +00:00
|
|
|
}
|
2011-07-24 15:15:57 +00:00
|
|
|
|
2011-07-22 22:00:53 +00:00
|
|
|
ocount = count;
|
2011-07-24 15:15:57 +00:00
|
|
|
//////////
|
2011-07-22 22:00:53 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
prrts = (_prrt *)Xcalloc(count, sizeof(_prrt));
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i < count)
|
|
|
|
{
|
2009-03-26 16:32:00 +00:00
|
|
|
if (!i) {
|
|
|
|
prrts[i].target = GL_TEXTURE_RECTANGLE;
|
|
|
|
prrts[i].xdim = xdim;
|
|
|
|
prrts[i].ydim = ydim;
|
2009-03-23 14:18:20 +00:00
|
|
|
|
2009-03-26 16:32:00 +00:00
|
|
|
bglGenTextures(1, &prrts[i].color);
|
|
|
|
bglBindTexture(prrts[i].target, prrts[i].color);
|
|
|
|
|
2009-08-12 17:43:17 +00:00
|
|
|
bglTexImage2D(prrts[i].target, 0, GL_RGB, prrts[i].xdim, prrts[i].ydim, 0, GL_RGB, GL_SHORT, NULL);
|
2009-03-26 16:32:00 +00:00
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2009-07-24 02:31:34 +00:00
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_WRAP_S, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_WRAP_T, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
2009-03-26 16:32:00 +00:00
|
|
|
} else {
|
|
|
|
prrts[i].target = GL_TEXTURE_2D;
|
2009-04-12 17:14:18 +00:00
|
|
|
prrts[i].xdim = 128 << pr_shadowdetail;
|
|
|
|
prrts[i].ydim = 128 << pr_shadowdetail;
|
2009-03-26 16:32:00 +00:00
|
|
|
prrts[i].color = 0;
|
2009-05-20 22:30:18 +00:00
|
|
|
|
2009-06-28 21:03:50 +00:00
|
|
|
if (pr_ati_fboworkaround) {
|
2009-06-06 16:00:48 +00:00
|
|
|
bglGenTextures(1, &prrts[i].color);
|
|
|
|
bglBindTexture(prrts[i].target, prrts[i].color);
|
2009-05-20 22:30:18 +00:00
|
|
|
|
2009-08-12 17:43:17 +00:00
|
|
|
bglTexImage2D(prrts[i].target, 0, GL_RGB, prrts[i].xdim, prrts[i].ydim, 0, GL_RGB, GL_SHORT, NULL);
|
2009-06-06 16:00:48 +00:00
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
2009-07-24 02:31:34 +00:00
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_WRAP_S, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_WRAP_T, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
2009-06-06 16:00:48 +00:00
|
|
|
}
|
2009-03-26 16:32:00 +00:00
|
|
|
}
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
bglGenTextures(1, &prrts[i].z);
|
2009-03-26 16:32:00 +00:00
|
|
|
bglBindTexture(prrts[i].target, prrts[i].z);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
2009-05-17 21:55:50 +00:00
|
|
|
bglTexImage2D(prrts[i].target, 0, GL_DEPTH_COMPONENT, prrts[i].xdim, prrts[i].ydim, 0, GL_DEPTH_COMPONENT, GL_SHORT, NULL);
|
2009-06-06 16:00:48 +00:00
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_MIN_FILTER, pr_shadowfiltering ? GL_LINEAR : GL_NEAREST);
|
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_MAG_FILTER, pr_shadowfiltering ? GL_LINEAR : GL_NEAREST);
|
2009-07-24 02:31:34 +00:00
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_WRAP_S, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_WRAP_T, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
|
2009-03-26 16:32:00 +00:00
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);
|
|
|
|
bglTexParameteri(prrts[i].target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
|
|
|
|
bglTexParameteri(prrts[i].target, GL_DEPTH_TEXTURE_MODE_ARB, GL_ALPHA);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
bglGenFramebuffersEXT(1, &prrts[i].fbo);
|
|
|
|
bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, prrts[i].fbo);
|
|
|
|
|
2009-03-26 16:32:00 +00:00
|
|
|
if (prrts[i].color)
|
|
|
|
bglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
|
|
|
|
prrts[i].target, prrts[i].color, 0);
|
|
|
|
else {
|
|
|
|
bglDrawBuffer(GL_NONE);
|
|
|
|
bglReadBuffer(GL_NONE);
|
|
|
|
}
|
|
|
|
bglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, prrts[i].target, prrts[i].z, 0);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
if (bglCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT)
|
2013-08-07 00:56:37 +00:00
|
|
|
{
|
2009-04-14 13:58:38 +00:00
|
|
|
OSD_Printf("PR : FBO #%d initialization failed.\n", i);
|
2013-08-07 00:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bglBindTexture(prrts[i].target, 0);
|
|
|
|
bglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
2009-03-23 14:18:20 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-02 05:56:35 +00:00
|
|
|
// DEBUG OUTPUT
|
2011-10-03 00:14:56 +00:00
|
|
|
void PR_CALLBACK polymer_debugoutputcallback(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,GLvoid *userParam)
|
2011-10-02 05:56:35 +00:00
|
|
|
{
|
|
|
|
UNREFERENCED_PARAMETER(source);
|
|
|
|
UNREFERENCED_PARAMETER(type);
|
|
|
|
UNREFERENCED_PARAMETER(id);
|
|
|
|
UNREFERENCED_PARAMETER(severity);
|
|
|
|
UNREFERENCED_PARAMETER(length);
|
|
|
|
UNREFERENCED_PARAMETER(userParam);
|
|
|
|
|
2015-07-13 03:46:35 +00:00
|
|
|
if (type == GL_DEBUG_TYPE_ERROR_ARB)
|
|
|
|
{
|
|
|
|
OSD_Printf("PR : Received OpenGL debug message: %s\n", message);
|
|
|
|
}
|
2011-10-02 05:56:35 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 20:18:04 +00:00
|
|
|
#endif
|