These files were meant to be part of the previous checkin. I blame AnkhSVN yet again. Someone needs to write a Subversion tool with proper changelist support!

This commit is contained in:
wrenczes@gmail.com
2010-12-01 07:20:26 +00:00
parent 69c1ba8717
commit a0427d99df
3 changed files with 108 additions and 93 deletions

View File

@@ -144,6 +144,15 @@ public:
//////////////////////////////////////////////////////////////////////////
JTexture* LoadTexture(const char* filename, int mode = 0, int textureFormat = TEXTURE_FORMAT);
/*
** Helper function - on Win, LoadTexture previously performed the image transfer into GL memory.
** 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
** happens in LoadTexture, and the JQuad constructor will complete the texture binding with this helper function.
*/
#if defined (WIN32) || defined (LINUX)
void static TransferTextureToGLContext(JTexture& inTexture);
#endif
//////////////////////////////////////////////////////////////////////////
/// Create texture from memory on the fly.
///

View File

@@ -340,6 +340,7 @@ public:
#if defined (WIN32) || defined (LINUX) || defined (IOS)
GLuint mTexId;
u8* mBuffer;
#else
int mTextureFormat;
int mTexId;

View File

@@ -290,6 +290,8 @@ JQuad::JQuad(JTexture *tex, float x, float y, float width, float height)
JASSERT(tex != NULL);
JRenderer::TransferTextureToGLContext(*tex);
mHotSpotX = 0.0f;
mHotSpotY = 0.0f;
//mBlend = BLEND_DEFAULT;
@@ -341,7 +343,7 @@ void JQuad::SetHotSpot(float x, float y)
//////////////////////////////////////////////////////////////////////////
JTexture::JTexture()
JTexture::JTexture() : mBuffer(NULL)
{
mTexId = -1;
}
@@ -352,6 +354,12 @@ JTexture::~JTexture()
if (mTexId != (GLuint)-1)
glDeleteTextures(1, &mTexId);
checkGlError();
if (mBuffer)
{
delete [] mBuffer;
mBuffer = NULL;
}
}
@@ -1653,6 +1661,61 @@ static void PNGCustomReadDataFn(png_structp png_ptr, png_bytep data, png_size_t
}
}
void JRenderer::TransferTextureToGLContext(JTexture& inTexture)
{
if (inTexture.mBuffer != NULL)
{
GLuint texid;
checkGlError();
glGenTextures(1, &texid);
inTexture.mTexId = texid;
JRenderer::GetInstance()->mCurrentTex = texid;
// glError = glGetError();
if (1)///*texid*/ glError == 0)
{
// OpenGL texture has (0,0) at lower-left
// Pay attention when doing texture mapping!!!
glBindTexture(GL_TEXTURE_2D, inTexture.mTexId); // Bind To The Texture ID
/* NOT USED
if (mode == TEX_TYPE_MIPMAP) // generate mipmaps
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureInfo.mTexWidth, textureInfo.mTexHeight, GL_RGBA, GL_UNSIGNED_BYTE, textureInfo.mBits);
}
else if (mode == TEX_TYPE_SKYBOX) // for skybox
{
#define GL_CLAMP_TO_EDGE 0x812F
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureInfo.mTexWidth, textureInfo.mTexHeight, GL_RGBA, GL_UNSIGNED_BYTE, textureInfo.mBits);
}
else // single texture
*/
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, inTexture.mTexWidth, inTexture.mTexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, inTexture.mBuffer);
}
}
delete [] inTexture.mBuffer;
inTexture.mBuffer = NULL;
checkGlError();
}
}
JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureFormat __attribute__((unused)))
{
TextureInfo textureInfo;
@@ -1686,78 +1749,20 @@ JTexture* JRenderer::LoadTexture(const char* filename, int mode, int TextureForm
tex->mTexWidth = textureInfo.mTexWidth;
tex->mTexHeight = textureInfo.mTexHeight;
tex->mBuffer = textureInfo.mBits;
GLuint texid;
checkGlError();
//checkGlError();
glGenTextures(1, &texid);
tex->mTexId = texid;
// glError = glGetError();
if (1)///*texid*/ glError == 0)
{
// OpenGL texture has (0,0) at lower-left
// Pay attention when doing texture mapping!!!
mCurrentTex = texid;
glBindTexture(GL_TEXTURE_2D, mCurrentTex); // Bind To The Texture ID
/* NOT USED
if (mode == TEX_TYPE_MIPMAP) // generate mipmaps
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureInfo.mTexWidth, textureInfo.mTexHeight, GL_RGBA, GL_UNSIGNED_BYTE, textureInfo.mBits);
}
else if (mode == TEX_TYPE_SKYBOX) // for skybox
{
#define GL_CLAMP_TO_EDGE 0x812F
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureInfo.mTexWidth, textureInfo.mTexHeight, GL_RGBA, GL_UNSIGNED_BYTE, textureInfo.mBits);
}
else // single texture
*/ {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureInfo.mTexWidth, textureInfo.mTexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureInfo.mBits);
}
ret = true;
}
else
{
// printf("LoadTexture> TextureId is 0, GLerror is %u\n", glError);
}
}
delete [] textureInfo.mBits;
//delete textureInfo;
if (!ret)
{
if (tex)
delete tex;
tex = NULL;
}
checkGlError();
return tex;
}
int JRenderer::LoadPNG(TextureInfo &textureInfo, const char *filename, int mode __attribute__((unused)), int TextureFormat __attribute__((unused)))
{
textureInfo.mBits = NULL;
DWORD* p32;
png_structp png_ptr;