Implemented notification system needed for occlusion culling and transparency sorting

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4072
This commit is contained in:
kearwood
2012-08-17 01:04:49 +00:00
parent 3b2d71221a
commit 5768902ee2
46 changed files with 328 additions and 106 deletions

View File

@@ -17,6 +17,14 @@
E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */ = {isa = PBXBuildFile; fileRef = E42CB1EB158446940066E0D8 /* KRQuaternion.h */; };
E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */; };
E42CB1F1158446AB0066E0D8 /* KRQuaternion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */; };
E43B0AC915DDBB8500A5CB9F /* KRNotified.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */; };
E43B0ACA15DDBB8500A5CB9F /* KRNotified.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */; };
E43B0ACB15DDBB8500A5CB9F /* KRNotified.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AC815DDBB8500A5CB9F /* KRNotified.h */; };
E43B0ACC15DDBB8500A5CB9F /* KRNotified.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AC815DDBB8500A5CB9F /* KRNotified.h */; };
E43B0AD615DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */; };
E43B0AD715DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */; };
E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; };
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; };
E461A152152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; };
E461A153152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (Public, ); }; };
E461A156152E54F800F2044A /* KRLight.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E461A155152E54F700F2044A /* KRLight.cpp */; };
@@ -159,6 +167,10 @@
E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRBoundingVolume.cpp; path = Classes/KRBoundingVolume.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E42CB1EB158446940066E0D8 /* KRQuaternion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRQuaternion.h; path = Classes/KRQuaternion.h; sourceTree = "<group>"; };
E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRQuaternion.cpp; path = Classes/KRQuaternion.cpp; sourceTree = "<group>"; };
E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRNotified.cpp; path = Classes/KRNotified.cpp; sourceTree = "<group>"; };
E43B0AC815DDBB8500A5CB9F /* KRNotified.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRNotified.h; path = Classes/KRNotified.h; sourceTree = "<group>"; };
E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRContextObject.cpp; path = Classes/KRContextObject.cpp; sourceTree = "<group>"; };
E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRContextObject.h; path = Classes/KRContextObject.h; sourceTree = "<group>"; };
E45772F113C9A13C0037BEEA /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ShadowShader.vsh; path = Shaders/ShadowShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E45772F213C9A13C0037BEEA /* ShadowShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.fsh; path = Shaders/ShadowShader.fsh; sourceTree = "<group>"; };
E45772F313C9A13C0037BEEA /* PostShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.fsh; path = Shaders/PostShader.fsh; sourceTree = "<group>"; };
@@ -434,6 +446,8 @@
E491016E13C99BAE0098455B /* Classes */ = {
isa = PBXGroup;
children = (
E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */,
E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */,
E4F9753815362A5200FD60B2 /* 3rdparty */,
E461A173152E59DF00F2044A /* Math */,
E461A170152E598200F2044A /* Resources */,
@@ -441,10 +455,10 @@
E491017213C99BDC0098455B /* KREngine.h */,
E491017913C99BDC0098455B /* KRModel.cpp */,
E491017A13C99BDC0098455B /* KRModel.h */,
E491018413C99BDC0098455B /* KRMaterialManager.h */,
E491017B13C99BDC0098455B /* KRMaterialManager.cpp */,
E491018213C99BDC0098455B /* KRModelManager.cpp */,
E491018313C99BDC0098455B /* KRModelManager.h */,
E491018413C99BDC0098455B /* KRMaterialManager.h */,
E491018513C99BDC0098455B /* KRTextureManager.h */,
E491018013C99BDC0098455B /* KRTextureManager.cpp */,
E491018613C99BDC0098455B /* KRTexture.h */,
@@ -460,6 +474,8 @@
E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */,
E48C696E15374F5A00232E28 /* KRContext.h */,
E48C697115374F7E00232E28 /* KRContext.cpp */,
E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */,
E43B0AC815DDBB8500A5CB9F /* KRNotified.h */,
E46F49FF155DF46700CCF8B8 /* KRWorld.h */,
E46F4A0A155E002100CCF8B8 /* KRDataBlock.h */,
E46F4A0D155E003000CCF8B8 /* KRDataBlock.cpp */,
@@ -544,6 +560,8 @@
E46F4A00155DF46700CCF8B8 /* KRWorld.h in Headers */,
E46F4A0B155E002100CCF8B8 /* KRDataBlock.h in Headers */,
E42CB1EC158446940066E0D8 /* KRQuaternion.h in Headers */,
E43B0ACB15DDBB8500A5CB9F /* KRNotified.h in Headers */,
E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -583,6 +601,8 @@
E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */,
E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */,
E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */,
E43B0ACC15DDBB8500A5CB9F /* KRNotified.h in Headers */,
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -698,6 +718,8 @@
E46F4A04155DF47C00CCF8B8 /* KRWorld.cpp in Sources */,
E46F4A0E155E003000CCF8B8 /* KRDataBlock.cpp in Sources */,
E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */,
E43B0AC915DDBB8500A5CB9F /* KRNotified.cpp in Sources */,
E43B0AD615DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -736,6 +758,8 @@
E46F4A05155DF47C00CCF8B8 /* KRWorld.cpp in Sources */,
E46F4A0F155E003000CCF8B8 /* KRDataBlock.cpp in Sources */,
E42CB1F1158446AB0066E0D8 /* KRQuaternion.cpp in Sources */,
E43B0ACA15DDBB8500A5CB9F /* KRNotified.cpp in Sources */,
E43B0AD715DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -38,7 +38,7 @@
#import "KRCamera.h"
#import "KRBoundingVolume.h"
KRCamera::KRCamera(KRContext &context, GLint width, GLint height) {
KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRNotified(context) {
backingWidth = width;
backingHeight = height;
@@ -904,3 +904,19 @@ void KRCamera::loadShaders(KRContext &context)
m_shadowUniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_shadowShaderProgram, "shadow_mvp1");
}
void KRCamera::notify_sceneGraphCreate(KRNode *pNode)
{
fprintf(stderr, "KRCamera - notify_sceneGraphCreate");
}
void KRCamera::notify_sceneGraphDelete(KRNode *pNode)
{
fprintf(stderr, "KRCamera - notify_sceneGraphDelete");
}
void KRCamera::notify_sceneGraphModify(KRNode *pNode)
{
fprintf(stderr, "KRCamera - notify_sceneGraphModify");
}

View File

@@ -36,6 +36,7 @@
#import "KRMat4.h"
#import "KRVector2.h"
#import "KRNotified.h"
#define KRENGINE_MAX_SHADOW_BUFFERS 3
@@ -46,10 +47,10 @@ class KRInstance;
class KRScene;
class KRContext;
class KRCamera {
class KRCamera : public KRNotified {
public:
KRCamera(KRContext &context, GLint width, GLint height);
~KRCamera();
virtual ~KRCamera();
GLint backingWidth, backingHeight;
@@ -109,6 +110,10 @@ public:
std::string m_debug_text;
virtual void notify_sceneGraphCreate(KRNode *pNode);
virtual void notify_sceneGraphDelete(KRNode *pNode);
virtual void notify_sceneGraphModify(KRNode *pNode);
private:
KRVector3 m_position;

View File

@@ -9,13 +9,14 @@
#include <iostream>
#include "KRContext.h"
#include "KRCamera.h"
KRContext::KRContext() {
m_pShaderManager = new KRShaderManager();
m_pTextureManager = new KRTextureManager();
m_pMaterialManager = new KRMaterialManager(m_pTextureManager, m_pShaderManager);
m_pModelManager = new KRModelManager();
m_pSceneManager = new KRSceneManager();
m_pShaderManager = new KRShaderManager(*this);
m_pTextureManager = new KRTextureManager(*this);
m_pMaterialManager = new KRMaterialManager(*this, m_pTextureManager, m_pShaderManager);
m_pModelManager = new KRModelManager(*this);
m_pSceneManager = new KRSceneManager(*this);
}
KRContext::~KRContext() {
@@ -83,3 +84,29 @@ void KRContext::loadResource(std::string path) {
fprintf(stderr, "KRContext::loadResource - Unknown resource file type: %s\n", path.c_str());
}
}
void KRContext::registerNotified(KRNotified *pNotified)
{
m_notifiedObjects.insert(pNotified);
}
void KRContext::unregisterNotified(KRNotified *pNotified)
{
m_notifiedObjects.erase(pNotified);
}
void KRContext::notify_sceneGraphCreate(KRNode *pNode)
{
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
(*itr)->notify_sceneGraphCreate(pNode);
}
}
void KRContext::notify_sceneGraphDelete(KRNode *pNode)
{
}
void KRContext::notify_sceneGraphModify(KRNode *pNode)
{
}

View File

@@ -14,6 +14,7 @@
#import "KRMaterialManager.h"
#import "KRShaderManager.h"
#import "KRModelManager.h"
#import "KRNotified.h"
class KRContext {
public:
@@ -28,12 +29,23 @@ public:
KRShaderManager *getShaderManager();
KRModelManager *getModelManager();
KRCamera *createCamera(int width, int height);
void registerNotified(KRNotified *pNotified);
void unregisterNotified(KRNotified *pNotified);
void notify_sceneGraphCreate(KRNode *pNode);
void notify_sceneGraphDelete(KRNode *pNode);
void notify_sceneGraphModify(KRNode *pNode);
private:
KRSceneManager *m_pSceneManager;
KRTextureManager *m_pTextureManager;
KRMaterialManager *m_pMaterialManager;
KRShaderManager *m_pShaderManager;
KRModelManager *m_pModelManager;
std::set<KRNotified *> m_notifiedObjects;
};
#endif

View File

@@ -0,0 +1,19 @@
//
// KRContextObject.cpp
// KREngine
//
// Created by Kearwood Gilbert on 2012-08-16.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#include "KRContextObject.h"
KRContextObject::KRContextObject(KRContext &context)
{
m_pContext = &context;
}
KRContextObject::~KRContextObject()
{
}

View File

@@ -0,0 +1,23 @@
//
// KRContextObject.h
// KREngine
//
// Created by Kearwood Gilbert on 2012-08-16.
// Copyright (c) 2012 Kearwood Software. All rights reserved.
//
#ifndef KRCONTEXTOBJECT_H
#define KRCONTEXTOBJECT_H
class KRContext;
class KRContextObject {
public:
KRContextObject(KRContext &context);
~KRContextObject();
protected:
KRContext *m_pContext;
};
#endif

View File

@@ -13,7 +13,7 @@
#import "KRContext.h"
#import "KRMat4.h"
KRDirectionalLight::KRDirectionalLight(std::string name) : KRLight(name)
KRDirectionalLight::KRDirectionalLight(KRContext &context, std::string name) : KRLight(context, name)
{
}

View File

@@ -16,7 +16,7 @@ class KRDirectionalLight : public KRLight {
public:
KRDirectionalLight(std::string name);
KRDirectionalLight(KRContext &context, std::string name);
virtual ~KRDirectionalLight();
virtual std::string getElementName();

View File

@@ -34,7 +34,7 @@
#import "KRContext.h"
#include <assert.h>
KRInstance::KRInstance(std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map) : KRNode(instance_name) {
KRInstance::KRInstance(KRContext &context, std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map) : KRNode(context, instance_name) {
m_modelMatrix = modelMatrix;
m_lightMap = light_map;
m_pLightMap = NULL;

View File

@@ -53,7 +53,7 @@ class KRBoundingVolume;
class KRInstance : public KRNode {
public:
KRInstance(std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map);
KRInstance(KRContext &context, std::string instance_name, std::string model_name, const KRMat4 modelMatrix, std::string light_map);
virtual ~KRInstance();
virtual std::string getElementName();

View File

@@ -22,7 +22,7 @@
#import "KRShaderManager.h"
#import "KRShader.h"
KRLight::KRLight(std::string name) : KRNode(name)
KRLight::KRLight(KRContext &context, std::string name) : KRNode(context, name)
{
m_intensity = 1.0f;
m_flareTexture = "";

View File

@@ -41,7 +41,7 @@ public:
#endif
protected:
KRLight(std::string name);
KRLight(KRContext &context, std::string name);
float m_intensity;
float m_decayStart;

View File

@@ -39,7 +39,7 @@
#import "KRcontext.h"
KRMaterial::KRMaterial(const char *szName) : KRResource(szName) {
KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(context, szName) {
strcpy(m_szName, szName);
m_pAmbientMap = NULL;
m_pDiffuseMap = NULL;

View File

@@ -62,8 +62,8 @@ public:
KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
} alpha_mode_type;
KRMaterial(const char *szName);
~KRMaterial();
KRMaterial(KRContext &context, const char *szName);
virtual ~KRMaterial();
virtual std::string getExtension();
virtual bool save(const std::string& path);

View File

@@ -39,7 +39,8 @@
#include <unistd.h>
KRMaterialManager::KRMaterialManager(KRTextureManager *pTextureManager, KRShaderManager *pShaderManager) {
KRMaterialManager::KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRShaderManager *pShaderManager) : KRContextObject(context)
{
m_pTextureManager = pTextureManager;
m_pShaderManager = pShaderManager;
}
@@ -112,7 +113,7 @@ bool KRMaterialManager::loadFile(const char *szPath) {
if(strcmp(szSymbol[0], "newmtl") == 0 && cSymbols >= 2) {
pMaterial = new KRMaterial(szSymbol[1]);
pMaterial = new KRMaterial(*m_pContext, szSymbol[1]);
m_materials[szSymbol[1]] = pMaterial;
}
if(pMaterial != NULL) {

View File

@@ -45,10 +45,10 @@
using std::map;
class KRMaterialManager {
class KRMaterialManager : public KRContextObject {
public:
KRMaterialManager(KRTextureManager *pTextureManager, KRShaderManager *pShaderManager);
~KRMaterialManager();
KRMaterialManager(KRContext &context, KRTextureManager *pTextureManager, KRShaderManager *pShaderManager);
virtual ~KRMaterialManager();
bool loadFile(const char *szPath);
KRMaterial *getMaterial(const char *szName);

View File

@@ -40,7 +40,7 @@
#include <string.h>
#include <assert.h>
KRMesh::KRMesh(std::string name) : KRResource(name) {
KRMesh::KRMesh(KRContext &context, std::string name) : KRResource(context, name) {
m_fdPackFile = 0;
m_pPackData = NULL;
m_iPackFileSize = 0;

View File

@@ -58,8 +58,8 @@ using std::vector;
class KRMesh : public KRResource {
public:
KRMesh(std::string name);
~KRMesh();
KRMesh(KRContext &context, std::string name);
virtual ~KRMesh();
virtual std::string getExtension();
virtual bool save(const std::string& path);

View File

@@ -46,7 +46,7 @@
#import "KRShaderManager.h"
#import "KRContext.h"
KRModel::KRModel(std::string name, std::string path) {
KRModel::KRModel(KRContext &context, std::string name, std::string path) : KRContextObject(context) {
m_name = name;
loadPack(path);
}
@@ -54,7 +54,7 @@ KRModel::KRModel(std::string name, std::string path) {
void KRModel::loadPack(std::string path) {
m_materials.clear();
m_uniqueMaterials.clear();
m_pMesh = new KRMesh(KRResource::GetFileBase(path));
m_pMesh = new KRMesh(*m_pContext, KRResource::GetFileBase(path));
m_pMesh->loadPack(path);
}

View File

@@ -49,11 +49,11 @@ using std::set;
class KRMaterial;
class KRModel {
class KRModel : public KRContextObject {
public:
KRModel(std::string name, std::string path);
~KRModel();
KRModel(KRContext &context, std::string name, std::string path);
virtual ~KRModel();
#if TARGET_OS_IPHONE

View File

@@ -33,7 +33,7 @@
#import "KRModel.h"
KRModelManager::KRModelManager() {
KRModelManager::KRModelManager(KRContext &context) : KRContextObject(context) {
}
@@ -45,7 +45,7 @@ KRModelManager::~KRModelManager() {
}
KRModel *KRModelManager::loadModel(const char *szName, const char *szPath) {
KRModel *pModel = new KRModel(szName, szPath);
KRModel *pModel = new KRModel(*m_pContext, szName, szPath);
m_models[szName] = pModel;
return pModel;
}

View File

@@ -33,6 +33,7 @@
#define KRMODELMANAGER_H
#import "KREngine-common.h"
#import "KRContextObject.h"
class KRContext;
class KRModel;
@@ -41,10 +42,10 @@ class KRModel;
#import <string>
using std::map;
class KRModelManager {
class KRModelManager : public KRContextObject {
public:
KRModelManager();
~KRModelManager();
KRModelManager(KRContext &context);
virtual ~KRModelManager();
KRModel *loadModel(const char *szName, const char *szPath);
KRModel *getModel(const char *szName);

View File

@@ -16,7 +16,7 @@
#import "KRInstance.h"
KRNode::KRNode(std::string name)
KRNode::KRNode(KRContext &context, std::string name) : KRContextObject(context)
{
m_pExtents = NULL;
m_name = name;
@@ -81,7 +81,7 @@ void KRNode::loadXML(tinyxml2::XMLElement *e) {
m_localRotation = KRVector3(x,y,z);
for(tinyxml2::XMLElement *child_element=e->FirstChildElement(); child_element != NULL; child_element = child_element->NextSiblingElement()) {
KRNode *child_node = KRNode::LoadXML(child_element);
KRNode *child_node = KRNode::LoadXML(*m_pContext, child_element);
if(child_node) {
addChild(child_node);
}
@@ -126,20 +126,20 @@ std::string KRNode::getElementName() {
return "node";
}
KRNode *KRNode::LoadXML(tinyxml2::XMLElement *e) {
KRNode *KRNode::LoadXML(KRContext &context, tinyxml2::XMLElement *e) {
KRNode *new_node = NULL;
const char *szElementName = e->Name();
const char *szName = e->Attribute("name");
if(strcmp(szElementName, "node") == 0) {
new_node = new KRNode(szName);
new_node = new KRNode(context, szName);
} else if(strcmp(szElementName, "point_light") == 0) {
new_node = new KRPointLight(szName);
new_node = new KRPointLight(context, szName);
} else if(strcmp(szElementName, "directional_light") == 0) {
new_node = new KRDirectionalLight(szName);
new_node = new KRDirectionalLight(context, szName);
} else if(strcmp(szElementName, "spot_light") == 0) {
new_node = new KRSpotLight(szName);
new_node = new KRSpotLight(context, szName);
} else if(strcmp(szElementName, "mesh") == 0) {
new_node = new KRInstance(szName, szName, KRMat4(), e->Attribute("light_map"));
new_node = new KRInstance(context, szName, szName, KRMat4(), e->Attribute("light_map"));
}

View File

@@ -22,7 +22,7 @@ class KRMat4;
class KRTextureManager;
class KRContext;
class KRNode
class KRNode : public KRContextObject
{
public:
enum RenderPass {
@@ -35,11 +35,11 @@ public:
RENDER_PASS_SHADOWMAP
};
KRNode(std::string name);
KRNode(KRContext &context, std::string name);
virtual ~KRNode();
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
static KRNode *LoadXML(tinyxml2::XMLElement *e);
static KRNode *LoadXML(KRContext &context, tinyxml2::XMLElement *e);
virtual void loadXML(tinyxml2::XMLElement *e);
virtual std::string getElementName();

View File

@@ -0,0 +1,43 @@
//
// KRNotified.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 "KRNotified.h"
#include "KRContext.h"
KRNotified::KRNotified(KRContext &context) : KRContextObject(context)
{
context.registerNotified(this);
}
KRNotified::~KRNotified()
{
m_pContext->unregisterNotified(this);
}

View File

@@ -0,0 +1,54 @@
//
// KRNotified.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 "KRContextObject.h"
#ifndef KRNOTIFIED_H
#define KRNOTIFIED_H
class KRContext;
class KRNode;
class KRNotified : public KRContextObject {
public:
KRNotified(KRContext &context);
virtual ~KRNotified();
virtual void notify_sceneGraphCreate(KRNode *pNode) = 0;
virtual void notify_sceneGraphDelete(KRNode *pNode) = 0;
virtual void notify_sceneGraphModify(KRNode *pNode) = 0;
protected:
KRContext *m_pContext;
};
#endif

View File

@@ -16,7 +16,7 @@
#import "KRContext.h"
#import "KRBoundingVolume.h"
KRPointLight::KRPointLight(std::string name) : KRLight(name)
KRPointLight::KRPointLight(KRContext &context, std::string name) : KRLight(context, name)
{
m_sphereVertices = NULL;
m_cVertices = 0;

View File

@@ -16,7 +16,7 @@ class KRPointLight : public KRLight {
public:
KRPointLight(std::string name);
KRPointLight(KRContext &context, std::string name);
virtual ~KRPointLight();
virtual std::string getElementName();

View File

@@ -19,11 +19,11 @@
#include "KRResource.h"
#include "KRMesh.h"
std::vector<KRResource *> KRResource::LoadObj(const std::string& path)
std::vector<KRResource *> KRResource::LoadObj(KRContext &context, const std::string& path)
{
std::vector<KRResource *> resources;
KRMesh *new_mesh = new KRMesh(KRResource::GetFileBase(path));
KRMesh *new_mesh = new KRMesh(context, KRResource::GetFileBase(path));
resources.push_back(new_mesh);
std::vector<KRVector3> vertices;
std::vector<KRVector2> uva;

View File

@@ -10,7 +10,7 @@
#import "KRResource.h"
KRResource::KRResource(std::string name) {
KRResource::KRResource(KRContext &context, std::string name) : KRContextObject(context) {
m_name = name;
}
KRResource::~KRResource() {
@@ -56,16 +56,16 @@ std::string KRResource::GetFilePath(const std::string& name)
}
}
std::vector<KRResource *> KRResource::Load(const std::string& path)
std::vector<KRResource *> KRResource::Load(KRContext &context, const std::string& path)
{
std::vector<KRResource *> resources;
std::string extension = GetFileExtension(path);
if(extension.compare("obj") == 0) {
return LoadObj(path);
return LoadObj(context, path);
} else if(extension.compare("fbx") == 0) {
return LoadFbx(path);
return LoadFbx(context, path);
} else if(extension.compare("blend") == 0) {
return LoadBlenderScene(path);
return LoadBlenderScene(context, path);
}
return resources;

View File

@@ -12,11 +12,12 @@
#import <list>
#import <string>
#import "KREngine-common.h"
#import "KRContextObject.h"
#ifndef KREngine_KRResource_h
#define KREngine_KRResource_h
class KRResource
class KRResource : public KRContextObject
{
public:
std::string getName();
@@ -27,20 +28,20 @@ public:
static std::string GetFileBase(const std::string& name);
static std::string GetFilePath(const std::string& name);
static std::vector<KRResource *> Load(const std::string& path);
static std::vector<KRResource *> Load(KRContext &context, const std::string& path);
virtual ~KRResource();
protected:
KRResource(std::string name);
KRResource(KRContext &context, std::string name);
private:
std::string m_name;
static std::vector<KRResource *> LoadObj(const std::string& path);
static std::vector<KRResource *> LoadFbx(const std::string& path);
static std::vector<KRResource *> LoadBlenderScene(const std::string& path);
static std::vector<KRResource *> LoadObj(KRContext &context, const std::string& path);
static std::vector<KRResource *> LoadFbx(KRContext &context, const std::string& path);
static std::vector<KRResource *> LoadBlenderScene(KRContext &context, const std::string& path);
};
#endif

View File

@@ -39,9 +39,10 @@
#import "KRScene.h"
KRScene::KRScene(std::string name) : KRResource(name) {
KRScene::KRScene(KRContext &context, std::string name) : KRResource(context, name) {
m_pContext = &context;
m_pFirstDirectionalLight = NULL;
m_pRootNode = new KRNode("scene_root");
m_pRootNode = new KRNode(context, "scene_root");
sun_yaw = 4.333; // TODO - Remove temporary testing code
sun_pitch = 0.55;
@@ -138,13 +139,13 @@ KRDirectionalLight *KRScene::findFirstDirectionalLight(KRNode &node) {
return NULL;
}
KRScene *KRScene::LoadXML(const std::string& path)
KRScene *KRScene::LoadXML(KRContext &context, const std::string& path)
{
tinyxml2::XMLDocument doc;
doc.LoadFile(path.c_str());
KRScene *new_scene = new KRScene(KRResource::GetFileBase(path));
KRScene *new_scene = new KRScene(context, KRResource::GetFileBase(path));
KRNode *n = KRNode::LoadXML(doc.RootElement()->FirstChildElement());
KRNode *n = KRNode::LoadXML(context, doc.RootElement()->FirstChildElement());
if(n) {
new_scene->getRootNode()->addChild(n);
}

View File

@@ -50,13 +50,13 @@ using std::vector;
class KRScene : public KRResource {
public:
KRScene(std::string name);
KRScene(KRContext &context, std::string name);
~KRScene();
virtual std::string getExtension();
virtual bool save(const std::string& path);
static KRScene *LoadXML(const std::string& path);
static KRScene *LoadXML(KRContext &context, const std::string& path);
KRNode *getRootNode();
KRDirectionalLight *getFirstDirectionalLight();
@@ -70,6 +70,7 @@ public:
KRBoundingVolume getExtents(KRContext *pContext);
double sun_pitch, sun_yaw;
private:
KRContext *m_pContext;
KRDirectionalLight *findFirstDirectionalLight(KRNode &node);
KRNode *m_pRootNode;

View File

@@ -32,7 +32,7 @@
#import "KRSceneManager.h"
#import "KRScene.h"
KRSceneManager::KRSceneManager() {
KRSceneManager::KRSceneManager(KRContext &context) : KRContextObject(context){
}
KRSceneManager::~KRSceneManager() {
@@ -43,7 +43,7 @@ KRSceneManager::~KRSceneManager() {
}
KRScene *KRSceneManager::loadScene(const char *szName, const char *szPath) {
KRScene *pScene = KRScene::LoadXML(szPath);
KRScene *pScene = KRScene::LoadXML(*m_pContext, szPath);
m_scenes[szName] = pScene;
return pScene;
}

View File

@@ -33,6 +33,7 @@
#define KRENGINE_KRSCENEMANAGER_H
#import "KREngine-common.h"
#import "KRContextObject.h"
class KRScene;
@@ -41,10 +42,10 @@ class KRScene;
using std::map;
class KRSceneManager {
class KRSceneManager : public KRContextObject {
public:
KRSceneManager();
~KRSceneManager();
KRSceneManager(KRContext &context);
virtual ~KRSceneManager();
KRScene *loadScene(const char *szName, const char *szPath);

View File

@@ -36,7 +36,7 @@
using namespace std;
KRShaderManager::KRShaderManager() {
KRShaderManager::KRShaderManager(KRContext &context) : KRContextObject(context) {
}

View File

@@ -45,9 +45,9 @@ using std::vector;
#define KRENGINE_MAX_SHADER_HANDLES 100
class KRShaderManager {
class KRShaderManager : public KRContextObject {
public:
KRShaderManager();
KRShaderManager(KRContext &context);
~KRShaderManager();
void loadFragmentShader(const std::string &name, const std::string &path);

View File

@@ -10,7 +10,7 @@
#import "KRSpotLight.h"
KRSpotLight::KRSpotLight(std::string name) : KRLight(name)
KRSpotLight::KRSpotLight(KRContext &context, std::string name) : KRLight(context, name)
{
}

View File

@@ -13,7 +13,7 @@
class KRSpotLight : public KRLight {
public:
KRSpotLight(std::string name);
KRSpotLight(KRContext &context, std::string name);
virtual ~KRSpotLight();
virtual std::string getElementName();

View File

@@ -32,7 +32,7 @@
#include "KRTextureManager.h"
#include <string.h>
KRTextureManager::KRTextureManager() {
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
}

View File

@@ -33,16 +33,17 @@
#define KRTEXTUREMANAGER_H
#include "KRTexture.h"
#include "KRContextObject.h"
#include <map>
#import <string>
using std::map;
class KRTextureManager {
class KRTextureManager : public KRContextObject {
public:
KRTextureManager();
~KRTextureManager();
KRTextureManager(KRContext &context);
virtual ~KRTextureManager();
#if TARGET_OS_IPHONE

View File

@@ -44,8 +44,6 @@
/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
GLuint viewFramebuffer, viewRenderbuffer;
KREngine *renderEngine;
}
// OpenGL drawing
@@ -53,9 +51,11 @@
- (void)destroyFramebuffer;
- (void)setDisplayFramebuffer;
- (BOOL)presentFramebuffer;
- (KREngine *)getEngine;
- (KRScene *)getScene;
- (BOOL)loadObjects;
@property(nonatomic,retain) KREngine *engine;
- (KRScene *)getScene;
@end

View File

@@ -43,7 +43,6 @@
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
@@ -79,17 +78,14 @@
}
// Initialize KREngine
renderEngine = [[KREngine alloc] initForWidth: backingWidth Height: backingHeight];
_engine = [[KREngine alloc] initForWidth: backingWidth Height: backingHeight];
[self loadObjects];
}
return self;
}
- (void)dealloc {
if(renderEngine) {
[renderEngine release];
renderEngine = nil;
}
[_engine release]; _engine = nil;
[super dealloc];
}
@@ -105,11 +101,11 @@
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath: documentsDirectory error:nil]) {
NSString* path = [NSString stringWithFormat:@"%@/%@", documentsDirectory, fileName];
[renderEngine loadResource: path];
[self.engine loadResource: path];
}
[renderEngine setNearZ: 5.0];
[renderEngine setFarZ: 500.0];
[self.engine setNearZ: 5.0];
[self.engine setFarZ: 500.0];
//[renderEngine setNearZ: 1.0];
//[renderEngine setFarZ: 3000.0];
@@ -194,14 +190,9 @@
return success;
}
- (KREngine *)getEngine;
- (KRScene *)getScene
{
return renderEngine;
}
- (KRScene *)getScene;
{
return renderEngine.context.getSceneManager()->getFirstScene();
return self.engine.context->getSceneManager()->getFirstScene();
}
#pragma mark -

View File

@@ -194,7 +194,7 @@
const GLfloat d2r = PI * 2 / 360;
KREngine *engine = [glView getEngine];
KREngine *engine = glView.engine;
int iParam = int(dLeftSlider * ([engine getParameterCount] + 1));
if(iParam > [engine getParameterCount]) {
iParam = [engine getParameterCount];
@@ -256,7 +256,8 @@
[glView setDisplayFramebuffer];
[engine renderScene: [glView getScene] WithPosition:camera_position Yaw: camera_yaw Pitch: camera_pitch Roll:0.0f];
KRScene *scene = [glView getScene];
[engine renderScene: scene WithPosition:camera_position Yaw: camera_yaw Pitch: camera_pitch Roll:0.0f];
[glView presentFramebuffer];
[framePool release];

View File

@@ -246,7 +246,7 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0430;
LastUpgradeCheck = 0440;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "KRObjView" */;
compatibilityVersion = "Xcode 3.2";