From d38419b454194c8a36bea25da10b8b820280551b Mon Sep 17 00:00:00 2001 From: Peter Courtemanche Date: Mon, 6 Jan 2014 12:48:26 -0800 Subject: [PATCH 1/2] For iOS target - defined out parts of the TGA code that use GL constants that are not defined in GLES2 Commented out an assert() that crashes the app when the debug interface is asked to draw text at the bottom of the screen (i.e. the FPS) --HG-- branch : nfb --- KREngine/Kraken.xcodeproj/project.pbxproj | 6 ++---- KREngine/kraken/KRTexture.cpp | 4 +++- KREngine/kraken/KRTextureTGA.cpp | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/KREngine/Kraken.xcodeproj/project.pbxproj b/KREngine/Kraken.xcodeproj/project.pbxproj index 18e49e4..f250401 100644 --- a/KREngine/Kraken.xcodeproj/project.pbxproj +++ b/KREngine/Kraken.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 104A335E1672D31C001C8BA6 /* KRCollider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 104A335C1672D31B001C8BA6 /* KRCollider.cpp */; }; 104A335F1672D31C001C8BA6 /* KRCollider.h in Headers */ = {isa = PBXBuildFile; fileRef = 104A335D1672D31C001C8BA6 /* KRCollider.h */; settings = {ATTRIBUTES = (); }; }; 10CC33A5168534F000BB9846 /* KRCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */; }; + 60B07F8C187B42A8004710D4 /* KRTextureTGA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4CA10EE1637BD58005D9400 /* KRTextureTGA.cpp */; }; E4030E4C160A3CF000592648 /* KRStockGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = E4030E4B160A3CF000592648 /* KRStockGeometry.h */; settings = {ATTRIBUTES = (); }; }; E4030E4D160A3CF000592648 /* KRStockGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = E4030E4B160A3CF000592648 /* KRStockGeometry.h */; settings = {ATTRIBUTES = (Public, ); }; }; E404702018695DD200F01F42 /* KRTextureKTX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E404701E18695DD200F01F42 /* KRTextureKTX.cpp */; }; @@ -228,7 +229,6 @@ E499BF1E16AE751E007FCDBE /* KRSceneManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E46C214915364DDB009CABF3 /* KRSceneManager.h */; settings = {ATTRIBUTES = (); }; }; E499BF1F16AE753E007FCDBE /* KRCollider.h in Headers */ = {isa = PBXBuildFile; fileRef = 104A335D1672D31C001C8BA6 /* KRCollider.h */; settings = {ATTRIBUTES = (Public, ); }; }; E499BF2016AE755B007FCDBE /* KRPointLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A157152E555400F2044A /* KRPointLight.h */; settings = {ATTRIBUTES = (); }; }; - E499BF2116AE75A7007FCDBE /* KREngine-common.h in Headers */ = {isa = PBXBuildFile; fileRef = E46DBE841512B9E200D59F86 /* KREngine-common.h */; settings = {ATTRIBUTES = (); }; }; E499BF2216AE760F007FCDBE /* krengine_osx.h in Headers */ = {isa = PBXBuildFile; fileRef = E4BBBB8C1512A40300F43B5B /* krengine_osx.h */; settings = {ATTRIBUTES = (Public, ); }; }; E499BF2316AE7636007FCDBE /* kraken-prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = E4BBBB8B1512A40300F43B5B /* kraken-prefix.pch */; }; E499BF2516AE8C20007FCDBE /* KREngine.mm in Sources */ = {isa = PBXBuildFile; fileRef = E491016F13C99BDC0098455B /* KREngine.mm */; }; @@ -277,7 +277,6 @@ E4CA10EA1637BD2B005D9400 /* KRTexturePVR.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4CA10E81637BD2B005D9400 /* KRTexturePVR.cpp */; }; E4CA10EC1637BD47005D9400 /* KRTextureTGA.h in Headers */ = {isa = PBXBuildFile; fileRef = E4CA10EB1637BD47005D9400 /* KRTextureTGA.h */; settings = {ATTRIBUTES = (); }; }; E4CA10ED1637BD47005D9400 /* KRTextureTGA.h in Headers */ = {isa = PBXBuildFile; fileRef = E4CA10EB1637BD47005D9400 /* KRTextureTGA.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 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 */; }; @@ -1308,7 +1307,6 @@ E499BF1B16AE747C007FCDBE /* KRVector2.h in Headers */, E499BF1E16AE751E007FCDBE /* KRSceneManager.h in Headers */, E499BF2016AE755B007FCDBE /* KRPointLight.h in Headers */, - E499BF2116AE75A7007FCDBE /* KREngine-common.h in Headers */, E404702218695DD200F01F42 /* KRTextureKTX.h in Headers */, E4F027D016979CE200D4427D /* KRAudioSample.h in Headers */, E450273B16E0491D00FDEC5C /* KRReverbZone.h in Headers */, @@ -1611,6 +1609,7 @@ E491019713C99BDC0098455B /* KRVector3.cpp in Sources */, E491019813C99BDC0098455B /* KRTextureManager.cpp in Sources */, E491019913C99BDC0098455B /* KRTexture2D.cpp in Sources */, + 60B07F8C187B42A8004710D4 /* KRTextureTGA.cpp in Sources */, E491019A13C99BDC0098455B /* KRMeshManager.cpp in Sources */, E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */, E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */, @@ -1643,7 +1642,6 @@ E4B175AC161F5A1000B8FB80 /* KRTexture.cpp in Sources */, E4B175B2161F5FAF00B8FB80 /* KRTextureCube.cpp in Sources */, E4CA10E91637BD2B005D9400 /* KRTexturePVR.cpp in Sources */, - E4CA10EF1637BD58005D9400 /* KRTextureTGA.cpp in Sources */, E4CA11781639CC90005D9400 /* KRViewport.cpp in Sources */, E4324BA816444C230043185B /* KRParticleSystem.cpp in Sources */, E4324BAE16444E120043185B /* KRParticleSystemNewtonian.cpp in Sources */, diff --git a/KREngine/kraken/KRTexture.cpp b/KREngine/kraken/KRTexture.cpp index af9f351..0f64489 100644 --- a/KREngine/kraken/KRTexture.cpp +++ b/KREngine/kraken/KRTexture.cpp @@ -79,7 +79,9 @@ void KRTexture::resize(int max_dim) if(!createGLTexture(target_dim)) { getContext().getTextureManager()->memoryChanged(-m_newTextureMemUsed); m_newTextureMemUsed = 0; - assert(false); +// assert(false); +// FINDME - assert commented out .. this crashes the app when running in the debug UI and changing 'Debug-Display' to show the framerate +// the FPS doesn't draw anymore either (the drop shadow draws but the text doesn't) } } } diff --git a/KREngine/kraken/KRTextureTGA.cpp b/KREngine/kraken/KRTextureTGA.cpp index 3451117..257be52 100644 --- a/KREngine/kraken/KRTextureTGA.cpp +++ b/KREngine/kraken/KRTextureTGA.cpp @@ -75,16 +75,23 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo m_pData->lock(); TGA_HEADER *pHeader = (TGA_HEADER *)m_pData->getStart(); unsigned char *pData = (unsigned char *)pHeader + (long)pHeader->idlength + (long)pHeader->colourmaplength * (long)pHeader->colourmaptype + sizeof(TGA_HEADER); - - + +// +// FINDME - many of the GL constants in here are not defined in GLES2 +#ifdef TARGET_OS_IPHONE + GLenum base_internal_format = GL_BGRA; +#else GLenum base_internal_format = pHeader->bitsperpixel == 24 ? GL_BGR : GL_BGRA; +#endif GLenum internal_format = 0; + +#ifndef TARGET_OS_IPHONE if(compress) { internal_format = pHeader->bitsperpixel == 24 ? GL_COMPRESSED_RGB_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; } +#endif - if(pHeader->colourmaptype != 0) { m_pData->unlock(); return false; // Mapped colors not supported @@ -169,7 +176,8 @@ KRTexture *KRTextureTGA::compress() GLDEBUG(glGenerateMipmap(GL_TEXTURE_2D)); GLint width = 0, height = 0, internal_format, base_internal_format; - + +#ifndef TARGET_OS_IPHONE GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width)); GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height)); GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &internal_format)); @@ -186,7 +194,6 @@ KRTexture *KRTextureTGA::compress() assert(false); // Not yet supported break; } - GLuint lod_level = 0; GLint compressed_size = 0; @@ -209,7 +216,7 @@ KRTexture *KRTextureTGA::compress() // err will equal GL_INVALID_VALUE when // assert(false); // Unexpected error } - +#endif GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0)); getContext().getTextureManager()->selectTexture(0, NULL); From 5b77f22f2d8cf4222adfef2031f0e22358f39817 Mon Sep 17 00:00:00 2001 From: Peter Courtemanche Date: Tue, 7 Jan 2014 16:52:47 -0800 Subject: [PATCH 2/2] Changed AUGraph frame buffer size to match the AU render size (improves performance by about 10 times) Comment in AudioSample.cpp where we can hook in an alternate mp3 input streamer --HG-- branch : nfb --- KREngine/kraken/KRAudioManager.cpp | 3 +++ KREngine/kraken/KRAudioManager.h | 5 ++++- KREngine/kraken/KRAudioSample.cpp | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/KREngine/kraken/KRAudioManager.cpp b/KREngine/kraken/KRAudioManager.cpp index 4d8158f..fd7f485 100644 --- a/KREngine/kraken/KRAudioManager.cpp +++ b/KREngine/kraken/KRAudioManager.cpp @@ -215,8 +215,11 @@ void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData) uint64_t end_time = mach_absolute_time(); // uint64_t duration = (end_time - start_time) * m_timebase_info.numer / m_timebase_info.denom; // Nanoseconds +// double ms = duration; +// ms = ms / 1000000.0; // uint64_t max_duration = (uint64_t)inNumberFrames * 1000000000 / 44100; // fprintf(stderr, "audio load: %5.1f%% hrtf channels: %li\n", (float)(duration * 1000 / max_duration) / 10.0f, m_mapped_sources.size()); +// printf("ms %2.3f frames %ld audio load: %5.1f%% hrtf channels: %li\n", ms, (unsigned long) inNumberFrames, (float)(duration * 1000 / max_duration) / 10.0f, m_mapped_sources.size()); } float *KRAudioManager::getBlockAddress(int block_offset) diff --git a/KREngine/kraken/KRAudioManager.h b/KREngine/kraken/KRAudioManager.h index e3d0474..2c14c92 100644 --- a/KREngine/kraken/KRAudioManager.h +++ b/KREngine/kraken/KRAudioManager.h @@ -44,7 +44,10 @@ const int KRENGINE_AUDIO_MAX_POOL_SIZE = 32; const int KRENGINE_AUDIO_MAX_BUFFER_SIZE = 64*1024; const int KRENGINE_AUDIO_BUFFERS_PER_SOURCE = 3; -const int KRENGINE_AUDIO_BLOCK_LENGTH = 128; // Length of one block to process. Determines the latency of the audio system and sets size for FFT's used in HRTF convolution +const int KRENGINE_AUDIO_BLOCK_LENGTH = 1024; // Length of one block to process. Determines the latency of the audio system and sets size for FFT's used in HRTF convolution + // the AUGraph works in 1024 sample chunks. If we put a value of less then 1024 in here then we are making mutliple calls to our render functions without any + // improvement in latency and our audio render perfomance goes down significantly + const int KRENGINE_AUDIO_BLOCK_LOG2N = 7; // 2 ^ KRENGINE_AUDIO_BLOCK_LOG2N = KRENGINE_AUDIO_BLOCK_LENGTH const int KRENGINE_REVERB_MAX_FFT_LOG2 = 15; diff --git a/KREngine/kraken/KRAudioSample.cpp b/KREngine/kraken/KRAudioSample.cpp index b115711..f1f7cc4 100644 --- a/KREngine/kraken/KRAudioSample.cpp +++ b/KREngine/kraken/KRAudioSample.cpp @@ -231,6 +231,11 @@ void KRAudioSample::openFile() { // AudioFileInitializeWithCallbacks if(m_fileRef == NULL) { + +// printf("Call to KRAudioSample::openFile() with extension: %s\n", m_extension.c_str()); +// The m_extension is valid (it's either wav or mp3 for the files in Circa project) +// so we can key off the extension and use a different data handler for mp3 files if we want to +// // Temp variables UInt32 propertySize;