mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Merge pull request #3005 from raven02/getwh
GPUstate :Add getTextureWidth(int level) & getTextureHeight(int level)
This commit is contained in:
commit
338f2a100b
6 changed files with 31 additions and 34 deletions
|
@ -633,8 +633,8 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff) {
|
|||
}
|
||||
|
||||
case GE_CMD_TEXSIZE0:
|
||||
gstate_c.curTextureWidth = 1 << (gstate.texsize[0] & 0xf);
|
||||
gstate_c.curTextureHeight = 1 << ((gstate.texsize[0] >> 8) & 0xf);
|
||||
gstate_c.curTextureWidth = gstate.getTextureWidth(0);
|
||||
gstate_c.curTextureHeight = gstate.getTextureHeight(0);
|
||||
shaderManager_->DirtyUniform(DIRTY_UVSCALEOFFSET);
|
||||
//fall thru - ignoring the mipmap sizes for now
|
||||
case GE_CMD_TEXSIZE1:
|
||||
|
|
|
@ -113,7 +113,7 @@ LinkedShader::LinkedShader(Shader *vs, Shader *fs, bool useHWTransform)
|
|||
u_view = glGetUniformLocation(program, "u_view");
|
||||
u_world = glGetUniformLocation(program, "u_world");
|
||||
u_texmtx = glGetUniformLocation(program, "u_texmtx");
|
||||
if ((gstate.vertType & GE_VTYPE_WEIGHT_MASK) != 0)
|
||||
if (gstate.getWeightMask() != 0)
|
||||
numBones = TranslateNumBones(gstate.getNumBoneWeights());
|
||||
else
|
||||
numBones = 0;
|
||||
|
@ -331,11 +331,11 @@ void LinkedShader::updateUniforms() {
|
|||
uvscaleoff[3] = gstate_c.uv.vOff / gstate_c.curTextureHeight;
|
||||
glUniform4fv(u_uvscaleoffset, 1, uvscaleoff);
|
||||
} else {
|
||||
int w = 1 << (gstate.texsize[0] & 0xf);
|
||||
int h = 1 << ((gstate.texsize[0] >> 8) & 0xf);
|
||||
int w = gstate.getTextureWidth(0);
|
||||
int h = gstate.getTextureHeight(0);
|
||||
float widthFactor = (float)w / (float)gstate_c.curTextureWidth;
|
||||
float heightFactor = (float)h / (float)gstate_c.curTextureHeight;
|
||||
if ((gstate.texmapmode & 3) == 0) {
|
||||
if (gstate.getUVGenMode() == 0) {
|
||||
static const float rescale[4] = {1.0f, 2*127.5f/128.f, 2*32767.5f/32768.f, 1.0f};
|
||||
float factor = rescale[(gstate.vertType & GE_VTYPE_TC_MASK) >> GE_VTYPE_TC_SHIFT];
|
||||
uvscaleoff[0] = gstate_c.uv.uScale * factor * widthFactor;
|
||||
|
|
|
@ -245,7 +245,7 @@ void *TextureCache::UnswizzleFromMem(u32 texaddr, u32 bufw, u32 bytesPerPixel, u
|
|||
const u32 rowWidth = (bytesPerPixel > 0) ? (bufw * bytesPerPixel) : (bufw / 2);
|
||||
const u32 pitch = rowWidth / 4;
|
||||
const int bxc = rowWidth / 16;
|
||||
int byc = ((1 << ((gstate.texsize[level] >> 8) & 0xf)) + 7) / 8;
|
||||
int byc = (gstate.getTextureHeight(level) + 7) / 8;
|
||||
if (byc == 0)
|
||||
byc = 1;
|
||||
|
||||
|
@ -392,8 +392,8 @@ inline void DeIndexTexture4Optimal(ClutT *dest, const u32 texaddr, int length, C
|
|||
|
||||
void *TextureCache::readIndexedTex(int level, u32 texaddr, int bytesPerIndex, GLuint dstFmt) {
|
||||
int bufw = GetLevelBufw(level, texaddr);
|
||||
int w = 1 << (gstate.texsize[0] & 0xf);
|
||||
int h = 1 << ((gstate.texsize[0] >> 8) & 0xf);
|
||||
int w = gstate.getTextureWidth(level);
|
||||
int h = gstate.getTextureHeight(level);
|
||||
int length = bufw * h;
|
||||
void *buf = NULL;
|
||||
switch (gstate.getClutPaletteFormat()) {
|
||||
|
@ -996,8 +996,8 @@ void TextureCache::SetTexture() {
|
|||
cluthash = 0;
|
||||
}
|
||||
|
||||
int w = 1 << (gstate.texsize[0] & 0xf);
|
||||
int h = 1 << ((gstate.texsize[0] >> 8) & 0xf);
|
||||
int w = gstate.getTextureWidth(0);
|
||||
int h = gstate.getTextureHeight(0);
|
||||
int bufw = GetLevelBufw(0, texaddr);
|
||||
int maxLevel = ((gstate.texmode >> 16) & 0x7);
|
||||
|
||||
|
@ -1019,26 +1019,22 @@ void TextureCache::SetTexture() {
|
|||
if (useBufferedRendering) {
|
||||
if (entry->framebuffer->fbo) {
|
||||
fbo_bind_color_as_texture(entry->framebuffer->fbo, 0);
|
||||
lastBoundTexture = -1;
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
lastBoundTexture = -1;
|
||||
gstate_c.skipDrawReason |= SKIPDRAW_BAD_FB_TEXTURE;
|
||||
}
|
||||
UpdateSamplingParams(*entry, false);
|
||||
// This isn't right.
|
||||
gstate_c.curTextureWidth = entry->framebuffer->width;
|
||||
gstate_c.curTextureHeight = entry->framebuffer->height;
|
||||
gstate_c.flipTexture = true;
|
||||
gstate_c.textureFullAlpha = entry->framebuffer->format == GE_FORMAT_565;
|
||||
entry->lastFrame = gpuStats.numFrames;
|
||||
} else {
|
||||
if (entry->framebuffer->fbo)
|
||||
entry->framebuffer->fbo = 0;
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
lastBoundTexture = -1;
|
||||
entry->lastFrame = gpuStats.numFrames;
|
||||
}
|
||||
lastBoundTexture = -1;
|
||||
entry->lastFrame = gpuStats.numFrames;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1245,8 +1241,8 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
|
|||
|
||||
int bufw = GetLevelBufw(level, texaddr);
|
||||
|
||||
int w = 1 << (gstate.texsize[level] & 0xf);
|
||||
int h = 1 << ((gstate.texsize[level] >> 8) & 0xf);
|
||||
int w = gstate.getTextureWidth(level);
|
||||
int h = gstate.getTextureHeight(level);
|
||||
const u8 *texptr = Memory::GetPointer(texaddr);
|
||||
|
||||
switch (format)
|
||||
|
@ -1548,8 +1544,8 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level, bool replac
|
|||
return;
|
||||
}
|
||||
|
||||
int w = 1 << (gstate.texsize[level] & 0xf);
|
||||
int h = 1 << ((gstate.texsize[level] >> 8) & 0xf);
|
||||
int w = gstate.getTextureWidth(level);
|
||||
int h = gstate.getTextureHeight(level);
|
||||
|
||||
gpuStats.numTexturesDecoded++;
|
||||
|
||||
|
@ -1612,8 +1608,8 @@ bool TextureCache::DecodeTexture(u8* output, GPUgstate state)
|
|||
|
||||
int bufw = GetLevelBufw(level, texaddr);
|
||||
|
||||
int w = 1 << (gstate.texsize[level] & 0xf);
|
||||
int h = 1 << ((gstate.texsize[level]>>8) & 0xf);
|
||||
int w = gstate.getTextureWidth(level);
|
||||
int h = gstate.getTextureHeight(level);
|
||||
|
||||
void *finalBuf = DecodeTextureLevel(format, clutformat, level, texByteAlign, dstFmt);
|
||||
if (finalBuf == NULL) {
|
||||
|
|
|
@ -524,8 +524,8 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
|
|||
vscale /= gstate_c.curTextureHeight;
|
||||
}
|
||||
|
||||
int w = 1 << (gstate.texsize[0] & 0xf);
|
||||
int h = 1 << ((gstate.texsize[0] >> 8) & 0xf);
|
||||
int w = gstate.getTextureWidth(0);
|
||||
int h = gstate.getTextureHeight(0);
|
||||
float widthFactor = (float) w / (float) gstate_c.curTextureWidth;
|
||||
float heightFactor = (float) h / (float) gstate_c.curTextureHeight;
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim, bool useHWTransform) {
|
|||
|
||||
bool hasColor = (vertType & GE_VTYPE_COL_MASK) != 0;
|
||||
bool hasNormal = (vertType & GE_VTYPE_NRM_MASK) != 0;
|
||||
bool hasBones = (vertType & GE_VTYPE_WEIGHT_MASK) != 0;
|
||||
bool hasBones = gstate.getWeightMask() != 0;
|
||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled();
|
||||
|
||||
|
@ -108,7 +108,7 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim, bool useHWTransform) {
|
|||
}
|
||||
}
|
||||
id->d[1] |= gstate.isLightingEnabled() << 24;
|
||||
id->d[1] |= ((vertType & GE_VTYPE_WEIGHT_MASK) >> GE_VTYPE_WEIGHT_SHIFT) << 25;
|
||||
id->d[1] |= (gstate.getWeightMask() >> GE_VTYPE_WEIGHT_SHIFT) << 25;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
|||
}
|
||||
}
|
||||
|
||||
if ((vertType & GE_VTYPE_WEIGHT_MASK) != GE_VTYPE_WEIGHT_NONE) {
|
||||
if (gstate.getWeightMask() != GE_VTYPE_WEIGHT_NONE) {
|
||||
WRITE(p, "%s", boneWeightAttrDecl[TranslateNumBones(gstate.getNumBoneWeights())]);
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
|||
WRITE(p, "uniform mat4 u_view;\n");
|
||||
if (gstate.getUVGenMode() == 1)
|
||||
WRITE(p, "uniform mediump mat4 u_texmtx;\n");
|
||||
if ((vertType & GE_VTYPE_WEIGHT_MASK) != GE_VTYPE_WEIGHT_NONE) {
|
||||
if (gstate.getWeightMask() != GE_VTYPE_WEIGHT_NONE) {
|
||||
int numBones = TranslateNumBones(gstate.getNumBoneWeights());
|
||||
#ifdef USE_BONE_ARRAY
|
||||
WRITE(p, "uniform mediump mat4 u_bone[%i];\n", numBones);
|
||||
|
@ -299,7 +299,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
|||
}
|
||||
} else {
|
||||
// Step 1: World Transform / Skinning
|
||||
if ((vertType & GE_VTYPE_WEIGHT_MASK) == GE_VTYPE_WEIGHT_NONE) {
|
||||
if (gstate.getWeightMask() == GE_VTYPE_WEIGHT_NONE) {
|
||||
// No skinning, just standard T&L.
|
||||
WRITE(p, " vec3 worldpos = (u_world * vec4(a_position.xyz, 1.0)).xyz;\n");
|
||||
if (hasNormal)
|
||||
|
@ -310,7 +310,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
|||
int numWeights = TranslateNumBones(gstate.getNumBoneWeights());
|
||||
|
||||
static const char *rescale[4] = {"", " * 1.9921875", " * 1.999969482421875", ""}; // 2*127.5f/128.f, 2*32767.5f/32768.f, 1.0f};
|
||||
const char *factor = rescale[(vertType & GE_VTYPE_WEIGHT_MASK) >> GE_VTYPE_WEIGHT_SHIFT];
|
||||
const char *factor = rescale[gstate.getWeightMask() >> GE_VTYPE_WEIGHT_SHIFT];
|
||||
|
||||
static const char * const boneWeightAttr[8] = {
|
||||
"a_w1.x", "a_w1.y", "a_w1.z", "a_w1.w",
|
||||
|
|
|
@ -246,6 +246,8 @@ struct GPUgstate
|
|||
u32 getColorTestMask() const { return colormask & 0xFFFFFF; }
|
||||
|
||||
// Texturing
|
||||
int getTextureWidth(int level) const { return 1 << (texsize[level] & 0xf);}
|
||||
int getTextureHeight(int level) const { return 1 << ((texsize[level] >> 8) & 0xf);}
|
||||
bool isTextureMapEnabled() const { return textureMapEnable & 1; }
|
||||
GETexFunc getTextureFunction() const { return static_cast<GETexFunc>(texfunc & 0x7); }
|
||||
bool isColorDoublingEnabled() const { return (texfunc & 0x10000) != 0; }
|
||||
|
@ -314,9 +316,8 @@ struct GPUgstate
|
|||
|
||||
// Vertex type
|
||||
bool isModeThrough() const { return (vertType & GE_VTYPE_THROUGH) != 0; }
|
||||
int getNumBoneWeights() const {
|
||||
return 1 + ((vertType & GE_VTYPE_WEIGHTCOUNT_MASK) >> GE_VTYPE_WEIGHTCOUNT_SHIFT);
|
||||
}
|
||||
int getWeightMask() const { return vertType & GE_VTYPE_WEIGHT_MASK; }
|
||||
int getNumBoneWeights() const { return 1 + ((vertType & GE_VTYPE_WEIGHTCOUNT_MASK) >> GE_VTYPE_WEIGHTCOUNT_SHIFT); }
|
||||
|
||||
// Real data in the context ends here
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue