Fixed the graphics whiteout bug I introduced when switching profiles. When Refresh() was being called on the texture, the bitmap wasn't been re-transferred back into the openGL context.
While debugging this, I noticed a separate issue: when changing profiles, we'd actually call refresh twice. Removed the spurious call, as reloading profiles doesn't need to concern itself with the image cache - that's already covered by the game options menu. Also did some minor formatting / cleanup in the JGfx code for PSP - stubbed out a bunch of JLOG calls I had put in while debugging the PNG loading code.
This commit is contained in:
@@ -149,10 +149,11 @@ public:
|
|||||||
** However, this doesn't work if you want to call LoadTexture in a separate worker thread, as
|
** However, this doesn't work if you want to call LoadTexture in a separate worker thread, as
|
||||||
** OpenGL has a limitation where only one thread can run the context. Now, the image loading/decompression
|
** OpenGL has a limitation where only one thread can run the context. Now, the image loading/decompression
|
||||||
** happens in LoadTexture, and the JQuad constructor will complete the texture binding with this helper function.
|
** happens in LoadTexture, and the JQuad constructor will complete the texture binding with this helper function.
|
||||||
|
**
|
||||||
|
** On PSP, this is a no-op.
|
||||||
*/
|
*/
|
||||||
#if defined (WIN32) || defined (LINUX)
|
void TransferTextureToGLContext(JTexture& inTexture);
|
||||||
void static TransferTextureToGLContext(JTexture& inTexture);
|
|
||||||
#endif
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
/// Create texture from memory on the fly.
|
/// Create texture from memory on the fly.
|
||||||
///
|
///
|
||||||
|
|||||||
+54
-28
@@ -770,6 +770,14 @@ void JRenderer::RenderQuad(JQuad* quad, VertexColor* points)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** No-op on PSP. This is purely a PC openGL utility.
|
||||||
|
*/
|
||||||
|
void JRenderer::TransferTextureToGLContext(JTexture& inTexture)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
// Taken from:
|
// Taken from:
|
||||||
@@ -1057,9 +1065,12 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
if (useVideoRAM)
|
if (useVideoRAM)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (pixelSize == 2){
|
if (pixelSize == 2)
|
||||||
|
{
|
||||||
bits16 = (u16*)valloc(size);
|
bits16 = (u16*)valloc(size);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
bits32 = (u32*)valloc(size);
|
bits32 = (u32*)valloc(size);
|
||||||
}
|
}
|
||||||
videoRAMUsed = true;
|
videoRAMUsed = true;
|
||||||
@@ -1069,9 +1080,12 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
if (bits16 == NULL && bits32 == NULL)
|
if (bits16 == NULL && bits32 == NULL)
|
||||||
{
|
{
|
||||||
videoRAMUsed = false;
|
videoRAMUsed = false;
|
||||||
if (pixelSize == 2){
|
if (pixelSize == 2)
|
||||||
|
{
|
||||||
bits16 = (u16*)memalign(16, size);
|
bits16 = (u16*)memalign(16, size);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
bits32 = (u32*)memalign(16, size);
|
bits32 = (u32*)memalign(16, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1086,10 +1100,13 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
if(!rgbadata16 && !rgbadata32)
|
if(!rgbadata16 && !rgbadata32)
|
||||||
{
|
{
|
||||||
jpeg_destroy_decompress(&cinfo);
|
jpeg_destroy_decompress(&cinfo);
|
||||||
if (videoRAMUsed){
|
if (videoRAMUsed)
|
||||||
|
{
|
||||||
if (bits16) vfree(bits16);
|
if (bits16) vfree(bits16);
|
||||||
if (bits32) vfree(bits32);
|
if (bits32) vfree(bits32);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (bits16) free(bits16);
|
if (bits16) free(bits16);
|
||||||
if (bits32) free(bits32);
|
if (bits32) free(bits32);
|
||||||
}
|
}
|
||||||
@@ -1102,14 +1119,18 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
{
|
{
|
||||||
jpeg_destroy_decompress(&cinfo);
|
jpeg_destroy_decompress(&cinfo);
|
||||||
|
|
||||||
if (videoRAMUsed){
|
if (videoRAMUsed)
|
||||||
|
{
|
||||||
if (bits16) vfree(bits16);
|
if (bits16) vfree(bits16);
|
||||||
if (bits32) vfree(bits32);
|
if (bits32) vfree(bits32);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (bits16) free(bits16);
|
if (bits16) free(bits16);
|
||||||
if (bits32) free(bits32);
|
if (bits32) free(bits32);
|
||||||
}
|
}
|
||||||
if (mSwizzle){
|
if (mSwizzle)
|
||||||
|
{
|
||||||
if (rgbadata16)
|
if (rgbadata16)
|
||||||
free(rgbadata16);
|
free(rgbadata16);
|
||||||
if (rgbadata32)
|
if (rgbadata32)
|
||||||
@@ -1129,12 +1150,14 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
|
|
||||||
q16 = currRow16;
|
q16 = currRow16;
|
||||||
q32 = currRow32;
|
q32 = currRow32;
|
||||||
for(i=0; i<(int)cinfo.output_width; i++){
|
for (i=0; i<(int)cinfo.output_width; ++i)
|
||||||
|
{
|
||||||
int a = 255;
|
int a = 255;
|
||||||
int r = p[0];
|
int r = p[0];
|
||||||
int g = p[1];
|
int g = p[1];
|
||||||
int b = p[2];
|
int b = p[2];
|
||||||
switch (textureMode) {
|
switch (textureMode)
|
||||||
|
{
|
||||||
case GU_PSM_5650:
|
case GU_PSM_5650:
|
||||||
color16 = (r >> 3) | ((g >> 2) << 5) | ((b >> 3) << 11);
|
color16 = (r >> 3) | ((g >> 2) << 5) | ((b >> 3) << 11);
|
||||||
*(q16) = color16;
|
*(q16) = color16;
|
||||||
@@ -1163,10 +1186,12 @@ void JRenderer::LoadJPG(TextureInfo &textureInfo, const char *filename, int mode
|
|||||||
|
|
||||||
free(scanline);
|
free(scanline);
|
||||||
|
|
||||||
try{
|
try
|
||||||
|
{
|
||||||
jpeg_finish_decompress(&cinfo);
|
jpeg_finish_decompress(&cinfo);
|
||||||
}catch(...){}
|
}
|
||||||
|
catch(...)
|
||||||
|
{}
|
||||||
|
|
||||||
if (mSwizzle)
|
if (mSwizzle)
|
||||||
{
|
{
|
||||||
@@ -1207,14 +1232,17 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int textureMode
|
|||||||
|
|
||||||
if (strstr(filename, ".jpg")!=NULL || strstr(filename, ".JPG")!=NULL)
|
if (strstr(filename, ".jpg")!=NULL || strstr(filename, ".JPG")!=NULL)
|
||||||
LoadJPG(textureInfo, filename, mode, textureMode);
|
LoadJPG(textureInfo, filename, mode, textureMode);
|
||||||
else if(strstr(filename, ".gif")!=NULL || strstr(filename, ".GIF")!=NULL) {
|
else if(strstr(filename, ".gif")!=NULL || strstr(filename, ".GIF")!=NULL)
|
||||||
|
{
|
||||||
textureMode = TEXTURE_FORMAT; //textureMode not supported in Gif yet
|
textureMode = TEXTURE_FORMAT; //textureMode not supported in Gif yet
|
||||||
LoadGIF(textureInfo,filename, mode, textureMode);
|
LoadGIF(textureInfo,filename, mode, textureMode);
|
||||||
}
|
}
|
||||||
else if(strstr(filename, ".png")!=NULL || strstr(filename, ".PNG")!=NULL) {
|
else if(strstr(filename, ".png")!=NULL || strstr(filename, ".PNG")!=NULL)
|
||||||
|
{
|
||||||
textureMode = TEXTURE_FORMAT; //textureMode not supported in PNG yet
|
textureMode = TEXTURE_FORMAT; //textureMode not supported in PNG yet
|
||||||
ret = LoadPNG(textureInfo, filename, mode, textureMode);
|
ret = LoadPNG(textureInfo, filename, mode, textureMode);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
sprintf(buf, "--LoadPNG sent error code: %i for file %s", ret, filename);
|
sprintf(buf, "--LoadPNG sent error code: %i for file %s", ret, filename);
|
||||||
JLOG(buf);
|
JLOG(buf);
|
||||||
@@ -1226,7 +1254,6 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int textureMode
|
|||||||
|
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
JLOG("Allocating Texture");
|
|
||||||
JTexture* tex = new JTexture();
|
JTexture* tex = new JTexture();
|
||||||
if (tex)
|
if (tex)
|
||||||
{
|
{
|
||||||
@@ -1243,7 +1270,6 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int textureMode
|
|||||||
tex->mBits = (PIXEL_TYPE *)textureInfo.mBits;
|
tex->mBits = (PIXEL_TYPE *)textureInfo.mBits;
|
||||||
|
|
||||||
done = true;
|
done = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!done)
|
if (!done)
|
||||||
@@ -1300,8 +1326,8 @@ void ReadPngLine( png_structp& png_ptr, u32_ptr& line, png_uint_32 width, int pi
|
|||||||
//------------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------------
|
||||||
int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode, int textureMode)
|
int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode, int textureMode)
|
||||||
{
|
{
|
||||||
JLOG("JRenderer::LoadPNG: ");
|
//JLOG("JRenderer::LoadPNG: ");
|
||||||
JLOG(filename);
|
//JLOG(filename);
|
||||||
textureInfo.mBits = NULL;
|
textureInfo.mBits = NULL;
|
||||||
|
|
||||||
bool useVideoRAM = (mode == TEX_TYPE_USE_VRAM);
|
bool useVideoRAM = (mode == TEX_TYPE_USE_VRAM);
|
||||||
@@ -1319,13 +1345,13 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode,
|
|||||||
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
JFileSystem* fileSystem = JFileSystem::GetInstance();
|
||||||
if (!fileSystem->OpenFile(filename)) return JGE_ERR_CANT_OPEN_FILE;
|
if (!fileSystem->OpenFile(filename)) return JGE_ERR_CANT_OPEN_FILE;
|
||||||
|
|
||||||
JLOG("PNG opened - creating read struct");
|
//JLOG("PNG opened - creating read struct");
|
||||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (png_ptr == NULL) {
|
if (png_ptr == NULL) {
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile();
|
||||||
return JGE_ERR_PNG;
|
return JGE_ERR_PNG;
|
||||||
}
|
}
|
||||||
JLOG("Setting error callback func");
|
//JLOG("Setting error callback func");
|
||||||
png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, PNGCustomWarningFn);
|
png_set_error_fn(png_ptr, (png_voidp) NULL, (png_error_ptr) NULL, PNGCustomWarningFn);
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (info_ptr == NULL) {
|
if (info_ptr == NULL) {
|
||||||
@@ -1377,7 +1403,7 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode,
|
|||||||
const unsigned int kVerticalBlockSize = 8;
|
const unsigned int kVerticalBlockSize = 8;
|
||||||
if (mSwizzle)
|
if (mSwizzle)
|
||||||
{
|
{
|
||||||
JLOG("allocating swizzle buffer");
|
//JLOG("allocating swizzle buffer");
|
||||||
buffer = (PIXEL_TYPE*) memalign(16, texWidth * kVerticalBlockSize * sizeof(PIXEL_TYPE));
|
buffer = (PIXEL_TYPE*) memalign(16, texWidth * kVerticalBlockSize * sizeof(PIXEL_TYPE));
|
||||||
if (!buffer)
|
if (!buffer)
|
||||||
{
|
{
|
||||||
@@ -1452,14 +1478,14 @@ int JRenderer::LoadPNG(TextureInfo &textureInfo, const char* filename, int mode,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JLOG("Freeing line");
|
//JLOG("Freeing line");
|
||||||
free (line);
|
free (line);
|
||||||
JLOG("Reading end");
|
//JLOG("Reading end");
|
||||||
png_read_end(png_ptr, info_ptr);
|
png_read_end(png_ptr, info_ptr);
|
||||||
JLOG("Destroying read struct");
|
//JLOG("Destroying read struct");
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
|
png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
|
||||||
|
|
||||||
JLOG("Closing PNG");
|
//JLOG("Closing PNG");
|
||||||
fileSystem->CloseFile();
|
fileSystem->CloseFile();
|
||||||
|
|
||||||
if (done)
|
if (done)
|
||||||
|
|||||||
+3
-11
@@ -287,10 +287,8 @@ static glslFunctions g_glslfuncts;
|
|||||||
JQuad::JQuad(JTexture *tex, float x, float y, float width, float height)
|
JQuad::JQuad(JTexture *tex, float x, float y, float width, float height)
|
||||||
:mTex(tex), mX(x), mY(y), mWidth(width), mHeight(height)
|
:mTex(tex), mX(x), mY(y), mWidth(width), mHeight(height)
|
||||||
{
|
{
|
||||||
|
|
||||||
JASSERT(tex != NULL);
|
JASSERT(tex != NULL);
|
||||||
|
JRenderer::GetInstance()->TransferTextureToGLContext(*tex);
|
||||||
JRenderer::TransferTextureToGLContext(*tex);
|
|
||||||
|
|
||||||
mHotSpotX = 0.0f;
|
mHotSpotX = 0.0f;
|
||||||
mHotSpotY = 0.0f;
|
mHotSpotY = 0.0f;
|
||||||
@@ -302,7 +300,6 @@ JQuad::JQuad(JTexture *tex, float x, float y, float width, float height)
|
|||||||
mVFlipped = false;
|
mVFlipped = false;
|
||||||
|
|
||||||
SetTextureRect(x, y, width, height);
|
SetTextureRect(x, y, width, height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JQuad::SetTextureRect(float x, float y, float w, float h)
|
void JQuad::SetTextureRect(float x, float y, float w, float h)
|
||||||
@@ -316,7 +313,6 @@ void JQuad::SetTextureRect(float x, float y, float w, float h)
|
|||||||
mTY0 = y/mTex->mTexHeight;
|
mTY0 = y/mTex->mTexHeight;
|
||||||
mTX1 = (x+w)/mTex->mTexWidth;
|
mTX1 = (x+w)/mTex->mTexWidth;
|
||||||
mTY1 = (y+h)/mTex->mTexHeight;
|
mTY1 = (y+h)/mTex->mTexHeight;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1669,7 +1665,7 @@ void JRenderer::TransferTextureToGLContext(JTexture& inTexture)
|
|||||||
checkGlError();
|
checkGlError();
|
||||||
glGenTextures(1, &texid);
|
glGenTextures(1, &texid);
|
||||||
inTexture.mTexId = texid;
|
inTexture.mTexId = texid;
|
||||||
JRenderer::GetInstance()->mCurrentTex = texid;
|
mCurrentTex = texid;
|
||||||
|
|
||||||
// glError = glGetError();
|
// glError = glGetError();
|
||||||
|
|
||||||
@@ -1679,7 +1675,7 @@ void JRenderer::TransferTextureToGLContext(JTexture& inTexture)
|
|||||||
// OpenGL texture has (0,0) at lower-left
|
// OpenGL texture has (0,0) at lower-left
|
||||||
// Pay attention when doing texture mapping!!!
|
// Pay attention when doing texture mapping!!!
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, inTexture.mTexId); // Bind To The Texture ID
|
glBindTexture(GL_TEXTURE_2D, mCurrentTex); // Bind To The Texture ID
|
||||||
|
|
||||||
/* NOT USED
|
/* NOT USED
|
||||||
if (mode == TEX_TYPE_MIPMAP) // generate mipmaps
|
if (mode == TEX_TYPE_MIPMAP) // generate mipmaps
|
||||||
@@ -1750,10 +1746,6 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
|
|||||||
tex->mTexHeight = textureInfo.mTexHeight;
|
tex->mTexHeight = textureInfo.mTexHeight;
|
||||||
|
|
||||||
tex->mBuffer = textureInfo.mBits;
|
tex->mBuffer = textureInfo.mBits;
|
||||||
GLuint texid;
|
|
||||||
//checkGlError();
|
|
||||||
glGenTextures(1, &texid);
|
|
||||||
tex->mTexId = texid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return tex;
|
return tex;
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ public:
|
|||||||
//The sanity=false option returns the adjusted path even if the file doesn't exist.
|
//The sanity=false option returns the adjusted path even if the file doesn't exist.
|
||||||
string profileFile(string filename="", string fallback="", bool sanity=false,bool relative=false);
|
string profileFile(string filename="", string fallback="", bool sanity=false,bool relative=false);
|
||||||
|
|
||||||
void reloadProfile(bool images = true); //Reloads profile using current options[ACTIVE_PROFILE]
|
void reloadProfile(); //Reloads profile using current options[ACTIVE_PROFILE]
|
||||||
void checkProfile(); //Confirms that a profile is loaded and contains a collection.
|
void checkProfile(); //Confirms that a profile is loaded and contains a collection.
|
||||||
void createUsersFirstDeck(int setId);
|
void createUsersFirstDeck(int setId);
|
||||||
|
|
||||||
|
|||||||
@@ -635,12 +635,10 @@ string GameSettings::profileFile(string filename, string fallback, bool sanity,
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSettings::reloadProfile(bool images)
|
void GameSettings::reloadProfile()
|
||||||
{
|
{
|
||||||
SAFE_DELETE(profileOptions);
|
SAFE_DELETE(profileOptions);
|
||||||
checkProfile();
|
checkProfile();
|
||||||
if (images)
|
|
||||||
WResourceManager::Instance()->Refresh(); //Update images
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameSettings::checkProfile()
|
void GameSettings::checkProfile()
|
||||||
|
|||||||
@@ -509,7 +509,7 @@ void GameStateMenu::Update(float dt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Reload list of unlocked sets, now that we know about the sets.
|
//Reload list of unlocked sets, now that we know about the sets.
|
||||||
options.reloadProfile(false);
|
options.reloadProfile();
|
||||||
genNbCardsStr();
|
genNbCardsStr();
|
||||||
resetDirectory();
|
resetDirectory();
|
||||||
//All major things have been loaded, resize the cache to use it as efficiently as possible
|
//All major things have been loaded, resize the cache to use it as efficiently as possible
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ void GameStateOptions::Update(float dt)
|
|||||||
if (newProfile != "")
|
if (newProfile != "")
|
||||||
{
|
{
|
||||||
options[Options::ACTIVE_PROFILE] = newProfile;
|
options[Options::ACTIVE_PROFILE] = newProfile;
|
||||||
options.reloadProfile(false);
|
options.reloadProfile();
|
||||||
optionsTabs->Reload();
|
optionsTabs->Reload();
|
||||||
}
|
}
|
||||||
newProfile = "";
|
newProfile = "";
|
||||||
@@ -192,7 +192,7 @@ void GameStateOptions::Update(float dt)
|
|||||||
}
|
}
|
||||||
if (mReload)
|
if (mReload)
|
||||||
{
|
{
|
||||||
options.reloadProfile(true);
|
options.reloadProfile();
|
||||||
Translator::EndInstance();
|
Translator::EndInstance();
|
||||||
Translator::GetInstance()->init();
|
Translator::GetInstance()->init();
|
||||||
optionsTabs->Reload();
|
optionsTabs->Reload();
|
||||||
|
|||||||
@@ -259,6 +259,8 @@ void WCachedTexture::Refresh()
|
|||||||
else
|
else
|
||||||
SAFE_DELETE(old);
|
SAFE_DELETE(old);
|
||||||
|
|
||||||
|
JRenderer::GetInstance()->TransferTextureToGLContext(*texture);
|
||||||
|
|
||||||
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it++)
|
for (vector<WTrackedQuad*>::iterator it = trackedQuads.begin(); it != trackedQuads.end(); it++)
|
||||||
{
|
{
|
||||||
if ((*it) && (*it)->quad) (*it)->quad->mTex = texture;
|
if ((*it) && (*it)->quad) (*it)->quad->mTex = texture;
|
||||||
|
|||||||
Reference in New Issue
Block a user