- Implemented device detection and automatic selection of KREngine memory management parameters
- Now detecting iPad 3 and adjusting parameters to utilize the greater RAM capacity --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40135
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
#import "KRShader.h"
|
||||
#import "KRContextObject.h"
|
||||
#import "KRTexture.h"
|
||||
|
||||
#import "KRContext.h"
|
||||
|
||||
#define KRENGINE_MAX_SHADOW_BUFFERS 3
|
||||
#define KRENGINE_SHADOW_MAP_WIDTH 2048
|
||||
@@ -48,7 +48,6 @@
|
||||
|
||||
class KRInstance;
|
||||
class KRScene;
|
||||
class KRContext;
|
||||
|
||||
class KRCamera : public KRContextObject {
|
||||
public:
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
#include "KRContext.h"
|
||||
#include "KRCamera.h"
|
||||
|
||||
int KRContext::KRENGINE_MAX_VBO_HANDLES;
|
||||
int KRContext::KRENGINE_MAX_VBO_MEM;
|
||||
int KRContext::KRENGINE_MAX_SHADER_HANDLES;
|
||||
int KRContext::KRENGINE_MAX_TEXTURE_HANDLES;
|
||||
int KRContext::KRENGINE_MAX_TEXTURE_MEM;
|
||||
int KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX;
|
||||
int KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN;
|
||||
int KRContext::KRENGINE_MAX_TEXTURE_DIM;
|
||||
int KRContext::KRENGINE_MIN_TEXTURE_DIM;
|
||||
|
||||
KRContext::KRContext() {
|
||||
m_pBundleManager = new KRBundleManager(*this);
|
||||
m_pShaderManager = new KRShaderManager(*this);
|
||||
|
||||
@@ -9,14 +9,27 @@
|
||||
#ifndef KREngine_KRContext_h
|
||||
#define KREngine_KRContext_h
|
||||
|
||||
#import "KREngine-common.h"
|
||||
#import "KRBundleManager.h"
|
||||
#import "KRSceneManager.h"
|
||||
#import "KRTextureManager.h"
|
||||
#import "KRMaterialManager.h"
|
||||
#import "KRShaderManager.h"
|
||||
#import "KRModelManager.h"
|
||||
|
||||
class KRContext {
|
||||
public:
|
||||
static int KRENGINE_MAX_VBO_HANDLES;
|
||||
static int KRENGINE_MAX_VBO_MEM;
|
||||
static int KRENGINE_MAX_SHADER_HANDLES;
|
||||
static int KRENGINE_MAX_TEXTURE_HANDLES;
|
||||
static int KRENGINE_MAX_TEXTURE_MEM;
|
||||
static int KRENGINE_TARGET_TEXTURE_MEM_MAX;
|
||||
static int KRENGINE_TARGET_TEXTURE_MEM_MIN;
|
||||
static int KRENGINE_MAX_TEXTURE_DIM;
|
||||
static int KRENGINE_MIN_TEXTURE_DIM;
|
||||
|
||||
|
||||
KRContext();
|
||||
~KRContext();
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#ifndef KREngine_KREngine_common_h
|
||||
#define KREngine_KREngine_common_h
|
||||
|
||||
#define KRENGINE_MAX_TEXTURE_UNITS 8
|
||||
|
||||
#import <stdint.h>
|
||||
#import <vector>
|
||||
#import <string>
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "KREngine.h"
|
||||
#import "KRVector3.h"
|
||||
#import "KRScene.h"
|
||||
@@ -64,6 +66,31 @@ double const PI = 3.141592653589793f;
|
||||
|
||||
- (id)init
|
||||
{
|
||||
BOOL isIpad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
|
||||
BOOL isRetina = [[UIScreen mainScreen] scale] >= 2.0;
|
||||
|
||||
if(isIpad && isRetina) {
|
||||
KRContext::KRENGINE_MAX_VBO_HANDLES = 10000;
|
||||
KRContext::KRENGINE_MAX_VBO_MEM = 128000000 * 2;
|
||||
KRContext::KRENGINE_MAX_SHADER_HANDLES = 100;
|
||||
KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000;
|
||||
KRContext::KRENGINE_MAX_TEXTURE_MEM = 64000000 * 2;
|
||||
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 48000000 * 2;
|
||||
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 32000000 * 2;
|
||||
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
|
||||
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
|
||||
} else {
|
||||
KRContext::KRENGINE_MAX_VBO_HANDLES = 10000;
|
||||
KRContext::KRENGINE_MAX_VBO_MEM = 128000000;
|
||||
KRContext::KRENGINE_MAX_SHADER_HANDLES = 100;
|
||||
KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000;
|
||||
KRContext::KRENGINE_MAX_TEXTURE_MEM = 64000000;
|
||||
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 48000000;
|
||||
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 32000000;
|
||||
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
|
||||
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
|
||||
}
|
||||
|
||||
_camera = NULL;
|
||||
_context = NULL;
|
||||
if ((self = [super init])) {
|
||||
|
||||
@@ -54,6 +54,8 @@ using std::list;
|
||||
#import "KRCamera.h"
|
||||
|
||||
class KRMaterial;
|
||||
class KRNode;
|
||||
|
||||
|
||||
class KRModel : public KRResource {
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ void KRModelManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex,
|
||||
} else {
|
||||
m_vboMemUsed += size;
|
||||
|
||||
while(m_vbosPool.size() + m_vbosActive.size() >= KRENGINE_MAX_VBO_HANDLES || m_vboMemUsed >= KRENGINE_MAX_VBO_MEM) {
|
||||
while(m_vbosPool.size() + m_vbosActive.size() >= KRContext::KRENGINE_MAX_VBO_HANDLES || m_vboMemUsed >= KRContext::KRENGINE_MAX_VBO_MEM) {
|
||||
if(m_vbosPool.empty()) {
|
||||
fprintf(stderr, "flushBuffers due to VBO exhaustion...\n");
|
||||
m_pContext->rotateBuffers(false);
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#ifndef KRMODELMANAGER_H
|
||||
#define KRMODELMANAGER_H
|
||||
|
||||
#define KRENGINE_MAX_VBO_HANDLES 10000
|
||||
#define KRENGINE_MAX_VBO_MEM 128000000
|
||||
|
||||
#import "KREngine-common.h"
|
||||
#import "KRContextObject.h"
|
||||
#import "KRDataBlock.h"
|
||||
|
||||
@@ -53,7 +53,7 @@ KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera,
|
||||
KRShader *pShader = m_shaders[szKey];
|
||||
|
||||
if(pShader == NULL) {
|
||||
if(m_shaders.size() > KRENGINE_MAX_SHADER_HANDLES) {
|
||||
if(m_shaders.size() > KRContext::KRENGINE_MAX_SHADER_HANDLES) {
|
||||
// Keep the size of the shader cache reasonable
|
||||
std::map<std::string, KRShader *>::iterator itr = m_shaders.begin();
|
||||
delete (*itr).second;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#import <string>
|
||||
#import "KRCamera.h"
|
||||
#import "KRDataBlock.h"
|
||||
#import "KRNode.h"
|
||||
|
||||
using std::map;
|
||||
using std::vector;
|
||||
@@ -44,7 +45,8 @@ using std::vector;
|
||||
#ifndef KRSHADERMANAGER_H
|
||||
#define KRSHADERMANAGER_H
|
||||
|
||||
#define KRENGINE_MAX_SHADER_HANDLES 100
|
||||
class KRShader;
|
||||
class KRCamera;
|
||||
|
||||
class KRShaderManager : public KRContextObject {
|
||||
public:
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "KRContext.h"
|
||||
#include "KRTexture2D.h"
|
||||
#include "KRTextureCube.h"
|
||||
#include "KRContext.h"
|
||||
#include <string.h>
|
||||
|
||||
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
|
||||
@@ -119,7 +120,7 @@ void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture, int
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
|
||||
}
|
||||
m_boundTextures[iTextureUnit] = pTexture;
|
||||
while(m_activeTextures.size() + m_poolTextures.size() > KRENGINE_MAX_TEXTURE_HANDLES || m_textureMemUsed > KRENGINE_MAX_TEXTURE_MEM) {
|
||||
while(m_activeTextures.size() + m_poolTextures.size() > KRContext::KRENGINE_MAX_TEXTURE_HANDLES || m_textureMemUsed > KRContext::KRContext::KRENGINE_MAX_TEXTURE_MEM) {
|
||||
if(m_poolTextures.empty()) {
|
||||
fprintf(stderr, "Kraken - Texture swapping...\n");
|
||||
decreaseLODCap();
|
||||
@@ -150,10 +151,10 @@ size_t KRTextureManager::getActiveMemUsed() {
|
||||
|
||||
void KRTextureManager::rotateBuffers(bool new_frame)
|
||||
{
|
||||
if(new_frame && m_activeTextureMemUsed < KRENGINE_TARGET_TEXTURE_MEM_MIN && m_activeTextureMemUsed * 4 < KRENGINE_TARGET_TEXTURE_MEM_MAX) {
|
||||
if(new_frame && m_activeTextureMemUsed < KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN && m_activeTextureMemUsed * 4 < KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX) {
|
||||
// Increasing the LOD level will generally increase active texture memory usage by 4 times, don't increase the texture level until we can ensure that the LOD won't immediately be dropped back to the current level
|
||||
increaseLODCap();
|
||||
} else if(new_frame && m_activeTextureMemUsed > KRENGINE_TARGET_TEXTURE_MEM_MAX) {
|
||||
} else if(new_frame && m_activeTextureMemUsed > KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX) {
|
||||
decreaseLODCap();
|
||||
}
|
||||
m_poolTextures.insert(m_activeTextures.begin(), m_activeTextures.end());
|
||||
@@ -174,14 +175,14 @@ void KRTextureManager::rotateBuffers(bool new_frame)
|
||||
|
||||
void KRTextureManager::decreaseLODCap()
|
||||
{
|
||||
if(m_lod_max_dim_cap > KRENGINE_MIN_TEXTURE_DIM) {
|
||||
if(m_lod_max_dim_cap > KRContext::KRENGINE_MIN_TEXTURE_DIM) {
|
||||
m_lod_max_dim_cap = m_lod_max_dim_cap >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
void KRTextureManager::increaseLODCap()
|
||||
{
|
||||
if(m_lod_max_dim_cap < KRENGINE_MAX_TEXTURE_DIM) {
|
||||
if(m_lod_max_dim_cap < KRContext::KRENGINE_MAX_TEXTURE_DIM) {
|
||||
m_lod_max_dim_cap = m_lod_max_dim_cap << 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,14 +29,6 @@
|
||||
// or implied, of Kearwood Gilbert.
|
||||
//
|
||||
|
||||
#define KRENGINE_MAX_TEXTURE_UNITS 8
|
||||
#define KRENGINE_MAX_TEXTURE_HANDLES 10000
|
||||
#define KRENGINE_MAX_TEXTURE_MEM 64000000
|
||||
#define KRENGINE_TARGET_TEXTURE_MEM_MAX 48000000
|
||||
#define KRENGINE_TARGET_TEXTURE_MEM_MIN 32000000
|
||||
#define KRENGINE_MAX_TEXTURE_DIM 2048
|
||||
#define KRENGINE_MIN_TEXTURE_DIM 64
|
||||
|
||||
#ifndef KRTEXTUREMANAGER_H
|
||||
#define KRTEXTUREMANAGER_H
|
||||
|
||||
@@ -44,6 +36,7 @@
|
||||
#include "KRContextObject.h"
|
||||
#include "KREngine-common.h"
|
||||
#include "KRDataBlock.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
Reference in New Issue
Block a user