diff --git a/graphics/tinygl/clip.cpp b/graphics/tinygl/clip.cpp index 0ff6812e6bf..d2a2e83d170 100644 --- a/graphics/tinygl/clip.cpp +++ b/graphics/tinygl/clip.cpp @@ -41,8 +41,8 @@ void gl_transform_to_viewport(GLContext *c, GLVertex *v) { // texture if (c->texture_2d_enabled) { - v->zp.s = (int)(v->tex_coord.X * (ZB_POINT_S_MAX - ZB_POINT_S_MIN) + ZB_POINT_S_MIN); - v->zp.t = (int)(v->tex_coord.Y * (ZB_POINT_S_MAX - ZB_POINT_S_MIN) + ZB_POINT_S_MIN); + v->zp.s = (int)(v->tex_coord.X * (ZB_POINT_ST_MAX - ZB_POINT_ST_MIN) + ZB_POINT_ST_MIN); + v->zp.t = (int)(v->tex_coord.Y * (ZB_POINT_ST_MAX - ZB_POINT_ST_MIN) + ZB_POINT_ST_MIN); } } diff --git a/graphics/tinygl/texture.cpp b/graphics/tinygl/texture.cpp index 4b2f117afd4..4ab4f1a966b 100644 --- a/graphics/tinygl/texture.cpp +++ b/graphics/tinygl/texture.cpp @@ -107,7 +107,7 @@ void glopTexImage2D(GLContext *c, GLParam *p) { sourceFormat = Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0); break; default: - error("glTexImage2D: Pixel format not handled."); + error("tglTexImage2D: Pixel format not handled."); } Graphics::PixelFormat pf; @@ -149,19 +149,18 @@ void glopTexImage2D(GLContext *c, GLParam *p) { do_free_after_rgb2rgba = true; } } else if (format != TGL_RGBA || type != TGL_UNSIGNED_BYTE) { - error("glTexImage2D: combination of parameters not handled"); + error("tglTexImage2D: combination of parameters not handled"); } - pixels1 = new byte[MAX_TEXTURE_SIZE * MAX_TEXTURE_SIZE * bytes]; - + pixels1 = new byte[INTERNAL_TEXTURE_SIZE * INTERNAL_TEXTURE_SIZE * bytes]; if (pixels != NULL) { - if (width != MAX_TEXTURE_SIZE || height != MAX_TEXTURE_SIZE) { + if (width != INTERNAL_TEXTURE_SIZE || height != INTERNAL_TEXTURE_SIZE) { // we use interpolation for better looking result - gl_resizeImage(pixels1, MAX_TEXTURE_SIZE, MAX_TEXTURE_SIZE, pixels, width, height); - width = MAX_TEXTURE_SIZE; - height = MAX_TEXTURE_SIZE; + gl_resizeImage(pixels1, INTERNAL_TEXTURE_SIZE, INTERNAL_TEXTURE_SIZE, pixels, width, height); + width = INTERNAL_TEXTURE_SIZE; + height = INTERNAL_TEXTURE_SIZE; } else { - memcpy(pixels1, pixels, MAX_TEXTURE_SIZE * MAX_TEXTURE_SIZE * bytes); + memcpy(pixels1, pixels, INTERNAL_TEXTURE_SIZE * INTERNAL_TEXTURE_SIZE * bytes); } } diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h index 68b1834b068..4dc9877bda9 100644 --- a/graphics/tinygl/zbuffer.h +++ b/graphics/tinygl/zbuffer.h @@ -12,10 +12,10 @@ namespace TinyGL { #define ZB_POINT_Z_FRAC_BITS 14 -#define ZB_POINT_S_MIN ( (1 << 13) ) -#define ZB_POINT_S_MAX ( (1 << 22) - (1 << 13) ) -#define ZB_POINT_T_MIN ( (1 << 21) ) -#define ZB_POINT_T_MAX ( (1 << 30) - (1 << 21) ) +#define ZB_POINT_ST_FRAC_BITS 14 +#define ZB_POINT_ST_FRAC_SHIFT (ZB_POINT_ST_FRAC_BITS - 1) +#define ZB_POINT_ST_MIN ( (1 << ZB_POINT_ST_FRAC_SHIFT) ) +#define ZB_POINT_ST_MAX ( (INTERNAL_TEXTURE_SIZE << ZB_POINT_ST_FRAC_BITS) - (1 << ZB_POINT_ST_FRAC_SHIFT) ) #define ZB_POINT_RED_MIN ( (1 << 10) ) #define ZB_POINT_RED_MAX ( (1 << 16) - (1 << 10) ) diff --git a/graphics/tinygl/zgl.h b/graphics/tinygl/zgl.h index bffeb0b3762..d1cce1f3ef8 100644 --- a/graphics/tinygl/zgl.h +++ b/graphics/tinygl/zgl.h @@ -29,11 +29,12 @@ enum { // specular buffer granularity #define SPECULAR_BUFFER_RESOLUTION 1024 +#define INTERNAL_TEXTURE_SIZE 1024 #define MAX_MODELVIEW_STACK_DEPTH 35 #define MAX_PROJECTION_STACK_DEPTH 8 #define MAX_TEXTURE_STACK_DEPTH 8 -#define MAX_TEXTURE_SIZE 256 +#define MAX_TEXTURE_SIZE INTERNAL_TEXTURE_SIZE #define MAX_NAME_STACK_DEPTH 64 #define MAX_TEXTURE_LEVELS 11 #define T_MAX_LIGHTS 32 diff --git a/graphics/tinygl/ztriangle.cpp b/graphics/tinygl/ztriangle.cpp index e5e311b151d..53d32d1307a 100644 --- a/graphics/tinygl/ztriangle.cpp +++ b/graphics/tinygl/ztriangle.cpp @@ -1,6 +1,7 @@ #include "common/endian.h" #include "graphics/tinygl/zbuffer.h" +#include "graphics/tinygl/zgl.h" namespace TinyGL { @@ -13,7 +14,10 @@ FORCEINLINE static void putPixelMapping(FrameBuffer *buffer, int buf, unsigned i Graphics::PixelBuffer &texture, int _a, unsigned int &z, unsigned int &t, unsigned int &s, int &dzdx, int &dsdx, int &dtdx) { if (buffer->compareDepth(z, pz[_a])) { - buffer->writePixel(buf + _a, texture.getRawBuffer()[((t & 0x3FC00000) | s) >> 14]); + unsigned sss = (s & ((INTERNAL_TEXTURE_SIZE - 1) << ZB_POINT_ST_FRAC_BITS)) >> ZB_POINT_ST_FRAC_BITS; + unsigned ttt = (t & ((INTERNAL_TEXTURE_SIZE - 1) << ZB_POINT_ST_FRAC_BITS)) >> ZB_POINT_ST_FRAC_BITS; + int pixel = ttt * INTERNAL_TEXTURE_SIZE + sss; + buffer->writePixel(buf + _a, texture.getRawBuffer()[pixel]); if (depthWrite) { pz[_a] = z; } @@ -65,9 +69,9 @@ FORCEINLINE static void putPixelMappingPerspective(FrameBuffer *buffer, int buf, unsigned int &z, unsigned int &t, unsigned int &s, int &tmp, unsigned int &rgba, unsigned int &a, int &dzdx, int &dsdx, int &dtdx, unsigned int &drgbdx, unsigned int dadx) { if (buffer->compareDepth(z, pz[_a])) { - unsigned ttt = (t & 0x003FC000) >> 5; - unsigned sss = (s & 0x003FC000) >> 13; - int pixel = ((ttt | sss) >> 1); + unsigned sss = (s & ((INTERNAL_TEXTURE_SIZE - 1) << ZB_POINT_ST_FRAC_BITS)) >> ZB_POINT_ST_FRAC_BITS; + unsigned ttt = (t & ((INTERNAL_TEXTURE_SIZE - 1) << ZB_POINT_ST_FRAC_BITS)) >> ZB_POINT_ST_FRAC_BITS; + int pixel = ttt * INTERNAL_TEXTURE_SIZE + sss; uint8 c_a, c_r, c_g, c_b; uint32 *textureBuffer = (uint32 *)texture.getRawBuffer(pixel); uint32 col = *textureBuffer;