KRTextureCube implementation in progress

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40121
This commit is contained in:
kearwood
2012-10-05 21:22:47 +00:00
parent a46bfaf489
commit 8d47e0bdb9
10 changed files with 534 additions and 310 deletions

View File

@@ -100,12 +100,12 @@
E491019613C99BDC0098455B /* KRVector3.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017E13C99BDC0098455B /* KRVector3.h */; settings = {ATTRIBUTES = (); }; };
E491019713C99BDC0098455B /* KRVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017F13C99BDC0098455B /* KRVector3.cpp */; };
E491019813C99BDC0098455B /* KRTextureManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018013C99BDC0098455B /* KRTextureManager.cpp */; };
E491019913C99BDC0098455B /* KRTexture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018113C99BDC0098455B /* KRTexture.cpp */; };
E491019913C99BDC0098455B /* KRTexture2D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018113C99BDC0098455B /* KRTexture2D.cpp */; };
E491019A13C99BDC0098455B /* KRModelManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRModelManager.cpp */; };
E491019B13C99BDC0098455B /* KRModelManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018313C99BDC0098455B /* KRModelManager.h */; settings = {ATTRIBUTES = (); }; };
E491019C13C99BDC0098455B /* KRMaterialManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018413C99BDC0098455B /* KRMaterialManager.h */; settings = {ATTRIBUTES = (); }; };
E491019D13C99BDC0098455B /* KRTextureManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018513C99BDC0098455B /* KRTextureManager.h */; settings = {ATTRIBUTES = (); }; };
E491019E13C99BDC0098455B /* KRTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture.h */; settings = {ATTRIBUTES = (); }; };
E491019E13C99BDC0098455B /* KRTexture2D.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture2D.h */; settings = {ATTRIBUTES = (); }; };
E49101A013C99BF50098455B /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E491019F13C99BF50098455B /* OpenGLES.framework */; };
E4924C2615EE95E800B965C6 /* KROctree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4924C2415EE95E700B965C6 /* KROctree.cpp */; };
E4924C2715EE95E800B965C6 /* KROctree.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2515EE95E800B965C6 /* KROctree.h */; };
@@ -130,6 +130,14 @@
E4AFC6BC15F7C95D00DDB4C8 /* KRSceneManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E46C214915364DDB009CABF3 /* KRSceneManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4AFC6BD15F7C9DA00DDB4C8 /* KROctree.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2515EE95E800B965C6 /* KROctree.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4AFC6BE15F7C9E600DDB4C8 /* KROctreeNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4B175AC161F5A1000B8FB80 /* KRTexture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B175AA161F5A1000B8FB80 /* KRTexture.cpp */; };
E4B175AD161F5A1000B8FB80 /* KRTexture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B175AA161F5A1000B8FB80 /* KRTexture.cpp */; };
E4B175AE161F5A1000B8FB80 /* KRTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B175AB161F5A1000B8FB80 /* KRTexture.h */; };
E4B175AF161F5A1000B8FB80 /* KRTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B175AB161F5A1000B8FB80 /* KRTexture.h */; };
E4B175B2161F5FAF00B8FB80 /* KRTextureCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B175B0161F5FAE00B8FB80 /* KRTextureCube.cpp */; };
E4B175B3161F5FAF00B8FB80 /* KRTextureCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B175B0161F5FAE00B8FB80 /* KRTextureCube.cpp */; };
E4B175B4161F5FAF00B8FB80 /* KRTextureCube.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B175B1161F5FAF00B8FB80 /* KRTextureCube.h */; };
E4B175B5161F5FAF00B8FB80 /* KRTextureCube.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B175B1161F5FAF00B8FB80 /* KRTextureCube.h */; };
E4B2A4391523B027004CB0EC /* KRMaterial.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017D13C99BDC0098455B /* KRMaterial.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4B2A43B1523B02E004CB0EC /* KRMaterial.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017C13C99BDC0098455B /* KRMaterial.cpp */; };
E4BBBB8A1512A40300F43B5B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E4BBBB881512A40300F43B5B /* InfoPlist.strings */; };
@@ -167,8 +175,8 @@
E4F975501536333500FD60B2 /* KRModel.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017A13C99BDC0098455B /* KRModel.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4F97551153633E200FD60B2 /* KRMaterialManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017B13C99BDC0098455B /* KRMaterialManager.cpp */; };
E4F97552153633EF00FD60B2 /* KRMaterialManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018413C99BDC0098455B /* KRMaterialManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4F975531536340000FD60B2 /* KRTexture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018113C99BDC0098455B /* KRTexture.cpp */; };
E4F975541536340400FD60B2 /* KRTexture.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4F975531536340000FD60B2 /* KRTexture2D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491018113C99BDC0098455B /* KRTexture2D.cpp */; };
E4F975541536340400FD60B2 /* KRTexture2D.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018613C99BDC0098455B /* KRTexture2D.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
@@ -259,12 +267,12 @@
E491017E13C99BDC0098455B /* KRVector3.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRVector3.h; path = Classes/KRVector3.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E491017F13C99BDC0098455B /* KRVector3.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRVector3.cpp; path = Classes/KRVector3.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E491018013C99BDC0098455B /* KRTextureManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRTextureManager.cpp; path = Classes/KRTextureManager.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E491018113C99BDC0098455B /* KRTexture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRTexture.cpp; path = Classes/KRTexture.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E491018113C99BDC0098455B /* KRTexture2D.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRTexture2D.cpp; path = Classes/KRTexture2D.cpp; sourceTree = "<group>"; };
E491018213C99BDC0098455B /* KRModelManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRModelManager.cpp; path = Classes/KRModelManager.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E491018313C99BDC0098455B /* KRModelManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRModelManager.h; path = Classes/KRModelManager.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E491018413C99BDC0098455B /* KRMaterialManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRMaterialManager.h; path = Classes/KRMaterialManager.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E491018513C99BDC0098455B /* KRTextureManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTextureManager.h; path = Classes/KRTextureManager.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E491018613C99BDC0098455B /* KRTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTexture.h; path = Classes/KRTexture.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E491018613C99BDC0098455B /* KRTexture2D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRTexture2D.h; path = Classes/KRTexture2D.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E491019F13C99BF50098455B /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
E4924C2415EE95E700B965C6 /* KROctree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KROctree.cpp; path = Classes/KROctree.cpp; sourceTree = "<group>"; };
E4924C2515EE95E800B965C6 /* KROctree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KROctree.h; path = Classes/KROctree.h; sourceTree = "<group>"; };
@@ -280,6 +288,10 @@
E497B95E151BF09600D3DC67 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
E4A9DEBD154120C4009DF363 /* light_point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.fsh; path = Shaders/light_point.fsh; sourceTree = "<group>"; };
E4A9DEC0154120E8009DF363 /* light_point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.vsh; path = Shaders/light_point.vsh; sourceTree = "<group>"; };
E4B175AA161F5A1000B8FB80 /* KRTexture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTexture.cpp; path = Classes/KRTexture.cpp; sourceTree = "<group>"; };
E4B175AB161F5A1000B8FB80 /* KRTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTexture.h; path = Classes/KRTexture.h; sourceTree = "<group>"; };
E4B175B0161F5FAE00B8FB80 /* KRTextureCube.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTextureCube.cpp; path = Classes/KRTextureCube.cpp; sourceTree = "<group>"; };
E4B175B1161F5FAF00B8FB80 /* KRTextureCube.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTextureCube.h; path = Classes/KRTextureCube.h; sourceTree = "<group>"; };
E4BBBB7E1512A40300F43B5B /* krengine_osx.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = krengine_osx.framework; sourceTree = BUILT_PRODUCTS_DIR; };
E4BBBB871512A40300F43B5B /* krengine_osx-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "krengine_osx-Info.plist"; sourceTree = "<group>"; };
E4BBBB891512A40300F43B5B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
@@ -451,8 +463,12 @@
children = (
E491018513C99BDC0098455B /* KRTextureManager.h */,
E491018013C99BDC0098455B /* KRTextureManager.cpp */,
E491018613C99BDC0098455B /* KRTexture.h */,
E491018113C99BDC0098455B /* KRTexture.cpp */,
E491018613C99BDC0098455B /* KRTexture2D.h */,
E491018113C99BDC0098455B /* KRTexture2D.cpp */,
E4B175AA161F5A1000B8FB80 /* KRTexture.cpp */,
E4B175AB161F5A1000B8FB80 /* KRTexture.h */,
E4B175B0161F5FAE00B8FB80 /* KRTextureCube.cpp */,
E4B175B1161F5FAF00B8FB80 /* KRTextureCube.h */,
);
name = Texture;
sourceTree = "<group>";
@@ -643,7 +659,7 @@
E491019513C99BDC0098455B /* KRMaterial.h in Headers */,
E491019C13C99BDC0098455B /* KRMaterialManager.h in Headers */,
E491019D13C99BDC0098455B /* KRTextureManager.h in Headers */,
E491019E13C99BDC0098455B /* KRTexture.h in Headers */,
E491019E13C99BDC0098455B /* KRTexture2D.h in Headers */,
E491018A13C99BDC0098455B /* KREngine.h in Headers */,
E491018E13C99BDC0098455B /* KRMat4.h in Headers */,
E491019B13C99BDC0098455B /* KRModelManager.h in Headers */,
@@ -673,6 +689,8 @@
E488399615F928CA00BD66D5 /* KRBundle.h in Headers */,
E488399E15F92BE000BD66D5 /* KRBundleManager.h in Headers */,
E4030E4C160A3CF000592648 /* KRStockGeometry.h in Headers */,
E4B175AE161F5A1000B8FB80 /* KRTexture.h in Headers */,
E4B175B4161F5FAF00B8FB80 /* KRTextureCube.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -705,7 +723,7 @@
E4F97552153633EF00FD60B2 /* KRMaterialManager.h in Headers */,
E461A176152E5C5600F2044A /* KRPointLight.h in Headers */,
E46F4A09155DF6E400CCF8B8 /* KRWorld.cpp in Headers */,
E4F975541536340400FD60B2 /* KRTexture.h in Headers */,
E4F975541536340400FD60B2 /* KRTexture2D.h in Headers */,
E46F4A01155DF46700CCF8B8 /* KRWorld.h in Headers */,
E48C697015374F5B00232E28 /* KRContext.h in Headers */,
E46F4A10155E004100CCF8B8 /* KRDataBlock.cpp in Headers */,
@@ -720,6 +738,8 @@
E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */,
E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */,
E4030E4D160A3CF000592648 /* KRStockGeometry.h in Headers */,
E4B175AF161F5A1000B8FB80 /* KRTexture.h in Headers */,
E4B175B5161F5FAF00B8FB80 /* KRTextureCube.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -812,7 +832,7 @@
E491019413C99BDC0098455B /* KRMaterial.cpp in Sources */,
E491019713C99BDC0098455B /* KRVector3.cpp in Sources */,
E491019813C99BDC0098455B /* KRTextureManager.cpp in Sources */,
E491019913C99BDC0098455B /* KRTexture.cpp in Sources */,
E491019913C99BDC0098455B /* KRTexture2D.cpp in Sources */,
E491019A13C99BDC0098455B /* KRModelManager.cpp in Sources */,
E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */,
E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */,
@@ -846,6 +866,8 @@
E48839A115F92C2800BD66D5 /* visualize_overlay.fsh in Sources */,
E4CE184D15FF124600F80870 /* light_point_inside.fsh in Sources */,
E4CE184F15FF125700F80870 /* light_point_inside.vsh in Sources */,
E4B175AC161F5A1000B8FB80 /* KRTexture.cpp in Sources */,
E4B175B2161F5FAF00B8FB80 /* KRTextureCube.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -868,7 +890,7 @@
E4F9754B153632D800FD60B2 /* KRModelManager.cpp in Sources */,
E461A160152E565700F2044A /* KRDirectionalLight.cpp in Sources */,
E4F9754515362D2C00FD60B2 /* KRBoundingVolume.cpp in Sources */,
E4F975531536340000FD60B2 /* KRTexture.cpp in Sources */,
E4F975531536340000FD60B2 /* KRTexture2D.cpp in Sources */,
E4F9754015362CD400FD60B2 /* KRScene.cpp in Sources */,
E461A166152E56C000F2044A /* KRSpotLight.cpp in Sources */,
E4F9754315362D0F00FD60B2 /* KRInstance.cpp in Sources */,
@@ -890,6 +912,8 @@
E40BA45515EFF79500D7C3DD /* KRAABB.cpp in Sources */,
E488399515F928CA00BD66D5 /* KRBundle.cpp in Sources */,
E488399D15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */,
E4B175AD161F5A1000B8FB80 /* KRTexture.cpp in Sources */,
E4B175B3161F5FAF00B8FB80 /* KRTextureCube.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -85,10 +85,10 @@ void KRContext::loadResource(const std::string &file_name, KRDataBlock *data) {
m_pModelManager->loadModel(name.c_str(), data);
} else if(extension.compare("krscene") == 0) {
m_pSceneManager->loadScene(name.c_str(), data);
#if TARGET_OS_IPHONE
} else if(extension.compare("pvr") == 0) {
m_pTextureManager->loadTexture(name.c_str(), data);
#endif
} else if(extension.compare("krcubemap") == 0) {
m_pTextureManager->loadTextureCube(name.c_str(), data);
} else if(extension.compare("vsh") == 0) {
m_pShaderManager->loadVertexShader(name.c_str(), data);
} else if(extension.compare("fsh") == 0) {

View File

@@ -2,258 +2,17 @@
// KRTexture.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.
// Created by Kearwood Gilbert on 2012-10-05.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#include "KRTexture.h"
#include "KRTextureManager.h"
#import <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#import <stdint.h>
#import <assert.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;
KRTexture::KRTexture(KRDataBlock *data, KRTextureManager *manager) {
m_pData = data;
m_iHandle = 0;
m_pManager = manager;
m_current_lod_max_dim = 0;
m_textureMemUsed = 0;
load();
}
KRTexture::~KRTexture() {
long textureMemFreed = 0;
releaseHandle(textureMemFreed);
delete m_pData;
}
bool KRTexture::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 KRTexture::createGLTexture(int lod_max_dim) {
m_current_lod_max_dim = 0;
int width = m_iWidth;
int height = m_iHeight;
GLenum err;
if(m_blocks.size() == 0) {
return false;
}
GLDEBUG(glGenTextures(1, &m_iHandle));
if(m_iHandle == 0) {
return false;
}
GLDEBUG(glBindTexture(GL_TEXTURE_2D, m_iHandle));
if (m_blocks.size() > 1) {
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
} else {
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
}
int i=0;
for(std::list<dataBlockStruct>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
dataBlockStruct block = *itr;
if(width <= lod_max_dim && height <= lod_max_dim) {
if(width > m_current_lod_max_dim) {
m_current_lod_max_dim = width;
}
if(height > m_current_lod_max_dim) {
m_current_lod_max_dim = height;
}
GLDEBUG(glCompressedTexImage2D(GL_TEXTURE_2D, i, m_internalFormat, width, height, 0, block.length, block.start));
err = glGetError();
if (err != GL_NO_ERROR) {
GLDEBUG(glDeleteTextures(1, &m_iHandle));
m_textureMemUsed = 0;
m_iHandle = 0;
lod_max_dim = 0;
return false;
}
m_textureMemUsed += block.length;
i++;
}
width = width >> 1;
if(width < 1) {
width = 1;
}
height = height >> 1;
if(height < 1) {
height = 1;
}
}
return true;
}
GLuint KRTexture::getHandle(long &textureMemUsed, int max_dim, bool can_resize) {
// Constrain target LOD to be within mipmap levels of texture
int target_dim = max_dim;
if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim;
if(target_dim > m_max_lod_max_dim) target_dim = m_max_lod_max_dim;
if(can_resize && m_current_lod_max_dim != target_dim) {
releaseHandle(textureMemUsed);
}
if(m_iHandle == 0) {
if(createGLTexture(target_dim)) {
textureMemUsed += getMemSize();
} else {
assert(false);
}
//createGLTexture();
}
return m_iHandle;
}
void KRTexture::releaseHandle(long &textureMemUsed) {
if(m_iHandle != 0) {
textureMemUsed -= getMemSize();
GLDEBUG(glDeleteTextures(1, &m_iHandle));
m_iHandle = 0;
m_textureMemUsed = 0;
}
}
long KRTexture::getMemSize() {
return m_textureMemUsed; // TODO - This is not 100% accurate, as loaded format may differ in size while in GPU memory
}

View File

@@ -3,17 +3,17 @@
// 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
@@ -23,64 +23,36 @@
// 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.
//
#import <stdint.h>
#import <list>
#import <string>
#import "KREngine-common.h"
#import "KRDataBlock.h"
using std::list;
#ifndef KRTEXTURE_H
#define KRTEXTURE_H
#import <OpenGLES/ES2/gl.h>
class KRTextureManager;
class KRDataBlock;
class KRTexture {
public:
KRTexture(KRDataBlock *data, KRTextureManager *manager);
~KRTexture();
virtual ~KRTexture();
bool createGLTexture(int lod_max_dim);
GLuint getHandle(long &textureMemUsed, int max_dim, bool can_resize);
void releaseHandle(long &textureMemUsed);
virtual GLuint getHandle(long &textureMemUsed, int max_dim, bool can_resize) = 0;
virtual void releaseHandle(long &textureMemUsed) = 0;
virtual long getMemSize() = 0;
long getMemSize();
private:
GLuint m_iHandle;
uint32_t m_iWidth;
uint32_t m_iHeight;
GLenum m_internalFormat;
bool m_bHasAlpha;
struct dataBlockStruct {
void *start;
uint32_t length;
};
std::list<dataBlockStruct> m_blocks;
protected:
KRDataBlock *m_pData;
bool load();
KRTextureManager *m_pManager;
int m_current_lod_max_dim;
uint32_t m_max_lod_max_dim;
uint32_t m_min_lod_max_dim;
uint32_t m_textureMemUsed;
};
#endif
#endif /* defined(KRTEXTURE_H) */

View File

@@ -0,0 +1,257 @@
//
// KRTexture2D.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 "KRTexture2D.h"
#include "KRTextureManager.h"
#import <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#import <stdint.h>
#import <assert.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;
KRTexture2D::KRTexture2D(KRDataBlock *data, KRTextureManager *manager) : KRTexture(data, manager) {
m_iHandle = 0;
m_current_lod_max_dim = 0;
m_textureMemUsed = 0;
load();
}
KRTexture2D::~KRTexture2D() {
long textureMemFreed = 0;
releaseHandle(textureMemFreed);
delete m_pData;
}
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;
int width = m_iWidth;
int height = m_iHeight;
GLenum err;
if(m_blocks.size() == 0) {
return false;
}
GLDEBUG(glGenTextures(1, &m_iHandle));
if(m_iHandle == 0) {
return false;
}
GLDEBUG(glBindTexture(GL_TEXTURE_2D, m_iHandle));
if (m_blocks.size() > 1) {
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR));
} else {
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
}
int i=0;
for(std::list<dataBlockStruct>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
dataBlockStruct block = *itr;
if(width <= lod_max_dim && height <= lod_max_dim) {
if(width > m_current_lod_max_dim) {
m_current_lod_max_dim = width;
}
if(height > m_current_lod_max_dim) {
m_current_lod_max_dim = height;
}
GLDEBUG(glCompressedTexImage2D(GL_TEXTURE_2D, i, m_internalFormat, width, height, 0, block.length, block.start));
err = glGetError();
if (err != GL_NO_ERROR) {
GLDEBUG(glDeleteTextures(1, &m_iHandle));
m_textureMemUsed = 0;
m_iHandle = 0;
lod_max_dim = 0;
return false;
}
m_textureMemUsed += block.length;
i++;
}
width = width >> 1;
if(width < 1) {
width = 1;
}
height = height >> 1;
if(height < 1) {
height = 1;
}
}
return true;
}
GLuint KRTexture2D::getHandle(long &textureMemUsed, int max_dim, bool can_resize) {
// Constrain target LOD to be within mipmap levels of texture
int target_dim = max_dim;
if(target_dim < m_min_lod_max_dim) target_dim = m_min_lod_max_dim;
if(target_dim > m_max_lod_max_dim) target_dim = m_max_lod_max_dim;
if(can_resize && m_current_lod_max_dim != target_dim) {
releaseHandle(textureMemUsed);
}
if(m_iHandle == 0) {
if(createGLTexture(target_dim)) {
textureMemUsed += getMemSize();
} else {
assert(false);
}
//createGLTexture();
}
return m_iHandle;
}
void KRTexture2D::releaseHandle(long &textureMemUsed) {
if(m_iHandle != 0) {
textureMemUsed -= getMemSize();
GLDEBUG(glDeleteTextures(1, &m_iHandle));
m_iHandle = 0;
m_textureMemUsed = 0;
}
}
long KRTexture2D::getMemSize() {
return m_textureMemUsed; // TODO - This is not 100% accurate, as loaded format may differ in size while in GPU memory
}

View File

@@ -0,0 +1,85 @@
//
// KRTexture2D.h
// 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.
//
#import <stdint.h>
#import <list>
#import <string>
#import "KREngine-common.h"
#import "KRDataBlock.h"
using std::list;
#ifndef KRTEXTURE2D_H
#define KRTEXTURE2D_H
#include "KRTexture.h"
class KRTextureManager;
class KRTexture2D : public KRTexture {
public:
KRTexture2D(KRDataBlock *data, KRTextureManager *manager);
~KRTexture2D();
virtual GLuint getHandle(long &textureMemUsed, int max_dim, bool can_resize);
virtual void releaseHandle(long &textureMemUsed);
virtual long getMemSize();
private:
bool createGLTexture(int lod_max_dim);
GLuint m_iHandle;
uint32_t m_iWidth;
uint32_t m_iHeight;
GLenum m_internalFormat;
bool m_bHasAlpha;
struct dataBlockStruct {
void *start;
uint32_t length;
};
std::list<dataBlockStruct> m_blocks;
bool load();
int m_current_lod_max_dim;
uint32_t m_max_lod_max_dim;
uint32_t m_min_lod_max_dim;
uint32_t m_textureMemUsed;
};
#endif

View File

@@ -0,0 +1,57 @@
//
// KRTextureCube.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 "KRTextureCube.h"
KRTextureCube::KRTextureCube(KRDataBlock *data, KRTextureManager *manager) : KRTexture(data, manager)
{
m_iHandle = 0;
}
KRTextureCube::~KRTextureCube()
{
if(m_iHandle != 0) glDeleteTextures(1, &m_iHandle);
}
GLuint KRTextureCube::getHandle(long &textureMemUsed, int max_dim, bool can_resize)
{
return 0;
}
void KRTextureCube::releaseHandle(long &textureMemUsed)
{
}
long KRTextureCube::getMemSize()
{
return 0;
}

View File

@@ -0,0 +1,59 @@
//
// KRTextureCube.h
// 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.
//
#ifndef KRTEXTURECUBE_H
#define KRTEXTURECUBE_H
#include "KRTexture.h"
#include "KRTextureManager.h"
class KRTextureCube : public KRTexture {
public:
KRTextureCube(KRDataBlock *data, KRTextureManager *manager);
virtual ~KRTextureCube();
virtual GLuint getHandle(long &textureMemUsed, int max_dim, bool can_resize);
virtual void releaseHandle(long &textureMemUsed);
virtual long getMemSize();
private:
std::string m_frontTextureName;
std::string m_backTextureName;
std::string m_leftTextureName;
std::string m_rightTextureName;
std::string m_topTextureName;
std::string m_bottomTextureName;
GLuint m_iHandle;
};
#endif /* defined(KRTEXTURECUBE_H) */

View File

@@ -31,6 +31,8 @@
#include "KRTextureManager.h"
#include "KRContext.h"
#include "KRTexture2D.h"
#include "KRTextureCube.h"
#include <string.h>
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
@@ -48,10 +50,8 @@ KRTextureManager::~KRTextureManager() {
}
}
#if TARGET_OS_IPHONE
KRTexture *KRTextureManager::loadTexture(const char *szName, KRDataBlock *data) {
KRTexture *pTexture = new KRTexture(data, this);
KRTexture *pTexture = new KRTexture2D(data, this);
std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(),
@@ -63,7 +63,18 @@ KRTexture *KRTextureManager::loadTexture(const char *szName, KRDataBlock *data)
return pTexture;
}
#endif
KRTexture *KRTextureManager::loadTextureCube(const char *szName, KRDataBlock *data) {
KRTexture *pTexture = new KRTextureCube(data, this);
std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower);
m_textures[lowerName] = pTexture;
return pTexture;
}
KRTexture *KRTextureManager::getTexture(const char *szName) {
std::string lowerName = szName;

View File

@@ -42,8 +42,11 @@
#include "KRTexture.h"
#include "KRContextObject.h"
#include "KREngine-common.h"
#include "KRDataBlock.h"
#include <map>
#include <set>
#import <string>
using std::map;
@@ -57,12 +60,9 @@ public:
void selectTexture(int iTextureUnit, KRTexture *pTexture, int lod_max_dim);
#if TARGET_OS_IPHONE
KRTexture *loadTexture(const char *szName, KRDataBlock *data);
#endif
KRTexture *loadTextureCube(const char *szName, KRDataBlock *data);
KRTexture *getTexture(const char *szFile);
long getMemUsed();