mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-28 23:11:58 +00:00
- remove use of builtin texture matrices.
- make matrix class single precision.
This commit is contained in:
parent
9230a20f18
commit
dbb05c5f33
14 changed files with 198 additions and 175 deletions
|
@ -18,16 +18,16 @@ This is a simplified version of VSMatrix that has been adjusted for GZDoom's nee
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
#include "gl/data/gl_matrix.h"
|
#include "gl/data/gl_matrix.h"
|
||||||
|
|
||||||
static inline double
|
static inline FLOATTYPE
|
||||||
DegToRad(double degrees)
|
DegToRad(FLOATTYPE degrees)
|
||||||
{
|
{
|
||||||
return (double)(degrees * (M_PI / 180.0f));
|
return (FLOATTYPE)(degrees * (M_PI / 180.0f));
|
||||||
};
|
};
|
||||||
|
|
||||||
// sets the square matrix mat to the identity matrix,
|
// sets the square matrix mat to the identity matrix,
|
||||||
// size refers to the number of rows (or columns)
|
// size refers to the number of rows (or columns)
|
||||||
void
|
void
|
||||||
VSMatrix::setIdentityMatrix( double *mat, int size) {
|
VSMatrix::setIdentityMatrix( FLOATTYPE *mat, int size) {
|
||||||
|
|
||||||
// fill matrix with 0s
|
// fill matrix with 0s
|
||||||
for (int i = 0; i < size * size; ++i)
|
for (int i = 0; i < size * size; ++i)
|
||||||
|
@ -56,10 +56,10 @@ VSMatrix::loadIdentity()
|
||||||
|
|
||||||
// glMultMatrix implementation
|
// glMultMatrix implementation
|
||||||
void
|
void
|
||||||
VSMatrix::multMatrix(const double *aMatrix)
|
VSMatrix::multMatrix(const FLOATTYPE *aMatrix)
|
||||||
{
|
{
|
||||||
|
|
||||||
double res[16];
|
FLOATTYPE res[16];
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
|
@ -72,15 +72,16 @@ VSMatrix::multMatrix(const double *aMatrix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(mMatrix, res, 16 * sizeof(double));
|
memcpy(mMatrix, res, 16 * sizeof(FLOATTYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_DOUBLE
|
||||||
// glMultMatrix implementation
|
// glMultMatrix implementation
|
||||||
void
|
void
|
||||||
VSMatrix::multMatrix(const float *aMatrix)
|
VSMatrix::multMatrix(const float *aMatrix)
|
||||||
{
|
{
|
||||||
|
|
||||||
double res[16];
|
FLOATTYPE res[16];
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
|
@ -93,18 +94,20 @@ VSMatrix::multMatrix(const float *aMatrix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(mMatrix, res, 16 * sizeof(double));
|
memcpy(mMatrix, res, 16 * sizeof(FLOATTYPE));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// glLoadMatrix implementation
|
// glLoadMatrix implementation
|
||||||
void
|
void
|
||||||
VSMatrix::loadMatrix(const double *aMatrix)
|
VSMatrix::loadMatrix(const FLOATTYPE *aMatrix)
|
||||||
{
|
{
|
||||||
memcpy(mMatrix, aMatrix, 16 * sizeof(double));
|
memcpy(mMatrix, aMatrix, 16 * sizeof(FLOATTYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_DOUBLE
|
||||||
// glLoadMatrix implementation
|
// glLoadMatrix implementation
|
||||||
void
|
void
|
||||||
VSMatrix::loadMatrix(const float *aMatrix)
|
VSMatrix::loadMatrix(const float *aMatrix)
|
||||||
|
@ -114,13 +117,14 @@ VSMatrix::loadMatrix(const float *aMatrix)
|
||||||
mMatrix[i] = aMatrix[i];
|
mMatrix[i] = aMatrix[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// gl Translate implementation with matrix selection
|
// gl Translate implementation with matrix selection
|
||||||
void
|
void
|
||||||
VSMatrix::translate(double x, double y, double z)
|
VSMatrix::translate(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z)
|
||||||
{
|
{
|
||||||
double mat[16];
|
FLOATTYPE mat[16];
|
||||||
|
|
||||||
setIdentityMatrix(mat);
|
setIdentityMatrix(mat);
|
||||||
mat[12] = x;
|
mat[12] = x;
|
||||||
|
@ -133,9 +137,9 @@ VSMatrix::translate(double x, double y, double z)
|
||||||
|
|
||||||
// gl Scale implementation with matrix selection
|
// gl Scale implementation with matrix selection
|
||||||
void
|
void
|
||||||
VSMatrix::scale(double x, double y, double z)
|
VSMatrix::scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z)
|
||||||
{
|
{
|
||||||
double mat[16];
|
FLOATTYPE mat[16];
|
||||||
|
|
||||||
setIdentityMatrix(mat,4);
|
setIdentityMatrix(mat,4);
|
||||||
mat[0] = x;
|
mat[0] = x;
|
||||||
|
@ -148,22 +152,22 @@ VSMatrix::scale(double x, double y, double z)
|
||||||
|
|
||||||
// gl Rotate implementation with matrix selection
|
// gl Rotate implementation with matrix selection
|
||||||
void
|
void
|
||||||
VSMatrix::rotate(double angle, double x, double y, double z)
|
VSMatrix::rotate(FLOATTYPE angle, FLOATTYPE x, FLOATTYPE y, FLOATTYPE z)
|
||||||
{
|
{
|
||||||
double mat[16];
|
FLOATTYPE mat[16];
|
||||||
double v[3];
|
FLOATTYPE v[3];
|
||||||
|
|
||||||
v[0] = x;
|
v[0] = x;
|
||||||
v[1] = y;
|
v[1] = y;
|
||||||
v[2] = z;
|
v[2] = z;
|
||||||
|
|
||||||
double radAngle = DegToRad(angle);
|
FLOATTYPE radAngle = DegToRad(angle);
|
||||||
double co = cos(radAngle);
|
FLOATTYPE co = cos(radAngle);
|
||||||
double si = sin(radAngle);
|
FLOATTYPE si = sin(radAngle);
|
||||||
normalize(v);
|
normalize(v);
|
||||||
double x2 = v[0]*v[0];
|
FLOATTYPE x2 = v[0]*v[0];
|
||||||
double y2 = v[1]*v[1];
|
FLOATTYPE y2 = v[1]*v[1];
|
||||||
double z2 = v[2]*v[2];
|
FLOATTYPE z2 = v[2]*v[2];
|
||||||
|
|
||||||
// mat[0] = x2 + (y2 + z2) * co;
|
// mat[0] = x2 + (y2 + z2) * co;
|
||||||
mat[0] = co + x2 * (1 - co);// + (y2 + z2) * co;
|
mat[0] = co + x2 * (1 - co);// + (y2 + z2) * co;
|
||||||
|
@ -194,11 +198,11 @@ VSMatrix::rotate(double angle, double x, double y, double z)
|
||||||
|
|
||||||
// gluLookAt implementation
|
// gluLookAt implementation
|
||||||
void
|
void
|
||||||
VSMatrix::lookAt(double xPos, double yPos, double zPos,
|
VSMatrix::lookAt(FLOATTYPE xPos, FLOATTYPE yPos, FLOATTYPE zPos,
|
||||||
double xLook, double yLook, double zLook,
|
FLOATTYPE xLook, FLOATTYPE yLook, FLOATTYPE zLook,
|
||||||
double xUp, double yUp, double zUp)
|
FLOATTYPE xUp, FLOATTYPE yUp, FLOATTYPE zUp)
|
||||||
{
|
{
|
||||||
double dir[3], right[3], up[3];
|
FLOATTYPE dir[3], right[3], up[3];
|
||||||
|
|
||||||
up[0] = xUp; up[1] = yUp; up[2] = zUp;
|
up[0] = xUp; up[1] = yUp; up[2] = zUp;
|
||||||
|
|
||||||
|
@ -213,7 +217,7 @@ VSMatrix::lookAt(double xPos, double yPos, double zPos,
|
||||||
crossProduct(right,dir,up);
|
crossProduct(right,dir,up);
|
||||||
normalize(up);
|
normalize(up);
|
||||||
|
|
||||||
double m1[16],m2[16];
|
FLOATTYPE m1[16],m2[16];
|
||||||
|
|
||||||
m1[0] = right[0];
|
m1[0] = right[0];
|
||||||
m1[4] = right[1];
|
m1[4] = right[1];
|
||||||
|
@ -247,11 +251,11 @@ VSMatrix::lookAt(double xPos, double yPos, double zPos,
|
||||||
|
|
||||||
// gluPerspective implementation
|
// gluPerspective implementation
|
||||||
void
|
void
|
||||||
VSMatrix::perspective(double fov, double ratio, double nearp, double farp)
|
VSMatrix::perspective(FLOATTYPE fov, FLOATTYPE ratio, FLOATTYPE nearp, FLOATTYPE farp)
|
||||||
{
|
{
|
||||||
double projMatrix[16];
|
FLOATTYPE projMatrix[16];
|
||||||
|
|
||||||
double f = 1.0f / tan (fov * (M_PI / 360.0f));
|
FLOATTYPE f = 1.0f / tan (fov * (M_PI / 360.0f));
|
||||||
|
|
||||||
setIdentityMatrix(projMatrix,4);
|
setIdentityMatrix(projMatrix,4);
|
||||||
|
|
||||||
|
@ -268,11 +272,11 @@ VSMatrix::perspective(double fov, double ratio, double nearp, double farp)
|
||||||
|
|
||||||
// glOrtho implementation
|
// glOrtho implementation
|
||||||
void
|
void
|
||||||
VSMatrix::ortho(double left, double right,
|
VSMatrix::ortho(FLOATTYPE left, FLOATTYPE right,
|
||||||
double bottom, double top,
|
FLOATTYPE bottom, FLOATTYPE top,
|
||||||
double nearp, double farp)
|
FLOATTYPE nearp, FLOATTYPE farp)
|
||||||
{
|
{
|
||||||
double m[16];
|
FLOATTYPE m[16];
|
||||||
|
|
||||||
setIdentityMatrix(m,4);
|
setIdentityMatrix(m,4);
|
||||||
|
|
||||||
|
@ -289,11 +293,11 @@ VSMatrix::ortho(double left, double right,
|
||||||
|
|
||||||
// glFrustum implementation
|
// glFrustum implementation
|
||||||
void
|
void
|
||||||
VSMatrix::frustum(double left, double right,
|
VSMatrix::frustum(FLOATTYPE left, FLOATTYPE right,
|
||||||
double bottom, double top,
|
FLOATTYPE bottom, FLOATTYPE top,
|
||||||
double nearp, double farp)
|
FLOATTYPE nearp, FLOATTYPE farp)
|
||||||
{
|
{
|
||||||
double m[16];
|
FLOATTYPE m[16];
|
||||||
|
|
||||||
setIdentityMatrix(m,4);
|
setIdentityMatrix(m,4);
|
||||||
|
|
||||||
|
@ -312,7 +316,7 @@ VSMatrix::frustum(double left, double right,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// returns a pointer to the requested matrix
|
// returns a pointer to the requested matrix
|
||||||
double *
|
FLOATTYPE *
|
||||||
VSMatrix::get(MatrixTypes aType)
|
VSMatrix::get(MatrixTypes aType)
|
||||||
{
|
{
|
||||||
return mMatrix[aType];
|
return mMatrix[aType];
|
||||||
|
@ -331,9 +335,13 @@ VSMatrix::get(MatrixTypes aType)
|
||||||
void
|
void
|
||||||
VSMatrix::matrixToGL(int loc)
|
VSMatrix::matrixToGL(int loc)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_DOUBLE
|
||||||
float copyto[16];
|
float copyto[16];
|
||||||
copy(copyto);
|
copy(copyto);
|
||||||
glUniformMatrix4fv(loc, 1, false, copyto);
|
glUniformMatrix4fv(loc, 1, false, copyto);
|
||||||
|
#else
|
||||||
|
glUniformMatrix4fv(loc, 1, false, mMatrix);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
@ -343,7 +351,7 @@ VSMatrix::matrixToGL(int loc)
|
||||||
|
|
||||||
// Compute res = M * point
|
// Compute res = M * point
|
||||||
void
|
void
|
||||||
VSMatrix::multMatrixPoint(const double *point, double *res)
|
VSMatrix::multMatrixPoint(const FLOATTYPE *point, FLOATTYPE *res)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
|
@ -360,7 +368,7 @@ VSMatrix::multMatrixPoint(const double *point, double *res)
|
||||||
|
|
||||||
// res = a cross b;
|
// res = a cross b;
|
||||||
void
|
void
|
||||||
VSMatrix::crossProduct(const double *a, const double *b, double *res) {
|
VSMatrix::crossProduct(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res) {
|
||||||
|
|
||||||
res[0] = a[1] * b[2] - b[1] * a[2];
|
res[0] = a[1] * b[2] - b[1] * a[2];
|
||||||
res[1] = a[2] * b[0] - b[2] * a[0];
|
res[1] = a[2] * b[0] - b[2] * a[0];
|
||||||
|
@ -369,10 +377,10 @@ VSMatrix::crossProduct(const double *a, const double *b, double *res) {
|
||||||
|
|
||||||
|
|
||||||
// returns a . b
|
// returns a . b
|
||||||
double
|
FLOATTYPE
|
||||||
VSMatrix::dotProduct(const double *a, const double *b) {
|
VSMatrix::dotProduct(const FLOATTYPE *a, const FLOATTYPE *b) {
|
||||||
|
|
||||||
double res = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
FLOATTYPE res = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -380,9 +388,9 @@ VSMatrix::dotProduct(const double *a, const double *b) {
|
||||||
|
|
||||||
// Normalize a vec3
|
// Normalize a vec3
|
||||||
void
|
void
|
||||||
VSMatrix::normalize(double *a) {
|
VSMatrix::normalize(FLOATTYPE *a) {
|
||||||
|
|
||||||
double mag = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
|
FLOATTYPE mag = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
|
||||||
|
|
||||||
a[0] /= mag;
|
a[0] /= mag;
|
||||||
a[1] /= mag;
|
a[1] /= mag;
|
||||||
|
@ -392,7 +400,7 @@ VSMatrix::normalize(double *a) {
|
||||||
|
|
||||||
// res = b - a
|
// res = b - a
|
||||||
void
|
void
|
||||||
VSMatrix::subtract(const double *a, const double *b, double *res) {
|
VSMatrix::subtract(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res) {
|
||||||
|
|
||||||
res[0] = b[0] - a[0];
|
res[0] = b[0] - a[0];
|
||||||
res[1] = b[1] - a[1];
|
res[1] = b[1] - a[1];
|
||||||
|
@ -402,7 +410,7 @@ VSMatrix::subtract(const double *a, const double *b, double *res) {
|
||||||
|
|
||||||
// res = a + b
|
// res = a + b
|
||||||
void
|
void
|
||||||
VSMatrix::add(const double *a, const double *b, double *res) {
|
VSMatrix::add(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res) {
|
||||||
|
|
||||||
res[0] = b[0] + a[0];
|
res[0] = b[0] + a[0];
|
||||||
res[1] = b[1] + a[1];
|
res[1] = b[1] + a[1];
|
||||||
|
@ -411,8 +419,8 @@ VSMatrix::add(const double *a, const double *b, double *res) {
|
||||||
|
|
||||||
|
|
||||||
// returns |a|
|
// returns |a|
|
||||||
double
|
FLOATTYPE
|
||||||
VSMatrix::length(const double *a) {
|
VSMatrix::length(const FLOATTYPE *a) {
|
||||||
|
|
||||||
return(sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]));
|
return(sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]));
|
||||||
|
|
||||||
|
@ -429,10 +437,10 @@ M3(int i, int j)
|
||||||
|
|
||||||
// computes the derived normal matrix for the view matrix
|
// computes the derived normal matrix for the view matrix
|
||||||
void
|
void
|
||||||
VSMatrix::computeNormalMatrix(const double *aMatrix)
|
VSMatrix::computeNormalMatrix(const FLOATTYPE *aMatrix)
|
||||||
{
|
{
|
||||||
|
|
||||||
double mMat3x3[9];
|
FLOATTYPE mMat3x3[9];
|
||||||
|
|
||||||
mMat3x3[0] = aMatrix[0];
|
mMat3x3[0] = aMatrix[0];
|
||||||
mMat3x3[1] = aMatrix[1];
|
mMat3x3[1] = aMatrix[1];
|
||||||
|
@ -446,7 +454,7 @@ VSMatrix::computeNormalMatrix(const double *aMatrix)
|
||||||
mMat3x3[7] = aMatrix[9];
|
mMat3x3[7] = aMatrix[9];
|
||||||
mMat3x3[8] = aMatrix[10];
|
mMat3x3[8] = aMatrix[10];
|
||||||
|
|
||||||
double det, invDet;
|
FLOATTYPE det, invDet;
|
||||||
|
|
||||||
det = mMat3x3[0] * (mMat3x3[4] * mMat3x3[8] - mMat3x3[5] * mMat3x3[7]) +
|
det = mMat3x3[0] * (mMat3x3[4] * mMat3x3[8] - mMat3x3[5] * mMat3x3[7]) +
|
||||||
mMat3x3[1] * (mMat3x3[5] * mMat3x3[6] - mMat3x3[8] * mMat3x3[3]) +
|
mMat3x3[1] * (mMat3x3[5] * mMat3x3[6] - mMat3x3[8] * mMat3x3[3]) +
|
||||||
|
@ -476,10 +484,10 @@ VSMatrix::computeNormalMatrix(const double *aMatrix)
|
||||||
|
|
||||||
// aux function resMat = resMat * aMatrix
|
// aux function resMat = resMat * aMatrix
|
||||||
void
|
void
|
||||||
VSMatrix::multMatrix(double *resMat, const double *aMatrix)
|
VSMatrix::multMatrix(FLOATTYPE *resMat, const FLOATTYPE *aMatrix)
|
||||||
{
|
{
|
||||||
|
|
||||||
double res[16];
|
FLOATTYPE res[16];
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
|
@ -492,5 +500,5 @@ VSMatrix::multMatrix(double *resMat, const double *aMatrix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(resMat, res, 16 * sizeof(double));
|
memcpy(resMat, res, 16 * sizeof(FLOATTYPE));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,12 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef USE_DOUBLE
|
||||||
|
typedef double FLOATTYPE;
|
||||||
|
#else
|
||||||
|
typedef float FLOATTYPE;
|
||||||
|
#endif
|
||||||
|
|
||||||
class VSMatrix {
|
class VSMatrix {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -35,27 +41,32 @@ class VSMatrix {
|
||||||
loadIdentity();
|
loadIdentity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void translate(double x, double y, double z);
|
void translate(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
||||||
void scale(double x, double y, double z);
|
void scale(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
||||||
void rotate(double angle, double x, double y, double z);
|
void rotate(FLOATTYPE angle, FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
||||||
void loadIdentity();
|
void loadIdentity();
|
||||||
|
#ifdef USE_DOUBLE
|
||||||
void multMatrix(const float *aMatrix);
|
void multMatrix(const float *aMatrix);
|
||||||
void multMatrix(const double *aMatrix);
|
#endif
|
||||||
|
void multMatrix(const FLOATTYPE *aMatrix);
|
||||||
void multMatrix(const VSMatrix &aMatrix)
|
void multMatrix(const VSMatrix &aMatrix)
|
||||||
{
|
{
|
||||||
multMatrix(aMatrix.mMatrix);
|
multMatrix(aMatrix.mMatrix);
|
||||||
}
|
}
|
||||||
void loadMatrix(const double *aMatrix);
|
void loadMatrix(const FLOATTYPE *aMatrix);
|
||||||
|
#ifdef USE_DOUBLE
|
||||||
void loadMatrix(const float *aMatrix);
|
void loadMatrix(const float *aMatrix);
|
||||||
void lookAt(double xPos, double yPos, double zPos, double xLook, double yLook, double zLook, double xUp, double yUp, double zUp);
|
#endif
|
||||||
void perspective(double fov, double ratio, double nearp, double farp);
|
void lookAt(FLOATTYPE xPos, FLOATTYPE yPos, FLOATTYPE zPos, FLOATTYPE xLook, FLOATTYPE yLook, FLOATTYPE zLook, FLOATTYPE xUp, FLOATTYPE yUp, FLOATTYPE zUp);
|
||||||
void ortho(double left, double right, double bottom, double top, double nearp=-1.0f, double farp=1.0f);
|
void perspective(FLOATTYPE fov, FLOATTYPE ratio, FLOATTYPE nearp, FLOATTYPE farp);
|
||||||
void frustum(double left, double right, double bottom, double top, double nearp, double farp);
|
void ortho(FLOATTYPE left, FLOATTYPE right, FLOATTYPE bottom, FLOATTYPE top, FLOATTYPE nearp=-1.0f, FLOATTYPE farp=1.0f);
|
||||||
void copy(double * pDest)
|
void frustum(FLOATTYPE left, FLOATTYPE right, FLOATTYPE bottom, FLOATTYPE top, FLOATTYPE nearp, FLOATTYPE farp);
|
||||||
|
void copy(FLOATTYPE * pDest)
|
||||||
{
|
{
|
||||||
memcpy(pDest, mMatrix, 16 * sizeof(double));
|
memcpy(pDest, mMatrix, 16 * sizeof(FLOATTYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_DOUBLE
|
||||||
void copy(float * pDest)
|
void copy(float * pDest)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
|
@ -63,30 +74,38 @@ class VSMatrix {
|
||||||
pDest[i] = (float)mMatrix[i];
|
pDest[i] = (float)mMatrix[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const FLOATTYPE *get() const
|
||||||
|
{
|
||||||
|
return mMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
void matrixToGL(int location);
|
void matrixToGL(int location);
|
||||||
void multMatrixPoint(const double *point, double *res);
|
void multMatrixPoint(const FLOATTYPE *point, FLOATTYPE *res);
|
||||||
|
|
||||||
|
#ifdef USE_DOUBLE
|
||||||
void computeNormalMatrix(const float *aMatrix);
|
void computeNormalMatrix(const float *aMatrix);
|
||||||
void computeNormalMatrix(const double *aMatrix);
|
#endif
|
||||||
|
void computeNormalMatrix(const FLOATTYPE *aMatrix);
|
||||||
void computeNormalMatrix(const VSMatrix &aMatrix)
|
void computeNormalMatrix(const VSMatrix &aMatrix)
|
||||||
{
|
{
|
||||||
computeNormalMatrix(aMatrix.mMatrix);
|
computeNormalMatrix(aMatrix.mMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void crossProduct(const double *a, const double *b, double *res);
|
static void crossProduct(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res);
|
||||||
static double dotProduct(const double *a, const double * b);
|
static FLOATTYPE dotProduct(const FLOATTYPE *a, const FLOATTYPE * b);
|
||||||
static void normalize(double *a);
|
static void normalize(FLOATTYPE *a);
|
||||||
static void subtract(const double *a, const double *b, double *res);
|
static void subtract(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res);
|
||||||
static void add(const double *a, const double *b, double *res);
|
static void add(const FLOATTYPE *a, const FLOATTYPE *b, FLOATTYPE *res);
|
||||||
static double length(const double *a);
|
static FLOATTYPE length(const FLOATTYPE *a);
|
||||||
static void multMatrix(double *resMatrix, const double *aMatrix);
|
static void multMatrix(FLOATTYPE *resMatrix, const FLOATTYPE *aMatrix);
|
||||||
|
|
||||||
static void setIdentityMatrix(double *mat, int size = 4);
|
static void setIdentityMatrix(FLOATTYPE *mat, int size = 4);
|
||||||
|
|
||||||
/// The storage for matrices
|
/// The storage for matrices
|
||||||
double mMatrix[16];
|
FLOATTYPE mMatrix[16];
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -807,64 +807,40 @@ void gl_RenderModel(GLSprite * spr)
|
||||||
if(smf->flags & MDL_INHERITACTORPITCH) pitch += float(static_cast<double>(spr->actor->pitch >> 16) / (1 << 13) * 45 + static_cast<double>(spr->actor->pitch & 0x0000FFFF) / (1 << 29) * 45);
|
if(smf->flags & MDL_INHERITACTORPITCH) pitch += float(static_cast<double>(spr->actor->pitch >> 16) / (1 << 13) * 45 + static_cast<double>(spr->actor->pitch & 0x0000FFFF) / (1 << 29) * 45);
|
||||||
if(smf->flags & MDL_INHERITACTORROLL) roll += float(static_cast<double>(spr->actor->roll >> 16) / (1 << 13) * 45 + static_cast<double>(spr->actor->roll & 0x0000FFFF) / (1 << 29) * 45);
|
if(smf->flags & MDL_INHERITACTORROLL) roll += float(static_cast<double>(spr->actor->roll >> 16) / (1 << 13) * 45 + static_cast<double>(spr->actor->roll & 0x0000FFFF) / (1 << 29) * 45);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE7); // Hijack the otherwise unused seventh texture matrix for the model to world transformation.
|
gl_RenderState.mModelMatrix.loadIdentity();
|
||||||
glMatrixMode(GL_TEXTURE);
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
// Model space => World space
|
// Model space => World space
|
||||||
glTranslatef(spr->x, spr->z, spr->y );
|
gl_RenderState.mModelMatrix.translate(spr->x, spr->z, spr->y );
|
||||||
|
|
||||||
// Applying model transformations:
|
// Applying model transformations:
|
||||||
// 1) Applying actor angle, pitch and roll to the model
|
// 1) Applying actor angle, pitch and roll to the model
|
||||||
glRotatef(-angle, 0, 1, 0);
|
gl_RenderState.mModelMatrix.rotate(-angle, 0, 1, 0);
|
||||||
glRotatef(pitch, 0, 0, 1);
|
gl_RenderState.mModelMatrix.rotate(pitch, 0, 0, 1);
|
||||||
glRotatef(-roll, 1, 0, 0);
|
gl_RenderState.mModelMatrix.rotate(-roll, 1, 0, 0);
|
||||||
|
|
||||||
// 2) Applying Doomsday like rotation of the weapon pickup models
|
// 2) Applying Doomsday like rotation of the weapon pickup models
|
||||||
// The rotation angle is based on the elapsed time.
|
// The rotation angle is based on the elapsed time.
|
||||||
|
|
||||||
if( smf->flags & MDL_ROTATING )
|
if( smf->flags & MDL_ROTATING )
|
||||||
{
|
{
|
||||||
glTranslatef(smf->rotationCenterX, smf->rotationCenterY, smf->rotationCenterZ);
|
gl_RenderState.mModelMatrix.translate(smf->rotationCenterX, smf->rotationCenterY, smf->rotationCenterZ);
|
||||||
glRotatef(rotateOffset, smf->xrotate, smf->yrotate, smf->zrotate);
|
gl_RenderState.mModelMatrix.rotate(rotateOffset, smf->xrotate, smf->yrotate, smf->zrotate);
|
||||||
glTranslatef(-smf->rotationCenterX, -smf->rotationCenterY, -smf->rotationCenterZ);
|
gl_RenderState.mModelMatrix.translate(-smf->rotationCenterX, -smf->rotationCenterY, -smf->rotationCenterZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) Scaling model.
|
// 3) Scaling model.
|
||||||
glScalef(scaleFactorX, scaleFactorZ, scaleFactorY);
|
gl_RenderState.mModelMatrix.scale(scaleFactorX, scaleFactorZ, scaleFactorY);
|
||||||
|
|
||||||
// 4) Aplying model offsets (model offsets do not depend on model scalings).
|
// 4) Aplying model offsets (model offsets do not depend on model scalings).
|
||||||
glTranslatef(smf->xoffset / smf->xscale, smf->zoffset / smf->zscale, smf->yoffset / smf->yscale);
|
gl_RenderState.mModelMatrix.translate(smf->xoffset / smf->xscale, smf->zoffset / smf->zscale, smf->yoffset / smf->yscale);
|
||||||
|
|
||||||
// 5) Applying model rotations.
|
// 5) Applying model rotations.
|
||||||
glRotatef(-ANGLE_TO_FLOAT(smf->angleoffset), 0, 1, 0);
|
gl_RenderState.mModelMatrix.rotate(-ANGLE_TO_FLOAT(smf->angleoffset), 0, 1, 0);
|
||||||
glRotatef(smf->pitchoffset, 0, 0, 1);
|
gl_RenderState.mModelMatrix.rotate(smf->pitchoffset, 0, 0, 1);
|
||||||
glRotatef(-smf->rolloffset, 1, 0, 0);
|
gl_RenderState.mModelMatrix.rotate(-smf->rolloffset, 1, 0, 0);
|
||||||
|
gl_RenderState.EnableModelMatrix(true);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (gl_light_models)
|
|
||||||
{
|
|
||||||
// The normal transform matrix only contains the inverse rotations and scalings but not the translations
|
|
||||||
NormalTransform.MakeIdentity();
|
|
||||||
|
|
||||||
NormalTransform.Scale(1.f/scaleFactorX, 1.f/scaleFactorZ, 1.f/scaleFactorY);
|
|
||||||
if( smf->flags & MDL_ROTATING ) NormalTransform.Rotate(smf->xrotate, smf->yrotate, smf->zrotate, -rotateOffset);
|
|
||||||
if (pitch != 0) NormalTransform.Rotate(0,0,1,-pitch);
|
|
||||||
if (angle != 0) NormalTransform.Rotate(0,1,0, angle);
|
|
||||||
|
|
||||||
gl_RenderFrameModels( smf, spr->actor->state, spr->actor->tics, RUNTIME_TYPE(spr->actor), &ModelToWorld, &NormalTransform, translation );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gl_RenderFrameModels( smf, spr->actor->state, spr->actor->tics, RUNTIME_TYPE(spr->actor), NULL, translation );
|
gl_RenderFrameModels( smf, spr->actor->state, spr->actor->tics, RUNTIME_TYPE(spr->actor), NULL, translation );
|
||||||
|
gl_RenderState.EnableModelMatrix(false);
|
||||||
glActiveTexture(GL_TEXTURE7);
|
|
||||||
glMatrixMode(GL_TEXTURE);
|
|
||||||
glLoadIdentity();
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
|
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
if (!( spr->actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] ))
|
if (!( spr->actor->RenderStyle == LegacyRenderStyles[STYLE_Normal] ))
|
||||||
|
|
|
@ -56,6 +56,8 @@ FRenderState gl_RenderState;
|
||||||
CVAR(Bool, gl_direct_state_change, true, 0)
|
CVAR(Bool, gl_direct_state_change, true, 0)
|
||||||
|
|
||||||
|
|
||||||
|
static VSMatrix identityMatrix(1);
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -225,6 +227,27 @@ bool FRenderState::ApplyShader()
|
||||||
activeShader->muColormapStart.Set(r, g, b, 1.f);
|
activeShader->muColormapStart.Set(r, g, b, 1.f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mTextureMatrixEnabled)
|
||||||
|
{
|
||||||
|
mTextureMatrix.matrixToGL(activeShader->texturematrix_index);
|
||||||
|
activeShader->currentTextureMatrixState = true;
|
||||||
|
}
|
||||||
|
else if (activeShader->currentTextureMatrixState)
|
||||||
|
{
|
||||||
|
activeShader->currentTextureMatrixState = false;
|
||||||
|
identityMatrix.matrixToGL(activeShader->texturematrix_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mModelMatrixEnabled)
|
||||||
|
{
|
||||||
|
mModelMatrix.matrixToGL(activeShader->modelmatrix_index);
|
||||||
|
activeShader->currentModelMatrixState = true;
|
||||||
|
}
|
||||||
|
else if (activeShader->currentModelMatrixState)
|
||||||
|
{
|
||||||
|
activeShader->currentModelMatrixState = false;
|
||||||
|
identityMatrix.matrixToGL(activeShader->modelmatrix_index);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "gl/system/gl_interface.h"
|
#include "gl/system/gl_interface.h"
|
||||||
#include "gl/data/gl_data.h"
|
#include "gl/data/gl_data.h"
|
||||||
|
#include "gl/data/gl_matrix.h"
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
#include "r_defs.h"
|
#include "r_defs.h"
|
||||||
|
|
||||||
|
@ -58,6 +59,8 @@ class FRenderState
|
||||||
bool m2D;
|
bool m2D;
|
||||||
float mInterpolationFactor;
|
float mInterpolationFactor;
|
||||||
float mClipHeightTop, mClipHeightBottom;
|
float mClipHeightTop, mClipHeightBottom;
|
||||||
|
bool mModelMatrixEnabled;
|
||||||
|
bool mTextureMatrixEnabled;
|
||||||
|
|
||||||
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer;
|
FVertexBuffer *mVertexBuffer, *mCurrentVertexBuffer;
|
||||||
FStateVec4 mColor;
|
FStateVec4 mColor;
|
||||||
|
@ -80,6 +83,12 @@ class FRenderState
|
||||||
bool ApplyShader();
|
bool ApplyShader();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
VSMatrix mProjectionMatrix;
|
||||||
|
VSMatrix mViewMatrix;
|
||||||
|
VSMatrix mModelMatrix;
|
||||||
|
VSMatrix mTextureMatrix;
|
||||||
|
|
||||||
FRenderState()
|
FRenderState()
|
||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
|
@ -89,6 +98,7 @@ public:
|
||||||
|
|
||||||
void SetupShader(int &shaderindex, float warptime);
|
void SetupShader(int &shaderindex, float warptime);
|
||||||
void Apply();
|
void Apply();
|
||||||
|
void ApplyMatrices();
|
||||||
|
|
||||||
void SetVertexBuffer(FVertexBuffer *vb)
|
void SetVertexBuffer(FVertexBuffer *vb)
|
||||||
{
|
{
|
||||||
|
@ -180,6 +190,16 @@ public:
|
||||||
mBrightmapEnabled = on;
|
mBrightmapEnabled = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EnableModelMatrix(bool on)
|
||||||
|
{
|
||||||
|
mModelMatrixEnabled = on;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnableTextureMatrix(bool on)
|
||||||
|
{
|
||||||
|
mTextureMatrixEnabled = on;
|
||||||
|
}
|
||||||
|
|
||||||
void SetCameraPos(float x, float y, float z)
|
void SetCameraPos(float x, float y, float z)
|
||||||
{
|
{
|
||||||
mCameraPos.Set(x, z, y, 0);
|
mCameraPos.Set(x, z, y, 0);
|
||||||
|
|
|
@ -1083,10 +1083,9 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo
|
||||||
float fviewy = FIXED2FLOAT(viewy);
|
float fviewy = FIXED2FLOAT(viewy);
|
||||||
float fviewz = FIXED2FLOAT(viewz);
|
float fviewz = FIXED2FLOAT(viewz);
|
||||||
|
|
||||||
|
gl_SetPlaneTextureRotation(&plane, gltexture);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
|
||||||
bool pushed = gl_SetPlaneTextureRotation(&plane, gltexture);
|
|
||||||
|
|
||||||
float prj_fac1 = (planez-fviewz)/(ws->z1-fviewz);
|
float prj_fac1 = (planez-fviewz)/(ws->z1-fviewz);
|
||||||
float prj_fac2 = (planez-fviewz)/(ws->z2-fviewz);
|
float prj_fac2 = (planez-fviewz)/(ws->z2-fviewz);
|
||||||
|
|
||||||
|
@ -1113,11 +1112,7 @@ void FDrawInfo::DrawFloodedPlane(wallseg * ws, float planez, sector_t * sec, boo
|
||||||
ptr++;
|
ptr++;
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_FAN);
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_FAN);
|
||||||
|
|
||||||
if (pushed)
|
gl_RenderState.EnableTextureMatrix(false);
|
||||||
{
|
|
||||||
glPopMatrix();
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
|
@ -273,7 +273,7 @@ public:
|
||||||
|
|
||||||
extern FDrawInfo * gl_drawinfo;
|
extern FDrawInfo * gl_drawinfo;
|
||||||
|
|
||||||
bool gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture);
|
void gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture);
|
||||||
void gl_SetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblending);
|
void gl_SetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblending);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -70,7 +70,7 @@
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
bool gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture)
|
void gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * gltexture)
|
||||||
{
|
{
|
||||||
// only manipulate the texture matrix if needed.
|
// only manipulate the texture matrix if needed.
|
||||||
if (secplane->xoffs != 0 || secplane->yoffs != 0 ||
|
if (secplane->xoffs != 0 || secplane->yoffs != 0 ||
|
||||||
|
@ -93,15 +93,13 @@ bool gl_SetPlaneTextureRotation(const GLSectorPlane * secplane, FMaterial * glte
|
||||||
float xscale2=64.f/gltexture->TextureWidth(GLUSE_TEXTURE);
|
float xscale2=64.f/gltexture->TextureWidth(GLUSE_TEXTURE);
|
||||||
float yscale2=64.f/gltexture->TextureHeight(GLUSE_TEXTURE);
|
float yscale2=64.f/gltexture->TextureHeight(GLUSE_TEXTURE);
|
||||||
|
|
||||||
glMatrixMode(GL_TEXTURE);
|
gl_RenderState.mTextureMatrix.loadIdentity();
|
||||||
glPushMatrix();
|
gl_RenderState.mTextureMatrix.scale(xscale1 ,yscale1,1.0f);
|
||||||
glScalef(xscale1 ,yscale1,1.0f);
|
gl_RenderState.mTextureMatrix.translate(uoffs,voffs,0.0f);
|
||||||
glTranslatef(uoffs,voffs,0.0f);
|
gl_RenderState.mTextureMatrix.scale(xscale2 ,yscale2,1.0f);
|
||||||
glScalef(xscale2 ,yscale2,1.0f);
|
gl_RenderState.mTextureMatrix.rotate(angle,0.0f,0.0f,1.0f);
|
||||||
glRotatef(angle,0.0f,0.0f,1.0f);
|
gl_RenderState.EnableTextureMatrix(true);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -377,13 +375,9 @@ void GLFlat::Draw(int pass)
|
||||||
case GLPASS_TEXTURE:
|
case GLPASS_TEXTURE:
|
||||||
{
|
{
|
||||||
gltexture->Bind();
|
gltexture->Bind();
|
||||||
bool pushed = gl_SetPlaneTextureRotation(&plane, gltexture);
|
gl_SetPlaneTextureRotation(&plane, gltexture);
|
||||||
DrawSubsectors(pass, false);
|
DrawSubsectors(pass, false);
|
||||||
if (pushed)
|
gl_RenderState.EnableTextureMatrix(false);
|
||||||
{
|
|
||||||
glPopMatrix();
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,13 +434,9 @@ void GLFlat::Draw(int pass)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gltexture->Bind();
|
gltexture->Bind();
|
||||||
bool pushed = gl_SetPlaneTextureRotation(&plane, gltexture);
|
gl_SetPlaneTextureRotation(&plane, gltexture);
|
||||||
DrawSubsectors(pass, true);
|
DrawSubsectors(pass, true);
|
||||||
if (pushed)
|
gl_RenderState.EnableTextureMatrix(false);
|
||||||
{
|
|
||||||
glPopMatrix();
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
if (renderstyle==STYLE_Add) gl_RenderState.BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1000,7 +1000,7 @@ void GLHorizonPortal::DrawContents()
|
||||||
|
|
||||||
gltexture->Bind();
|
gltexture->Bind();
|
||||||
|
|
||||||
bool pushed = gl_SetPlaneTextureRotation(sp, gltexture);
|
gl_SetPlaneTextureRotation(sp, gltexture);
|
||||||
gl_RenderState.EnableAlphaTest(false);
|
gl_RenderState.EnableAlphaTest(false);
|
||||||
gl_RenderState.BlendFunc(GL_ONE,GL_ZERO);
|
gl_RenderState.BlendFunc(GL_ONE,GL_ZERO);
|
||||||
gl_RenderState.Apply();
|
gl_RenderState.Apply();
|
||||||
|
@ -1059,12 +1059,7 @@ void GLHorizonPortal::DrawContents()
|
||||||
ptr++;
|
ptr++;
|
||||||
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
GLRenderer->mVBO->RenderCurrent(ptr, GL_TRIANGLE_STRIP);
|
||||||
|
|
||||||
if (pushed)
|
gl_RenderState.EnableTextureMatrix(false);
|
||||||
{
|
|
||||||
glPopMatrix();
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
}
|
|
||||||
|
|
||||||
PortalAll.Unclock();
|
PortalAll.Unclock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,14 +286,6 @@ void FGLRenderer::SetProjection(float fov, float ratio, float fovratio)
|
||||||
|
|
||||||
void FGLRenderer::SetViewMatrix(bool mirror, bool planemirror)
|
void FGLRenderer::SetViewMatrix(bool mirror, bool planemirror)
|
||||||
{
|
{
|
||||||
glActiveTexture(GL_TEXTURE7);
|
|
||||||
glMatrixMode(GL_TEXTURE);
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glMatrixMode(GL_TEXTURE);
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
|
|
@ -293,20 +293,17 @@ void RenderDome(FMaterial * tex, float x_offset, float y_offset, bool mirror, in
|
||||||
glScalef(1.f, 1.2f * 1.17f, 1.f);
|
glScalef(1.f, 1.2f * 1.17f, 1.f);
|
||||||
yscale = 240.f / texh;
|
yscale = 240.f / texh;
|
||||||
}
|
}
|
||||||
glMatrixMode(GL_TEXTURE);
|
gl_RenderState.EnableTextureMatrix(true);
|
||||||
glPushMatrix();
|
gl_RenderState.mTextureMatrix.loadIdentity();
|
||||||
glLoadIdentity();
|
gl_RenderState.mTextureMatrix.scale(mirror? -xscale : xscale, yscale, 1.f);
|
||||||
glScalef(mirror? -xscale : xscale, yscale, 1.f);
|
gl_RenderState.mTextureMatrix.translate(1.f, y_offset / texh, 1.f);
|
||||||
glTranslatef(1.f, y_offset / texh, 1.f);
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLRenderer->mSkyVBO->RenderDome(tex, mode);
|
GLRenderer->mSkyVBO->RenderDome(tex, mode);
|
||||||
|
gl_RenderState.EnableTextureMatrix(false);
|
||||||
|
|
||||||
if (tex)
|
if (tex)
|
||||||
{
|
{
|
||||||
glMatrixMode(GL_TEXTURE);
|
|
||||||
glPopMatrix();
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,6 +206,8 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char *
|
||||||
timer_index = glGetUniformLocation(hShader, "timer");
|
timer_index = glGetUniformLocation(hShader, "timer");
|
||||||
lights_index = glGetUniformLocation(hShader, "lights");
|
lights_index = glGetUniformLocation(hShader, "lights");
|
||||||
fakevb_index = glGetUniformLocation(hShader, "fakeVB");
|
fakevb_index = glGetUniformLocation(hShader, "fakeVB");
|
||||||
|
modelmatrix_index = glGetUniformLocation(hShader, "ModelMatrix");
|
||||||
|
texturematrix_index = glGetUniformLocation(hShader, "TextureMatrix");
|
||||||
|
|
||||||
glBindAttribLocation(hShader, VATTR_VERTEX2, "aVertex2");
|
glBindAttribLocation(hShader, VATTR_VERTEX2, "aVertex2");
|
||||||
|
|
||||||
|
|
|
@ -198,11 +198,15 @@ class FShader
|
||||||
|
|
||||||
int timer_index;
|
int timer_index;
|
||||||
int lights_index;
|
int lights_index;
|
||||||
|
int modelmatrix_index;
|
||||||
|
int texturematrix_index;
|
||||||
public:
|
public:
|
||||||
int fakevb_index;
|
int fakevb_index;
|
||||||
private:
|
private:
|
||||||
int currentglowstate;
|
int currentglowstate;
|
||||||
int currentfixedcolormap;
|
int currentfixedcolormap;
|
||||||
|
bool currentTextureMatrixState;
|
||||||
|
bool currentModelMatrixState;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FShader(const char *name)
|
FShader(const char *name)
|
||||||
|
@ -211,6 +215,8 @@ public:
|
||||||
hShader = hVertProg = hFragProg = 0;
|
hShader = hVertProg = hFragProg = 0;
|
||||||
currentglowstate = 0;
|
currentglowstate = 0;
|
||||||
currentfixedcolormap = 0;
|
currentfixedcolormap = 0;
|
||||||
|
currentTextureMatrixState = true; // by setting the matrix state to 'true' it is guaranteed to be set the first time the render state gets applied.
|
||||||
|
currentModelMatrixState = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
~FShader();
|
~FShader();
|
||||||
|
|
|
@ -36,8 +36,8 @@ uniform ivec4 uLightRange;
|
||||||
|
|
||||||
|
|
||||||
// redefine the matrix names to what they actually represent.
|
// redefine the matrix names to what they actually represent.
|
||||||
#define ModelMatrix gl_TextureMatrix[7]
|
|
||||||
#define ViewMatrix gl_ModelViewMatrix
|
|
||||||
#define ProjectionMatrix gl_ProjectionMatrix
|
#define ProjectionMatrix gl_ProjectionMatrix
|
||||||
#define TextureMatrix gl_TextureMatrix[0]
|
#define ViewMatrix gl_ModelViewMatrix
|
||||||
|
uniform mat4 ModelMatrix;
|
||||||
|
uniform mat4 TextureMatrix;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue