Highpalookup maps implementation on the renderer side. Currently set to a hardcoded highpalookup of 6:6:6->RGB and causes a noticeable quality drop. Use the debug1 cvar to toggle ingame.

git-svn-id: https://svn.eduke32.com/eduke32@1745 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
plagman 2010-12-29 06:23:49 +00:00
parent d3a17f62a2
commit 5582d41553
4 changed files with 123 additions and 1 deletions

View file

@ -120,6 +120,7 @@ extern void (APIENTRY * bglGenTextures)( GLsizei n, GLuint *textures ); // 1.1
extern void (APIENTRY * bglDeleteTextures)( GLsizei n, const GLuint *textures); // 1.1
extern void (APIENTRY * bglBindTexture)( GLenum target, GLuint texture ); // 1.1
extern void (APIENTRY * bglTexImage2D)( GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels );
extern void (APIENTRY * bglTexImage3D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
extern void (APIENTRY * bglCopyTexImage2D)( GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border );
extern void (APIENTRY * bglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
extern void (APIENTRY * bglTexSubImage2D)( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels ); // 1.1

View file

@ -67,6 +67,8 @@ typedef enum {
PR_BIT_LIGHTING_PASS,
PR_BIT_NORMAL_MAP,
PR_BIT_DIFFUSE_MAP,
PR_BIT_HIGHPALOOKUP_MAP,
PR_BIT_DIFFUSE_MAP2,
PR_BIT_DIFFUSE_DETAIL_MAP,
PR_BIT_DIFFUSE_MODULATION,
PR_BIT_SPECULAR_MAP,
@ -94,6 +96,8 @@ typedef struct s_prmaterial {
// PR_BIT_DIFFUSE_MAP
GLuint diffusemap;
GLfloat diffusescale[2];
// PR_BIT_HIGHPALOOKUP_MAP
GLuint highpalookupmap;
// PR_BIT_DIFFUSE_DETAIL_MAP
GLuint detailmap;
GLfloat detailscale[2];
@ -127,6 +131,8 @@ typedef struct s_prrograminfo {
// PR_BIT_DIFFUSE_MAP
GLint uniform_diffuseMap;
GLint uniform_diffuseScale;
// PR_BIT_HIGHPALOOKUP_MAP
GLuint uniform_highPalookupMap;
// PR_BIT_DIFFUSE_DETAIL_MAP
GLint uniform_detailMap;
GLint uniform_detailScale;

View file

@ -87,6 +87,7 @@ void (APIENTRY * bglGenTextures)(GLsizei n, GLuint *textures); // 1.1
void (APIENTRY * bglDeleteTextures)(GLsizei n, const GLuint *textures); // 1.1
void (APIENTRY * bglBindTexture)(GLenum target, GLuint texture); // 1.1
void (APIENTRY * bglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
void (APIENTRY * bglTexImage3D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
void (APIENTRY * bglCopyTexImage2D)(GLenum target, GLint level, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
void (APIENTRY * bglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
void (APIENTRY * bglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels); // 1.1
@ -431,6 +432,7 @@ int32_t loadgldriver(const char *driver)
bglDeleteTextures = GETPROC("glDeleteTextures");
bglBindTexture = GETPROC("glBindTexture");
bglTexImage2D = GETPROC("glTexImage2D");
bglTexImage3D = GETPROC("glTexImage3D");
bglCopyTexImage2D = GETPROC("glCopyTexImage2D");
bglCopyTexSubImage2D= GETPROC("glCopyTexSubImage2D");
bglTexSubImage2D = GETPROC("glTexSubImage2D");
@ -709,6 +711,7 @@ int32_t unloadgldriver(void)
bglDeleteTextures = NULL;
bglBindTexture = NULL;
bglTexImage2D = NULL;
bglTexImage3D = NULL;
bglCopyTexImage2D = NULL;
bglCopyTexSubImage2D= NULL;
bglTexSubImage2D = NULL;

View file

@ -255,6 +255,30 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
"\n",
// frag_prog
" diffuseTexel = texture2D(diffuseMap, commonTexCoord.st);\n"
"\n",
},
{
1 << PR_BIT_HIGHPALOOKUP_MAP,
// vert_def
"",
// vert_prog
"",
// frag_def
"uniform sampler3D highPalookupMap;\n"
"\n",
// frag_prog
" diffuseTexel.rgb = texture3D(highPalookupMap, diffuseTexel.rgb).rgb;\n"
"\n",
},
{
1 << PR_BIT_DIFFUSE_MAP2,
// vert_def
"",
// vert_prog
"",
// frag_def
"",
// frag_prog
" if (isLightingPass == 0)\n"
" result *= diffuseTexel;\n"
"\n",
@ -554,6 +578,9 @@ int32_t globaloldoverridematerial;
// RENDER TARGETS
_prrt *prrts;
// HIGHPALOOKUP MAP NAMES
GLuint globalhighpalookupmap;
// CONTROL
GLfloat spritemodelview[16];
GLfloat mdspritespace[4][4];
@ -645,6 +672,60 @@ int32_t polymer_init(void)
polymersearching = FALSE;
polymer_initrendertargets(pr_shadowcount + 1);
// test highpalookup
int32_t j, k;
int32_t xbits = 6, ybits = 6, zbits = 6; // depth
int32_t x = 1 << xbits, y = 1 << ybits, z = 1 << zbits; // dimensions
int32_t bitdiff;
coltype *highpalookup;
highpalookup = malloc(x*y*z*sizeof(coltype));
k = 0;
while (k < z) {
j = 0;
while (j < y) {
i = 0;
while (i < x) {
bitdiff = 8 - xbits;
highpalookup[k * z * y + j * y + i].r = (i << bitdiff) | (i & ((1 << bitdiff) - 1));
bitdiff = 8 - ybits;
highpalookup[k * z * y + j * y + i].g = (j << bitdiff) | (j & ((1 << bitdiff) - 1));
bitdiff = 8 - zbits;
highpalookup[k * z * y + j * y + i].b = (k << bitdiff) | (k & ((1 << bitdiff) - 1));
// unneeded padding, will make the texture upload faster
highpalookup[k * z * y + j * y + i].a = 0;
i++;
}
j++;
}
k++;
}
bglGenTextures(1, &globalhighpalookupmap);
bglBindTexture(GL_TEXTURE_3D, globalhighpalookupmap);
bglTexImage3D(GL_TEXTURE_3D, // target
0, // mip level
GL_RGBA, // internalFormat
x, // width
y, // height
z, // depth
0, // border
GL_RGBA, // upload format
GL_UNSIGNED_BYTE, // upload component type
highpalookup); // data pointer
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
bglTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, glinfo.clamptoedge?GL_CLAMP_TO_EDGE:GL_CLAMP);
bglBindTexture(GL_TEXTURE_3D, 0);
free(highpalookup);
if (pr_verbosity >= 1) OSD_Printf("PR : Initialization complete.\n");
@ -4036,6 +4117,8 @@ static void polymer_getscratchmaterial(_prmaterial* material)
// PR_BIT_DIFFUSE_MAP
material->diffusemap = 0;
material->diffusescale[0] = material->diffusescale[1] = 1.0f;
// PR_BIT_HIGHPALOOKUP_MAP
material->highpalookupmap = 0;
// PR_BIT_DIFFUSE_DETAIL_MAP
material->detailmap = 0;
material->detailscale[0] = material->detailscale[1] = 1.0f;
@ -4149,6 +4232,11 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
programbits = 0;
// --------- bit validation
// hack to dynamically insert highpalookup
if (debug1) {
material.highpalookupmap = globalhighpalookupmap;
}
// PR_BIT_ANIM_INTERPOLATION
if (material.nextframedata)
@ -4163,8 +4251,14 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
programbits |= prprogrambits[PR_BIT_NORMAL_MAP].bit;
// PR_BIT_DIFFUSE_MAP
if (material.diffusemap)
if (material.diffusemap) {
programbits |= prprogrambits[PR_BIT_DIFFUSE_MAP].bit;
programbits |= prprogrambits[PR_BIT_DIFFUSE_MAP2].bit;
}
// PR_BIT_HIGHPALOOKUP_MAP
if (material.highpalookupmap)
programbits |= prprogrambits[PR_BIT_HIGHPALOOKUP_MAP].bit;
// PR_BIT_DIFFUSE_DETAIL_MAP
if (!curlight && r_detailmapping && material.detailmap)
@ -4317,6 +4411,17 @@ static int32_t polymer_bindmaterial(_prmaterial material, int16_t* lights,
texunit++;
}
// PR_BIT_HIGHPALOOKUP_MAP
if (programbits & prprogrambits[PR_BIT_HIGHPALOOKUP_MAP].bit)
{
bglActiveTextureARB(texunit + GL_TEXTURE0_ARB);
bglBindTexture(GL_TEXTURE_3D, material.highpalookupmap);
bglUniform1iARB(prprograms[programbits].uniform_highPalookupMap, texunit);
texunit++;
}
// PR_BIT_DIFFUSE_DETAIL_MAP
if (programbits & prprogrambits[PR_BIT_DIFFUSE_DETAIL_MAP].bit)
{
@ -4636,6 +4741,12 @@ static void polymer_compileprogram(int32_t programbits)
prprograms[programbits].uniform_diffuseScale = bglGetUniformLocationARB(program, "diffuseScale");
}
// PR_BIT_HIGHPALOOKUP_MAP
if (programbits & prprogrambits[PR_BIT_HIGHPALOOKUP_MAP].bit)
{
prprograms[programbits].uniform_highPalookupMap = bglGetUniformLocationARB(program, "highPalookupMap");
}
// PR_BIT_DIFFUSE_DETAIL_MAP
if (programbits & prprogrambits[PR_BIT_DIFFUSE_DETAIL_MAP].bit)
{
@ -5096,6 +5207,7 @@ static void polymer_prepareshadows(void)
overridematerial = prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit;
// used by alpha-testing for sprite silhouette
overridematerial |= prprogrambits[PR_BIT_DIFFUSE_MAP].bit;
overridematerial |= prprogrambits[PR_BIT_DIFFUSE_MAP2].bit;
// to force sprite drawing
mirrors[depth++].plane = NULL;