diff --git a/KREngine/KREngine.xcodeproj/project.pbxproj b/KREngine/KREngine.xcodeproj/project.pbxproj index ea537c5..ff8b581 100644 --- a/KREngine/KREngine.xcodeproj/project.pbxproj +++ b/KREngine/KREngine.xcodeproj/project.pbxproj @@ -146,6 +146,14 @@ E4BBBB9E1512A4AE00F43B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BBBB961512A46700F43B5B /* AppKit.framework */; }; E4BBBB9F1512A4B100F43B5B /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BBBB941512A45500F43B5B /* Cocoa.framework */; }; E4BBBBA71512A6DC00F43B5B /* KRVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017F13C99BDC0098455B /* KRVector3.cpp */; }; + E4CA10E51637BD0A005D9400 /* KRTexturePVR.h in Headers */ = {isa = PBXBuildFile; fileRef = E4CA10E41637BD0A005D9400 /* KRTexturePVR.h */; }; + E4CA10E61637BD0A005D9400 /* KRTexturePVR.h in Headers */ = {isa = PBXBuildFile; fileRef = E4CA10E41637BD0A005D9400 /* KRTexturePVR.h */; }; + E4CA10E91637BD2B005D9400 /* KRTexturePVR.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4CA10E81637BD2B005D9400 /* KRTexturePVR.cpp */; }; + E4CA10EA1637BD2B005D9400 /* KRTexturePVR.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4CA10E81637BD2B005D9400 /* KRTexturePVR.cpp */; }; + E4CA10EC1637BD47005D9400 /* KRTextureTGA.h in Headers */ = {isa = PBXBuildFile; fileRef = E4CA10EB1637BD47005D9400 /* KRTextureTGA.h */; }; + 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 */; }; 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, ); }; }; @@ -301,6 +309,10 @@ E4BBBB961512A46700F43B5B /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; E4BBBB981512A47500F43B5B /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; E4BBBB9A1512A48200F43B5B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + E4CA10E41637BD0A005D9400 /* KRTexturePVR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTexturePVR.h; path = Classes/KRTexturePVR.h; sourceTree = ""; }; + E4CA10E81637BD2B005D9400 /* KRTexturePVR.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTexturePVR.cpp; path = Classes/KRTexturePVR.cpp; sourceTree = ""; }; + E4CA10EB1637BD47005D9400 /* KRTextureTGA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTextureTGA.h; path = Classes/KRTextureTGA.h; sourceTree = ""; }; + E4CA10EE1637BD58005D9400 /* KRTextureTGA.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTextureTGA.cpp; path = Classes/KRTextureTGA.cpp; sourceTree = ""; }; E4CE184815FEEDA200F80870 /* font.pvr */ = {isa = PBXFileReference; lastKnownFileType = file; name = font.pvr; path = Shaders/font.pvr; sourceTree = ""; }; 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 = ""; 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 = ""; }; @@ -470,6 +482,10 @@ E4B175AB161F5A1000B8FB80 /* KRTexture.h */, E4B175B0161F5FAE00B8FB80 /* KRTextureCube.cpp */, E4B175B1161F5FAF00B8FB80 /* KRTextureCube.h */, + E4CA10E41637BD0A005D9400 /* KRTexturePVR.h */, + E4CA10E81637BD2B005D9400 /* KRTexturePVR.cpp */, + E4CA10EB1637BD47005D9400 /* KRTextureTGA.h */, + E4CA10EE1637BD58005D9400 /* KRTextureTGA.cpp */, ); name = Texture; sourceTree = ""; @@ -689,6 +705,8 @@ E4030E4C160A3CF000592648 /* KRStockGeometry.h in Headers */, E4B175AE161F5A1000B8FB80 /* KRTexture.h in Headers */, E4B175B4161F5FAF00B8FB80 /* KRTextureCube.h in Headers */, + E4CA10E51637BD0A005D9400 /* KRTexturePVR.h in Headers */, + E4CA10EC1637BD47005D9400 /* KRTextureTGA.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -738,6 +756,8 @@ E4030E4D160A3CF000592648 /* KRStockGeometry.h in Headers */, E4B175AF161F5A1000B8FB80 /* KRTexture.h in Headers */, E4B175B5161F5FAF00B8FB80 /* KRTextureCube.h in Headers */, + E4CA10E61637BD0A005D9400 /* KRTexturePVR.h in Headers */, + E4CA10ED1637BD47005D9400 /* KRTextureTGA.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -867,6 +887,8 @@ E4B175B2161F5FAF00B8FB80 /* KRTextureCube.cpp in Sources */, E41B841E16260C5600C7A771 /* sky_box.fsh in Sources */, E41B842116260C6500C7A771 /* sky_box.vsh in Sources */, + E4CA10E91637BD2B005D9400 /* KRTexturePVR.cpp in Sources */, + E4CA10EF1637BD58005D9400 /* KRTextureTGA.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -912,6 +934,8 @@ E488399D15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */, E4B175AD161F5A1000B8FB80 /* KRTexture.cpp in Sources */, E4B175B3161F5FAF00B8FB80 /* KRTextureCube.cpp in Sources */, + E4CA10EA1637BD2B005D9400 /* KRTexturePVR.cpp in Sources */, + E4CA10F01637BD58005D9400 /* KRTextureTGA.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/KREngine/KREngine/Classes/KRTexture2D.cpp b/KREngine/KREngine/Classes/KRTexture2D.cpp index 7ce3a1e..5edbea2 100644 --- a/KREngine/KREngine/Classes/KRTexture2D.cpp +++ b/KREngine/KREngine/Classes/KRTexture2D.cpp @@ -41,136 +41,14 @@ #import #import - -#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff - -static char gPVRTexIdentifier[5] = "PVR!"; - -enum -{ - kPVRTextureFlagTypePVRTC_2 = 24, - kPVRTextureFlagTypePVRTC_4 -}; - -typedef struct _PVRTexHeader -{ - uint32_t headerLength; - uint32_t height; - uint32_t width; - uint32_t numMipmaps; - uint32_t flags; - uint32_t dataLength; - uint32_t bpp; - uint32_t bitmaskRed; - uint32_t bitmaskGreen; - uint32_t bitmaskBlue; - uint32_t bitmaskAlpha; - uint32_t pvrTag; - uint32_t numSurfs; -} PVRTexHeader; - KRTexture2D::KRTexture2D(KRContext &context, KRDataBlock *data) : KRTexture(context) { m_pData = data; - m_current_lod_max_dim = 0; - load(); } KRTexture2D::~KRTexture2D() { delete m_pData; } -bool KRTexture2D::hasMipmaps() { - return m_blocks.size() > 1; -} - -int KRTexture2D::getMaxMipMap() { - return m_max_lod_max_dim; -} - -int KRTexture2D::getMinMipMap() { - return m_min_lod_max_dim; -} - -bool KRTexture2D::load() { -#if TARGET_OS_IPHONE - PVRTexHeader *header = (PVRTexHeader *)m_pData->getStart(); - uint32_t formatFlags = header->flags & PVR_TEXTURE_FLAG_TYPE_MASK; - if (formatFlags == kPVRTextureFlagTypePVRTC_4) { - m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; - } else if(formatFlags == kPVRTextureFlagTypePVRTC_2) { - m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; - } else { - assert(false); - } - - uint32_t pvrTag = header->pvrTag; - if (gPVRTexIdentifier[0] != ((pvrTag >> 0) & 0xff) || - gPVRTexIdentifier[1] != ((pvrTag >> 8) & 0xff) || - gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) || - gPVRTexIdentifier[3] != ((pvrTag >> 24) & 0xff)) - { - return false; - } - - m_iWidth = header->width; // Note: call __builtin_bswap32 when needed to switch endianness - m_iHeight = header->height; - m_bHasAlpha = header->bitmaskAlpha; - - uint8_t *bytes = ((uint8_t *)m_pData->getStart()) + sizeof(PVRTexHeader); - uint32_t dataLength = header->dataLength, dataOffset = 0, dataSize = 0; - uint32_t width = m_iWidth, height = m_iHeight, bpp = 4; - uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0; - - // Calculate the data size for each texture level and respect the minimum number of blocks - while(dataOffset < dataLength) { - if (formatFlags == kPVRTextureFlagTypePVRTC_4) { - blockSize = 4 * 4; // Pixel by pixel block size for 4bpp - widthBlocks = width / 4; - heightBlocks = height / 4; - bpp = 4; - } else { - blockSize = 8 * 4; // Pixel by pixel block size for 2bpp - widthBlocks = width / 8; - heightBlocks = height / 4; - bpp = 2; - } - - // Clamp to minimum number of blocks - if (widthBlocks < 2) { - widthBlocks = 2; - } - if (heightBlocks < 2) { - heightBlocks = 2; - } - dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8); - - dataBlockStruct newBlock; - newBlock.start = bytes+dataOffset; - newBlock.length = dataSize; - - m_blocks.push_back(newBlock); - - dataOffset += dataSize; - - width = width >> 1; - if(width < 1) { - width = 1; - } - height = height >> 1; - if(height < 1) { - height = 1; - } - } - - m_max_lod_max_dim = m_iWidth > m_iHeight ? m_iWidth : m_iHeight; - m_min_lod_max_dim = width >> height ? width : height; -#endif - return true; - -} - - - bool KRTexture2D::createGLTexture(int lod_max_dim) { m_current_lod_max_dim = 0; GLDEBUG(glGenTextures(1, &m_iHandle)); @@ -193,49 +71,6 @@ bool KRTexture2D::createGLTexture(int lod_max_dim) { return true; } -bool KRTexture2D::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, size_t &textureMemUsed) -{ - int width = m_iWidth; - int height = m_iHeight; - GLenum err; - - if(m_blocks.size() == 0) { - return false; - } - - int i=0; - for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { - dataBlockStruct block = *itr; - if(width <= lod_max_dim && height <= lod_max_dim) { - if(width > current_lod_max_dim) { - current_lod_max_dim = width; - } - if(height > current_lod_max_dim) { - current_lod_max_dim = height; - } - glCompressedTexImage2D(target, i, m_internalFormat, width, height, 0, block.length, block.start); - err = glGetError(); - if (err != GL_NO_ERROR) { - return false; - } - textureMemUsed += block.length; - i++; - } - - width = width >> 1; - if(width < 1) { - width = 1; - } - height = height >> 1; - if(height < 1) { - height = 1; - } - } - - return true; - -} - void KRTexture2D::bind(size_t &textureMemUsed, int max_dim, bool can_resize) { textureMemUsed -= getMemSize(); GLDEBUG(glBindTexture(GL_TEXTURE_2D, getHandle(max_dim, can_resize))); @@ -248,3 +83,15 @@ void KRTexture2D::bind(size_t &textureMemUsed, int max_dim, bool can_resize) { textureMemUsed += getMemSize(); } +int KRTexture2D::getMaxMipMap() { + return m_max_lod_max_dim; +} + +int KRTexture2D::getMinMipMap() { + return m_min_lod_max_dim; +} + +bool KRTexture2D::hasMipmaps() { + return m_max_lod_max_dim == m_min_lod_max_dim; +} + diff --git a/KREngine/KREngine/Classes/KRTexture2D.h b/KREngine/KREngine/Classes/KRTexture2D.h index 589737a..0515336 100644 --- a/KREngine/KREngine/Classes/KRTexture2D.h +++ b/KREngine/KREngine/Classes/KRTexture2D.h @@ -46,35 +46,19 @@ using std::list; class KRTexture2D : public KRTexture { public: KRTexture2D(KRContext &context, KRDataBlock *data); - ~KRTexture2D(); + virtual ~KRTexture2D(); bool hasMipmaps(); int getMaxMipMap(); int getMinMipMap(); - bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, size_t &textureMemUsed); + virtual bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, size_t &textureMemUsed) = 0; virtual void bind(size_t &textureMemUsed, int max_dim, bool can_resize); -private: +protected: KRDataBlock *m_pData; virtual bool createGLTexture(int lod_max_dim); - - - uint32_t m_iWidth; - uint32_t m_iHeight; - GLenum m_internalFormat; - bool m_bHasAlpha; - - struct dataBlockStruct { - void *start; - uint32_t length; - }; - - std::list m_blocks; - - bool load(); - }; #endif diff --git a/KREngine/KREngine/Classes/KRTextureManager.cpp b/KREngine/KREngine/Classes/KRTextureManager.cpp index fb6ea85..e770963 100644 --- a/KREngine/KREngine/Classes/KRTextureManager.cpp +++ b/KREngine/KREngine/Classes/KRTextureManager.cpp @@ -32,6 +32,8 @@ #include "KRTextureManager.h" #include "KRContext.h" #include "KRTexture2D.h" +#include "KRTexturePVR.h" +#include "KRTextureTGA.h" #include "KRTextureCube.h" #include "KRContext.h" #include @@ -52,7 +54,7 @@ KRTextureManager::~KRTextureManager() { } KRTexture *KRTextureManager::loadTexture(const char *szName, KRDataBlock *data) { - KRTexture *pTexture = new KRTexture2D(getContext(), data); + KRTexture *pTexture = new KRTexturePVR(getContext(), data); std::string lowerName = szName; std::transform(lowerName.begin(), lowerName.end(), diff --git a/KREngine/KREngine/Classes/KRTexturePVR.cpp b/KREngine/KREngine/Classes/KRTexturePVR.cpp new file mode 100644 index 0000000..13f6088 --- /dev/null +++ b/KREngine/KREngine/Classes/KRTexturePVR.cpp @@ -0,0 +1,194 @@ +// +// KRTexturePVR.cpp +// KREngine +// +// Copyright 2012 Kearwood Gilbert. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other materials +// provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those of the +// authors and should not be interpreted as representing official policies, either expressed +// or implied, of Kearwood Gilbert. +// + +#include "KRTexturePVR.h" +#include "KRTextureManager.h" + +#import +#include +#include +#include +#include +#include +#import +#import +#import "KREngine-common.h" + + +#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff + +static char gPVRTexIdentifier[5] = "PVR!"; + +enum +{ + kPVRTextureFlagTypePVRTC_2 = 24, + kPVRTextureFlagTypePVRTC_4 +}; + +typedef struct _PVRTexHeader +{ + uint32_t headerLength; + uint32_t height; + uint32_t width; + uint32_t numMipmaps; + uint32_t flags; + uint32_t dataLength; + uint32_t bpp; + uint32_t bitmaskRed; + uint32_t bitmaskGreen; + uint32_t bitmaskBlue; + uint32_t bitmaskAlpha; + uint32_t pvrTag; + uint32_t numSurfs; +} PVRTexHeader; + +KRTexturePVR::KRTexturePVR(KRContext &context, KRDataBlock *data) : KRTexture2D(context, data) { +#if TARGET_OS_IPHONE + PVRTexHeader *header = (PVRTexHeader *)m_pData->getStart(); + uint32_t formatFlags = header->flags & PVR_TEXTURE_FLAG_TYPE_MASK; + if (formatFlags == kPVRTextureFlagTypePVRTC_4) { + m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; + } else if(formatFlags == kPVRTextureFlagTypePVRTC_2) { + m_internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; + } else { + assert(false); + } + + uint32_t pvrTag = header->pvrTag; + if (gPVRTexIdentifier[0] != ((pvrTag >> 0) & 0xff) || + gPVRTexIdentifier[1] != ((pvrTag >> 8) & 0xff) || + gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) || + gPVRTexIdentifier[3] != ((pvrTag >> 24) & 0xff)) { + assert(false); + } + + m_iWidth = header->width; // Note: call __builtin_bswap32 when needed to switch endianness + m_iHeight = header->height; + m_bHasAlpha = header->bitmaskAlpha; + + uint8_t *bytes = ((uint8_t *)m_pData->getStart()) + sizeof(PVRTexHeader); + uint32_t dataLength = header->dataLength, dataOffset = 0, dataSize = 0; + uint32_t width = m_iWidth, height = m_iHeight, bpp = 4; + uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0; + + // Calculate the data size for each texture level and respect the minimum number of blocks + while(dataOffset < dataLength) { + if (formatFlags == kPVRTextureFlagTypePVRTC_4) { + blockSize = 4 * 4; // Pixel by pixel block size for 4bpp + widthBlocks = width / 4; + heightBlocks = height / 4; + bpp = 4; + } else { + blockSize = 8 * 4; // Pixel by pixel block size for 2bpp + widthBlocks = width / 8; + heightBlocks = height / 4; + bpp = 2; + } + + // Clamp to minimum number of blocks + if (widthBlocks < 2) { + widthBlocks = 2; + } + if (heightBlocks < 2) { + heightBlocks = 2; + } + dataSize = widthBlocks * heightBlocks * ((blockSize * bpp) / 8); + + dataBlockStruct newBlock; + newBlock.start = bytes+dataOffset; + newBlock.length = dataSize; + + m_blocks.push_back(newBlock); + + dataOffset += dataSize; + + width = width >> 1; + if(width < 1) { + width = 1; + } + height = height >> 1; + if(height < 1) { + height = 1; + } + } + + m_max_lod_max_dim = m_iWidth > m_iHeight ? m_iWidth : m_iHeight; + m_min_lod_max_dim = width > height ? width : height; + +#endif +} + +KRTexturePVR::~KRTexturePVR() { + +} + +bool KRTexturePVR::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, size_t &textureMemUsed) +{ + int width = m_iWidth; + int height = m_iHeight; + GLenum err; + + if(m_blocks.size() == 0) { + return false; + } + + int i=0; + for(std::list::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) { + dataBlockStruct block = *itr; + if(width <= lod_max_dim && height <= lod_max_dim) { + if(width > current_lod_max_dim) { + current_lod_max_dim = width; + } + if(height > current_lod_max_dim) { + current_lod_max_dim = height; + } + glCompressedTexImage2D(target, i, m_internalFormat, width, height, 0, block.length, block.start); + err = glGetError(); + if (err != GL_NO_ERROR) { + return false; + } + textureMemUsed += block.length; + i++; + } + + width = width >> 1; + if(width < 1) { + width = 1; + } + height = height >> 1; + if(height < 1) { + height = 1; + } + } + + return true; + +} diff --git a/KREngine/KREngine/Classes/KRTexturePVR.h b/KREngine/KREngine/Classes/KRTexturePVR.h new file mode 100644 index 0000000..cc76f42 --- /dev/null +++ b/KREngine/KREngine/Classes/KRTexturePVR.h @@ -0,0 +1,37 @@ +// +// KRTexturePVR.h +// KREngine +// +// Created by Kearwood Gilbert on 2012-10-23. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef KRTEXTUREPVR_H +#define KRTEXTUREPVR_H + +#include "KRTexture2D.h" + +class KRTexturePVR : public KRTexture2D +{ +public: + KRTexturePVR(KRContext &context, KRDataBlock *data); + virtual ~KRTexturePVR(); + + bool uploadTexture(GLenum target, int lod_max_dim, int ¤t_lod_max_dim, size_t &textureMemUsed); + +protected: + + uint32_t m_iWidth; + uint32_t m_iHeight; + GLenum m_internalFormat; + bool m_bHasAlpha; + + struct dataBlockStruct { + void *start; + uint32_t length; + }; + + std::list m_blocks; +}; + +#endif diff --git a/KREngine/KREngine/Classes/KRTextureTGA.cpp b/KREngine/KREngine/Classes/KRTextureTGA.cpp new file mode 100644 index 0000000..2aaf2cd --- /dev/null +++ b/KREngine/KREngine/Classes/KRTextureTGA.cpp @@ -0,0 +1,9 @@ +// +// KRTextureTGA.cpp +// KREngine +// +// Created by Kearwood Gilbert on 2012-10-23. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#include "KRTextureTGA.h" diff --git a/KREngine/KREngine/Classes/KRTextureTGA.h b/KREngine/KREngine/Classes/KRTextureTGA.h new file mode 100644 index 0000000..f4d2bed --- /dev/null +++ b/KREngine/KREngine/Classes/KRTextureTGA.h @@ -0,0 +1,19 @@ +// +// KRTextureTGA.h +// KREngine +// +// Created by Kearwood Gilbert on 2012-10-23. +// Copyright (c) 2012 Kearwood Software. All rights reserved. +// + +#ifndef KRTEXTURETGA_H +#define KRTEXTURETGA_H + +#include "KRTexture2D.h" + +class KRTextureTGA : public KRTexture2D +{ + +}; + +#endif