Merge branch 'master' of https://src.krakenengine.com/kraken
This commit is contained in:
@@ -373,6 +373,10 @@
|
||||
E45134B71746A4A300443C21 /* KRBehavior.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E45134B41746A4A300443C21 /* KRBehavior.cpp */; };
|
||||
E45134B91746A4A300443C21 /* KRBehavior.h in Headers */ = {isa = PBXBuildFile; fileRef = E45134B51746A4A300443C21 /* KRBehavior.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E459040416C30CC5002B00A0 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E459040316C30CC5002B00A0 /* AudioUnit.framework */; };
|
||||
E45C3C351EB2E5710053A9D2 /* KrakenView.h in Headers */ = {isa = PBXBuildFile; fileRef = E45C3C331EB2E5710053A9D2 /* KrakenView.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E45C3C361EB2E5710053A9D2 /* KrakenView.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45C3C341EB2E5710053A9D2 /* KrakenView.mm */; };
|
||||
E45C3C391EB2F4A90053A9D2 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45C3C381EB2F4A90053A9D2 /* UIKit.framework */; };
|
||||
E45C3C3C1EB2F52E0053A9D2 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E45C3C3B1EB2F52E0053A9D2 /* QuartzCore.framework */; };
|
||||
E45E03B118790DD1006DA23F /* PVRTArray.h in Headers */ = {isa = PBXBuildFile; fileRef = E45E03A418790DD1006DA23F /* PVRTArray.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E45E03B218790DD1006DA23F /* PVRTDecompress.h in Headers */ = {isa = PBXBuildFile; fileRef = E45E03A518790DD1006DA23F /* PVRTDecompress.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E45E03B318790DD1006DA23F /* PVRTError.h in Headers */ = {isa = PBXBuildFile; fileRef = E45E03A618790DD1006DA23F /* PVRTError.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -702,6 +706,10 @@
|
||||
E45134B41746A4A300443C21 /* KRBehavior.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KRBehavior.cpp; sourceTree = "<group>"; };
|
||||
E45134B51746A4A300443C21 /* KRBehavior.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KRBehavior.h; sourceTree = "<group>"; };
|
||||
E459040316C30CC5002B00A0 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/AudioUnit.framework; sourceTree = DEVELOPER_DIR; };
|
||||
E45C3C331EB2E5710053A9D2 /* KrakenView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KrakenView.h; sourceTree = "<group>"; };
|
||||
E45C3C341EB2E5710053A9D2 /* KrakenView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = KrakenView.mm; sourceTree = "<group>"; };
|
||||
E45C3C381EB2F4A90053A9D2 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
|
||||
E45C3C3B1EB2F52E0053A9D2 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk/System/Library/Frameworks/QuartzCore.framework; sourceTree = DEVELOPER_DIR; };
|
||||
E45E03A418790DD1006DA23F /* PVRTArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PVRTArray.h; sourceTree = "<group>"; };
|
||||
E45E03A518790DD1006DA23F /* PVRTDecompress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PVRTDecompress.h; sourceTree = "<group>"; };
|
||||
E45E03A618790DD1006DA23F /* PVRTError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PVRTError.h; sourceTree = "<group>"; };
|
||||
@@ -935,6 +943,8 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
E45C3C3C1EB2F52E0053A9D2 /* QuartzCore.framework in Frameworks */,
|
||||
E45C3C391EB2F4A90053A9D2 /* UIKit.framework in Frameworks */,
|
||||
E4159B4319C575EB00622D1E /* Foundation.framework in Frameworks */,
|
||||
E4159B4219C575E500622D1E /* OpenGLES.framework in Frameworks */,
|
||||
E4159B4119C575DF00622D1E /* Accelerate.framework in Frameworks */,
|
||||
@@ -1586,6 +1596,8 @@
|
||||
E48C527E19C570C50062E439 /* kraken.h */,
|
||||
E48C527D19C570C50062E439 /* Info.plist */,
|
||||
E491016813C99B9E0098455B /* Kraken-Prefix.pch */,
|
||||
E45C3C331EB2E5710053A9D2 /* KrakenView.h */,
|
||||
E45C3C341EB2E5710053A9D2 /* KrakenView.mm */,
|
||||
E4C8E50D16B9B5F80031DDCB /* Frameworks */,
|
||||
);
|
||||
path = kraken_ios;
|
||||
@@ -1594,6 +1606,8 @@
|
||||
E4C8E50D16B9B5F80031DDCB /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E45C3C3B1EB2F52E0053A9D2 /* QuartzCore.framework */,
|
||||
E45C3C381EB2F4A90053A9D2 /* UIKit.framework */,
|
||||
E4F027F91698116000D4427D /* AudioToolbox.framework */,
|
||||
E41B6BA716BE436100B510EB /* CoreAudio.framework */,
|
||||
E491016413C99B9E0098455B /* Foundation.framework */,
|
||||
@@ -1767,6 +1781,7 @@
|
||||
E4159B8A19C5760900622D1E /* KRRenderSettings.h in Headers */,
|
||||
E4159B8B19C5760900622D1E /* KRStockGeometry.h in Headers */,
|
||||
E4159B8C19C5760900622D1E /* KRStreamer.h in Headers */,
|
||||
E45C3C351EB2E5710053A9D2 /* KrakenView.h in Headers */,
|
||||
E4159B8D19C5760900622D1E /* KRViewport.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -2319,6 +2334,7 @@
|
||||
E4159BC919C5762F00622D1E /* KRTriangle3.cpp in Sources */,
|
||||
E4159BCA19C5762F00622D1E /* KRResource.cpp in Sources */,
|
||||
E4159BCB19C5762F00622D1E /* KRResource+obj.cpp in Sources */,
|
||||
E45C3C361EB2E5710053A9D2 /* KrakenView.mm in Sources */,
|
||||
E4159BCC19C5762F00622D1E /* KRBehavior.cpp in Sources */,
|
||||
E4159BCD19C5762F00622D1E /* KRContext.cpp in Sources */,
|
||||
E4159BCE19C5762F00622D1E /* KRContextObject.cpp in Sources */,
|
||||
@@ -2664,6 +2680,7 @@
|
||||
buildSettings = {
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
@@ -2703,6 +2720,7 @@
|
||||
buildSettings = {
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
|
||||
@@ -233,11 +233,11 @@ bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const
|
||||
quadrant[i] = LEFT;
|
||||
candidatePlane[i] = min.c[i];
|
||||
inside = false;
|
||||
}else if (v1.c[i] > max.c[i]) {
|
||||
} else if(v1.c[i] > max.c[i]) {
|
||||
quadrant[i] = RIGHT;
|
||||
candidatePlane[i] = max.c[i];
|
||||
inside = false;
|
||||
}else {
|
||||
} else {
|
||||
quadrant[i] = MIDDLE;
|
||||
}
|
||||
|
||||
|
||||
@@ -870,12 +870,11 @@ KRVector2 KRAudioManager::getNearestHRTFSample(const KRVector2 &dir)
|
||||
|
||||
KRVector2 min_direction;
|
||||
bool first = true;
|
||||
float min_distance;
|
||||
float min_distance = 360.0f;
|
||||
for(std::vector<KRVector2>::iterator itr = m_hrtf_sample_locations.begin(); itr != m_hrtf_sample_locations.end(); itr++) {
|
||||
if(first) {
|
||||
first = false;
|
||||
min_direction = (*itr);
|
||||
min_distance = 360.0f;
|
||||
} else if((*itr).x == elevation) {
|
||||
float distance = fabs(dir_deg.y - (*itr).y);
|
||||
if(min_distance > distance) {
|
||||
|
||||
@@ -95,7 +95,7 @@ const std::string KRCamera::getSkyBox() const
|
||||
return m_skyBox;
|
||||
}
|
||||
|
||||
void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint renderBufferHeight)
|
||||
void KRCamera::renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint renderBufferHeight)
|
||||
{
|
||||
// ----====---- Record timing information for measuring FPS ----====----
|
||||
uint64_t current_time = m_pContext->getAbsoluteTimeMilliseconds();
|
||||
@@ -105,9 +105,6 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
||||
}
|
||||
m_last_frame_start = current_time;
|
||||
|
||||
GLint defaultFBO = -1;
|
||||
GLDEBUG(glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO));
|
||||
|
||||
createBuffers(renderBufferWidth, renderBufferHeight);
|
||||
|
||||
KRScene &scene = getScene();
|
||||
@@ -507,6 +504,7 @@ void KRCamera::renderFrame(float deltaTime, GLint renderBufferWidth, GLint rende
|
||||
|
||||
|
||||
#if GL_EXT_discard_framebuffer
|
||||
|
||||
GLenum attachments[2] = {GL_DEPTH_ATTACHMENT, GL_COLOR_ATTACHMENT0};
|
||||
GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments));
|
||||
#endif
|
||||
@@ -671,6 +669,8 @@ void KRCamera::renderPost()
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
|
||||
|
||||
/*
|
||||
FINDME - Determine if we still need this...
|
||||
|
||||
static const GLfloat squareVerticesShadow[3][8] = {{
|
||||
-1.0f, -1.0f,
|
||||
@@ -688,6 +688,7 @@ void KRCamera::renderPost()
|
||||
0.00f, -0.60f,
|
||||
0.40f, -0.60f,
|
||||
}};
|
||||
*/
|
||||
|
||||
|
||||
GLDEBUG(glViewport(0, 0, m_viewport.getSize().x, m_viewport.getSize().y));
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
KRCamera(KRScene &scene, std::string name);
|
||||
virtual ~KRCamera();
|
||||
|
||||
void renderFrame(float deltaTime, GLint renderBufferWidth, GLint renderBufferHeight);
|
||||
void renderFrame(GLint defaultFBO, GLint renderBufferWidth, GLint renderBufferHeight);
|
||||
|
||||
KRRenderSettings settings;
|
||||
|
||||
|
||||
@@ -15,26 +15,29 @@ EAGLContext *gRenderContext = nil;
|
||||
|
||||
void KRContext::destroyDeviceContexts()
|
||||
{
|
||||
[gStreamerContext release];
|
||||
[gRenderContext release];
|
||||
}
|
||||
|
||||
void KRContext::createDeviceContexts()
|
||||
{
|
||||
if(!gRenderContext) {
|
||||
gRenderContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
gStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: gStreamerContext.sharegroup];
|
||||
gStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: gRenderContext.sharegroup];
|
||||
|
||||
// FIXME: need to add code check for iOS 7 and also this appears to cause crashing
|
||||
|
||||
//gTextureStreamerContext.multiThreaded = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void KRContext::activateStreamerContext()
|
||||
{
|
||||
createDeviceContexts();
|
||||
[EAGLContext setCurrentContext: gStreamerContext];
|
||||
}
|
||||
|
||||
void KRContext::activateRenderContext()
|
||||
{
|
||||
createDeviceContexts();
|
||||
[EAGLContext setCurrentContext: gRenderContext];
|
||||
}
|
||||
|
||||
|
||||
@@ -44,11 +44,15 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
|
||||
const float KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE = 1.25f; // Scale to apply to view frustrum bounds so that we don't need to refresh shadows on every frame
|
||||
int cShadows = 1;
|
||||
for(int iShadow=0; iShadow < cShadows; iShadow++) {
|
||||
/*
|
||||
TODO - Determine if we still need this...
|
||||
|
||||
GLfloat shadowMinDepths[3][3] = {{0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f},{0.0f, 0.05f, 0.3f}};
|
||||
GLfloat shadowMaxDepths[3][3] = {{0.0f, 0.0f, 1.0f},{0.1f, 0.0f, 0.0f},{0.1f, 0.3f, 1.0f}};
|
||||
|
||||
float min_depth = 0.0f;
|
||||
float max_depth = 1.0f;
|
||||
*/
|
||||
|
||||
KRAABB worldSpacefrustrumSliceBounds = KRAABB(KRVector3(-1.0f, -1.0f, -1.0f), KRVector3(1.0f, 1.0f, 1.0f), KRMat4::Invert(viewport.getViewProjectionMatrix()));
|
||||
worldSpacefrustrumSliceBounds.scale(KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE);
|
||||
|
||||
@@ -72,8 +72,8 @@ namespace kraken {
|
||||
-(void)setParameterValueWithName: (NSString *)name Value: (float)v;
|
||||
-(int)getParameterIndexWithName: (NSString *)name;
|
||||
|
||||
- (void)renderScene: (KRScene *)pScene WithDeltaTime: (float)deltaTime AndWidth: (int)width AndHeight: (int)height;
|
||||
- (void)renderScene: (KRScene *)pScene WithDeltaTime: (float)deltaTime;
|
||||
- (void)renderScene: (KRScene *)pScene WithDeltaTime: (float)deltaTime AndWidth: (int)width AndHeight: (int)height AndDefaultFBO: (GLint)defaultFBO;
|
||||
//- (void)renderScene: (KRScene *)pScene WithDeltaTime: (float)deltaTime;
|
||||
- (void)setNearZ: (float)dNearZ;
|
||||
- (void)setFarZ: (float)dFarZ;
|
||||
|
||||
|
||||
@@ -193,15 +193,16 @@ void kraken::set_debug_text(const std::string &print_text)
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)renderScene: (KRScene *)pScene WithDeltaTime: (float)deltaTime AndWidth: (int)width AndHeight: (int)height
|
||||
- (void)renderScene: (KRScene *)pScene WithDeltaTime: (float)deltaTime AndWidth: (int)width AndHeight: (int)height AndDefaultFBO: (GLint)defaultFBO
|
||||
{
|
||||
KRCamera *camera = pScene->find<KRCamera>("default_camera");
|
||||
if(camera) {
|
||||
camera->settings = _settings;
|
||||
}
|
||||
pScene->renderFrame(deltaTime, width, height);
|
||||
pScene->renderFrame(defaultFBO, deltaTime, width, height);
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)renderScene: (KRScene *)pScene WithDeltaTime: (float)deltaTime
|
||||
{
|
||||
GLint renderBufferWidth = 0, renderBufferHeight = 0;
|
||||
@@ -209,6 +210,7 @@ void kraken::set_debug_text(const std::string &print_text)
|
||||
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &renderBufferHeight));
|
||||
[self renderScene:pScene WithDeltaTime:deltaTime AndWidth:renderBufferWidth AndHeight:renderBufferHeight];
|
||||
}
|
||||
*/
|
||||
|
||||
- (BOOL)loadShaders
|
||||
{
|
||||
@@ -250,11 +252,10 @@ void kraken::set_debug_text(const std::string &print_text)
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_parameter_names release]; _parameter_names = nil;
|
||||
_parameter_names = nil;
|
||||
if(_context) {
|
||||
delete _context; _context = NULL;
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
-(int)getParameterCount
|
||||
@@ -721,9 +722,7 @@ void kraken::set_debug_text(const std::string &print_text)
|
||||
|
||||
- (void)setDebug_text:(NSString *)value
|
||||
{
|
||||
[_debug_text release];
|
||||
_debug_text = value;
|
||||
[_debug_text retain];
|
||||
|
||||
_settings.m_debug_text = value.UTF8String;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "KRMaterial.h"
|
||||
#include "KRTextureManager.h"
|
||||
|
||||
#include "KRcontext.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(context, szName) {
|
||||
m_name = szName;
|
||||
|
||||
@@ -173,11 +173,14 @@ void KRMesh::getMaterials()
|
||||
|
||||
for(std::vector<KRMesh::Submesh *>::iterator itr = m_submeshes.begin(); itr != m_submeshes.end(); itr++) {
|
||||
const char *szMaterialName = (*itr)->szMaterialName;
|
||||
KRMaterial *pMaterial = getContext().getMaterialManager()->getMaterial(szMaterialName);
|
||||
KRMaterial *pMaterial = nullptr;
|
||||
if(*szMaterialName != '\0') {
|
||||
pMaterial = getContext().getMaterialManager()->getMaterial(szMaterialName);
|
||||
}
|
||||
m_materials.push_back(pMaterial);
|
||||
if(pMaterial) {
|
||||
m_uniqueMaterials.insert(pMaterial);
|
||||
} else {
|
||||
} else if(*szMaterialName != '\0') {
|
||||
KRContext::Log(KRContext::LOG_LEVEL_WARNING, "Missing material: %s", szMaterialName);
|
||||
}
|
||||
}
|
||||
@@ -1456,7 +1459,7 @@ void KRMesh::convertToIndexed()
|
||||
}
|
||||
}
|
||||
|
||||
delete szKey;
|
||||
delete[] szKey;
|
||||
|
||||
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Convert to indexed, before: %i after: %i (%.2f%% saving)", getHeader()->vertex_count, mi.vertices.size(), ((float)getHeader()->vertex_count - (float)mi.vertices.size()) / (float)getHeader()->vertex_count * 100.0f);
|
||||
|
||||
@@ -1533,7 +1536,7 @@ void KRMesh::optimizeIndexes()
|
||||
pack_header *header = getHeader();
|
||||
|
||||
__uint16_t *index_data = getIndexData();
|
||||
unsigned char *vertex_data = getVertexData();
|
||||
// unsigned char *vertex_data = getVertexData(); // Uncomment when re-enabling Step 2 below
|
||||
|
||||
for(int submesh_index=0; submesh_index < header->submesh_count; submesh_index++) {
|
||||
pack_material *submesh = getSubmesh(submesh_index);
|
||||
|
||||
@@ -402,9 +402,9 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
|
||||
const char *szName = e->Attribute("name");
|
||||
if(strcmp(szElementName, "node") == 0) {
|
||||
new_node = new KRNode(scene, szName);
|
||||
} if(strcmp(szElementName, "lod_set") == 0) {
|
||||
} else if(strcmp(szElementName, "lod_set") == 0) {
|
||||
new_node = new KRLODSet(scene, szName);
|
||||
} if(strcmp(szElementName, "lod_group") == 0) {
|
||||
} else if(strcmp(szElementName, "lod_group") == 0) {
|
||||
new_node = new KRLODGroup(scene, szName);
|
||||
} else if(strcmp(szElementName, "point_light") == 0) {
|
||||
new_node = new KRPointLight(scene, szName);
|
||||
|
||||
@@ -57,7 +57,7 @@ KRScene::~KRScene() {
|
||||
m_pRootNode = NULL;
|
||||
}
|
||||
|
||||
void KRScene::renderFrame(float deltaTime, int width, int height) {
|
||||
void KRScene::renderFrame(GLint defaultFBO, float deltaTime, int width, int height) {
|
||||
getContext().startFrame(deltaTime);
|
||||
KRCamera *camera = find<KRCamera>("default_camera");
|
||||
if(camera == NULL) {
|
||||
@@ -73,7 +73,7 @@ void KRScene::renderFrame(float deltaTime, int width, int height) {
|
||||
getContext().getAudioManager()->setReverbMaxLength(camera->settings.siren_reverb_max_length);
|
||||
getContext().getTextureManager()->setMaxAnisotropy(camera->settings.max_anisotropy);
|
||||
|
||||
camera->renderFrame(deltaTime, width, height);
|
||||
camera->renderFrame(defaultFBO, width, height);
|
||||
getContext().endFrame(deltaTime);
|
||||
physicsUpdate(deltaTime);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
bool rayCast(const KRVector3 &v0, const KRVector3 &dir, KRHitInfo &hitinfo, unsigned int layer_mask);
|
||||
bool sphereCast(const KRVector3 &v0, const KRVector3 &v1, float radius, KRHitInfo &hitinfo, unsigned int layer_mask);
|
||||
|
||||
void renderFrame(float deltaTime, int width, int height);
|
||||
void renderFrame(GLint defaultFBO, float deltaTime, int width, int height);
|
||||
void render(KRCamera *pCamera, unordered_map<KRAABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame);
|
||||
|
||||
void render(KROctreeNode *pOctreeNode, unordered_map<KRAABB, int> &visibleBounds, KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
|
||||
|
||||
@@ -128,11 +128,12 @@ KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::st
|
||||
GLDEBUG(glCompileShader(vertexShader));
|
||||
|
||||
// Report any compile issues to stderr
|
||||
GLint logLength;
|
||||
GLint logLength = 0;
|
||||
GLDEBUG(glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength + 1);
|
||||
assert(log != NULL);
|
||||
log[0] = '\0'; // In case glGetShaderInfoLog fails
|
||||
GLDEBUG(glGetShaderInfoLog(vertexShader, logLength, &logLength, log));
|
||||
log[logLength] = '\0';
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KREngine - Failed to compile vertex shader: %s\nShader compile log:\n%s", szKey, log);
|
||||
@@ -146,10 +147,12 @@ KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::st
|
||||
GLDEBUG(glCompileShader(fragShader));
|
||||
|
||||
// Report any compile issues to stderr
|
||||
logLength = 0; // In case glGetShaderiv fails
|
||||
GLDEBUG(glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0) {
|
||||
GLchar *log = (GLchar *)malloc(logLength + 1);
|
||||
assert(log != NULL);
|
||||
log[0] = '\0'; // In case glGetShaderInfoLog fails
|
||||
GLDEBUG(glGetShaderInfoLog(fragShader, logLength, &logLength, log));
|
||||
log[logLength] = '\0';
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KREngine - Failed to compile fragment shader: %s\nShader compile log:\n%s", szKey, log);
|
||||
@@ -181,12 +184,13 @@ KRShader::KRShader(KRContext &context, char *szKey, std::string options, std::st
|
||||
if(link_success != GL_TRUE) {
|
||||
// Report any linking issues to stderr
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KREngine - Failed to link shader program: %s", szKey);
|
||||
|
||||
logLength = 0; // In case glGetProgramiv fails
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0)
|
||||
{
|
||||
GLchar *log = (GLchar *)malloc(logLength + 1);
|
||||
assert(log != NULL);
|
||||
log[0] = '\0'; // In case glGetProgramInfoLog fails
|
||||
GLDEBUG(glGetProgramInfoLog(m_iProgram, logLength, &logLength, log));
|
||||
log[logLength] = '\0';
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Program link log:\n%s", log);
|
||||
@@ -363,8 +367,8 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
setUniform(KRENGINE_UNIFORM_ABSOLUTE_TIME, getContext().getAbsoluteTime());
|
||||
|
||||
int light_directional_count = 0;
|
||||
int light_point_count = 0;
|
||||
int light_spot_count = 0;
|
||||
//int light_point_count = 0;
|
||||
//int light_spot_count = 0;
|
||||
// TODO - Need to support multiple lights and more light types in forward rendering
|
||||
if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && renderPass != KRNode::RENDER_PASS_DEFERRED_GBUFFER && renderPass != KRNode::RENDER_PASS_DEFERRED_OPAQUE && renderPass != KRNode::RENDER_PASS_GENERATE_SHADOWMAPS) {
|
||||
|
||||
@@ -422,8 +426,8 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
light_directional_count++;
|
||||
}
|
||||
|
||||
light_point_count = point_lights.size();
|
||||
light_spot_count = spot_lights.size();
|
||||
//light_point_count = point_lights.size();
|
||||
//light_spot_count = spot_lights.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -566,11 +570,13 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_VALIDATE_STATUS, &validate_status));
|
||||
if(validate_status != GL_TRUE) {
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KREngine - Failed to validate shader program: %s", m_szKey);
|
||||
logLength = 0; // In case glGetProgramiv fails
|
||||
GLDEBUG(glGetProgramiv(m_iProgram, GL_INFO_LOG_LENGTH, &logLength));
|
||||
if (logLength > 0)
|
||||
{
|
||||
GLchar *log = (GLchar *)malloc(logLength + 1);
|
||||
assert(log != NULL);
|
||||
log[0] = '\0'; // In case glGetProgramInfoLog fails
|
||||
GLDEBUG(glGetProgramInfoLog(m_iProgram, logLength, &logLength, log));
|
||||
log[logLength] = '\0';
|
||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Program validate log:\n%s", log);
|
||||
|
||||
@@ -65,8 +65,8 @@ long KRTexture::getReferencedMemSize() {
|
||||
|
||||
void KRTexture::resize(int max_dim)
|
||||
{
|
||||
while(m_handle_lock.test_and_set()); // Spin lock
|
||||
{
|
||||
while(m_handle_lock.test_and_set()) {}; // Spin lock
|
||||
|
||||
if(m_iHandle == m_iNewHandle) {
|
||||
if(max_dim == 0) {
|
||||
m_iNewHandle = 0;
|
||||
@@ -91,7 +91,6 @@ void KRTexture::resize(int max_dim)
|
||||
}
|
||||
|
||||
m_handle_lock.clear();
|
||||
}
|
||||
}
|
||||
|
||||
GLuint KRTexture::getHandle() {
|
||||
|
||||
@@ -148,15 +148,6 @@ KRTexture *KRTextureManager::getTextureCube(const char *szName) {
|
||||
if(itr == m_textures.end()) {
|
||||
|
||||
// Defer resolving the texture cube until its referenced textures are ready
|
||||
const GLenum TARGETS[6] = {
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
|
||||
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
||||
};
|
||||
|
||||
const char *SUFFIXES[6] = {
|
||||
"_positive_x",
|
||||
"_negative_x",
|
||||
|
||||
@@ -96,12 +96,6 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
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);
|
||||
|
||||
#if 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 = GL_RGBA;
|
||||
|
||||
#if !TARGET_OS_IPHONE
|
||||
@@ -115,8 +109,6 @@ bool KRTextureTGA::uploadTexture(GLenum target, int lod_max_dim, int ¤t_lo
|
||||
return false; // Mapped colors not supported
|
||||
}
|
||||
|
||||
GLenum err;
|
||||
|
||||
switch(pHeader->imagetype) {
|
||||
case 2: // rgb
|
||||
switch(pHeader->bitsperpixel) {
|
||||
|
||||
25
kraken_ios/KrakenView.h
Normal file
25
kraken_ios/KrakenView.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// KrakenView.h
|
||||
// Kraken
|
||||
//
|
||||
// Created by Kearwood Gilbert on 2017-04-27.
|
||||
// Copyright © 2017 Kearwood Software. All rights reserved.
|
||||
//
|
||||
class KRContext;
|
||||
class KRScene;
|
||||
|
||||
@protocol KrakenViewDelegate <NSObject>
|
||||
@optional
|
||||
- (void)preRender:(KRContext *)context withDeltaTime: (CFTimeInterval)deltaTime;
|
||||
- (void)postRender:(KRContext *)context withDeltaTime: (CFTimeInterval)deltaTime;
|
||||
@end
|
||||
|
||||
@interface KrakenView : UIView
|
||||
|
||||
@property (nonatomic, weak) IBOutlet id <KrakenViewDelegate> delegate;
|
||||
@property (nonatomic, assign) KRScene *scene;
|
||||
|
||||
- (void)startAnimation;
|
||||
- (void)stopAnimation;
|
||||
|
||||
@end
|
||||
201
kraken_ios/KrakenView.mm
Normal file
201
kraken_ios/KrakenView.mm
Normal file
@@ -0,0 +1,201 @@
|
||||
//
|
||||
// KrakenView.m
|
||||
// Kraken
|
||||
//
|
||||
// Created by Kearwood Gilbert on 2017-04-27.
|
||||
// Copyright © 2017 Kearwood Software. All rights reserved.
|
||||
//
|
||||
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
#import <OpenGLES/ES2/gl.h>
|
||||
#import <OpenGLES/ES2/glext.h>
|
||||
|
||||
#import "KrakenView.h"
|
||||
#import "KREngine-common.h"
|
||||
#import "KREngine.h"
|
||||
|
||||
@interface KrakenView() {
|
||||
GLint framebufferWidth;
|
||||
GLint framebufferHeight;
|
||||
GLuint defaultFramebuffer;
|
||||
GLuint colorRenderbuffer;
|
||||
GLuint depthRenderbuffer;
|
||||
|
||||
CFTimeInterval lastTimestamp;
|
||||
|
||||
struct {
|
||||
unsigned int preRender:1;
|
||||
unsigned int postRender:1;
|
||||
} delegateRespondsTo;
|
||||
}
|
||||
|
||||
@property (nonatomic, unsafe_unretained) CADisplayLink *__unsafe_unretained displayLink;
|
||||
@property (nonatomic, strong) EAGLContext *context;
|
||||
|
||||
@end
|
||||
|
||||
@implementation KrakenView
|
||||
|
||||
|
||||
+ (Class)layerClass
|
||||
{
|
||||
return [CAEAGLLayer class];
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder*)coder
|
||||
{
|
||||
self = [super initWithCoder:coder];
|
||||
if (self) {
|
||||
lastTimestamp = 0.0;
|
||||
delegateRespondsTo.preRender = 0;
|
||||
delegateRespondsTo.postRender = 0;
|
||||
[self startAnimation];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self stopAnimation];
|
||||
}
|
||||
|
||||
- (void)setDelegate:(id <KrakenViewDelegate>)aDelegate {
|
||||
if (_delegate != aDelegate) {
|
||||
_delegate = aDelegate;
|
||||
|
||||
delegateRespondsTo.preRender = [_delegate respondsToSelector:@selector(preRender:withDeltaTime:)];
|
||||
delegateRespondsTo.postRender = [_delegate respondsToSelector:@selector(postRender:withDeltaTime:)];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startAnimation
|
||||
{
|
||||
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
|
||||
|
||||
eaglLayer.contentsScale = [[UIScreen mainScreen] scale];
|
||||
eaglLayer.opaque = TRUE;
|
||||
eaglLayer.drawableProperties = @{
|
||||
kEAGLDrawablePropertyRetainedBacking: [NSNumber numberWithBool:FALSE],
|
||||
kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8
|
||||
};
|
||||
KRContext::activateRenderContext();
|
||||
|
||||
//EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
|
||||
EAGLContext *aContext = [EAGLContext currentContext];
|
||||
if (!aContext) {
|
||||
NSLog(@"Failed to create ES context");
|
||||
} else if (![EAGLContext setCurrentContext:aContext]) {
|
||||
NSLog(@"Failed to set ES context current");
|
||||
}
|
||||
|
||||
self.context = aContext;
|
||||
|
||||
|
||||
|
||||
[self createFrameBuffer];
|
||||
|
||||
CADisplayLink *aDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawFrame)];
|
||||
[aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
||||
self.displayLink = aDisplayLink;
|
||||
}
|
||||
|
||||
- (void)stopAnimation
|
||||
{
|
||||
[self.displayLink invalidate];
|
||||
self.displayLink = nil;
|
||||
|
||||
if (self.context) {
|
||||
[EAGLContext setCurrentContext:self.context];
|
||||
|
||||
if (defaultFramebuffer) {
|
||||
GLDEBUG(glDeleteFramebuffers(1, &defaultFramebuffer));
|
||||
defaultFramebuffer = 0;
|
||||
}
|
||||
|
||||
if (colorRenderbuffer) {
|
||||
GLDEBUG(glDeleteRenderbuffers(1, &colorRenderbuffer));
|
||||
colorRenderbuffer = 0;
|
||||
}
|
||||
|
||||
if (depthRenderbuffer) {
|
||||
GLDEBUG(glDeleteRenderbuffers(1, &depthRenderbuffer));
|
||||
depthRenderbuffer = 0;
|
||||
}
|
||||
|
||||
[EAGLContext setCurrentContext:nil];
|
||||
|
||||
self.context = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)drawFrame
|
||||
{
|
||||
CFTimeInterval timeStamp = self.displayLink.timestamp;
|
||||
CFTimeInterval deltaTime;
|
||||
if (lastTimestamp == 0.0) {
|
||||
deltaTime = 0.0;
|
||||
} else {
|
||||
deltaTime = timeStamp - lastTimestamp;
|
||||
}
|
||||
lastTimestamp = timeStamp;
|
||||
|
||||
KRContext *context = KREngine.sharedInstance.context;
|
||||
|
||||
if (self.delegate && delegateRespondsTo.preRender) {
|
||||
[self.delegate preRender:context withDeltaTime:deltaTime];
|
||||
}
|
||||
|
||||
// ---- Render the Buffer ----
|
||||
[EAGLContext setCurrentContext:self.context];
|
||||
if (self.scene) {
|
||||
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer));
|
||||
[[KREngine sharedInstance] renderScene: self.scene WithDeltaTime: deltaTime AndWidth: framebufferWidth AndHeight: framebufferHeight AndDefaultFBO: defaultFramebuffer];
|
||||
} else {
|
||||
GLDEBUG(glClearColor(0.0f, 0.0f, 1.0f, 1.0f));
|
||||
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
|
||||
}
|
||||
|
||||
// ---- Present the Buffer ----
|
||||
|
||||
#if GL_EXT_discard_framebuffer
|
||||
GLenum attachments[2] = {GL_DEPTH_ATTACHMENT};
|
||||
GLDEBUG(glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, attachments));
|
||||
#endif
|
||||
|
||||
GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer));
|
||||
BOOL success = [self.context presentRenderbuffer:GL_RENDERBUFFER];
|
||||
|
||||
if (self.delegate && delegateRespondsTo.postRender) {
|
||||
[self.delegate postRender:context withDeltaTime:deltaTime];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)createFrameBuffer
|
||||
{
|
||||
// Create default framebuffer object.
|
||||
GLDEBUG(glGenFramebuffers(1, &defaultFramebuffer));
|
||||
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebuffer));
|
||||
|
||||
// Create color render buffer and allocate backing store.
|
||||
GLDEBUG(glGenRenderbuffers(1, &colorRenderbuffer));
|
||||
GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, colorRenderbuffer));
|
||||
[self.context renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
|
||||
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth));
|
||||
GLDEBUG(glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight));
|
||||
|
||||
// Attach color render buffer
|
||||
GLDEBUG(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorRenderbuffer));
|
||||
|
||||
// Create depth render buffer and allocate backing store.
|
||||
GLDEBUG(glGenRenderbuffers(1, &depthRenderbuffer));
|
||||
GLDEBUG(glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer));
|
||||
GLDEBUG(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, framebufferWidth, framebufferHeight));
|
||||
|
||||
// Attach depth render buffer
|
||||
GLDEBUG(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user