mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-15 16:58:01 +00:00
TINYGL: Last optimization batch, performance comparable to the previous version.
This commit is contained in:
parent
d45c455be4
commit
6c7eaca2eb
@ -25,18 +25,18 @@ void glopArrayElement(GLContext *c, GLParam *param) {
|
||||
}
|
||||
if (states & NORMAL_ARRAY) {
|
||||
i = idx * (3 + c->normal_array_stride);
|
||||
c->current_normal.X = (c->normal_array[i]);
|
||||
c->current_normal.Y = (c->normal_array[i + 1]);
|
||||
c->current_normal.Z = (c->normal_array[i + 2]);
|
||||
c->current_normal.W = (0.0f); // NOTE: this used to be Z but assigning Z again seemed like a bug...
|
||||
c->current_normal.X = c->normal_array[i];
|
||||
c->current_normal.Y = c->normal_array[i + 1];
|
||||
c->current_normal.Z = c->normal_array[i + 2];
|
||||
c->current_normal.W = 0.0f; // NOTE: this used to be Z but assigning Z again seemed like a bug...
|
||||
}
|
||||
if (states & TEXCOORD_ARRAY) {
|
||||
int size = c->texcoord_array_size;
|
||||
i = idx * (size + c->texcoord_array_stride);
|
||||
c->current_tex_coord.X = (c->texcoord_array[i]);
|
||||
c->current_tex_coord.Y = (c->texcoord_array[i + 1]);
|
||||
c->current_tex_coord.Z = (size > 2 ? c->texcoord_array[i + 2] : 0.0f);
|
||||
c->current_tex_coord.W = (size > 3 ? c->texcoord_array[i + 3] : 1.0f);
|
||||
c->current_tex_coord.X = c->texcoord_array[i];
|
||||
c->current_tex_coord.Y = c->texcoord_array[i + 1];
|
||||
c->current_tex_coord.Z = size > 2 ? c->texcoord_array[i + 2] : 0.0f;
|
||||
c->current_tex_coord.W = size > 3 ? c->texcoord_array[i + 3] : 1.0f;
|
||||
}
|
||||
if (states & VERTEX_ARRAY) {
|
||||
GLParam p[5];
|
||||
|
@ -175,8 +175,8 @@ static float name(Vector4 *c, Vector4 *a, Vector4 *b) { \
|
||||
t = 0; \
|
||||
else \
|
||||
t = (sign a->dir - a->W) / den; \
|
||||
c-> dir1 = (a-> dir1 + t * d ## dir1); \
|
||||
c-> dir2 = (a-> dir2 + t * d ## dir2); \
|
||||
c-> dir1 = (a->dir1 + t * d ## dir1); \
|
||||
c-> dir2 = (a->dir2 + t * d ## dir2); \
|
||||
c->W = (a->W + t * dW); \
|
||||
c-> dir = (sign c->W); \
|
||||
return t; \
|
||||
@ -205,7 +205,6 @@ static inline void updateTmp(GLContext *c, GLVertex *q,
|
||||
q->color.X = (p0->color.X);
|
||||
q->color.Y = (p0->color.Y);
|
||||
q->color.Z = (p0->color.Z);
|
||||
//q->color = p0->color;
|
||||
}
|
||||
|
||||
if (c->texture_2d_enabled) {
|
||||
|
@ -134,7 +134,7 @@ void glInit(void *zbuffer1) {
|
||||
c->matrix_stack_depth_max[2] = MAX_TEXTURE_STACK_DEPTH;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
c->matrix_stack[i] = (Matrix4*)gl_zalloc(c->matrix_stack_depth_max[i] * sizeof(Matrix4));
|
||||
c->matrix_stack[i] = (Matrix4 *)gl_zalloc(c->matrix_stack_depth_max[i] * sizeof(Matrix4));
|
||||
c->matrix_stack_ptr[i] = c->matrix_stack[i];
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ void gl_shade_vertex(GLContext *c, GLVertex *v) {
|
||||
att = 1.0f / (l->attenuation[0] + dist * (l->attenuation[1] +
|
||||
dist * l->attenuation[2]));
|
||||
}
|
||||
dot = Vector3::dot(d, n);
|
||||
dot = d.X * n.X + d.Y * n.Y + d.Z * n.Z;//Vector3::dot(d, n);
|
||||
if (twoside && dot < 0)
|
||||
dot = -dot;
|
||||
if (dot > 0) {
|
||||
@ -225,7 +225,7 @@ void gl_shade_vertex(GLContext *c, GLVertex *v) {
|
||||
|
||||
// spot light
|
||||
if (l->spot_cutoff != 180) {
|
||||
dot_spot = -Vector3::dot(d, l->norm_spot_direction);
|
||||
dot_spot = -( d.X * l->norm_spot_direction.X + d.Y * l->norm_spot_direction.Y + d.Z * l->norm_spot_direction.Z); //Vector3::dot(d, l->norm_spot_direction);
|
||||
if (twoside && dot_spot < 0)
|
||||
dot_spot = -dot_spot;
|
||||
if (dot_spot < l->cos_spot_cutoff) {
|
||||
@ -255,7 +255,7 @@ void gl_shade_vertex(GLContext *c, GLVertex *v) {
|
||||
s = d;
|
||||
s.Z = (s.Z + 1.0);
|
||||
}
|
||||
dot_spec = Vector3::dot(n, s);
|
||||
dot_spec = n.X * s.X + n.Y + s.Y + n.Z * s.Z; //Vector3::dot(n, s);
|
||||
if (twoside && dot_spec < 0)
|
||||
dot_spec = -dot_spec;
|
||||
if (dot_spec > 0) {
|
||||
|
@ -168,12 +168,12 @@ void glopRotate(GLContext *c, GLParam *p) {
|
||||
}
|
||||
|
||||
void glopScale(GLContext *c, GLParam *p) {
|
||||
c->matrix_stack_ptr[c->matrix_mode]->scale(p[1].f,p[2].f,p[3].f);
|
||||
c->matrix_stack_ptr[c->matrix_mode]->scale(p[1].f, p[2].f, p[3].f);
|
||||
gl_matrix_update(c);
|
||||
}
|
||||
|
||||
void glopTranslate(GLContext *c, GLParam *p) {
|
||||
c->matrix_stack_ptr[c->matrix_mode]->translate(p[1].f,p[2].f,p[3].f);
|
||||
c->matrix_stack_ptr[c->matrix_mode]->translate(p[1].f, p[2].f, p[3].f);
|
||||
gl_matrix_update(c);
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ void glopFrustum(GLContext *c, GLParam *p) {
|
||||
float top = p[4].f;
|
||||
float nearp = p[5].f;
|
||||
float farp = p[6].f;
|
||||
Matrix4 m = Matrix4::frustrum(left,right,bottom,top,nearp,farp);
|
||||
Matrix4 m = Matrix4::frustrum(left, right, bottom, top, nearp, farp);
|
||||
|
||||
*c->matrix_stack_ptr[c->matrix_mode] *= m;
|
||||
|
||||
|
@ -141,14 +141,6 @@ static inline void gl_vertex_transform(GLContext *c, GLVertex *v) {
|
||||
m = c->matrix_stack_ptr[1];
|
||||
v->pc = m->transform(v->ec);
|
||||
|
||||
/*
|
||||
// NOTE: this transformation is not an ordinary matrix vector multiplication.
|
||||
v->pc = Vector4(v->ec.getX() * m->get(0, 0) + v->ec.getY() * m->get(1, 0) + v->ec.getZ() * m->get(2, 0) + v->ec.getW() * m->get(3, 0),
|
||||
v->ec.getX() * m->get(0, 1) + v->ec.getY() * m->get(1, 1) + v->ec.getZ() * m->get(2, 1) + v->ec.getW() * m->get(3, 1),
|
||||
v->ec.getX() * m->get(0, 2) + v->ec.getY() * m->get(1, 2) + v->ec.getZ() * m->get(2, 2) + v->ec.getW() * m->get(3, 2),
|
||||
v->ec.getX() * m->get(0, 3) + v->ec.getY() * m->get(1, 3) + v->ec.getZ() * m->get(2, 3) + v->ec.getW() * m->get(3, 3));
|
||||
*/
|
||||
|
||||
m = &c->matrix_model_view_inv;
|
||||
n = &c->current_normal;
|
||||
|
||||
|
@ -135,12 +135,6 @@ int Matrix_Inv(float *r, float *m, int n) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector3::Vector3(float x, float y, float z) {
|
||||
_v[0] = x;
|
||||
_v[1] = y;
|
||||
_v[2] = z;
|
||||
}
|
||||
|
||||
void Vector3::normalize() {
|
||||
float n;
|
||||
n = sqrt(_v[0] * _v[0] + _v[1] * _v[1] + _v[2] * _v[2]);
|
||||
@ -151,13 +145,6 @@ void Vector3::normalize() {
|
||||
}
|
||||
}
|
||||
|
||||
Vector4::Vector4(float x, float y, float z, float w) {
|
||||
_v[0] = x;
|
||||
_v[1] = y;
|
||||
_v[2] = z;
|
||||
_v[3] = w;
|
||||
}
|
||||
|
||||
Vector4::Vector4(const Vector3 &vec, float w) {
|
||||
_v[0] = vec.X;
|
||||
_v[1] = vec.Y;
|
||||
@ -276,10 +263,12 @@ bool Matrix4::IsIdentity() const {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
if (i == j) {
|
||||
if (_m[i][j] != 1.0)
|
||||
if (_m[i][j] != 1.0) {
|
||||
return false;
|
||||
} else if (_m[i][j] != 0.0)
|
||||
}
|
||||
} else if (_m[i][j] != 0.0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -12,16 +12,16 @@ namespace TinyGL {
|
||||
class Vector3 {
|
||||
public:
|
||||
Vector3() { }
|
||||
Vector3(float x, float y, float z);
|
||||
Vector3(float x, float y, float z) {
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
void normalize();
|
||||
|
||||
float getLength() const { return sqrt(_v[0] * _v[0] + _v[1] * _v[1] + _v[2] * _v[2]); }
|
||||
|
||||
static float dot(const Vector3 &a, const Vector3 &b) {
|
||||
return a._v[0] * b._v[0] + a._v[1] * b._v[1] + a._v[2] * b._v[2];
|
||||
}
|
||||
|
||||
bool operator==(const Vector3 &other) const {
|
||||
return _v[0] == other._v[0] && _v[1] == other._v[1] && _v[2] == other._v[2];
|
||||
}
|
||||
@ -74,7 +74,13 @@ class Vector4 {
|
||||
public:
|
||||
Vector4() { }
|
||||
Vector4(const Vector3 &vec, float w);
|
||||
Vector4(float x, float y, float z, float w);
|
||||
|
||||
Vector4(float x, float y, float z, float w) {
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
W = w;
|
||||
}
|
||||
|
||||
bool operator==(const Vector4 &other) const {
|
||||
return _v[0] == other._v[0] && _v[1] == other._v[1] && _v[2] == other._v[2] && _v[3] == other._v[3];
|
||||
|
Loading…
x
Reference in New Issue
Block a user