Shader Model 3 "compatibility" for multilights. The light count will be arbitrarily limited and performance will be suboptimal, but it should work.

git-svn-id: https://svn.eduke32.com/eduke32@1222 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
plagman 2009-02-05 08:56:59 +00:00
parent 768f3ad6d6
commit dba29b0fbe
6 changed files with 82 additions and 9 deletions

View file

@ -58,6 +58,7 @@ struct glinfo {
char envcombine; char envcombine;
char vbos; char vbos;
char vsync; char vsync;
char sm4;
char dumped; char dumped;
}; };
extern struct glinfo glinfo; extern struct glinfo glinfo;

View file

@ -23,6 +23,7 @@
# define _polymer_h_ # define _polymer_h_
# include "compat.h" # include "compat.h"
# include "baselayer.h"
# include "build.h" # include "build.h"
# include "glbuild.h" # include "glbuild.h"
# include "osd.h" # include "osd.h"
@ -45,13 +46,16 @@ extern int32_t glerror;
// MATERIAL // MATERIAL
typedef enum { typedef enum {
PR_BIT_HEADER, // must be first
PR_BIT_NV4X_COMPAT,
PR_BIT_G8X_COMPAT,
PR_BIT_ANIM_INTERPOLATION, PR_BIT_ANIM_INTERPOLATION,
PR_BIT_DIFFUSE_MAP, PR_BIT_DIFFUSE_MAP,
PR_BIT_DIFFUSE_DETAIL_MAP, PR_BIT_DIFFUSE_DETAIL_MAP,
PR_BIT_DIFFUSE_MODULATION, PR_BIT_DIFFUSE_MODULATION,
PR_BIT_POINT_LIGHT, PR_BIT_POINT_LIGHT,
PR_BIT_DIFFUSE_GLOW_MAP, PR_BIT_DIFFUSE_GLOW_MAP,
PR_BIT_DEFAULT, // must be just before last PR_BIT_FOOTER, // must be just before last
PR_BIT_COUNT // must be last PR_BIT_COUNT // must be last
} prbittype; } prbittype;

View file

@ -43,6 +43,7 @@ struct glinfo glinfo =
0, // env_combine 0, // env_combine
0, // Vertex Buffer Objects 0, // Vertex Buffer Objects
0, // VSync support 0, // VSync support
0, // Shader Model 4 support
0, // GL info dumped 0, // GL info dumped
}; };
#endif #endif
@ -145,6 +146,7 @@ int32_t osdcmd_glinfo(const osdfuncparm_t *parm)
" Multitexturing: %s\n" " Multitexturing: %s\n"
" env_combine: %s\n" " env_combine: %s\n"
" Vertex Buffer Objects: %s\n" " Vertex Buffer Objects: %s\n"
" Shader Model 4: %s\n"
" Extensions:\n", " Extensions:\n",
glinfo.maxanisotropy, glinfo.maxanisotropy>1.0?"":" (no anisotropic filtering)", glinfo.maxanisotropy, glinfo.maxanisotropy>1.0?"":" (no anisotropic filtering)",
glinfo.bgra ? "supported": "not supported", glinfo.bgra ? "supported": "not supported",
@ -160,7 +162,8 @@ int32_t osdcmd_glinfo(const osdfuncparm_t *parm)
glinfo.rect ? "supported": "not supported", glinfo.rect ? "supported": "not supported",
glinfo.multitex ? "supported": "not supported", glinfo.multitex ? "supported": "not supported",
glinfo.envcombine ? "supported": "not supported", glinfo.envcombine ? "supported": "not supported",
glinfo.vbos ? "supported": "not supported" glinfo.vbos ? "supported": "not supported",
glinfo.sm4 ? "supported": "not supported"
); );
s = Bstrdup(glinfo.extensions); s = Bstrdup(glinfo.extensions);

View file

@ -125,6 +125,43 @@ int32_t lightcount;
// MATERIALS // MATERIALS
_prprogrambit prprogrambits[PR_BIT_COUNT] = { _prprogrambit prprogrambits[PR_BIT_COUNT] = {
{
1 << PR_BIT_HEADER,
// vert_def
"#version 120\n"
"\n",
// vert_prog
"",
// frag_def
"#version 120\n"
"\n",
// frag_prog
"",
},
{
1 << PR_BIT_NV4X_COMPAT,
// vert_def
"",
// vert_prog
"",
// frag_def
"#define LIGHTCOUNT 4\n"
"\n",
// frag_prog
"",
},
{
1 << PR_BIT_G8X_COMPAT,
// vert_def
"",
// vert_prog
"",
// frag_def
"#define LIGHTCOUNT lightCount\n"
"\n",
// frag_prog
"",
},
{ {
1 << PR_BIT_ANIM_INTERPOLATION, 1 << PR_BIT_ANIM_INTERPOLATION,
// vert_def // vert_def
@ -216,7 +253,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
"\n" "\n"
" fragmentNormal = normalize(vertexNormal);\n" " fragmentNormal = normalize(vertexNormal);\n"
"\n" "\n"
" while (l < lightCount) {\n" " while (l < LIGHTCOUNT) {\n"
" lightPos = gl_LightSource[l].ambient.rgb;\n" " lightPos = gl_LightSource[l].ambient.rgb;\n"
" lightDiffuse = gl_LightSource[l].diffuse.rgb;\n" " lightDiffuse = gl_LightSource[l].diffuse.rgb;\n"
" lightRange.x = gl_LightSource[l].constantAttenuation;\n" " lightRange.x = gl_LightSource[l].constantAttenuation;\n"
@ -260,7 +297,7 @@ _prprogrambit prprogrambits[PR_BIT_COUNT] = {
"\n", "\n",
}, },
{ {
1 << PR_BIT_DEFAULT, 1 << PR_BIT_FOOTER,
// vert_def // vert_def
"void main(void)\n" "void main(void)\n"
"{\n" "{\n"
@ -2621,10 +2658,17 @@ static int32_t polymer_bindmaterial(_prmaterial material)
int32_t programbits; int32_t programbits;
int32_t texunit; int32_t texunit;
programbits = prprogrambits[PR_BIT_DEFAULT].bit; programbits = prprogrambits[PR_BIT_HEADER].bit;
programbits |= prprogrambits[PR_BIT_FOOTER].bit;
// --------- bit validation // --------- bit validation
// PR_BIT_*_COMPAT
if (glinfo.sm4)
programbits |= prprogrambits[PR_BIT_G8X_COMPAT].bit;
else
programbits |= prprogrambits[PR_BIT_NV4X_COMPAT].bit;
// PR_BIT_ANIM_INTERPOLATION // PR_BIT_ANIM_INTERPOLATION
if (material.nextframedata) if (material.nextframedata)
programbits |= prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit; programbits |= prprogrambits[PR_BIT_ANIM_INTERPOLATION].bit;
@ -2642,7 +2686,9 @@ static int32_t polymer_bindmaterial(_prmaterial material)
(material.diffusemodulation[2] != 1.0f) || (material.diffusemodulation[3] != 1.0f)) (material.diffusemodulation[2] != 1.0f) || (material.diffusemodulation[3] != 1.0f))
programbits |= prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit; programbits |= prprogrambits[PR_BIT_DIFFUSE_MODULATION].bit;
// PR_BIT_POINT_LIGHT
programbits |= prprogrambits[PR_BIT_POINT_LIGHT].bit; programbits |= prprogrambits[PR_BIT_POINT_LIGHT].bit;
// PR_BIT_DIFFUSE_GLOW_MAP // PR_BIT_DIFFUSE_GLOW_MAP
if (material.glowmap) if (material.glowmap)
programbits |= prprogrambits[PR_BIT_DIFFUSE_GLOW_MAP].bit; programbits |= prprogrambits[PR_BIT_DIFFUSE_GLOW_MAP].bit;
@ -2758,7 +2804,7 @@ static int32_t polymer_bindmaterial(_prmaterial material)
color[5] = 0.5f; color[5] = 0.5f;
color[6] = 0.5f; color[6] = 0.5f;
range[2] = 5000.0f / 1000.0; range[2] = 8000.0f / 1000.0;
range[3] = 10000.0f / 1000.0; range[3] = 10000.0f / 1000.0;
bglLightfv(GL_LIGHT0, GL_AMBIENT, lightpos); bglLightfv(GL_LIGHT0, GL_AMBIENT, lightpos);
@ -2771,6 +2817,16 @@ static int32_t polymer_bindmaterial(_prmaterial material)
bglLightfv(GL_LIGHT1, GL_CONSTANT_ATTENUATION, &range[2]); bglLightfv(GL_LIGHT1, GL_CONSTANT_ATTENUATION, &range[2]);
bglLightfv(GL_LIGHT1, GL_LINEAR_ATTENUATION, &range[3]); bglLightfv(GL_LIGHT1, GL_LINEAR_ATTENUATION, &range[3]);
range[3] = 0;
bglLightfv(GL_LIGHT2, GL_LINEAR_ATTENUATION, &range[3]);
bglLightfv(GL_LIGHT3, GL_LINEAR_ATTENUATION, &range[3]);
bglLightfv(GL_LIGHT4, GL_LINEAR_ATTENUATION, &range[3]);
bglLightfv(GL_LIGHT5, GL_LINEAR_ATTENUATION, &range[3]);
bglLightfv(GL_LIGHT6, GL_LINEAR_ATTENUATION, &range[3]);
bglLightfv(GL_LIGHT7, GL_LINEAR_ATTENUATION, &range[3]);
if (glinfo.sm4)
bglUniform1iARB(prprograms[programbits].uniform_lightCount, lightCount); bglUniform1iARB(prprograms[programbits].uniform_lightCount, lightCount);
} }
@ -2895,8 +2951,9 @@ static void polymer_compileprogram(int32_t programbits)
prprograms[programbits].uniform_detailMap = bglGetUniformLocationARB(program, "detailMap"); prprograms[programbits].uniform_detailMap = bglGetUniformLocationARB(program, "detailMap");
prprograms[programbits].uniform_detailScale = bglGetUniformLocationARB(program, "detailScale"); prprograms[programbits].uniform_detailScale = bglGetUniformLocationARB(program, "detailScale");
} }
// PR_BIT_POINT_LIGHT // PR_BIT_POINT_LIGHT
if (programbits & prprogrambits[PR_BIT_POINT_LIGHT].bit) if (programbits & prprogrambits[PR_BIT_POINT_LIGHT].bit && glinfo.sm4)
{ {
prprograms[programbits].uniform_lightCount = bglGetUniformLocationARB(program, "lightCount"); prprograms[programbits].uniform_lightCount = bglGetUniformLocationARB(program, "lightCount");
} }

View file

@ -1196,6 +1196,10 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs)
{ {
glinfo.vbos = 1; glinfo.vbos = 1;
} }
else if (!Bstrcmp((char *)p2, "GL_EXT_gpu_shader4"))
{
glinfo.sm4 = 1;
}
} }
Bfree(p); Bfree(p);

View file

@ -3472,6 +3472,10 @@ static int32_t SetupOpenGL(int32_t width, int32_t height, int32_t bitspp)
{ {
glinfo.vsync = 1; glinfo.vsync = 1;
} }
else if (!Bstrcmp((char *)p2, "GL_EXT_gpu_shader4"))
{
glinfo.sm4 = 1;
}
} }
Bfree(p); Bfree(p);
} }