2017-04-26 10:23:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* *
|
|
|
|
* Project64-video - A Nintendo 64 gfx plugin. *
|
|
|
|
* http://www.pj64-emu.com/ *
|
|
|
|
* Copyright (C) 2017 Project64. All rights reserved. *
|
|
|
|
* Copyright (C) 2003-2009 Sergey 'Gonetz' Lipski *
|
|
|
|
* Copyright (C) 2002 Dave2001 *
|
|
|
|
* *
|
|
|
|
* License: *
|
|
|
|
* GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html *
|
|
|
|
* version 2 of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2017-05-17 08:13:04 +00:00
|
|
|
#include <Project64-video/Renderer/Renderer.h>
|
2017-08-11 07:07:23 +00:00
|
|
|
#include <Project64-video/rdp.h>
|
|
|
|
#include <Project64-video/Settings.h>
|
2013-04-10 07:08:48 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif // _WIN32
|
2015-10-09 04:53:16 +00:00
|
|
|
#include "glitchmain.h"
|
2017-04-26 09:05:05 +00:00
|
|
|
#include <Project64-video/trace.h>
|
2013-04-10 07:08:48 +00:00
|
|
|
|
|
|
|
#define Z_MAX (65536.0f)
|
|
|
|
|
2017-08-16 22:18:19 +00:00
|
|
|
static int xy_off = offsetof(gfxVERTEX, x);
|
|
|
|
static int z_off = offsetof(gfxVERTEX, z);
|
|
|
|
static int q_off = offsetof(gfxVERTEX, q);
|
|
|
|
static int pargb_off = offsetof(gfxVERTEX, b);
|
|
|
|
static int st0_off = offsetof(gfxVERTEX, coord[0]);
|
|
|
|
static int st1_off = offsetof(gfxVERTEX, coord[2]);
|
|
|
|
static int fog_ext_off = offsetof(gfxVERTEX, f);
|
2013-04-10 07:08:48 +00:00
|
|
|
|
|
|
|
int w_buffer_mode;
|
|
|
|
int inverted_culling;
|
2017-08-02 21:48:55 +00:00
|
|
|
gfxCullMode_t culling_mode;
|
2017-01-02 22:01:39 +00:00
|
|
|
extern int fog_enabled;
|
2013-04-10 07:08:48 +00:00
|
|
|
|
|
|
|
inline float ZCALC(const float & z, const float & q) {
|
2017-08-11 07:07:23 +00:00
|
|
|
float res = ((z) / Z_MAX) / (q);
|
2016-02-04 08:34:02 +00:00
|
|
|
return res;
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define zclamp (1.0f-1.0f/zscale)
|
|
|
|
static inline void zclamp_glVertex4f(float a, float b, float c, float d)
|
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
if (c < zclamp) c = zclamp;
|
|
|
|
glVertex4f(a, b, c, d);
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
#define glVertex4f(a,b,c,d) zclamp_glVertex4f(a,b,c,d)
|
|
|
|
|
|
|
|
static inline float ytex(int tmu, float y) {
|
2016-02-04 08:34:02 +00:00
|
|
|
if (invtex[tmu])
|
|
|
|
return invtex[tmu] - y;
|
|
|
|
else
|
|
|
|
return y;
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init_geometry()
|
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
w_buffer_mode = 0;
|
|
|
|
inverted_culling = 0;
|
2013-04-10 07:08:48 +00:00
|
|
|
|
2016-02-04 08:34:02 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
grDisplayGLError("init_geometry");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 21:48:55 +00:00
|
|
|
void gfxCullMode(gfxCullMode_t mode)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "mode: %d", mode);
|
2016-02-04 08:34:02 +00:00
|
|
|
static int oldmode = -1, oldinv = -1;
|
|
|
|
culling_mode = mode;
|
|
|
|
if (inverted_culling == oldinv && oldmode == mode)
|
|
|
|
return;
|
|
|
|
oldmode = mode;
|
|
|
|
oldinv = inverted_culling;
|
|
|
|
switch (mode)
|
|
|
|
{
|
2017-08-02 21:48:55 +00:00
|
|
|
case GFX_CULL_DISABLE:
|
2016-02-04 08:34:02 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
break;
|
2017-08-02 21:48:55 +00:00
|
|
|
case GFX_CULL_NEGATIVE:
|
2016-02-04 08:34:02 +00:00
|
|
|
if (!inverted_culling)
|
|
|
|
glCullFace(GL_FRONT);
|
|
|
|
else
|
|
|
|
glCullFace(GL_BACK);
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
break;
|
2017-08-02 21:48:55 +00:00
|
|
|
case GFX_CULL_POSITIVE:
|
2016-02-04 08:34:02 +00:00
|
|
|
if (!inverted_culling)
|
|
|
|
glCullFace(GL_BACK);
|
|
|
|
else
|
|
|
|
glCullFace(GL_FRONT);
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
break;
|
|
|
|
default:
|
2016-02-14 08:59:33 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceWarning, "unknown cull mode : %x", mode);
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-05-24 22:36:49 +00:00
|
|
|
grDisplayGLError("gfxCullMode");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Depth buffer
|
2017-08-02 22:02:52 +00:00
|
|
|
void gfxDepthBufferMode(gfxDepthBufferMode_t mode)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "mode: %d", mode);
|
2016-02-04 08:34:02 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
2017-08-02 22:02:52 +00:00
|
|
|
case GFX_DEPTHBUFFER_DISABLE:
|
2016-02-04 08:34:02 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
w_buffer_mode = 0;
|
|
|
|
return;
|
2017-08-02 22:02:52 +00:00
|
|
|
case GFX_DEPTHBUFFER_WBUFFER:
|
|
|
|
case GFX_DEPTHBUFFER_WBUFFER_COMPARE_TO_BIAS:
|
2016-02-04 08:34:02 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
w_buffer_mode = 1;
|
|
|
|
break;
|
2017-08-02 22:02:52 +00:00
|
|
|
case GFX_DEPTHBUFFER_ZBUFFER:
|
|
|
|
case GFX_DEPTHBUFFER_ZBUFFER_COMPARE_TO_BIAS:
|
2016-02-04 08:34:02 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
w_buffer_mode = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2016-02-14 08:59:33 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceWarning, "unknown depth buffer mode : %x", mode);
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-05-24 22:44:15 +00:00
|
|
|
grDisplayGLError("gfxDepthBufferMode");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 11:05:29 +00:00
|
|
|
void gfxDepthBufferFunction(gfxCmpFnc_t function)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "function: %d", function);
|
2016-02-04 08:34:02 +00:00
|
|
|
switch (function)
|
|
|
|
{
|
2017-07-31 11:05:29 +00:00
|
|
|
case GFX_CMP_GEQUAL:
|
2016-02-04 08:34:02 +00:00
|
|
|
if (w_buffer_mode)
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
else
|
|
|
|
glDepthFunc(GL_GEQUAL);
|
|
|
|
break;
|
2017-07-31 11:05:29 +00:00
|
|
|
case GFX_CMP_LEQUAL:
|
2016-02-04 08:34:02 +00:00
|
|
|
if (w_buffer_mode)
|
|
|
|
glDepthFunc(GL_GEQUAL);
|
|
|
|
else
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
|
|
|
break;
|
2017-07-31 11:05:29 +00:00
|
|
|
case GFX_CMP_LESS:
|
2016-02-04 08:34:02 +00:00
|
|
|
if (w_buffer_mode)
|
|
|
|
glDepthFunc(GL_GREATER);
|
|
|
|
else
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
break;
|
2017-07-31 11:05:29 +00:00
|
|
|
case GFX_CMP_ALWAYS:
|
2016-02-04 08:34:02 +00:00
|
|
|
glDepthFunc(GL_ALWAYS);
|
|
|
|
break;
|
2017-07-31 11:05:29 +00:00
|
|
|
case GFX_CMP_EQUAL:
|
2016-02-04 08:34:02 +00:00
|
|
|
glDepthFunc(GL_EQUAL);
|
|
|
|
break;
|
2017-07-31 11:05:29 +00:00
|
|
|
case GFX_CMP_GREATER:
|
2016-02-04 08:34:02 +00:00
|
|
|
if (w_buffer_mode)
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
else
|
|
|
|
glDepthFunc(GL_GREATER);
|
|
|
|
break;
|
2017-07-31 11:05:29 +00:00
|
|
|
case GFX_CMP_NEVER:
|
2016-02-04 08:34:02 +00:00
|
|
|
glDepthFunc(GL_NEVER);
|
|
|
|
break;
|
2017-07-31 11:05:29 +00:00
|
|
|
case GFX_CMP_NOTEQUAL:
|
2016-02-04 08:34:02 +00:00
|
|
|
glDepthFunc(GL_NOTEQUAL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-02-14 08:59:33 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceWarning, "unknown depth buffer function : %x", function);
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-05-24 22:49:39 +00:00
|
|
|
grDisplayGLError("gfxDepthBufferFunction");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 23:03:22 +00:00
|
|
|
void gfxDepthMask(bool mask)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "mask: %d", mask);
|
2016-02-04 08:34:02 +00:00
|
|
|
glDepthMask((GLboolean)mask);
|
2017-05-24 22:51:36 +00:00
|
|
|
grDisplayGLError("gfxDepthMask");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float biasFactor = 0;
|
|
|
|
void FindBestDepthBias()
|
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
GLfloat vertices[4][3];
|
|
|
|
float f, bestz = 0.25f;
|
|
|
|
int x;
|
2013-04-10 07:08:48 +00:00
|
|
|
|
2016-02-04 08:34:02 +00:00
|
|
|
if (biasFactor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
biasFactor = 64.0f; // default value
|
|
|
|
glPushAttrib(GL_ALL_ATTRIB_BITS);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_ALWAYS);
|
|
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glDrawBuffer(GL_BACK);
|
|
|
|
glReadBuffer(GL_BACK);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
glColor4ub(255, 255, 255, 255);
|
|
|
|
glDepthMask(GL_TRUE);
|
|
|
|
|
|
|
|
for (x = 0; x < 4; x++)
|
|
|
|
vertices[x][2] = 0.5;
|
|
|
|
|
|
|
|
for (x = 0, f = 1.0f; f <= 65536.0f; x += 4, f *= 2.0f) {
|
|
|
|
float z;
|
|
|
|
|
2016-03-10 17:21:56 +00:00
|
|
|
vertices[0][0] = float(x + 4 - widtho) / (g_width / 2);
|
|
|
|
vertices[0][1] = float(0 + 0 - heighto) / (g_height / 2);
|
|
|
|
vertices[1][0] = float(x + 0 - widtho) / (g_width / 2);
|
|
|
|
vertices[1][1] = float(0 + 0 - heighto) / (g_height / 2);
|
|
|
|
vertices[2][0] = float(x + 4 - widtho) / (g_width / 2);
|
|
|
|
vertices[2][1] = float(0 + 4 - heighto) / (g_height / 2);
|
|
|
|
vertices[3][0] = float(x + 0 - widtho) / (g_width / 2);
|
|
|
|
vertices[3][1] = float(0 + 4 - heighto) / (g_height / 2);
|
2016-02-04 08:34:02 +00:00
|
|
|
glPolygonOffset(0, f);
|
|
|
|
|
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
glVertex3fv(vertices[0]);
|
|
|
|
glVertex3fv(vertices[1]);
|
|
|
|
glVertex3fv(vertices[2]);
|
|
|
|
glVertex3fv(vertices[3]);
|
|
|
|
glEnd();
|
|
|
|
|
2017-03-13 09:34:51 +00:00
|
|
|
glReadPixels(x + 2, 2 + g_viewport_offset, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
|
2016-02-04 08:34:02 +00:00
|
|
|
z -= 0.75f + 8e-6f;
|
|
|
|
if (z < 0.0f) z = -z;
|
|
|
|
if (z > 0.01f) continue;
|
|
|
|
if (z < bestz) {
|
|
|
|
bestz = z;
|
|
|
|
biasFactor = f;
|
|
|
|
}
|
|
|
|
//printf("f %g z %g\n", f, z);
|
|
|
|
}
|
|
|
|
//printf(" --> bias factor %g\n", biasFactor);
|
|
|
|
glPopAttrib();
|
|
|
|
grDisplayGLError("FindBestDepthBias");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-08-08 21:32:10 +00:00
|
|
|
void gfxDepthBiasLevel(int32_t level)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "level: %d", level);
|
2016-02-04 08:34:02 +00:00
|
|
|
if (level)
|
|
|
|
{
|
|
|
|
if (w_buffer_mode)
|
|
|
|
glPolygonOffset(1.0f, -(float)level*zscale / 255.0f);
|
|
|
|
else
|
|
|
|
glPolygonOffset(0, (float)level*biasFactor);
|
|
|
|
glEnable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
}
|
2013-04-10 07:08:48 +00:00
|
|
|
else
|
2016-02-04 08:34:02 +00:00
|
|
|
{
|
|
|
|
glPolygonOffset(0, 0);
|
|
|
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
}
|
2017-05-25 07:31:29 +00:00
|
|
|
grDisplayGLError("gfxDepthBiasLevel");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// draw
|
2017-08-16 22:18:19 +00:00
|
|
|
void gfxDrawTriangle(const gfxVERTEX *a, const gfxVERTEX *b, const gfxVERTEX *c)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
float *a_x = (float*)a + xy_off / sizeof(float);
|
|
|
|
float *a_y = (float*)a + xy_off / sizeof(float) + 1;
|
|
|
|
float *a_z = (float*)a + z_off / sizeof(float);
|
|
|
|
float *a_q = (float*)a + q_off / sizeof(float);
|
|
|
|
unsigned char *a_pargb = (unsigned char*)a + pargb_off;
|
|
|
|
float *a_s0 = (float*)a + st0_off / sizeof(float);
|
|
|
|
float *a_t0 = (float*)a + st0_off / sizeof(float) + 1;
|
|
|
|
float *a_s1 = (float*)a + st1_off / sizeof(float);
|
|
|
|
float *a_t1 = (float*)a + st1_off / sizeof(float) + 1;
|
|
|
|
float *a_fog = (float*)a + fog_ext_off / sizeof(float);
|
|
|
|
|
|
|
|
float *b_x = (float*)b + xy_off / sizeof(float);
|
|
|
|
float *b_y = (float*)b + xy_off / sizeof(float) + 1;
|
|
|
|
float *b_z = (float*)b + z_off / sizeof(float);
|
|
|
|
float *b_q = (float*)b + q_off / sizeof(float);
|
|
|
|
unsigned char *b_pargb = (unsigned char*)b + pargb_off;
|
|
|
|
float *b_s0 = (float*)b + st0_off / sizeof(float);
|
|
|
|
float *b_t0 = (float*)b + st0_off / sizeof(float) + 1;
|
|
|
|
float *b_s1 = (float*)b + st1_off / sizeof(float);
|
|
|
|
float *b_t1 = (float*)b + st1_off / sizeof(float) + 1;
|
|
|
|
float *b_fog = (float*)b + fog_ext_off / sizeof(float);
|
|
|
|
|
|
|
|
float *c_x = (float*)c + xy_off / sizeof(float);
|
|
|
|
float *c_y = (float*)c + xy_off / sizeof(float) + 1;
|
|
|
|
float *c_z = (float*)c + z_off / sizeof(float);
|
|
|
|
float *c_q = (float*)c + q_off / sizeof(float);
|
|
|
|
unsigned char *c_pargb = (unsigned char*)c + pargb_off;
|
|
|
|
float *c_s0 = (float*)c + st0_off / sizeof(float);
|
|
|
|
float *c_t0 = (float*)c + st0_off / sizeof(float) + 1;
|
|
|
|
float *c_s1 = (float*)c + st1_off / sizeof(float);
|
|
|
|
float *c_t1 = (float*)c + st1_off / sizeof(float) + 1;
|
|
|
|
float *c_fog = (float*)c + fog_ext_off / sizeof(float);
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "-");
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
// ugly ? i know but nvidia drivers are losing the viewport otherwise
|
|
|
|
|
|
|
|
if (nvidia_viewport_hack && !render_to_texture)
|
|
|
|
{
|
2017-03-13 09:34:51 +00:00
|
|
|
glViewport(0, g_viewport_offset, viewport_width, viewport_height);
|
2016-02-04 08:34:02 +00:00
|
|
|
nvidia_viewport_hack = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
reloadTexture();
|
|
|
|
|
|
|
|
if (need_to_compile) compile_shader();
|
|
|
|
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
|
|
|
|
if (nbTextureUnits > 2)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width, ytex(0, *a_t0 / *a_q / (float)tex1_height));
|
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width, ytex(1, *a_t1 / *a_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2013-04-10 07:08:48 +00:00
|
|
|
else
|
2016-02-04 08:34:02 +00:00
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glTexCoord2f(*a_s0 / *a_q / (float)tex0_width, ytex(0, *a_t0 / *a_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-08-11 07:07:23 +00:00
|
|
|
glColor4f(a_pargb[2] / 255.0f, a_pargb[1] / 255.0f, a_pargb[0] / 255.0f, a_pargb[3] / 255.0f);
|
2016-02-04 08:34:02 +00:00
|
|
|
if (fog_enabled && fog_coord_support)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
if (!g_settings->fog() || fog_enabled != 2)
|
2016-02-04 08:34:02 +00:00
|
|
|
glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f);
|
|
|
|
else
|
|
|
|
glSecondaryColor3f((1.0f / *a_fog) / 255.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2016-03-10 17:21:56 +00:00
|
|
|
glVertex4f((*a_x - (float)widtho) / (float)(g_width / 2) / *a_q,
|
|
|
|
-(*a_y - (float)heighto) / (float)(g_height / 2) / *a_q, ZCALC(*a_z, *a_q), 1.0f / *a_q);
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
if (nbTextureUnits > 2)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width, ytex(0, *b_t0 / *b_q / (float)tex1_height));
|
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width, ytex(1, *b_t1 / *b_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2013-04-10 07:08:48 +00:00
|
|
|
else
|
2016-02-04 08:34:02 +00:00
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glTexCoord2f(*b_s0 / *b_q / (float)tex0_width, ytex(0, *b_t0 / *b_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-08-11 07:07:23 +00:00
|
|
|
glColor4f(b_pargb[2] / 255.0f, b_pargb[1] / 255.0f, b_pargb[0] / 255.0f, b_pargb[3] / 255.0f);
|
2016-02-04 08:34:02 +00:00
|
|
|
if (fog_enabled && fog_coord_support)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
if (!g_settings->fog() || fog_enabled != 2)
|
2016-02-04 08:34:02 +00:00
|
|
|
glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f);
|
|
|
|
else
|
|
|
|
glSecondaryColor3f((1.0f / *b_fog) / 255.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
2016-03-10 17:21:56 +00:00
|
|
|
glVertex4f((*b_x - (float)widtho) / (float)(g_width / 2) / *b_q,
|
|
|
|
-(*b_y - (float)heighto) / (float)(g_height / 2) / *b_q, ZCALC(*b_z, *b_q), 1.0f / *b_q);
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
if (nbTextureUnits > 2)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *c_s0 / *c_q / (float)tex1_width, ytex(0, *c_t0 / *c_q / (float)tex1_height));
|
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *c_s1 / *c_q / (float)tex0_width, ytex(1, *c_t1 / *c_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2013-04-10 07:08:48 +00:00
|
|
|
else
|
2016-02-04 08:34:02 +00:00
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glTexCoord2f(*c_s0 / *c_q / (float)tex0_width, ytex(0, *c_t0 / *c_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-08-11 07:07:23 +00:00
|
|
|
glColor4f(c_pargb[2] / 255.0f, c_pargb[1] / 255.0f, c_pargb[0] / 255.0f, c_pargb[3] / 255.0f);
|
2016-02-04 08:34:02 +00:00
|
|
|
if (fog_enabled && fog_coord_support)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
if (!g_settings->fog() || fog_enabled != 2)
|
2016-02-04 08:34:02 +00:00
|
|
|
glSecondaryColor3f((1.0f / *c_q) / 255.0f, 0.0f, 0.0f);
|
|
|
|
else
|
|
|
|
glSecondaryColor3f((1.0f / *c_fog) / 255.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2016-03-10 17:21:56 +00:00
|
|
|
glVertex4f((*c_x - (float)widtho) / (float)(g_width / 2) / *c_q,
|
|
|
|
-(*c_y - (float)heighto) / (float)(g_height / 2) / *c_q, ZCALC(*c_z, *c_q), 1.0f / *c_q);
|
2013-04-10 07:08:48 +00:00
|
|
|
|
2016-02-04 08:34:02 +00:00
|
|
|
glEnd();
|
2017-05-24 22:54:10 +00:00
|
|
|
grDisplayGLError("gfxDrawTriangle");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-08-16 22:18:19 +00:00
|
|
|
void gfxDrawLine(const gfxVERTEX *a, const gfxVERTEX *b)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
float *a_x = (float*)a + xy_off / sizeof(float);
|
|
|
|
float *a_y = (float*)a + xy_off / sizeof(float) + 1;
|
|
|
|
float *a_z = (float*)a + z_off / sizeof(float);
|
|
|
|
float *a_q = (float*)a + q_off / sizeof(float);
|
|
|
|
unsigned char *a_pargb = (unsigned char*)a + pargb_off;
|
|
|
|
float *a_s0 = (float*)a + st0_off / sizeof(float);
|
|
|
|
float *a_t0 = (float*)a + st0_off / sizeof(float) + 1;
|
|
|
|
float *a_s1 = (float*)a + st1_off / sizeof(float);
|
|
|
|
float *a_t1 = (float*)a + st1_off / sizeof(float) + 1;
|
|
|
|
float *a_fog = (float*)a + fog_ext_off / sizeof(float);
|
|
|
|
|
|
|
|
float *b_x = (float*)b + xy_off / sizeof(float);
|
|
|
|
float *b_y = (float*)b + xy_off / sizeof(float) + 1;
|
|
|
|
float *b_z = (float*)b + z_off / sizeof(float);
|
|
|
|
float *b_q = (float*)b + q_off / sizeof(float);
|
|
|
|
unsigned char *b_pargb = (unsigned char*)b + pargb_off;
|
|
|
|
float *b_s0 = (float*)b + st0_off / sizeof(float);
|
|
|
|
float *b_t0 = (float*)b + st0_off / sizeof(float) + 1;
|
|
|
|
float *b_s1 = (float*)b + st1_off / sizeof(float);
|
|
|
|
float *b_t1 = (float*)b + st1_off / sizeof(float) + 1;
|
|
|
|
float *b_fog = (float*)b + fog_ext_off / sizeof(float);
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "-");
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
if (nvidia_viewport_hack && !render_to_texture)
|
|
|
|
{
|
2017-03-13 09:34:51 +00:00
|
|
|
glViewport(0, g_viewport_offset, viewport_width, viewport_height);
|
2016-02-04 08:34:02 +00:00
|
|
|
nvidia_viewport_hack = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
reloadTexture();
|
|
|
|
|
|
|
|
if (need_to_compile) compile_shader();
|
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
|
|
|
|
if (nbTextureUnits > 2)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *a_s0 / *a_q / (float)tex1_width, ytex(0, *a_t0 / *a_q / (float)tex1_height));
|
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *a_s1 / *a_q / (float)tex0_width, ytex(1, *a_t1 / *a_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2013-04-10 07:08:48 +00:00
|
|
|
else
|
2016-02-04 08:34:02 +00:00
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glTexCoord2f(*a_s0 / *a_q / (float)tex0_width, ytex(0, *a_t0 / *a_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-08-11 07:07:23 +00:00
|
|
|
glColor4f(a_pargb[2] / 255.0f, a_pargb[1] / 255.0f, a_pargb[0] / 255.0f, a_pargb[3] / 255.0f);
|
2016-02-04 08:34:02 +00:00
|
|
|
if (fog_enabled && fog_coord_support)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
if (!g_settings->fog() || fog_enabled != 2)
|
2016-02-04 08:34:02 +00:00
|
|
|
glSecondaryColor3f((1.0f / *a_q) / 255.0f, 0.0f, 0.0f);
|
|
|
|
else
|
|
|
|
glSecondaryColor3f((1.0f / *a_fog) / 255.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2016-03-10 17:21:56 +00:00
|
|
|
glVertex4f((*a_x - (float)widtho) / (float)(g_width / 2) / *a_q,
|
|
|
|
-(*a_y - (float)heighto) / (float)(g_height / 2) / *a_q, ZCALC(*a_z, *a_q), 1.0f / *a_q);
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
if (nbTextureUnits > 2)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *b_s0 / *b_q / (float)tex1_width, ytex(0, *b_t0 / *b_q / (float)tex1_height));
|
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *b_s1 / *b_q / (float)tex0_width, ytex(1, *b_t1 / *b_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2013-04-10 07:08:48 +00:00
|
|
|
else
|
2016-02-04 08:34:02 +00:00
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glTexCoord2f(*b_s0 / *b_q / (float)tex0_width, ytex(0, *b_t0 / *b_q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-08-11 07:07:23 +00:00
|
|
|
glColor4f(b_pargb[2] / 255.0f, b_pargb[1] / 255.0f, b_pargb[0] / 255.0f, b_pargb[3] / 255.0f);
|
2016-02-04 08:34:02 +00:00
|
|
|
if (fog_enabled && fog_coord_support)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
if (!g_settings->fog() || fog_enabled != 2)
|
2016-02-04 08:34:02 +00:00
|
|
|
glSecondaryColor3f((1.0f / *b_q) / 255.0f, 0.0f, 0.0f);
|
|
|
|
else
|
|
|
|
glSecondaryColor3f((1.0f / *b_fog) / 255.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2016-03-10 17:21:56 +00:00
|
|
|
glVertex4f((*b_x - (float)widtho) / (float)(g_width / 2) / *b_q,
|
|
|
|
-(*b_y - (float)heighto) / (float)(g_height / 2) / *b_q, ZCALC(*b_z, *b_q), 1.0f / *b_q);
|
2013-04-10 07:08:48 +00:00
|
|
|
|
2016-02-04 08:34:02 +00:00
|
|
|
glEnd();
|
2017-05-25 08:01:37 +00:00
|
|
|
grDisplayGLError("gfxDrawLine");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 07:37:41 +00:00
|
|
|
void gfxDrawVertexArray(gfxDrawMode_t mode, uint32_t Count, void *pointers2)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
unsigned int i;
|
|
|
|
float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog;
|
|
|
|
unsigned char *pargb;
|
|
|
|
void **pointers = (void**)pointers2;
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "mode: %d Count: %d", mode, Count);
|
2013-04-10 07:08:48 +00:00
|
|
|
|
2016-02-04 08:34:02 +00:00
|
|
|
if (nvidia_viewport_hack && !render_to_texture)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2017-03-13 09:34:51 +00:00
|
|
|
glViewport(0, g_viewport_offset, viewport_width, viewport_height);
|
2016-02-04 08:34:02 +00:00
|
|
|
nvidia_viewport_hack = 0;
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
reloadTexture();
|
|
|
|
|
|
|
|
if (need_to_compile) compile_shader();
|
|
|
|
|
|
|
|
switch (mode)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2017-08-10 07:37:41 +00:00
|
|
|
case GFX_TRIANGLE_FAN:
|
2016-02-04 08:34:02 +00:00
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
break;
|
|
|
|
default:
|
2017-05-25 08:05:53 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceWarning, "gfxDrawVertexArray : unknown mode : %x", mode);
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < Count; i++)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
x = (float*)pointers[i] + xy_off / sizeof(float);
|
|
|
|
y = (float*)pointers[i] + xy_off / sizeof(float) + 1;
|
|
|
|
z = (float*)pointers[i] + z_off / sizeof(float);
|
|
|
|
q = (float*)pointers[i] + q_off / sizeof(float);
|
|
|
|
pargb = (unsigned char*)pointers[i] + pargb_off;
|
|
|
|
s0 = (float*)pointers[i] + st0_off / sizeof(float);
|
|
|
|
t0 = (float*)pointers[i] + st0_off / sizeof(float) + 1;
|
|
|
|
s1 = (float*)pointers[i] + st1_off / sizeof(float);
|
|
|
|
t1 = (float*)pointers[i] + st1_off / sizeof(float) + 1;
|
|
|
|
fog = (float*)pointers[i] + fog_ext_off / sizeof(float);
|
|
|
|
|
|
|
|
if (nbTextureUnits > 2)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width, ytex(0, *t0 / *q / (float)tex1_height));
|
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width, ytex(1, *t1 / *q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glTexCoord2f(*s0 / *q / (float)tex0_width, ytex(0, *t0 / *q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-08-11 07:07:23 +00:00
|
|
|
glColor4f(pargb[2] / 255.0f, pargb[1] / 255.0f, pargb[0] / 255.0f, pargb[3] / 255.0f);
|
2016-02-04 08:34:02 +00:00
|
|
|
if (fog_enabled && fog_coord_support)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
if (!g_settings->fog() || fog_enabled != 2)
|
2016-02-04 08:34:02 +00:00
|
|
|
glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
|
|
|
|
else
|
|
|
|
glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2016-03-10 17:21:56 +00:00
|
|
|
glVertex4f((*x - (float)widtho) / (float)(g_width / 2) / *q,
|
|
|
|
-(*y - (float)heighto) / (float)(g_height / 2) / *q, ZCALC(*z, *q), 1.0f / *q);
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
2016-02-04 08:34:02 +00:00
|
|
|
glEnd();
|
2015-03-07 22:26:02 +00:00
|
|
|
|
2017-05-25 08:05:53 +00:00
|
|
|
grDisplayGLError("gfxDrawVertexArray");
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 07:37:41 +00:00
|
|
|
void gfxDrawVertexArrayContiguous(gfxDrawMode_t mode, uint32_t Count, void *pointers, uint32_t stride)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
unsigned int i;
|
|
|
|
float *x, *y, *q, *s0, *t0, *s1, *t1, *z, *fog;
|
|
|
|
unsigned char *pargb;
|
2016-02-04 10:22:19 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceDebug, "mode: %d Count: %d stride: %d", mode, Count, stride);
|
2013-04-10 07:08:48 +00:00
|
|
|
|
2016-02-04 08:34:02 +00:00
|
|
|
if (nvidia_viewport_hack && !render_to_texture)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2017-03-13 09:34:51 +00:00
|
|
|
glViewport(0, g_viewport_offset, viewport_width, viewport_height);
|
2016-02-04 08:34:02 +00:00
|
|
|
nvidia_viewport_hack = 0;
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
reloadTexture();
|
|
|
|
|
|
|
|
if (need_to_compile) compile_shader();
|
|
|
|
|
|
|
|
switch (mode)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2017-08-10 07:37:41 +00:00
|
|
|
case GFX_TRIANGLE_STRIP:
|
2016-02-04 08:34:02 +00:00
|
|
|
glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
break;
|
2017-08-10 07:37:41 +00:00
|
|
|
case GFX_TRIANGLE_FAN:
|
2016-02-04 08:34:02 +00:00
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
break;
|
|
|
|
default:
|
2017-05-25 08:10:13 +00:00
|
|
|
WriteTrace(TraceGlitch, TraceWarning, "gfxDrawVertexArrayContiguous : unknown mode : %x", mode);
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
2016-02-04 08:34:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < Count; i++)
|
2013-04-10 07:08:48 +00:00
|
|
|
{
|
2016-02-04 08:34:02 +00:00
|
|
|
x = (float*)((unsigned char*)pointers + stride*i) + xy_off / sizeof(float);
|
|
|
|
y = (float*)((unsigned char*)pointers + stride*i) + xy_off / sizeof(float) + 1;
|
|
|
|
z = (float*)((unsigned char*)pointers + stride*i) + z_off / sizeof(float);
|
|
|
|
q = (float*)((unsigned char*)pointers + stride*i) + q_off / sizeof(float);
|
|
|
|
pargb = (unsigned char*)pointers + stride*i + pargb_off;
|
|
|
|
s0 = (float*)((unsigned char*)pointers + stride*i) + st0_off / sizeof(float);
|
|
|
|
t0 = (float*)((unsigned char*)pointers + stride*i) + st0_off / sizeof(float) + 1;
|
|
|
|
s1 = (float*)((unsigned char*)pointers + stride*i) + st1_off / sizeof(float);
|
|
|
|
t1 = (float*)((unsigned char*)pointers + stride*i) + st1_off / sizeof(float) + 1;
|
|
|
|
fog = (float*)((unsigned char*)pointers + stride*i) + fog_ext_off / sizeof(float);
|
|
|
|
|
|
|
|
if (nbTextureUnits > 2)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, *s0 / *q / (float)tex1_width, ytex(0, *t0 / *q / (float)tex1_height));
|
|
|
|
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, *s1 / *q / (float)tex0_width, ytex(1, *t1 / *q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
glTexCoord2f(*s0 / *q / (float)tex0_width, ytex(0, *t0 / *q / (float)tex0_height));
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|
2017-08-11 07:07:23 +00:00
|
|
|
glColor4f(pargb[2] / 255.0f, pargb[1] / 255.0f, pargb[0] / 255.0f, pargb[3] / 255.0f);
|
2016-02-04 08:34:02 +00:00
|
|
|
if (fog_enabled && fog_coord_support)
|
|
|
|
{
|
2017-08-11 07:07:23 +00:00
|
|
|
if (!g_settings->fog() || fog_enabled != 2)
|
2016-02-04 08:34:02 +00:00
|
|
|
glSecondaryColor3f((1.0f / *q) / 255.0f, 0.0f, 0.0f);
|
|
|
|
else
|
|
|
|
glSecondaryColor3f((1.0f / *fog) / 255.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
|
2016-03-10 17:21:56 +00:00
|
|
|
glVertex4f((*x - (float)widtho) / (float)(g_width / 2) / *q,
|
|
|
|
-(*y - (float)heighto) / (float)(g_height / 2) / *q, ZCALC(*z, *q), 1.0f / *q);
|
2013-04-10 07:08:48 +00:00
|
|
|
}
|
2016-02-04 08:34:02 +00:00
|
|
|
glEnd();
|
2013-04-10 07:08:48 +00:00
|
|
|
|
2017-05-25 08:10:13 +00:00
|
|
|
grDisplayGLError("gfxDrawVertexArrayContiguous");
|
2016-02-04 08:34:02 +00:00
|
|
|
}
|