Implemented non-compressed (tga file) 24-bit and 32-bit textures
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40139
This commit is contained in:
@@ -154,6 +154,8 @@
|
||||
E4CA10ED1637BD47005D9400 /* KRTextureTGA.h in Headers */ = {isa = PBXBuildFile; fileRef = E4CA10EB1637BD47005D9400 /* KRTextureTGA.h */; };
|
||||
E4CA10EF1637BD58005D9400 /* KRTextureTGA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4CA10EE1637BD58005D9400 /* KRTextureTGA.cpp */; };
|
||||
E4CA10F01637BD58005D9400 /* KRTextureTGA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4CA10EE1637BD58005D9400 /* KRTextureTGA.cpp */; };
|
||||
E4CA10F61638BCAF005D9400 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4CA10F51638BCAE005D9400 /* Accelerate.framework */; };
|
||||
E4CA10F81638BCBB005D9400 /* Accelerate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4CA10F71638BCBB005D9400 /* Accelerate.framework */; };
|
||||
E4CE184D15FF124600F80870 /* light_point_inside.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E4CE184C15FF124600F80870 /* light_point_inside.fsh */; };
|
||||
E4CE184F15FF125700F80870 /* light_point_inside.vsh in Sources */ = {isa = PBXBuildFile; fileRef = E4CE184E15FF125700F80870 /* light_point_inside.vsh */; };
|
||||
E4D0683F1512A790005FFBEB /* KRVector3.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017E13C99BDC0098455B /* KRVector3.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -313,6 +315,8 @@
|
||||
E4CA10E81637BD2B005D9400 /* KRTexturePVR.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTexturePVR.cpp; path = Classes/KRTexturePVR.cpp; sourceTree = "<group>"; };
|
||||
E4CA10EB1637BD47005D9400 /* KRTextureTGA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTextureTGA.h; path = Classes/KRTextureTGA.h; sourceTree = "<group>"; };
|
||||
E4CA10EE1637BD58005D9400 /* KRTextureTGA.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTextureTGA.cpp; path = Classes/KRTextureTGA.cpp; sourceTree = "<group>"; };
|
||||
E4CA10F51638BCAE005D9400 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = System/Library/Frameworks/Accelerate.framework; sourceTree = SDKROOT; };
|
||||
E4CA10F71638BCBB005D9400 /* Accelerate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Accelerate.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Accelerate.framework; sourceTree = DEVELOPER_DIR; };
|
||||
E4CE184815FEEDA200F80870 /* font.pvr */ = {isa = PBXFileReference; lastKnownFileType = file; name = font.pvr; path = Shaders/font.pvr; sourceTree = "<group>"; };
|
||||
E4CE184C15FF124600F80870 /* light_point_inside.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = light_point_inside.fsh; path = Shaders/light_point_inside.fsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
|
||||
E4CE184E15FF125700F80870 /* light_point_inside.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point_inside.vsh; path = Shaders/light_point_inside.vsh; sourceTree = "<group>"; };
|
||||
@@ -328,6 +332,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
E4CA10F61638BCAF005D9400 /* Accelerate.framework in Frameworks */,
|
||||
E49101A013C99BF50098455B /* OpenGLES.framework in Frameworks */,
|
||||
E46DBE801512AF4600D59F86 /* Foundation.framework in Frameworks */,
|
||||
);
|
||||
@@ -337,6 +342,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
E4CA10F81638BCBB005D9400 /* Accelerate.framework in Frameworks */,
|
||||
E4BBBB9C1512A4A900F43B5B /* Foundation.framework in Frameworks */,
|
||||
E4BBBB9D1512A4AC00F43B5B /* CoreData.framework in Frameworks */,
|
||||
E46DBE7F1512AF0200D59F86 /* OpenGL.framework in Frameworks */,
|
||||
@@ -558,6 +564,7 @@
|
||||
E491016313C99B9E0098455B /* iOS Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E4CA10F51638BCAE005D9400 /* Accelerate.framework */,
|
||||
E491019F13C99BF50098455B /* OpenGLES.framework */,
|
||||
E491016413C99B9E0098455B /* Foundation.framework */,
|
||||
);
|
||||
@@ -634,6 +641,7 @@
|
||||
E4BBBB931512A41500F43B5B /* OSX Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E4CA10F71638BCBB005D9400 /* Accelerate.framework */,
|
||||
E4F711A41512BB56007EE923 /* libfbxsdk-2012.2-static.a */,
|
||||
E497B95E151BF09600D3DC67 /* SystemConfiguration.framework */,
|
||||
E497B95C151BF05F00D3DC67 /* CoreServices.framework */,
|
||||
|
||||
@@ -96,7 +96,9 @@ void KRContext::loadResource(const std::string &file_name, KRDataBlock *data) {
|
||||
} else if(extension.compare("krscene") == 0) {
|
||||
m_pSceneManager->loadScene(name.c_str(), data);
|
||||
} else if(extension.compare("pvr") == 0) {
|
||||
m_pTextureManager->loadTexture(name.c_str(), data);
|
||||
m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data);
|
||||
} else if(extension.compare("tga") == 0) {
|
||||
m_pTextureManager->loadTexture(name.c_str(), extension.c_str(), data);
|
||||
} else if(extension.compare("vsh") == 0) {
|
||||
m_pShaderManager->loadVertexShader(name.c_str(), data);
|
||||
} else if(extension.compare("fsh") == 0) {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include "TargetConditionals.h"
|
||||
#import <Accelerate/Accelerate.h>
|
||||
#endif
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
@@ -28,6 +29,7 @@
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#import <OpenGL/gl.h>
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#import <assert.h>
|
||||
|
||||
KRTexture2D::KRTexture2D(KRContext &context, KRDataBlock *data) : KRTexture(context) {
|
||||
m_current_lod_max_dim = 0;
|
||||
m_pData = data;
|
||||
}
|
||||
|
||||
@@ -92,6 +93,6 @@ int KRTexture2D::getMinMipMap() {
|
||||
}
|
||||
|
||||
bool KRTexture2D::hasMipmaps() {
|
||||
return m_max_lod_max_dim == m_min_lod_max_dim;
|
||||
return m_max_lod_max_dim != m_min_lod_max_dim;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,9 @@ bool KRTextureCube::createGLTexture(int lod_max_dim)
|
||||
if(bMipMaps) {
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
|
||||
} else {
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
// GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
|
||||
GLDEBUG(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
|
||||
GLDEBUG(glGenerateMipmap(GL_TEXTURE_CUBE_MAP));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -53,16 +53,27 @@ KRTextureManager::~KRTextureManager() {
|
||||
}
|
||||
}
|
||||
|
||||
KRTexture *KRTextureManager::loadTexture(const char *szName, KRDataBlock *data) {
|
||||
KRTexture *pTexture = new KRTexturePVR(getContext(), data);
|
||||
KRTexture *KRTextureManager::loadTexture(const char *szName, const char *szExtension, KRDataBlock *data) {
|
||||
KRTexture *pTexture = NULL;
|
||||
|
||||
std::string lowerName = szName;
|
||||
std::transform(lowerName.begin(), lowerName.end(),
|
||||
lowerName.begin(), ::tolower);
|
||||
|
||||
std::string lowerExtension = szExtension;
|
||||
std::transform(lowerExtension.begin(), lowerExtension.end(),
|
||||
lowerExtension.begin(), ::tolower);
|
||||
|
||||
|
||||
m_textures[lowerName] = pTexture;
|
||||
if(strcmp(szExtension, "pvr") == 0) {
|
||||
pTexture = new KRTexturePVR(getContext(), data);
|
||||
} else if(strcmp(szExtension, "tga") == 0) {
|
||||
pTexture = new KRTextureTGA(getContext(), data);
|
||||
}
|
||||
|
||||
if(pTexture) {
|
||||
m_textures[lowerName] = pTexture;
|
||||
}
|
||||
return pTexture;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
|
||||
void selectTexture(int iTextureUnit, KRTexture *pTexture, int lod_max_dim);
|
||||
|
||||
KRTexture *loadTexture(const char *szName, KRDataBlock *data);
|
||||
KRTexture *loadTexture(const char *szName, const char *szExtension, KRDataBlock *data);
|
||||
KRTexture *getTextureCube(const char *szName);
|
||||
KRTexture *getTexture(const char *szFile);
|
||||
|
||||
|
||||
@@ -7,3 +7,94 @@
|
||||
//
|
||||
|
||||
#include "KRTextureTGA.h"
|
||||
#include "KREngine-common.h"
|
||||
|
||||
typedef struct {
|
||||
char idlength;
|
||||
char colourmaptype;
|
||||
char imagetype;
|
||||
short int colourmaporigin;
|
||||
short int colourmaplength;
|
||||
char colourmapdepth;
|
||||
short int x_origin;
|
||||
short int y_origin;
|
||||
short width;
|
||||
short height;
|
||||
char bitsperpixel;
|
||||
char imagedescriptor;
|
||||
} __attribute__((packed)) TGA_HEADER;
|
||||
|
||||
|
||||
KRTextureTGA::KRTextureTGA(KRContext &context, KRDataBlock *data) : KRTexture2D(context, data)
|
||||
{
|
||||
TGA_HEADER *pHeader = (TGA_HEADER *)data->getStart();
|
||||
|
||||
m_max_lod_max_dim = pHeader->width > pHeader->height ? pHeader->width : pHeader->height;
|
||||
m_min_lod_max_dim = m_max_lod_max_dim; // Mipmaps not yet supported for TGA images
|
||||
}
|
||||
|
||||
KRTextureTGA::~KRTextureTGA()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, size_t &textureMemUsed)
|
||||
{
|
||||
TGA_HEADER *pHeader = (TGA_HEADER *)m_pData->getStart();
|
||||
unsigned char *pData = (unsigned char *)pHeader + (size_t)pHeader->idlength + (size_t)pHeader->colourmaplength * (size_t)pHeader->colourmaptype + sizeof(TGA_HEADER);
|
||||
|
||||
if(pHeader->colourmaptype != 0) {
|
||||
return false; // Mapped colors not supported
|
||||
}
|
||||
|
||||
GLenum err;
|
||||
|
||||
switch(pHeader->imagetype) {
|
||||
case 2: // rgb
|
||||
switch(pHeader->bitsperpixel) {
|
||||
case 24:
|
||||
{
|
||||
unsigned char *converted_image = (unsigned char *)malloc(pHeader->width * pHeader->height * 4);
|
||||
//#ifdef __APPLE__
|
||||
// vImage_Buffer source_image = { pData, pHeader->height, pHeader->width, pHeader->width*3 };
|
||||
// vImage_Buffer dest_image = { converted_image, pHeader->height, pHeader->width, pHeader->width*4 };
|
||||
// vImageConvert_RGB888toRGBA8888(&source_image, NULL, 0xff, &dest_image, false, kvImageDoNotTile);
|
||||
//#else
|
||||
unsigned char *pSource = pData;
|
||||
unsigned char *pDest = converted_image;
|
||||
unsigned char *pEnd = pData + pHeader->height * pHeader->width * 3;
|
||||
while(pSource < pEnd) {
|
||||
*pDest++ = pSource[0];
|
||||
*pDest++ = pSource[1];
|
||||
*pDest++ = pSource[2];
|
||||
*pDest++ = 0xff;
|
||||
pSource += 3;
|
||||
}
|
||||
//#endif
|
||||
glTexImage2D(target, 0, GL_RGBA, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)converted_image);
|
||||
delete converted_image;
|
||||
err = glGetError();
|
||||
if (err != GL_NO_ERROR) return false;
|
||||
textureMemUsed += pHeader->width * pHeader->height * 4;
|
||||
current_lod_max_dim = m_max_lod_max_dim;
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
{
|
||||
glTexImage2D(target, 0, GL_RGBA, pHeader->width, pHeader->height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid *)pData);
|
||||
err = glGetError();
|
||||
if (err != GL_NO_ERROR) return false;
|
||||
textureMemUsed += pHeader->width * pHeader->height * 4;
|
||||
current_lod_max_dim = m_max_lod_max_dim;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false; // 16-bit images not yet supported
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false; // Image type not yet supported
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
|
||||
class KRTextureTGA : public KRTexture2D
|
||||
{
|
||||
public:
|
||||
KRTextureTGA(KRContext &context, KRDataBlock *data);
|
||||
virtual ~KRTextureTGA();
|
||||
|
||||
bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, size_t &textureMemUsed);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user