softgpu: Implement texture scaling, texture offset and texture coordinate wrapping/clamping.

This commit is contained in:
Tony Wasserka 2013-07-23 20:47:18 +02:00 committed by neobrain
parent 44035df446
commit e1216e91cc
2 changed files with 36 additions and 4 deletions

View File

@ -330,6 +330,10 @@ struct GPUgstate
int getUVProjMode() const { return (texmapmode >> 8) & 3;} // 2 bits
int getUVLS0() const { return texshade & 0x3; } // 2 bits
int getUVLS1() const { return (texshade >> 8) & 0x3; } // 2 bits
bool isTexCoordClampedS() const { return texwrap & 1; }
bool isTexCoordClampedT() const { return (texwrap >> 8) & 1; }
int getScissorX1() const { return scissor1 & 0x3FF; }
int getScissorY1() const { return (scissor1 >> 10) & 0x3FF; }
int getScissorX2() const { return scissor2 & 0x3FF; }

View File

@ -100,11 +100,39 @@ static inline u32 SampleNearest(int level, float s, float t)
// TODO: Should probably check if textures are aligned properly...
// TODO: Not sure if that through mode treatment is correct..
unsigned int u = (gstate.isModeThrough()) ? s : s * width; // TODO: -1?
unsigned int v = (gstate.isModeThrough()) ? t : t * height; // TODO: -1?
unsigned int u, v;
if (gstate.isModeThrough()) {
// TODO: Is it really this simple?
u = s;
v = t;
} else {
if (gstate.getUVGenMode() == 0) {
s *= getFloat24(gstate.texscaleu);
t *= getFloat24(gstate.texscalev);
// TODO: texcoord wrapping!!
s += getFloat24(gstate.texoffsetu);
t += getFloat24(gstate.texoffsetv);
// TODO: Is this really only necessary for UV mapping?
if (gstate.isTexCoordClampedS()) {
if (s > 1.0) s = 1.0;
if (s < 0) s = 0;
} else {
// TODO: Does this work for negative coords?
s = fmod(s, 1.0f);
}
if (gstate.isTexCoordClampedT()) {
if (t > 1.0) t = 1.0;
if (t < 0.0) t = 0.0;
} else {
// TODO: Does this work for negative coords?
t = fmod(t, 1.0f);
}
}
u = s * width; // TODO: width-1 instead?
v = t * height; // TODO: width-1 instead?
}
// TODO: Assert tmap.tmn == 0 (uv texture mapping mode)