TINYGL: allow change internal texture size at compilation time. Now it's 1024x1024 pixels.

This commit is contained in:
Pawel Kolodziejski 2014-07-05 12:13:03 +02:00
parent 2072e51813
commit f477946646
5 changed files with 24 additions and 20 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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) )

View file

@ -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

View file

@ -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;