Skip to content

Commit

Permalink
[GLES2] Fixed some issue with texture mapping when using vec4 with q …
Browse files Browse the repository at this point in the history
…componant <> 1.0 (fixed Descent3)
  • Loading branch information
ptitSeb committed Jan 18, 2020
1 parent 0a64c57 commit 3ebf35d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/gl/fpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ void realize_glenv(int ispoint, int first, int count, GLenum type, const void* i
}
glstate->fpe_state->texformat |= tex->fpe_format<<(i*3);
glstate->fpe_state->texadjust |= tex->adjust<<i;
if(texunit==ENABLED_TEXTURE_RECTANGLE) glstate->fpe_state->texadjust |= 1<<i;
//if(texunit==ENABLED_TEXTURE_RECTANGLE) glstate->fpe_state->texadjust |= 1<<i;
glstate->fpe_state->textype |= fmt<<(i*3);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gl/fpe_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static gl4es_psa_t *psa = NULL;
static char *psa_name = NULL;

static const char PSA_SIGN[] = "GL4ES PrecompiledShaderArchive";
#define CACHE_VERSION 106
#define CACHE_VERSION 107

void fpe_readPSA()
{
Expand Down
30 changes: 19 additions & 11 deletions src/gl/fpe_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ static int comments = 1;

#define ShadAppend(S) shad = Append(shad, &shad_cap, S)

const char* texvecsize[] = {"vec2", "vec2", "vec2", "vec3", "vec2"};
const char* texxyzsize[] = {"xy", "xy", "xy", "xyz", "xy"};
// 2D Rectangle 3D CubeMap Stream
const char* texname[] = {"texture2D", "texture2D", "texture2D", "textureCube", "textureStreamIMG"}; // textureRectange and 3D are emulated with 2D
// 2D Rectangle 3D CubeMap Stream
const char* texvecsize[] = {"vec4", "vec3", "vec2", "vec3", "vec2"};
const char* texxyzsize[] = {"stpq", "stp", "st", "stp", "st"};
// 2D Rectangle 3D CubeMap Stream
const char* texname[] = {"texture2DProj", "texture2DProj", "texture2D", "textureCube", "textureStreamIMG"}; // textureRectange and 3D are emulated with 2D
const char* texsampler[] = {"sampler2D", "sampler2D", "sampler2D", "samplerCube", "samplerStreamIMG"};
int texnsize[] = {2, 2, 3, 3, 2};
const char texcoordname[] = {'s', 't', 'r', 'q'};
Expand Down Expand Up @@ -296,7 +297,7 @@ const char* const* fpe_VertexShader(fpe_state_t *state) {
for (int i=0; i<hardext.maxtex; i++) {
int t = (state->textype>>(i*3))&0x7;
if(t) {
sprintf(buff, "varying %s _gl4es_TexCoord_%d;\n", texvecsize[t-1], i);
sprintf(buff, "varying %s _gl4es_TexCoord_%d;\n", "vec4"/*texvecsize[t-1]*/, i);
ShadAppend(buff);
headers++;
if(state->textmat&(1<<i)) {
Expand Down Expand Up @@ -596,14 +597,21 @@ const char* const* fpe_VertexShader(fpe_state_t *state) {
} else {
sprintf(texcoord, "gl_MultiTexCoord%d", i);
}
const char* text_tmp = texcoord;
static const char* tmp_tex = "tmp_tex";
if(mat) {
// it would be better to use texture2Dproj in fragment shader, but that will complicate the varying definition...
sprintf(buff, "tmp_tex = (_gl4es_TextureMatrix_%d * %s);\n", i, texcoord);
text_tmp = tmp_tex;
sprintf(buff, "%s = (_gl4es_TextureMatrix_%d * %s);\n", text_tmp, i, texcoord);
ShadAppend(buff);
sprintf(buff, "_gl4es_TexCoord_%d = tmp_tex.%s / tmp_tex.q;\n", i, texxyzsize[t-1]);
//sprintf(buff, "_gl4es_TexCoord_%d = (_gl4es_TextureMatrix_%d * %s).%s;\n", i, i, texcoord, texxyzsize[t-1]);
} else
sprintf(buff, "_gl4es_TexCoord_%d = %s.%s / %s.q;\n", i, texcoord, texxyzsize[t-1], texcoord);
}
if(t==FPE_TEX_STRM) {
sprintf(buff, "_gl4es_TexCoord_%d = %s.%s / %s.q;\n", i, text_tmp, texxyzsize[t-1], text_tmp);
} else if(t==FPE_TEX_RECT) {
need_adjust[i] = 1;
sprintf(buff, "_gl4es_TexCoord_%d.st = %s.st\n_gl4es_TexCoord_%d.p = 1.0/_gl4es_TexAdjust_%d", i, text_tmp, i, text_tmp);
} else {
sprintf(buff, "_gl4es_TexCoord_%d = %s.%s;\n", i, text_tmp, texxyzsize[t-1]);
}
ShadAppend(buff);
if(adjust) {
need_adjust[i] = 1;
Expand Down

0 comments on commit 3ebf35d

Please sign in to comment.