Auto format C++ source

This commit is contained in:
2022-08-08 01:07:26 -07:00
parent c5a640e22d
commit 7433d54c16
155 changed files with 17259 additions and 16879 deletions

View File

@@ -52,10 +52,10 @@ KRAmbientZone::KRAmbientZone(KRScene &scene, std::string name) : KRNode(scene, n
} }
KRAmbientZone::~KRAmbientZone() KRAmbientZone::~KRAmbientZone()
{ {}
}
std::string KRAmbientZone::getElementName() { std::string KRAmbientZone::getElementName()
{
return "ambient_zone"; return "ambient_zone";
} }
@@ -163,7 +163,8 @@ void KRAmbientZone::setGradientDistance(float gradient_distance)
m_gradient_distance = gradient_distance; m_gradient_distance = gradient_distance;
} }
AABB KRAmbientZone::getBounds() { AABB KRAmbientZone::getBounds()
{
// Ambient zones always have a -1, -1, -1 to 1, 1, 1 bounding box // Ambient zones always have a -1, -1, -1 to 1, 1, 1 bounding box
return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix()); return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix());
} }

View File

@@ -35,7 +35,8 @@
#include "KRNode.h" #include "KRNode.h"
#include "KRTexture.h" #include "KRTexture.h"
class KRAmbientZone : public KRNode { class KRAmbientZone : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -51,7 +51,8 @@ KRAnimation::~KRAnimation()
} }
} }
std::string KRAnimation::getExtension() { std::string KRAnimation::getExtension()
{
return "kranimation"; return "kranimation";
} }
@@ -60,7 +61,8 @@ void KRAnimation::addLayer(KRAnimationLayer *layer)
m_layers[layer->getName()] = layer; m_layers[layer->getName()] = layer;
} }
bool KRAnimation::save(KRDataBlock &data) { bool KRAnimation::save(KRDataBlock& data)
{
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
tinyxml2::XMLElement* animation_node = doc.NewElement("animation"); tinyxml2::XMLElement* animation_node = doc.NewElement("animation");
doc.InsertEndChild(animation_node); doc.InsertEndChild(animation_node);

View File

@@ -38,7 +38,8 @@
#include "KRAnimationLayer.h" #include "KRAnimationLayer.h"
class KRAnimation : public KRResource { class KRAnimation : public KRResource
{
public: public:
KRAnimation(KRContext& context, std::string name); KRAnimation(KRContext& context, std::string name);

View File

@@ -36,7 +36,8 @@
#include "KRNode.h" #include "KRNode.h"
#include "KRAnimationCurve.h" #include "KRAnimationCurve.h"
class KRAnimationAttribute : public KRContextObject { class KRAnimationAttribute : public KRContextObject
{
public: public:
KRAnimationAttribute(KRContext& context); KRAnimationAttribute(KRContext& context);
~KRAnimationAttribute(); ~KRAnimationAttribute();

View File

@@ -59,15 +59,18 @@ bool KRAnimationCurve::load(KRDataBlock *data)
return true; return true;
} }
std::string KRAnimationCurve::getExtension() { std::string KRAnimationCurve::getExtension()
{
return "kranimationcurve"; return "kranimationcurve";
} }
bool KRAnimationCurve::save(const std::string& path) { bool KRAnimationCurve::save(const std::string& path)
{
return m_pData->save(path); return m_pData->save(path);
} }
bool KRAnimationCurve::save(KRDataBlock &data) { bool KRAnimationCurve::save(KRDataBlock& data)
{
data.append(*m_pData); data.append(*m_pData);
return true; return true;
} }

View File

@@ -36,7 +36,8 @@
#include "KRDataBlock.h" #include "KRDataBlock.h"
#include "KRResource.h" #include "KRResource.h"
class KRAnimationCurve : public KRResource { class KRAnimationCurve : public KRResource
{
public: public:
KRAnimationCurve(KRContext& context, const std::string& name); KRAnimationCurve(KRContext& context, const std::string& name);
@@ -72,7 +73,8 @@ public:
private: private:
KRDataBlock* m_pData; KRDataBlock* m_pData;
typedef struct { typedef struct
{
char szTag[16]; char szTag[16];
float frame_rate; float frame_rate;
int32_t frame_start; int32_t frame_start;

View File

@@ -37,13 +37,15 @@ KRAnimationCurveManager::KRAnimationCurveManager(KRContext &context) : KRResourc
} }
KRAnimationCurveManager::~KRAnimationCurveManager() { KRAnimationCurveManager::~KRAnimationCurveManager()
{
for (unordered_map<std::string, KRAnimationCurve*>::iterator itr = m_animationCurves.begin(); itr != m_animationCurves.end(); ++itr) { for (unordered_map<std::string, KRAnimationCurve*>::iterator itr = m_animationCurves.begin(); itr != m_animationCurves.end(); ++itr) {
delete (*itr).second; delete (*itr).second;
} }
} }
void KRAnimationCurveManager::deleteAnimationCurve(KRAnimationCurve *curve) { void KRAnimationCurveManager::deleteAnimationCurve(KRAnimationCurve* curve)
{
m_animationCurves.erase(curve->getName()); m_animationCurves.erase(curve->getName());
delete curve; delete curve;
} }
@@ -63,7 +65,8 @@ KRResource* KRAnimationCurveManager::getResource(const std::string& name, const
return nullptr; return nullptr;
} }
KRAnimationCurve *KRAnimationCurveManager::loadAnimationCurve(const std::string &name, KRDataBlock *data) { KRAnimationCurve* KRAnimationCurveManager::loadAnimationCurve(const std::string& name, KRDataBlock* data)
{
KRAnimationCurve* pAnimationCurve = KRAnimationCurve::Load(*m_pContext, name, data); KRAnimationCurve* pAnimationCurve = KRAnimationCurve::Load(*m_pContext, name, data);
if (pAnimationCurve) { if (pAnimationCurve) {
m_animationCurves[name] = pAnimationCurve; m_animationCurves[name] = pAnimationCurve;
@@ -71,7 +74,8 @@ KRAnimationCurve *KRAnimationCurveManager::loadAnimationCurve(const std::string
return pAnimationCurve; return pAnimationCurve;
} }
KRAnimationCurve *KRAnimationCurveManager::getAnimationCurve(const std::string &name) { KRAnimationCurve* KRAnimationCurveManager::getAnimationCurve(const std::string& name)
{
unordered_map<std::string, KRAnimationCurve*>::iterator itr = m_animationCurves.find(name); unordered_map<std::string, KRAnimationCurve*>::iterator itr = m_animationCurves.find(name);
if (itr == m_animationCurves.end()) { if (itr == m_animationCurves.end()) {
return NULL; // Not found return NULL; // Not found
@@ -80,7 +84,8 @@ KRAnimationCurve *KRAnimationCurveManager::getAnimationCurve(const std::string &
} }
} }
unordered_map<std::string, KRAnimationCurve *> &KRAnimationCurveManager::getAnimationCurves() { unordered_map<std::string, KRAnimationCurve*>& KRAnimationCurveManager::getAnimationCurves()
{
return m_animationCurves; return m_animationCurves;
} }

View File

@@ -41,7 +41,8 @@
using std::map; using std::map;
class KRAnimationCurveManager : public KRResourceManager { class KRAnimationCurveManager : public KRResourceManager
{
public: public:
KRAnimationCurveManager(KRContext& context); KRAnimationCurveManager(KRContext& context);
virtual ~KRAnimationCurveManager(); virtual ~KRAnimationCurveManager();

View File

@@ -40,7 +40,8 @@ namespace tinyxml2 {
class XMLAttribute; class XMLAttribute;
} }
class KRAnimationLayer : public KRContextObject { class KRAnimationLayer : public KRContextObject
{
public: public:
KRAnimationLayer(KRContext& context); KRAnimationLayer(KRContext& context);
~KRAnimationLayer(); ~KRAnimationLayer();
@@ -54,7 +55,8 @@ public:
float getWeight() const; float getWeight() const;
void setWeight(float weight); void setWeight(float weight);
typedef enum { typedef enum
{
KRENGINE_ANIMATION_BLEND_MODE_ADDITIVE, KRENGINE_ANIMATION_BLEND_MODE_ADDITIVE,
KRENGINE_ANIMATION_BLEND_MODE_OVERRIDE, KRENGINE_ANIMATION_BLEND_MODE_OVERRIDE,
KRENGINE_ANIMATION_BLEND_MODE_OVERRIDE_PASSTHROUGH KRENGINE_ANIMATION_BLEND_MODE_OVERRIDE_PASSTHROUGH
@@ -63,7 +65,8 @@ public:
blend_mode_t getBlendMode() const; blend_mode_t getBlendMode() const;
void setBlendMode(const blend_mode_t& blend_mode); void setBlendMode(const blend_mode_t& blend_mode);
typedef enum { typedef enum
{
KRENGINE_ANIMATION_ROTATION_ACCUMULATION_BY_LAYER, KRENGINE_ANIMATION_ROTATION_ACCUMULATION_BY_LAYER,
KRENGINE_ANIMATION_ROTATION_ACCUMULATION_BY_CHANNEL KRENGINE_ANIMATION_ROTATION_ACCUMULATION_BY_CHANNEL
} rotation_accumulation_mode_t; } rotation_accumulation_mode_t;
@@ -71,7 +74,8 @@ public:
rotation_accumulation_mode_t getRotationAccumulationMode() const; rotation_accumulation_mode_t getRotationAccumulationMode() const;
void setRotationAccumulationMode(const rotation_accumulation_mode_t& rotation_accumulation_mode); void setRotationAccumulationMode(const rotation_accumulation_mode_t& rotation_accumulation_mode);
typedef enum { typedef enum
{
KRENGINE_ANIMATION_SCALE_ACCUMULATION_MULTIPLY, KRENGINE_ANIMATION_SCALE_ACCUMULATION_MULTIPLY,
KRENGINE_ANIMATION_SCALE_ACCUMULATION_ADDITIVE KRENGINE_ANIMATION_SCALE_ACCUMULATION_ADDITIVE
} scale_accumulation_mode_t; } scale_accumulation_mode_t;

View File

@@ -37,7 +37,8 @@ KRAnimationManager::KRAnimationManager(KRContext &context) : KRResourceManager(c
} }
KRAnimationManager::~KRAnimationManager() { KRAnimationManager::~KRAnimationManager()
{
for (std::set<KRAnimation*>::iterator itr = m_activeAnimations.begin(); itr != m_activeAnimations.end(); itr++) { for (std::set<KRAnimation*>::iterator itr = m_activeAnimations.begin(); itr != m_activeAnimations.end(); itr++) {
KRAnimation* animation = *itr; KRAnimation* animation = *itr;
animation->_unlockData(); animation->_unlockData();
@@ -96,17 +97,20 @@ KRResource* KRAnimationManager::getResource(const std::string& name, const std::
return nullptr; return nullptr;
} }
KRAnimation *KRAnimationManager::loadAnimation(const char *szName, KRDataBlock *data) { KRAnimation* KRAnimationManager::loadAnimation(const char* szName, KRDataBlock* data)
{
KRAnimation* pAnimation = KRAnimation::Load(*m_pContext, szName, data); KRAnimation* pAnimation = KRAnimation::Load(*m_pContext, szName, data);
addAnimation(pAnimation); addAnimation(pAnimation);
return pAnimation; return pAnimation;
} }
KRAnimation *KRAnimationManager::getAnimation(const char *szName) { KRAnimation* KRAnimationManager::getAnimation(const char* szName)
{
return m_animations[szName]; return m_animations[szName];
} }
unordered_map<std::string, KRAnimation *> &KRAnimationManager::getAnimations() { unordered_map<std::string, KRAnimation*>& KRAnimationManager::getAnimations()
{
return m_animations; return m_animations;
} }
@@ -123,8 +127,7 @@ void KRAnimationManager::updateActiveAnimations(KRAnimation *animation)
void KRAnimationManager::deleteAnimation(KRAnimation* animation, bool delete_curves) void KRAnimationManager::deleteAnimation(KRAnimation* animation, bool delete_curves)
{ {
if(delete_curves) if (delete_curves) {
{
animation->deleteCurves(); animation->deleteCurves();
} }
m_animations.erase(animation->getName()); m_animations.erase(animation->getName());

View File

@@ -41,7 +41,8 @@
class KRAnimationManager : public KRResourceManager { class KRAnimationManager : public KRResourceManager
{
public: public:
KRAnimationManager(KRContext& context); KRAnimationManager(KRContext& context);
virtual ~KRAnimationManager(); virtual ~KRAnimationManager();

View File

@@ -1834,7 +1834,8 @@ static bool audioIsMuted = false;
static bool audioShouldBecomeMuted = false; static bool audioShouldBecomeMuted = false;
static bool audioShouldBecomeUnmuted = false; static bool audioShouldBecomeUnmuted = false;
void audioLimit_Mute(bool onNotOff) { void audioLimit_Mute(bool onNotOff)
{
if (onNotOff) { if (onNotOff) {
if (audioIsMuted) { if (audioIsMuted) {
audioShouldBecomeMuted = false; audioShouldBecomeMuted = false;
@@ -1843,8 +1844,7 @@ void audioLimit_Mute(bool onNotOff) {
} }
audioShouldBecomeMuted = true; audioShouldBecomeMuted = true;
audioShouldBecomeUnmuted = false; audioShouldBecomeUnmuted = false;
} } else {
else {
if (!audioIsMuted) { if (!audioIsMuted) {
audioShouldBecomeMuted = false; audioShouldBecomeMuted = false;
audioShouldBecomeUnmuted = false; audioShouldBecomeUnmuted = false;
@@ -1889,12 +1889,18 @@ void audioLimit_Stereo(float *stereo_buffer, unsigned long framesize)
// (1a) check for a mute or unmute state then get the next limit volume // (1a) check for a mute or unmute state then get the next limit volume
float nextlimitvol = 0.0; float nextlimitvol = 0.0;
if (audioIsMuted && audioShouldBecomeUnmuted) { audioIsMuted = false; audioShouldBecomeUnmuted = false; } if (audioIsMuted && audioShouldBecomeUnmuted) {
if (audioShouldBecomeMuted) { audioIsMuted = true; audioShouldBecomeMuted = false; } audioIsMuted = false; audioShouldBecomeUnmuted = false;
}
if (audioShouldBecomeMuted) {
audioIsMuted = true; audioShouldBecomeMuted = false;
}
if (!audioIsMuted) nextlimitvol = audioGetLimitParameters_Stereo(stereo_buffer, framesize, &attack_sample_position, &peak); if (!audioIsMuted) nextlimitvol = audioGetLimitParameters_Stereo(stereo_buffer, framesize, &attack_sample_position, &peak);
// (1b) if no limiting is needed then return // (1b) if no limiting is needed then return
if ((1.0 == nextlimitvol) && (1.0 == previouslimitvol)) { return; } // no limiting necessary if ((1.0 == nextlimitvol) && (1.0 == previouslimitvol)) {
return;
} // no limiting necessary
// (2) calculate limiting factors // (2) calculate limiting factors
float deltavol = 0.0; float deltavol = 0.0;
@@ -1912,8 +1918,7 @@ void audioLimit_Stereo(float *stereo_buffer, unsigned long framesize)
*src = *src * nextlimitvol; *src = *src * nextlimitvol;
src++; src++;
} }
} } else {
else {
for (unsigned long i = 0; i < attack_sample_position; i++) { // attack phase for (unsigned long i = 0; i < attack_sample_position; i++) { // attack phase
*src = *src * previouslimitvol; *src = *src * previouslimitvol;
src++; src++;

View File

@@ -79,19 +79,22 @@ const int KRENGINE_AUDIO_ANTICLICK_SAMPLES = 64;
class KRAmbientZone; class KRAmbientZone;
class KRReverbZone; class KRReverbZone;
typedef struct { typedef struct
{
float weight; float weight;
KRAmbientZone* ambient_zone; KRAmbientZone* ambient_zone;
KRAudioSample* ambient_sample; KRAudioSample* ambient_sample;
} siren_ambient_zone_weight_info; } siren_ambient_zone_weight_info;
typedef struct { typedef struct
{
float weight; float weight;
KRReverbZone* reverb_zone; KRReverbZone* reverb_zone;
KRAudioSample* reverb_sample; KRAudioSample* reverb_sample;
} siren_reverb_zone_weight_info; } siren_reverb_zone_weight_info;
class KRAudioManager : public KRResourceManager { class KRAudioManager : public KRResourceManager
{
public: public:
KRAudioManager(KRContext& context); KRAudioManager(KRContext& context);
virtual ~KRAudioManager(); virtual ~KRAudioManager();

View File

@@ -38,7 +38,8 @@
class KRAudioBuffer; class KRAudioBuffer;
class KRAudioSample : public KRResource { class KRAudioSample : public KRResource
{
public: public:
KRAudioSample(KRContext& context, std::string name, std::string extension); KRAudioSample(KRContext& context, std::string name, std::string extension);

View File

@@ -80,7 +80,8 @@ KRAudioSource::~KRAudioSource()
} }
} }
std::string KRAudioSource::getElementName() { std::string KRAudioSource::getElementName()
{
return "audio_source"; return "audio_source";
} }

View File

@@ -39,7 +39,8 @@
class KRAudioSample; class KRAudioSample;
class KRAudioBuffer; class KRAudioBuffer;
class KRAudioSource : public KRNode { class KRAudioSource : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -45,10 +45,10 @@ KRBone::KRBone(KRScene &scene, std::string name) : KRNode(scene, name)
} }
KRBone::~KRBone() KRBone::~KRBone()
{ {}
}
std::string KRBone::getElementName() { std::string KRBone::getElementName()
{
return "bone"; return "bone";
} }
@@ -65,7 +65,8 @@ void KRBone::loadXML(tinyxml2::XMLElement *e)
setScaleCompensation(true); setScaleCompensation(true);
} }
AABB KRBone::getBounds() { AABB KRBone::getBounds()
{
return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix()); // Only required for bone debug visualization return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix()); // Only required for bone debug visualization
} }

View File

@@ -37,7 +37,8 @@
class RenderInfo; class RenderInfo;
class KRBone : public KRNode { class KRBone : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -106,7 +106,8 @@ bool KRBundle::save(const std::string& path)
return m_pData->save(path); return m_pData->save(path);
} }
bool KRBundle::save(KRDataBlock &data) { bool KRBundle::save(KRDataBlock& data)
{
if (m_pData->getSize() > KRENGINE_KRBUNDLE_HEADER_SIZE * 2) { if (m_pData->getSize() > KRENGINE_KRBUNDLE_HEADER_SIZE * 2) {
// Only output krbundles that contain files // Only output krbundles that contain files
data.append(*m_pData); data.append(*m_pData);

View File

@@ -34,7 +34,8 @@
#include "KRResource.h" #include "KRResource.h"
#include "KRDataBlock.h" #include "KRDataBlock.h"
class KRBundle : public KRResource { class KRBundle : public KRResource
{
public: public:
KRBundle(KRContext& context, std::string name, KRDataBlock* pData); KRBundle(KRContext& context, std::string name, KRDataBlock* pData);
KRBundle(KRContext& context, std::string name); KRBundle(KRContext& context, std::string name);

View File

@@ -33,11 +33,13 @@
#include "KRBundle.h" #include "KRBundle.h"
KRBundleManager::KRBundleManager(KRContext &context) : KRResourceManager(context) { KRBundleManager::KRBundleManager(KRContext& context) : KRResourceManager(context)
{
} }
KRBundleManager::~KRBundleManager() { KRBundleManager::~KRBundleManager()
{
for (unordered_map<std::string, KRBundle*>::iterator itr = m_bundles.begin(); itr != m_bundles.end(); ++itr) { for (unordered_map<std::string, KRBundle*>::iterator itr = m_bundles.begin(); itr != m_bundles.end(); ++itr) {
delete (*itr).second; delete (*itr).second;
} }
@@ -74,10 +76,12 @@ KRBundle *KRBundleManager::createBundle(const char *szName)
return pBundle; return pBundle;
} }
KRBundle *KRBundleManager::getBundle(const char *szName) { KRBundle* KRBundleManager::getBundle(const char* szName)
{
return m_bundles[szName]; return m_bundles[szName];
} }
unordered_map<std::string, KRBundle *> KRBundleManager::getBundles() { unordered_map<std::string, KRBundle*> KRBundleManager::getBundles()
{
return m_bundles; return m_bundles;
} }

View File

@@ -40,7 +40,8 @@
class KRContext; class KRContext;
class KRBundle; class KRBundle;
class KRBundleManager : public KRResourceManager { class KRBundleManager : public KRResourceManager
{
public: public:
KRBundleManager(KRContext& context); KRBundleManager(KRContext& context);
~KRBundleManager(); ~KRBundleManager();

View File

@@ -42,7 +42,8 @@ void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo)
nodeInfo->camera.skybox_texture = -1; nodeInfo->camera.skybox_texture = -1;
} }
KRCamera::KRCamera(KRScene &scene, std::string name) : KRNode(scene, name) { KRCamera::KRCamera(KRScene& scene, std::string name) : KRNode(scene, name)
{
m_last_frame_start = 0; m_last_frame_start = 0;
m_particlesAbsoluteTime = 0.0f; m_particlesAbsoluteTime = 0.0f;
@@ -70,11 +71,13 @@ KRCamera::KRCamera(KRScene &scene, std::string name) : KRNode(scene, name) {
); );
} }
KRCamera::~KRCamera() { KRCamera::~KRCamera()
{
destroyBuffers(); destroyBuffers();
} }
std::string KRCamera::getElementName() { std::string KRCamera::getElementName()
{
return "camera"; return "camera";
} }
@@ -376,7 +379,8 @@ void KRCamera::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& compositeS
} }
void KRCamera::createBuffers(GLint renderBufferWidth, GLint renderBufferHeight) { void KRCamera::createBuffers(GLint renderBufferWidth, GLint renderBufferHeight)
{
// TODO - Vulkan Refactoring.. // TODO - Vulkan Refactoring..
/* /*
if(renderBufferWidth != m_backingWidth || renderBufferHeight != m_backingHeight) { if(renderBufferWidth != m_backingWidth || renderBufferHeight != m_backingHeight) {

View File

@@ -48,7 +48,8 @@ class KRScene;
class KRViewport; class KRViewport;
class KRSurface; class KRSurface;
class KRCamera : public KRNode { class KRCamera : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);
KRCamera(KRScene& scene, std::string name); KRCamera(KRScene& scene, std::string name);
@@ -102,7 +103,8 @@ private:
Vector4 m_fade_color; Vector4 m_fade_color;
typedef struct { typedef struct
{
float x; float x;
float y; float y;
float z; float z;

View File

@@ -43,18 +43,21 @@ void KRCollider::InitNodeInfo(KrNodeInfo* nodeInfo)
nodeInfo->collider.mesh = -1; nodeInfo->collider.mesh = -1;
} }
KRCollider::KRCollider(KRScene &scene, std::string collider_name, std::string model_name, unsigned int layer_mask, float audio_occlusion) : KRNode(scene, collider_name) { KRCollider::KRCollider(KRScene& scene, std::string collider_name, std::string model_name, unsigned int layer_mask, float audio_occlusion) : KRNode(scene, collider_name)
{
m_model_name = model_name; m_model_name = model_name;
m_layer_mask = layer_mask; m_layer_mask = layer_mask;
m_audio_occlusion = audio_occlusion; m_audio_occlusion = audio_occlusion;
m_model = nullptr; m_model = nullptr;
} }
KRCollider::~KRCollider() { KRCollider::~KRCollider()
{
} }
std::string KRCollider::getElementName() { std::string KRCollider::getElementName()
{
return "collider"; return "collider";
} }
@@ -67,7 +70,8 @@ tinyxml2::XMLElement *KRCollider::saveXML( tinyxml2::XMLNode *parent)
return e; return e;
} }
void KRCollider::loadXML(tinyxml2::XMLElement *e) { void KRCollider::loadXML(tinyxml2::XMLElement* e)
{
KRNode::loadXML(e); KRNode::loadXML(e);
m_model_name = e->Attribute("mesh"); m_model_name = e->Attribute("mesh");
@@ -83,7 +87,8 @@ void KRCollider::loadXML(tinyxml2::XMLElement *e) {
} }
} }
void KRCollider::loadModel() { void KRCollider::loadModel()
{
if (m_model == nullptr) { if (m_model == nullptr) {
m_model = m_pContext->getMeshManager()->getMaxLODModel(m_model_name.c_str()); m_model = m_pContext->getMeshManager()->getMaxLODModel(m_model_name.c_str());
if (m_model) { if (m_model) {
@@ -92,7 +97,8 @@ void KRCollider::loadModel() {
} }
} }
AABB KRCollider::getBounds() { AABB KRCollider::getBounds()
{
loadModel(); loadModel();
if (m_model) { if (m_model) {
return AABB::Create(m_model->getMinPoint(), m_model->getMaxPoint(), getModelMatrix()); return AABB::Create(m_model->getMinPoint(), m_model->getMaxPoint(), getModelMatrix());

View File

@@ -46,7 +46,8 @@
#include "KRMesh.h" #include "KRMesh.h"
#include "KRTexture.h" #include "KRTexture.h"
class KRCollider : public KRNode { class KRCollider : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -138,7 +138,8 @@ KRContext::KRContext(const KrInitializeInfo* initializeInfo)
m_streamerThread->start(); m_streamerThread->start();
} }
KRContext::~KRContext() { KRContext::~KRContext()
{
m_presentationThread->stop(); m_presentationThread->stop();
m_streamerThread->stop(); m_streamerThread->stop();
m_pSceneManager.reset(); m_pSceneManager.reset();
@@ -193,46 +194,60 @@ void KRContext::Log(log_level level, const std::string message_format, ...)
va_end(args); va_end(args);
} }
KRBundleManager *KRContext::getBundleManager() { KRBundleManager* KRContext::getBundleManager()
{
return m_pBundleManager.get(); return m_pBundleManager.get();
} }
KRSceneManager *KRContext::getSceneManager() { KRSceneManager* KRContext::getSceneManager()
{
return m_pSceneManager.get(); return m_pSceneManager.get();
} }
KRTextureManager *KRContext::getTextureManager() { KRTextureManager* KRContext::getTextureManager()
{
return m_pTextureManager.get(); return m_pTextureManager.get();
} }
KRMaterialManager *KRContext::getMaterialManager() { KRMaterialManager* KRContext::getMaterialManager()
{
return m_pMaterialManager.get(); return m_pMaterialManager.get();
} }
KRPipelineManager *KRContext::getPipelineManager() { KRPipelineManager* KRContext::getPipelineManager()
{
return m_pPipelineManager.get(); return m_pPipelineManager.get();
} }
KRMeshManager *KRContext::getMeshManager() { KRMeshManager* KRContext::getMeshManager()
{
return m_pMeshManager.get(); return m_pMeshManager.get();
} }
KRAnimationManager *KRContext::getAnimationManager() { KRAnimationManager* KRContext::getAnimationManager()
{
return m_pAnimationManager.get(); return m_pAnimationManager.get();
} }
KRAnimationCurveManager *KRContext::getAnimationCurveManager() { KRAnimationCurveManager* KRContext::getAnimationCurveManager()
{
return m_pAnimationCurveManager.get(); return m_pAnimationCurveManager.get();
} }
KRAudioManager *KRContext::getAudioManager() { KRAudioManager* KRContext::getAudioManager()
{
return m_pSoundManager.get(); return m_pSoundManager.get();
} }
KRShaderManager *KRContext::getShaderManager() { KRShaderManager* KRContext::getShaderManager()
{
return m_pShaderManager.get(); return m_pShaderManager.get();
} }
KRSourceManager *KRContext::getSourceManager() { KRSourceManager* KRContext::getSourceManager()
{
return m_pSourceManager.get(); return m_pSourceManager.get();
} }
KRSurfaceManager* KRContext::getSurfaceManager() { KRSurfaceManager* KRContext::getSurfaceManager()
{
return m_surfaceManager.get(); return m_surfaceManager.get();
} }
KRDeviceManager* KRContext::getDeviceManager() { KRDeviceManager* KRContext::getDeviceManager()
{
return m_deviceManager.get(); return m_deviceManager.get();
} }
KRUnknownManager *KRContext::getUnknownManager() { KRUnknownManager* KRContext::getUnknownManager()
{
return m_pUnknownManager.get(); return m_pUnknownManager.get();
} }
std::vector<KRResource*> KRContext::getResources() std::vector<KRResource*> KRContext::getResources()
@@ -285,7 +300,8 @@ std::vector<KRResource *> KRContext::getResources()
return resources; return resources;
} }
KRResource* KRContext::loadResource(const std::string &file_name, KRDataBlock *data) { KRResource* KRContext::loadResource(const std::string& file_name, KRDataBlock* data)
{
std::string name = KRResource::GetFileBase(file_name); std::string name = KRResource::GetFileBase(file_name);
std::string extension = KRResource::GetFileExtension(file_name); std::string extension = KRResource::GetFileExtension(file_name);
@@ -385,7 +401,8 @@ KRResource* KRContext::loadResource(const std::string &file_name, KRDataBlock *d
return resource; return resource;
} }
KrResult KRContext::loadResource(const KrLoadResourceInfo* loadResourceInfo) { KrResult KRContext::loadResource(const KrLoadResourceInfo* loadResourceInfo)
{
if (loadResourceInfo->resourceHandle < 0 || loadResourceInfo->resourceHandle >= m_resourceMapSize) { if (loadResourceInfo->resourceHandle < 0 || loadResourceInfo->resourceHandle >= m_resourceMapSize) {
return KR_ERROR_OUT_OF_BOUNDS; return KR_ERROR_OUT_OF_BOUNDS;
} }

View File

@@ -54,7 +54,8 @@ class KRStreamerThread;
class KRDeviceManager; class KRDeviceManager;
class KRSurfaceManager; class KRSurfaceManager;
class KRContext { class KRContext
{
public: public:
static int KRENGINE_MAX_PIPELINE_HANDLES; static int KRENGINE_MAX_PIPELINE_HANDLES;
static int KRENGINE_GPU_MEM_MAX; static int KRENGINE_GPU_MEM_MAX;
@@ -131,7 +132,8 @@ public:
void getMemoryStats(long& free_memory); void getMemoryStats(long& free_memory);
#endif #endif
typedef enum { typedef enum
{
LOG_LEVEL_INFORMATION, LOG_LEVEL_INFORMATION,
LOG_LEVEL_WARNING, LOG_LEVEL_WARNING,
LOG_LEVEL_ERROR LOG_LEVEL_ERROR

View File

@@ -33,7 +33,8 @@
class KRContext; class KRContext;
class KRContextObject { class KRContextObject
{
public: public:
KRContextObject(KRContext& context); KRContextObject(KRContext& context);

View File

@@ -47,7 +47,8 @@ namespace KRDSP {
// Apple vDSP // Apple vDSP
typedef DSPSplitComplex SplitComplex; typedef DSPSplitComplex SplitComplex;
struct FFTWorkspace { struct FFTWorkspace
{
FFTSetup setup; FFTSetup setup;
void create(size_t length); void create(size_t length);
@@ -58,12 +59,14 @@ namespace KRDSP {
#elif defined(KRDSP_SLOW) #elif defined(KRDSP_SLOW)
typedef struct { typedef struct
{
float* realp; float* realp;
float* imagp; float* imagp;
} SplitComplex; } SplitComplex;
struct FFTWorkspace { struct FFTWorkspace
{
float* sin_table; float* sin_table;
float* cos_table; float* cos_table;

View File

@@ -47,7 +47,8 @@ int m_mapCount = 0;
size_t m_mapSize = 0; size_t m_mapSize = 0;
size_t m_mapOverhead = 0; size_t m_mapOverhead = 0;
KRDataBlock::KRDataBlock() { KRDataBlock::KRDataBlock()
{
m_data = NULL; m_data = NULL;
m_data_size = 0; m_data_size = 0;
m_data_offset = 0; m_data_offset = 0;
@@ -65,7 +66,8 @@ KRDataBlock::KRDataBlock() {
m_bReadOnly = false; m_bReadOnly = false;
} }
KRDataBlock::KRDataBlock(void *data, size_t size) { KRDataBlock::KRDataBlock(void* data, size_t size)
{
m_data = NULL; m_data = NULL;
m_data_size = 0; m_data_size = 0;
m_data_offset = 0; m_data_offset = 0;
@@ -84,7 +86,8 @@ KRDataBlock::KRDataBlock(void *data, size_t size) {
load(data, size); load(data, size);
} }
KRDataBlock::~KRDataBlock() { KRDataBlock::~KRDataBlock()
{
unload(); unload();
} }
@@ -203,19 +206,22 @@ KRDataBlock *KRDataBlock::getSubBlock(int start, int length)
} }
// Return a pointer to the start of the data block // Return a pointer to the start of the data block
void *KRDataBlock::getStart() { void* KRDataBlock::getStart()
{
assertLocked(); assertLocked();
return m_data; return m_data;
} }
// Return a pointer to the byte after the end of the data block // Return a pointer to the byte after the end of the data block
void *KRDataBlock::getEnd() { void* KRDataBlock::getEnd()
{
assertLocked(); assertLocked();
return (unsigned char*)m_data + m_data_size; return (unsigned char*)m_data + m_data_size;
} }
// Return the size of the data block. Use append() or expand() to make the data block larger // Return the size of the data block. Use append() or expand() to make the data block larger
size_t KRDataBlock::getSize() const { size_t KRDataBlock::getSize() const
{
return m_data_size; return m_data_size;
} }
@@ -259,7 +265,8 @@ void KRDataBlock::expand(size_t size)
} }
// Append data to the end of the block, increasing the size of the block and making it read-write. // Append data to the end of the block, increasing the size of the block and making it read-write.
void KRDataBlock::append(void *data, size_t size) { void KRDataBlock::append(void* data, size_t size)
{
// Expand the data block // Expand the data block
expand(size); expand(size);
@@ -271,12 +278,14 @@ void KRDataBlock::append(void *data, size_t size) {
// Copy the entire data block to the destination pointer // Copy the entire data block to the destination pointer
void KRDataBlock::copy(void *dest) { void KRDataBlock::copy(void* dest)
{
copy(dest, 0, (int)m_data_size); copy(dest, 0, (int)m_data_size);
} }
// Copy a range of data to the destination pointer // Copy a range of data to the destination pointer
void KRDataBlock::copy(void *dest, int start, int count) { void KRDataBlock::copy(void* dest, int start, int count)
{
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
if (m_lockCount == 0 && m_hPackFile != INVALID_HANDLE_VALUE) { if (m_lockCount == 0 && m_hPackFile != INVALID_HANDLE_VALUE) {
// Optimization: If we haven't mmap'ed or malloced the data already, ReadFile() it directly from the file into the buffer // Optimization: If we haven't mmap'ed or malloced the data already, ReadFile() it directly from the file into the buffer
@@ -312,7 +321,8 @@ void KRDataBlock::copy(void *dest, int start, int count) {
} }
// Append data to the end of the block, increasing the size of the block and making it read-write. // Append data to the end of the block, increasing the size of the block and making it read-write.
void KRDataBlock::append(KRDataBlock &data) { void KRDataBlock::append(KRDataBlock & data)
{
data.lock(); data.lock();
append(data.getStart(), data.getSize()); append(data.getStart(), data.getSize());
data.unlock(); data.unlock();
@@ -339,7 +349,8 @@ void KRDataBlock::append(const std::string &s)
} }
// Save the data to a file. // Save the data to a file.
bool KRDataBlock::save(const std::string& path) { bool KRDataBlock::save(const std::string & path)
{
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
bool success = true; bool success = true;
HANDLE hNewFile = INVALID_HANDLE_VALUE; HANDLE hNewFile = INVALID_HANDLE_VALUE;

View File

@@ -39,7 +39,8 @@
#define KRENGINE_MIN_MMAP 32768 #define KRENGINE_MIN_MMAP 32768
class KRDataBlock { class KRDataBlock
{
public: public:
KRDataBlock(); KRDataBlock();
KRDataBlock(void* data, size_t size); KRDataBlock(void* data, size_t size);

View File

@@ -101,7 +101,8 @@ public:
std::vector<VkCommandBuffer> m_transferCommandBuffers; std::vector<VkCommandBuffer> m_transferCommandBuffers;
VmaAllocator m_allocator; VmaAllocator m_allocator;
struct StagingBufferInfo { struct StagingBufferInfo
{
VkBuffer buffer; VkBuffer buffer;
VmaAllocation allocation; VmaAllocation allocation;
size_t size; size_t size;

View File

@@ -162,23 +162,19 @@ void KRDeviceManager::createDevices()
bool addDevice = false; bool addDevice = false;
if (candidateDevices.empty()) { if (candidateDevices.empty()) {
addDevice = true; addDevice = true;
} } else {
else {
VkPhysicalDeviceType collectedType = candidateDevices[0]->m_deviceProperties.deviceType; VkPhysicalDeviceType collectedType = candidateDevices[0]->m_deviceProperties.deviceType;
if (collectedType == device->m_deviceProperties.deviceType) { if (collectedType == device->m_deviceProperties.deviceType) {
addDevice = true; addDevice = true;
} } else if (device->m_deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
else if (device->m_deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
// Discrete GPU's are always the best choice // Discrete GPU's are always the best choice
candidateDevices.clear(); candidateDevices.clear();
addDevice = true; addDevice = true;
} } else if (collectedType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && device->m_deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) {
else if (collectedType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && device->m_deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) {
// Integrated GPU's are the second best choice // Integrated GPU's are the second best choice
candidateDevices.clear(); candidateDevices.clear();
addDevice = true; addDevice = true;
} } else if (collectedType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && collectedType != VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU && device->m_deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU) {
else if (collectedType != VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU && collectedType != VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU && device->m_deviceProperties.deviceType == VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU) {
// Virtual GPU's are the 3rd best choice // Virtual GPU's are the 3rd best choice
candidateDevices.clear(); candidateDevices.clear();
addDevice = true; addDevice = true;

View File

@@ -53,20 +53,24 @@ KRDirectionalLight::~KRDirectionalLight()
} }
std::string KRDirectionalLight::getElementName() { std::string KRDirectionalLight::getElementName()
{
return "directional_light"; return "directional_light";
} }
Vector3 KRDirectionalLight::getWorldLightDirection() { Vector3 KRDirectionalLight::getWorldLightDirection()
{
return Matrix4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection()); return Matrix4::Dot(getWorldRotation().rotationMatrix(), getLocalLightDirection());
} }
Vector3 KRDirectionalLight::getLocalLightDirection() { Vector3 KRDirectionalLight::getLocalLightDirection()
{
return Vector3::Up(); //&KRF HACK changed from Vector3::Forward(); - to compensate for the way Maya handles post rotation. return Vector3::Up(); //&KRF HACK changed from Vector3::Forward(); - to compensate for the way Maya handles post rotation.
} }
int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewport) { int KRDirectionalLight::configureShadowBufferViewports(const KRViewport& viewport)
{
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 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; int cShadows = 1;
@@ -118,7 +122,8 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
return 1; return 1;
} }
void KRDirectionalLight::render(RenderInfo& ri) { void KRDirectionalLight::render(RenderInfo& ri)
{
if (m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return; if (m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;

View File

@@ -33,7 +33,8 @@
#include "KRLight.h" #include "KRLight.h"
class KRDirectionalLight : public KRLight { class KRDirectionalLight : public KRLight
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -253,7 +253,8 @@ fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n"
#endif #endif
typedef enum { typedef enum
{
STREAM_LEVEL_OUT, STREAM_LEVEL_OUT,
STREAM_LEVEL_IN_LQ, STREAM_LEVEL_IN_LQ,
STREAM_LEVEL_IN_HQ STREAM_LEVEL_IN_HQ

View File

@@ -37,7 +37,10 @@
#include "KREngine-common.h" #include "KREngine-common.h"
typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_FLOAT, KRENGINE_PARAMETER_BOOL} KREngineParameterType; typedef enum KREngineParameterType
{
KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_FLOAT, KRENGINE_PARAMETER_BOOL
} KREngineParameterType;
namespace kraken { namespace kraken {
void set_parameter(const std::string& parameter_name, float parameter_value); void set_parameter(const std::string& parameter_name, float parameter_value);

View File

@@ -53,10 +53,10 @@ KRLODGroup::KRLODGroup(KRScene &scene, std::string name) : KRNode(scene, name)
} }
KRLODGroup::~KRLODGroup() KRLODGroup::~KRLODGroup()
{ {}
}
std::string KRLODGroup::getElementName() { std::string KRLODGroup::getElementName()
{
return "lod_group"; return "lod_group";
} }

View File

@@ -34,7 +34,8 @@
#include "KRResource.h" #include "KRResource.h"
#include "KRNode.h" #include "KRNode.h"
class KRLODGroup : public KRNode { class KRLODGroup : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);
KRLODGroup(KRScene& scene, std::string name); KRLODGroup(KRScene& scene, std::string name);

View File

@@ -46,10 +46,10 @@ KRLODSet::KRLODSet(KRScene &scene, std::string name) : KRNode(scene, name)
} }
KRLODSet::~KRLODSet() KRLODSet::~KRLODSet()
{ {}
}
std::string KRLODSet::getElementName() { std::string KRLODSet::getElementName()
{
return "lod_set"; return "lod_set";
} }

View File

@@ -36,7 +36,8 @@
class KRLODGroup; class KRLODGroup;
class KRLODSet : public KRNode { class KRLODSet : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);
KRLODSet(KRScene& scene, std::string name); KRLODSet(KRScene& scene, std::string name);

View File

@@ -114,7 +114,8 @@ tinyxml2::XMLElement *KRLight::saveXML( tinyxml2::XMLNode *parent)
return e; return e;
} }
void KRLight::loadXML(tinyxml2::XMLElement *e) { void KRLight::loadXML(tinyxml2::XMLElement* e)
{
KRNode::loadXML(e); KRNode::loadXML(e);
float x = 1.0f, y = 1.0f, z = 1.0f; float x = 1.0f, y = 1.0f, z = 1.0f;
if (e->QueryFloatAttribute("color_r", &x) != tinyxml2::XML_SUCCESS) { if (e->QueryFloatAttribute("color_r", &x) != tinyxml2::XML_SUCCESS) {
@@ -176,43 +177,53 @@ void KRLight::loadXML(tinyxml2::XMLElement *e) {
m_pFlareTexture = NULL; m_pFlareTexture = NULL;
} }
void KRLight::setFlareTexture(std::string flare_texture) { void KRLight::setFlareTexture(std::string flare_texture)
{
m_flareTexture = flare_texture; m_flareTexture = flare_texture;
m_pFlareTexture = NULL; m_pFlareTexture = NULL;
} }
void KRLight::setFlareSize(float flare_size) { void KRLight::setFlareSize(float flare_size)
{
m_flareSize = flare_size; m_flareSize = flare_size;
} }
void KRLight::setFlareOcclusionSize(float occlusion_size) { void KRLight::setFlareOcclusionSize(float occlusion_size)
{
m_flareOcclusionSize = occlusion_size; m_flareOcclusionSize = occlusion_size;
} }
void KRLight::setIntensity(float intensity) { void KRLight::setIntensity(float intensity)
{
m_intensity = intensity; m_intensity = intensity;
} }
float KRLight::getIntensity() { float KRLight::getIntensity()
{
return m_intensity; return m_intensity;
} }
const Vector3 &KRLight::getColor() { const Vector3& KRLight::getColor()
{
return m_color; return m_color;
} }
void KRLight::setColor(const Vector3 &color) { void KRLight::setColor(const Vector3& color)
{
m_color = color; m_color = color;
} }
void KRLight::setDecayStart(float decayStart) { void KRLight::setDecayStart(float decayStart)
{
m_decayStart = decayStart; m_decayStart = decayStart;
} }
float KRLight::getDecayStart() { float KRLight::getDecayStart()
{
return m_decayStart; return m_decayStart;
} }
void KRLight::render(RenderInfo& ri) { void KRLight::render(RenderInfo& ri)
{
if (m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return; if (m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
@@ -426,7 +437,8 @@ void KRLight::render(RenderInfo& ri) {
} }
} }
void KRLight::allocateShadowBuffers(int cBuffers) { void KRLight::allocateShadowBuffers(int cBuffers)
{
// First deallocate buffers no longer needed // First deallocate buffers no longer needed
for (int iShadow = cBuffers; iShadow < KRENGINE_MAX_SHADOW_BUFFERS; iShadow++) { for (int iShadow = cBuffers; iShadow < KRENGINE_MAX_SHADOW_BUFFERS; iShadow++) {
if (shadowDepthTexture[iShadow]) { if (shadowDepthTexture[iShadow]) {

View File

@@ -42,7 +42,8 @@ static const float KRLIGHT_MIN_INFLUENCE = 0.15f; // 0.05f
#define KRENGINE_SHADOW_MAP_WIDTH 1024 #define KRENGINE_SHADOW_MAP_WIDTH 1024
#define KRENGINE_SHADOW_MAP_HEIGHT 1024 #define KRENGINE_SHADOW_MAP_HEIGHT 1024
class KRLight : public KRNode { class KRLight : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -45,10 +45,10 @@ KRLocator::KRLocator(KRScene &scene, std::string name) : KRNode(scene, name)
} }
KRLocator::~KRLocator() KRLocator::~KRLocator()
{ {}
}
std::string KRLocator::getElementName() { std::string KRLocator::getElementName()
{
return "locator"; return "locator";
} }

View File

@@ -35,7 +35,8 @@
#include "KRNode.h" #include "KRNode.h"
#include "KRTexture.h" #include "KRTexture.h"
class KRLocator : public KRNode { class KRLocator : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -36,7 +36,8 @@
#include "KRContext.h" #include "KRContext.h"
KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(context, szName) { KRMaterial::KRMaterial(KRContext& context, const char* szName) : KRResource(context, szName)
{
m_name = szName; m_name = szName;
m_pAmbientMap = NULL; m_pAmbientMap = NULL;
m_pDiffuseMap = NULL; m_pDiffuseMap = NULL;
@@ -67,11 +68,13 @@ KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(cont
m_alpha_mode = KRMATERIAL_ALPHA_MODE_OPAQUE; m_alpha_mode = KRMATERIAL_ALPHA_MODE_OPAQUE;
} }
KRMaterial::~KRMaterial() { KRMaterial::~KRMaterial()
{
} }
std::string KRMaterial::getExtension() { std::string KRMaterial::getExtension()
{
return "mtl"; return "mtl";
} }
@@ -80,7 +83,8 @@ bool KRMaterial::needsVertexTangents()
return m_normalMap.size() > 0; return m_normalMap.size() > 0;
} }
bool KRMaterial::save(KRDataBlock &data) { bool KRMaterial::save(KRDataBlock& data)
{
std::stringstream stream; std::stringstream stream;
stream.precision(std::numeric_limits<long double>::digits10); stream.precision(std::numeric_limits<long double>::digits10);
stream.setf(std::ios::fixed, std::ios::floatfield); stream.setf(std::ios::fixed, std::ios::floatfield);
@@ -144,76 +148,91 @@ bool KRMaterial::save(KRDataBlock &data) {
return true; return true;
} }
void KRMaterial::setAmbientMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset) { void KRMaterial::setAmbientMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset)
{
m_ambientMap = texture_name; m_ambientMap = texture_name;
m_ambientMapScale = texture_scale; m_ambientMapScale = texture_scale;
m_ambientMapOffset = texture_offset; m_ambientMapOffset = texture_offset;
} }
void KRMaterial::setDiffuseMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset) { void KRMaterial::setDiffuseMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset)
{
m_diffuseMap = texture_name; m_diffuseMap = texture_name;
m_diffuseMapScale = texture_scale; m_diffuseMapScale = texture_scale;
m_diffuseMapOffset = texture_offset; m_diffuseMapOffset = texture_offset;
} }
void KRMaterial::setSpecularMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset) { void KRMaterial::setSpecularMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset)
{
m_specularMap = texture_name; m_specularMap = texture_name;
m_specularMapScale = texture_scale; m_specularMapScale = texture_scale;
m_specularMapOffset = texture_offset; m_specularMapOffset = texture_offset;
} }
void KRMaterial::setNormalMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset) { void KRMaterial::setNormalMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset)
{
m_normalMap = texture_name; m_normalMap = texture_name;
m_normalMapScale = texture_scale; m_normalMapScale = texture_scale;
m_normalMapOffset = texture_offset; m_normalMapOffset = texture_offset;
} }
void KRMaterial::setReflectionMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset) { void KRMaterial::setReflectionMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset)
{
m_reflectionMap = texture_name; m_reflectionMap = texture_name;
m_reflectionMapScale = texture_scale; m_reflectionMapScale = texture_scale;
m_reflectionMapOffset = texture_offset; m_reflectionMapOffset = texture_offset;
} }
void KRMaterial::setReflectionCube(std::string texture_name) { void KRMaterial::setReflectionCube(std::string texture_name)
{
m_reflectionCube = texture_name; m_reflectionCube = texture_name;
} }
void KRMaterial::setAlphaMode(KRMaterial::alpha_mode_type alpha_mode) { void KRMaterial::setAlphaMode(KRMaterial::alpha_mode_type alpha_mode)
{
m_alpha_mode = alpha_mode; m_alpha_mode = alpha_mode;
} }
KRMaterial::alpha_mode_type KRMaterial::getAlphaMode() { KRMaterial::alpha_mode_type KRMaterial::getAlphaMode()
{
return m_alpha_mode; return m_alpha_mode;
} }
void KRMaterial::setAmbient(const Vector3 &c) { void KRMaterial::setAmbient(const Vector3& c)
{
m_ambientColor = c; m_ambientColor = c;
} }
void KRMaterial::setDiffuse(const Vector3 &c) { void KRMaterial::setDiffuse(const Vector3& c)
{
m_diffuseColor = c; m_diffuseColor = c;
} }
void KRMaterial::setSpecular(const Vector3 &c) { void KRMaterial::setSpecular(const Vector3& c)
{
m_specularColor = c; m_specularColor = c;
} }
void KRMaterial::setReflection(const Vector3 &c) { void KRMaterial::setReflection(const Vector3& c)
{
m_reflectionColor = c; m_reflectionColor = c;
} }
void KRMaterial::setTransparency(float a) { void KRMaterial::setTransparency(float a)
{
if (a < 1.0f && m_alpha_mode == KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE) { if (a < 1.0f && m_alpha_mode == KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE) {
setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE); setAlphaMode(KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE);
} }
m_tr = a; m_tr = a;
} }
void KRMaterial::setShininess(float s) { void KRMaterial::setShininess(float s)
{
m_ns = s; m_ns = s;
} }
bool KRMaterial::isTransparent() { bool KRMaterial::isTransparent()
{
return m_tr < 1.0 || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE; return m_tr < 1.0 || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE;
} }

View File

@@ -50,9 +50,11 @@ class KRTextureManager;
class KRContext; class KRContext;
class KRSurface; class KRSurface;
class KRMaterial : public KRResource { class KRMaterial : public KRResource
{
public: public:
typedef enum { typedef enum
{
KRMATERIAL_ALPHA_MODE_OPAQUE, // Non-transparent materials KRMATERIAL_ALPHA_MODE_OPAQUE, // Non-transparent materials
KRMATERIAL_ALPHA_MODE_TEST, // Alpha in diffuse texture is interpreted as punch-through when < 0.5 KRMATERIAL_ALPHA_MODE_TEST, // Alpha in diffuse texture is interpreted as punch-through when < 0.5
KRMATERIAL_ALPHA_MODE_BLENDONESIDE, // Blended alpha with backface culling KRMATERIAL_ALPHA_MODE_BLENDONESIDE, // Blended alpha with backface culling

View File

@@ -39,7 +39,8 @@ KRMaterialManager::KRMaterialManager(KRContext &context, KRTextureManager *pText
m_pPipelineManager = pPipelineManager; m_pPipelineManager = pPipelineManager;
} }
KRMaterialManager::~KRMaterialManager() { KRMaterialManager::~KRMaterialManager()
{
} }
@@ -67,7 +68,8 @@ unordered_map<std::string, KRMaterial *> &KRMaterialManager::getMaterials()
return m_materials; return m_materials;
} }
KRMaterial *KRMaterialManager::getMaterial(const std::string &name) { KRMaterial* KRMaterialManager::getMaterial(const std::string& name)
{
std::string lowerName = name; std::string lowerName = name;
std::transform(lowerName.begin(), lowerName.end(), std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower); lowerName.begin(), ::tolower);
@@ -83,7 +85,8 @@ KRMaterial *KRMaterialManager::getMaterial(const std::string &name) {
} }
} }
void KRMaterialManager::add(KRMaterial *new_material) { void KRMaterialManager::add(KRMaterial* new_material)
{
// FINDME, TODO - Potential memory leak if multiple materials with the same name are added // FINDME, TODO - Potential memory leak if multiple materials with the same name are added
std::string lowerName = new_material->getName(); std::string lowerName = new_material->getName();
std::transform(lowerName.begin(), lowerName.end(), std::transform(lowerName.begin(), lowerName.end(),
@@ -92,7 +95,8 @@ void KRMaterialManager::add(KRMaterial *new_material) {
m_materials[lowerName] = new_material; m_materials[lowerName] = new_material;
} }
KRMaterial* KRMaterialManager::load(const char *szName, KRDataBlock *data) { KRMaterial* KRMaterialManager::load(const char* szName, KRDataBlock* data)
{
KRMaterial* pMaterial = NULL; KRMaterial* pMaterial = NULL;
char szSymbol[16][256]; char szSymbol[16][256];
data->lock(); data->lock();

View File

@@ -43,7 +43,8 @@ class KRMaterial;
using std::map; using std::map;
class KRMaterialManager : public KRResourceManager { class KRMaterialManager : public KRResourceManager
{
public: public:
KRMaterialManager(KRContext& context, KRTextureManager* pTextureManager, KRPipelineManager* pPipelineManager); KRMaterialManager(KRContext& context, KRTextureManager* pTextureManager, KRPipelineManager* pPipelineManager);
virtual ~KRMaterialManager(); virtual ~KRMaterialManager();

View File

@@ -39,7 +39,8 @@
#include "KRContext.h" #include "KRContext.h"
#include "../3rdparty/forsyth/forsyth.h" #include "../3rdparty/forsyth/forsyth.h"
KRMesh::KRMesh(KRContext &context, std::string name) : KRResource(context, name) { KRMesh::KRMesh(KRContext& context, std::string name) : KRResource(context, name)
{
setName(name); setName(name);
m_hasTransparency = false; m_hasTransparency = false;
@@ -49,7 +50,8 @@ KRMesh::KRMesh(KRContext &context, std::string name) : KRResource(context, name)
m_constant = false; m_constant = false;
} }
KRMesh::KRMesh(KRContext &context, std::string name, KRDataBlock *data) : KRResource(context, name) { KRMesh::KRMesh(KRContext& context, std::string name, KRDataBlock* data) : KRResource(context, name)
{
setName(name); setName(name);
m_hasTransparency = false; m_hasTransparency = false;
@@ -83,7 +85,8 @@ void KRMesh::parseName(const std::string& name, std::string& lodBaseName, int& l
} }
} }
void KRMesh::setName(const std::string name) { void KRMesh::setName(const std::string name)
{
parseName(name, m_lodBaseName, m_lodCoverage); parseName(name, m_lodBaseName, m_lodCoverage);
m_lodCoverage = 100; m_lodCoverage = 100;
m_lodBaseName = name; m_lodBaseName = name;
@@ -111,11 +114,13 @@ int KRMesh::GetLODCoverage(const std::string &name)
KRMesh::~KRMesh() { KRMesh::~KRMesh()
{
releaseData(); releaseData();
} }
void KRMesh::releaseData() { void KRMesh::releaseData()
{
m_hasTransparency = false; m_hasTransparency = false;
m_submeshes.clear(); m_submeshes.clear();
if (m_pIndexBaseData) { if (m_pIndexBaseData) {
@@ -134,20 +139,24 @@ void KRMesh::releaseData() {
} }
} }
std::string KRMesh::getExtension() { std::string KRMesh::getExtension()
{
return "krmesh"; return "krmesh";
} }
bool KRMesh::save(const std::string& path) { bool KRMesh::save(const std::string& path)
{
return m_pData->save(path); return m_pData->save(path);
} }
bool KRMesh::save(KRDataBlock &data) { bool KRMesh::save(KRDataBlock& data)
{
data.append(*m_pData); data.append(*m_pData);
return true; return true;
} }
void KRMesh::loadPack(KRDataBlock *data) { void KRMesh::loadPack(KRDataBlock* data)
{
releaseData(); releaseData();
m_pData = data; m_pData = data;
@@ -310,7 +319,8 @@ void KRMesh::render(const KRNode::RenderInfo& ri, const std::string& object_name
} }
} }
float KRMesh::getMaxDimension() { float KRMesh::getMaxDimension()
{
float m = 0.0; float m = 0.0;
if (m_maxPoint.x - m_minPoint.x > m) m = m_maxPoint.x - m_minPoint.x; if (m_maxPoint.x - m_minPoint.x > m) m = m_maxPoint.x - m_minPoint.x;
if (m_maxPoint.y - m_minPoint.y > m) m = m_maxPoint.y - m_minPoint.y; if (m_maxPoint.y - m_minPoint.y > m) m = m_maxPoint.y - m_minPoint.y;
@@ -318,12 +328,14 @@ float KRMesh::getMaxDimension() {
return m; return m;
} }
bool KRMesh::hasTransparency() { bool KRMesh::hasTransparency()
{
return m_hasTransparency; return m_hasTransparency;
} }
void KRMesh::getSubmeshes() { void KRMesh::getSubmeshes()
{
if (m_submeshes.size() == 0) { if (m_submeshes.size() == 0) {
pack_header* pHeader = getHeader(); pack_header* pHeader = getHeader();
pack_material* pPackMaterials = (pack_material*)(pHeader + 1); pack_material* pPackMaterials = (pack_material*)(pHeader + 1);
@@ -452,7 +464,8 @@ bool KRMesh::isReady() const
return true; return true;
} }
void KRMesh::renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, KRNode::RenderPass renderPass, const std::string &object_name, const std::string &material_name, float lodCoverage) { void KRMesh::renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, KRNode::RenderPass renderPass, const std::string& object_name, const std::string& material_name, float lodCoverage)
{
getSubmeshes(); getSubmeshes();
Submesh* pSubmesh = m_submeshes[iSubmesh]; Submesh* pSubmesh = m_submeshes[iSubmesh];
@@ -533,7 +546,8 @@ void KRMesh::renderSubmesh(VkCommandBuffer& commandBuffer, int iSubmesh, KRNode:
} }
} }
void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool calculate_tangents) { void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool calculate_tangents)
{
releaseData(); releaseData();
@@ -781,19 +795,23 @@ void KRMesh::LoadData(const KRMesh::mesh_info &mi, bool calculate_normals, bool
} }
} }
Vector3 KRMesh::getMinPoint() const { Vector3 KRMesh::getMinPoint() const
{
return m_minPoint; return m_minPoint;
} }
Vector3 KRMesh::getMaxPoint() const { Vector3 KRMesh::getMaxPoint() const
{
return m_maxPoint; return m_maxPoint;
} }
int KRMesh::getLODCoverage() const { int KRMesh::getLODCoverage() const
{
return m_lodCoverage; return m_lodCoverage;
} }
std::string KRMesh::getLODBaseName() const { std::string KRMesh::getLODBaseName() const
{
return m_lodBaseName; return m_lodBaseName;
} }
@@ -825,26 +843,31 @@ KRMesh::pack_bone *KRMesh::getBone(int index)
return (pack_bone*)((unsigned char*)m_pMetaData->getStart() + sizeof(pack_header) + sizeof(pack_material) * header->submesh_count + sizeof(pack_bone) * index); return (pack_bone*)((unsigned char*)m_pMetaData->getStart() + sizeof(pack_header) + sizeof(pack_material) * header->submesh_count + sizeof(pack_bone) * index);
} }
unsigned char *KRMesh::getVertexData() const { unsigned char* KRMesh::getVertexData() const
{
return ((unsigned char*)m_pData->getStart()) + getVertexDataOffset(); return ((unsigned char*)m_pData->getStart()) + getVertexDataOffset();
} }
size_t KRMesh::getVertexDataOffset() const { size_t KRMesh::getVertexDataOffset() const
{
pack_header* pHeader = getHeader(); pack_header* pHeader = getHeader();
return sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count) + KRALIGN(8 * pHeader->index_base_count); return sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count) + KRALIGN(8 * pHeader->index_base_count);
} }
__uint16_t *KRMesh::getIndexData() const { __uint16_t* KRMesh::getIndexData() const
{
return (__uint16_t*)((unsigned char*)m_pData->getStart() + getIndexDataOffset()); return (__uint16_t*)((unsigned char*)m_pData->getStart() + getIndexDataOffset());
} }
size_t KRMesh::getIndexDataOffset() const { size_t KRMesh::getIndexDataOffset() const
{
pack_header* pHeader = getHeader(); pack_header* pHeader = getHeader();
return sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count; return sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count;
} }
__uint32_t *KRMesh::getIndexBaseData() const { __uint32_t* KRMesh::getIndexBaseData() const
{
if (m_pIndexBaseData == NULL) { if (m_pIndexBaseData == NULL) {
pack_header* pHeader = getHeader(); pack_header* pHeader = getHeader();
return (__uint32_t*)((unsigned char*)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count)); return (__uint32_t*)((unsigned char*)m_pData->getStart() + sizeof(pack_header) + sizeof(pack_material) * pHeader->submesh_count + sizeof(pack_bone) * pHeader->bone_count + KRALIGN(2 * pHeader->index_count));
@@ -1539,7 +1562,8 @@ void KRMesh::optimize()
} }
} }
void KRMesh::getIndexedRange(int index_group, int &start_index_offset, int &start_vertex_offset, int &index_count, int &vertex_count) const { void KRMesh::getIndexedRange(int index_group, int& start_index_offset, int& start_vertex_offset, int& index_count, int& vertex_count) const
{
pack_header* h = getHeader(); pack_header* h = getHeader();
__uint32_t* index_base_data = getIndexBaseData(); __uint32_t* index_base_data = getIndexBaseData();
start_index_offset = index_base_data[index_group * 2]; start_index_offset = index_base_data[index_group * 2];

View File

@@ -65,7 +65,8 @@ enum class ModelFormat : __uint8_t
KRENGINE_MODEL_FORMAT_INDEXED_STRIP KRENGINE_MODEL_FORMAT_INDEXED_STRIP
}; };
class KRMesh : public KRResource { class KRMesh : public KRResource
{
public: public:
static void parseName(const std::string& name, std::string& lodBaseName, int& lodCoverage); static void parseName(const std::string& name, std::string& lodBaseName, int& lodCoverage);
@@ -79,7 +80,8 @@ public:
bool hasTransparency(); bool hasTransparency();
typedef enum { typedef enum
{
KRENGINE_ATTRIB_VERTEX = 0, KRENGINE_ATTRIB_VERTEX = 0,
KRENGINE_ATTRIB_NORMAL, KRENGINE_ATTRIB_NORMAL,
KRENGINE_ATTRIB_TANGENT, KRENGINE_ATTRIB_TANGENT,
@@ -97,7 +99,8 @@ public:
typedef struct { typedef struct
{
ModelFormat format; ModelFormat format;
std::vector<Vector3> vertices; std::vector<Vector3> vertices;
std::vector<__uint16_t> vertex_indexes; std::vector<__uint16_t> vertex_indexes;
@@ -138,10 +141,13 @@ public:
Vector3 getMinPoint() const; Vector3 getMinPoint() const;
Vector3 getMaxPoint() const; Vector3 getMaxPoint() const;
class Submesh { class Submesh
{
public: public:
Submesh() {}; Submesh()
~Submesh() { {};
~Submesh()
{
for (auto itr = vbo_data_blocks.begin(); itr != vbo_data_blocks.end(); itr++) { for (auto itr = vbo_data_blocks.begin(); itr != vbo_data_blocks.end(); itr++) {
delete (*itr); delete (*itr);
} }
@@ -161,9 +167,12 @@ public:
vector<KRMeshManager::KRVBOData*> vbo_data_blocks; vector<KRMeshManager::KRVBOData*> vbo_data_blocks;
}; };
typedef struct { typedef struct
union { {
struct { // For Indexed triangles / strips union
{
struct
{ // For Indexed triangles / strips
uint16_t index_group; uint16_t index_group;
uint16_t index_group_offset; uint16_t index_group_offset;
}; };
@@ -173,7 +182,8 @@ public:
char szName[KRENGINE_MAX_NAME_LENGTH]; char szName[KRENGINE_MAX_NAME_LENGTH];
} pack_material; } pack_material;
typedef struct { typedef struct
{
char szName[KRENGINE_MAX_NAME_LENGTH]; char szName[KRENGINE_MAX_NAME_LENGTH];
float bind_pose[16]; float bind_pose[16];
} pack_bone; } pack_bone;
@@ -251,7 +261,8 @@ private:
typedef struct { typedef struct
{
char szTag[16]; char szTag[16];
int32_t model_format; // 0 == Triangle list, 1 == Triangle strips, 2 == Indexed triangle list, 3 == Indexed triangle strips, rest are reserved (model_format_t enum) int32_t model_format; // 0 == Triangle list, 1 == Triangle strips, 2 == Indexed triangle list, 3 == Indexed triangle strips, rest are reserved (model_format_t enum)
int32_t vertex_attrib_flags; int32_t vertex_attrib_flags;

View File

@@ -33,7 +33,8 @@
#include "KRMesh.h" #include "KRMesh.h"
class KRMeshCube : public KRMesh { class KRMeshCube : public KRMesh
{
public: public:
KRMeshCube(KRContext& context); KRMeshCube(KRContext& context);
virtual ~KRMeshCube(); virtual ~KRMeshCube();

View File

@@ -50,7 +50,8 @@ KRMeshManager::KRMeshManager(KRContext& context)
} }
void KRMeshManager::init() { void KRMeshManager::init()
{
addModel(new KRMeshCube(*m_pContext)); addModel(new KRMeshCube(*m_pContext));
addModel(new KRMeshQuad(*m_pContext)); addModel(new KRMeshQuad(*m_pContext));
addModel(new KRMeshSphere(*m_pContext)); addModel(new KRMeshSphere(*m_pContext));
@@ -108,7 +109,8 @@ void KRMeshManager::init() {
} }
KRMeshManager::~KRMeshManager() { KRMeshManager::~KRMeshManager()
{
for (unordered_multimap<std::string, KRMesh*>::iterator itr = m_models.begin(); itr != m_models.end(); ++itr) { for (unordered_multimap<std::string, KRMesh*>::iterator itr = m_models.begin(); itr != m_models.end(); ++itr) {
delete (*itr).second; delete (*itr).second;
} }
@@ -138,13 +140,15 @@ KRResource* KRMeshManager::getResource(const std::string& name, const std::strin
return nullptr; return nullptr;
} }
KRMesh *KRMeshManager::loadModel(const char *szName, KRDataBlock *pData) { KRMesh* KRMeshManager::loadModel(const char* szName, KRDataBlock* pData)
{
KRMesh* pModel = new KRMesh(*m_pContext, szName, pData); KRMesh* pModel = new KRMesh(*m_pContext, szName, pData);
addModel(pModel); addModel(pModel);
return pModel; return pModel;
} }
void KRMeshManager::addModel(KRMesh *model) { void KRMeshManager::addModel(KRMesh* model)
{
std::string lowerName = model->getLODBaseName(); std::string lowerName = model->getLODBaseName();
std::transform(lowerName.begin(), lowerName.end(), std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower); lowerName.begin(), ::tolower);
@@ -152,7 +156,8 @@ void KRMeshManager::addModel(KRMesh *model) {
m_models.insert(std::pair<std::string, KRMesh*>(lowerName, model)); m_models.insert(std::pair<std::string, KRMesh*>(lowerName, model));
} }
KRMesh* KRMeshManager::getMaxLODModel(const char* szName) { KRMesh* KRMeshManager::getMaxLODModel(const char* szName)
{
std::vector<KRMesh*> models = getModel(szName); std::vector<KRMesh*> models = getModel(szName);
// models are always in order of highest LOD first // models are always in order of highest LOD first
if (models.size()) { if (models.size()) {
@@ -161,7 +166,8 @@ KRMesh* KRMeshManager::getMaxLODModel(const char* szName) {
return nullptr; return nullptr;
} }
std::vector<KRMesh *> KRMeshManager::getModel(const char *szName) { std::vector<KRMesh*> KRMeshManager::getModel(const char* szName)
{
std::string lowerName = szName; std::string lowerName = szName;
std::transform(lowerName.begin(), lowerName.end(), std::transform(lowerName.begin(), lowerName.end(),
lowerName.begin(), ::tolower); lowerName.begin(), ::tolower);
@@ -183,7 +189,8 @@ std::vector<KRMesh *> KRMeshManager::getModel(const char *szName) {
return matching_models; return matching_models;
} }
unordered_multimap<std::string, KRMesh *> &KRMeshManager::getModels() { unordered_multimap<std::string, KRMesh*>& KRMeshManager::getModels()
{
return m_models; return m_models;
} }

View File

@@ -41,7 +41,8 @@
class KRContext; class KRContext;
class KRMesh; class KRMesh;
class KRMeshManager : public KRResourceManager { class KRMeshManager : public KRResourceManager
{
public: public:
static const int KRENGINE_MAX_VOLUMETRIC_PLANES = 500; static const int KRENGINE_MAX_VOLUMETRIC_PLANES = 500;
static const int KRENGINE_MAX_RANDOM_PARTICLES = 150000; static const int KRENGINE_MAX_RANDOM_PARTICLES = 150000;
@@ -64,11 +65,13 @@ public:
std::vector<std::string> getModelNames(); std::vector<std::string> getModelNames();
unordered_multimap<std::string, KRMesh*>& getModels(); unordered_multimap<std::string, KRMesh*>& getModels();
class KRVBOData { class KRVBOData
{
public: public:
typedef enum { typedef enum
{
STREAMING, STREAMING,
// STREAMING data is loaded asynchronously, with transfer queues in the streamer thread. // STREAMING data is loaded asynchronously, with transfer queues in the streamer thread.
@@ -97,8 +100,14 @@ public:
KRDataBlock* m_data; KRDataBlock* m_data;
KRDataBlock* m_index_data; KRDataBlock* m_index_data;
bool isVBOLoaded() { return m_is_vbo_loaded; } bool isVBOLoaded()
bool isVBOReady() { return m_is_vbo_ready; } {
return m_is_vbo_loaded;
}
bool isVBOReady()
{
return m_is_vbo_ready;
}
void load(); void load();
void load(VkCommandBuffer& commandBuffer); void load(VkCommandBuffer& commandBuffer);
void unload(); void unload();
@@ -108,12 +117,21 @@ public:
KRVBOData(const KRVBOData& o) = delete; KRVBOData(const KRVBOData& o) = delete;
KRVBOData& operator=(const KRVBOData& o) = delete; KRVBOData& operator=(const KRVBOData& o) = delete;
long getSize() { return (long)m_size; } long getSize()
{
return (long)m_size;
}
void resetPoolExpiry(float lodCoverage); void resetPoolExpiry(float lodCoverage);
long getLastFrameUsed() { return m_last_frame_used; } long getLastFrameUsed()
{
return m_last_frame_used;
}
vbo_type getType() { return m_type; } vbo_type getType()
{
return m_type;
}
float getStreamPriority(); float getStreamPriority();
@@ -135,7 +153,8 @@ public:
bool m_is_vbo_loaded; bool m_is_vbo_loaded;
bool m_is_vbo_ready; bool m_is_vbo_ready;
typedef struct { typedef struct
{
KrDeviceHandle device; KrDeviceHandle device;
VkBuffer vertex_buffer; VkBuffer vertex_buffer;
VmaAllocation vertex_allocation; VmaAllocation vertex_allocation;
@@ -154,12 +173,14 @@ public:
long getMemUsed(); long getMemUsed();
long getMemActive(); long getMemActive();
typedef struct { typedef struct
{
Vector3 vertex; Vector3 vertex;
Vector2 uva; Vector2 uva;
} RandomParticleVertexData; } RandomParticleVertexData;
typedef struct { typedef struct
{
Vector3 vertex; Vector3 vertex;
} VolumetricLightingVertexData; } VolumetricLightingVertexData;
@@ -167,7 +188,8 @@ public:
size_t getActiveVBOCount(); size_t getActiveVBOCount();
struct draw_call_info { struct draw_call_info
{
KRNode::RenderPass pass; KRNode::RenderPass pass;
char object_name[256]; char object_name[256];
char material_name[256]; char material_name[256];

View File

@@ -33,7 +33,8 @@
#include "KRMesh.h" #include "KRMesh.h"
class KRMeshQuad : public KRMesh { class KRMeshQuad : public KRMesh
{
public: public:
KRMeshQuad(KRContext& context); KRMeshQuad(KRContext& context);
virtual ~KRMeshQuad(); virtual ~KRMeshQuad();

View File

@@ -33,7 +33,8 @@
#include "KRMesh.h" #include "KRMesh.h"
class KRMeshSphere : public KRMesh { class KRMeshSphere : public KRMesh
{
public: public:
KRMeshSphere(KRContext& context); KRMeshSphere(KRContext& context);
virtual ~KRMeshSphere(); virtual ~KRMeshSphere();

View File

@@ -49,7 +49,8 @@ void KRModel::InitNodeInfo(KrNodeInfo* nodeInfo)
nodeInfo->model.rim_power = 0.0f; nodeInfo->model.rim_power = 0.0f;
} }
KRModel::KRModel(KRScene &scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, Vector3 rim_color, float rim_power) : KRNode(scene, instance_name) { KRModel::KRModel(KRScene& scene, std::string instance_name, std::string model_name, std::string light_map, float lod_min_coverage, bool receives_shadow, bool faces_camera, Vector3 rim_color, float rim_power) : KRNode(scene, instance_name)
{
m_lightMap = light_map; m_lightMap = light_map;
m_pLightMap = NULL; m_pLightMap = NULL;
m_model_name = model_name; m_model_name = model_name;
@@ -77,11 +78,13 @@ KRModel::KRModel(KRScene &scene, std::string instance_name, std::string model_na
m_boundsCachedMat.c[15] = -1.0f; m_boundsCachedMat.c[15] = -1.0f;
} }
KRModel::~KRModel() { KRModel::~KRModel()
{
} }
std::string KRModel::getElementName() { std::string KRModel::getElementName()
{
return "model"; return "model";
} }
@@ -129,7 +132,8 @@ std::string KRModel::getLightMap()
return m_lightMap; return m_lightMap;
} }
void KRModel::loadModel() { void KRModel::loadModel()
{
if (m_models.size() == 0) { if (m_models.size() == 0) {
std::vector<KRMesh*> models = m_pContext->getMeshManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first std::vector<KRMesh*> models = m_pContext->getMeshManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first
unordered_map<KRMesh*, std::vector<KRBone*> > bones; unordered_map<KRMesh*, std::vector<KRBone*> > bones;
@@ -160,7 +164,8 @@ void KRModel::loadModel() {
} }
} }
void KRModel::render(KRNode::RenderInfo& ri) { void KRModel::render(KRNode::RenderInfo& ri)
{
if (m_lod_visible >= LOD_VISIBILITY_PRESTREAM && ri.renderPass == KRNode::RENDER_PASS_PRESTREAM) { if (m_lod_visible >= LOD_VISIBILITY_PRESTREAM && ri.renderPass == KRNode::RENDER_PASS_PRESTREAM) {
preStream(ri.viewport); preStream(ri.viewport);
@@ -260,7 +265,8 @@ kraken_stream_level KRModel::getStreamLevel(const KRViewport &viewport)
return stream_level; return stream_level;
} }
AABB KRModel::getBounds() { AABB KRModel::getBounds()
{
loadModel(); loadModel();
if (m_models.size() > 0) { if (m_models.size() > 0) {
if (m_faces_camera) { if (m_faces_camera) {

View File

@@ -43,7 +43,8 @@
#include "KRTexture.h" #include "KRTexture.h"
#include "KRBone.h" #include "KRBone.h"
class KRModel : public KRNode { class KRModel : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -109,7 +109,8 @@ KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getCont
} }
} }
KRNode::~KRNode() { KRNode::~KRNode()
{
while (m_childNodes.size() > 0) { while (m_childNodes.size() > 0) {
@@ -149,14 +150,16 @@ void KRNode::childDeleted(KRNode *child_node)
getScene().notify_sceneGraphModify(this); getScene().notify_sceneGraphModify(this);
} }
void KRNode::addChild(KRNode *child) { void KRNode::addChild(KRNode* child)
{
assert(child->m_parentNode == NULL); assert(child->m_parentNode == NULL);
child->m_parentNode = this; child->m_parentNode = this;
m_childNodes.insert(child); m_childNodes.insert(child);
child->setLODVisibility(m_lod_visible); // Child node inherits LOD visibility status from parent child->setLODVisibility(m_lod_visible); // Child node inherits LOD visibility status from parent
} }
tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) { tinyxml2::XMLElement* KRNode::saveXML(tinyxml2::XMLNode* parent)
{
tinyxml2::XMLDocument* doc = parent->GetDocument(); tinyxml2::XMLDocument* doc = parent->GetDocument();
tinyxml2::XMLElement* e = doc->NewElement(getElementName().c_str()); tinyxml2::XMLElement* e = doc->NewElement(getElementName().c_str());
tinyxml2::XMLNode* n = parent->InsertEndChild(e); tinyxml2::XMLNode* n = parent->InsertEndChild(e);
@@ -178,7 +181,8 @@ tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) {
return e; return e;
} }
void KRNode::loadXML(tinyxml2::XMLElement *e) { void KRNode::loadXML(tinyxml2::XMLElement* e)
{
m_name = e->Attribute("name"); m_name = e->Attribute("name");
m_localTranslation = kraken::getXMLAttribute("translate", e, Vector3::Zero()); m_localTranslation = kraken::getXMLAttribute("translate", e, Vector3::Zero());
m_localScale = kraken::getXMLAttribute("scale", e, Vector3::One()); m_localScale = kraken::getXMLAttribute("scale", e, Vector3::One());
@@ -229,7 +233,8 @@ void KRNode::loadXML(tinyxml2::XMLElement *e) {
} }
} }
void KRNode::setLocalTranslation(const Vector3 &v, bool set_original) { void KRNode::setLocalTranslation(const Vector3& v, bool set_original)
{
m_localTranslation = v; m_localTranslation = v;
if (set_original) { if (set_original) {
m_initialLocalTranslation = v; m_initialLocalTranslation = v;
@@ -271,7 +276,8 @@ void KRNode::setWorldScale(const Vector3 &v)
} }
} }
void KRNode::setLocalScale(const Vector3 &v, bool set_original) { void KRNode::setLocalScale(const Vector3& v, bool set_original)
{
m_localScale = v; m_localScale = v;
if (set_original) { if (set_original) {
m_initialLocalScale = v; m_initialLocalScale = v;
@@ -280,7 +286,8 @@ void KRNode::setLocalScale(const Vector3 &v, bool set_original) {
invalidateModelMatrix(); invalidateModelMatrix();
} }
void KRNode::setLocalRotation(const Vector3 &v, bool set_original) { void KRNode::setLocalRotation(const Vector3& v, bool set_original)
{
m_localRotation = v; m_localRotation = v;
if (set_original) { if (set_original) {
m_initialLocalRotation = v; m_initialLocalRotation = v;
@@ -396,39 +403,49 @@ const Vector3 &KRNode::getInitialPostRotation()
return m_initialPostRotation; return m_initialPostRotation;
} }
const Vector3 &KRNode::getLocalTranslation() { const Vector3& KRNode::getLocalTranslation()
{
return m_localTranslation; return m_localTranslation;
} }
const Vector3 &KRNode::getLocalScale() { const Vector3& KRNode::getLocalScale()
{
return m_localScale; return m_localScale;
} }
const Vector3 &KRNode::getLocalRotation() { const Vector3& KRNode::getLocalRotation()
{
return m_localRotation; return m_localRotation;
} }
const Vector3 &KRNode::getInitialLocalTranslation() { const Vector3& KRNode::getInitialLocalTranslation()
{
return m_initialLocalTranslation; return m_initialLocalTranslation;
} }
const Vector3 &KRNode::getInitialLocalScale() { const Vector3& KRNode::getInitialLocalScale()
{
return m_initialLocalScale; return m_initialLocalScale;
} }
const Vector3 &KRNode::getInitialLocalRotation() { const Vector3& KRNode::getInitialLocalRotation()
{
return m_initialLocalRotation; return m_initialLocalRotation;
} }
const Vector3 KRNode::getWorldTranslation() { const Vector3 KRNode::getWorldTranslation()
{
return localToWorld(Vector3::Zero()); return localToWorld(Vector3::Zero());
} }
const Vector3 KRNode::getWorldScale() { const Vector3 KRNode::getWorldScale()
{
return Matrix4::DotNoTranslate(getModelMatrix(), m_localScale); return Matrix4::DotNoTranslate(getModelMatrix(), m_localScale);
} }
std::string KRNode::getElementName() { std::string KRNode::getElementName()
{
return "node"; return "node";
} }
KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) { KRNode* KRNode::LoadXML(KRScene& scene, tinyxml2::XMLElement* e)
{
KRNode* new_node = NULL; KRNode* new_node = NULL;
const char* szElementName = e->Name(); const char* szElementName = e->Name();
const char* szName = e->Attribute("name"); const char* szName = e->Attribute("name");
@@ -498,23 +515,28 @@ void KRNode::render(const RenderInfo& ri)
m_lastRenderFrame = getContext().getCurrentFrame(); m_lastRenderFrame = getContext().getCurrentFrame();
} }
const std::set<KRNode *> &KRNode::getChildren() { const std::set<KRNode*>& KRNode::getChildren()
{
return m_childNodes; return m_childNodes;
} }
KRNode *KRNode::getParent() { KRNode* KRNode::getParent()
{
return m_parentNode; return m_parentNode;
} }
const std::string &KRNode::getName() const { const std::string& KRNode::getName() const
{
return m_name; return m_name;
} }
KRScene &KRNode::getScene() { KRScene& KRNode::getScene()
{
return *m_pScene; return *m_pScene;
} }
AABB KRNode::getBounds() { AABB KRNode::getBounds()
{
if (!m_boundsValid) { if (!m_boundsValid) {
AABB bounds = AABB::Zero(); AABB bounds = AABB::Zero();
@@ -739,7 +761,8 @@ const Matrix4 &KRNode::getActivePoseMatrix()
} }
const Quaternion KRNode::getWorldRotation() { const Quaternion KRNode::getWorldRotation()
{
Quaternion world_rotation = Quaternion::Create(m_postRotation) * Quaternion::Create(m_localRotation) * Quaternion::Create(m_preRotation); Quaternion world_rotation = Quaternion::Create(m_postRotation) * Quaternion::Create(m_localRotation) * Quaternion::Create(m_preRotation);
if (m_parentNode) { if (m_parentNode) {
world_rotation = world_rotation * m_parentNode->getWorldRotation(); world_rotation = world_rotation * m_parentNode->getWorldRotation();
@@ -747,7 +770,8 @@ const Quaternion KRNode::getWorldRotation() {
return world_rotation; return world_rotation;
} }
const Quaternion KRNode::getBindPoseWorldRotation() { const Quaternion KRNode::getBindPoseWorldRotation()
{
Quaternion world_rotation = Quaternion::Create(m_initialPostRotation) * Quaternion::Create(m_initialLocalRotation) * Quaternion::Create(m_initialPreRotation); Quaternion world_rotation = Quaternion::Create(m_initialPostRotation) * Quaternion::Create(m_initialLocalRotation) * Quaternion::Create(m_initialPreRotation);
if (dynamic_cast<KRBone*>(m_parentNode)) { if (dynamic_cast<KRBone*>(m_parentNode)) {
world_rotation = world_rotation * m_parentNode->getBindPoseWorldRotation(); world_rotation = world_rotation * m_parentNode->getBindPoseWorldRotation();
@@ -755,7 +779,8 @@ const Quaternion KRNode::getBindPoseWorldRotation() {
return world_rotation; return world_rotation;
} }
const Quaternion KRNode::getActivePoseWorldRotation() { const Quaternion KRNode::getActivePoseWorldRotation()
{
Quaternion world_rotation = Quaternion::Create(m_postRotation) * Quaternion::Create(m_localRotation) * Quaternion::Create(m_preRotation); Quaternion world_rotation = Quaternion::Create(m_postRotation) * Quaternion::Create(m_localRotation) * Quaternion::Create(m_preRotation);
if (dynamic_cast<KRBone*>(m_parentNode)) { if (dynamic_cast<KRBone*>(m_parentNode)) {
world_rotation = world_rotation * m_parentNode->getActivePoseWorldRotation(); world_rotation = world_rotation * m_parentNode->getActivePoseWorldRotation();

View File

@@ -63,7 +63,8 @@ namespace tinyxml2 {
class KRNode : public KRContextObject class KRNode : public KRContextObject
{ {
public: public:
enum RenderPass { enum RenderPass
{
RENDER_PASS_FORWARD_OPAQUE, RENDER_PASS_FORWARD_OPAQUE,
RENDER_PASS_DEFERRED_GBUFFER, RENDER_PASS_DEFERRED_GBUFFER,
RENDER_PASS_DEFERRED_LIGHTS, RENDER_PASS_DEFERRED_LIGHTS,
@@ -77,13 +78,15 @@ public:
RENDER_PASS_PRESTREAM RENDER_PASS_PRESTREAM
}; };
enum LodVisibility { enum LodVisibility
{
LOD_VISIBILITY_HIDDEN, LOD_VISIBILITY_HIDDEN,
LOD_VISIBILITY_PRESTREAM, LOD_VISIBILITY_PRESTREAM,
LOD_VISIBILITY_VISIBLE LOD_VISIBILITY_VISIBLE
}; };
class RenderInfo { class RenderInfo
{
public: public:
RenderInfo(VkCommandBuffer& cb) RenderInfo(VkCommandBuffer& cb)
: commandBuffer(cb) : commandBuffer(cb)
@@ -178,7 +181,8 @@ public:
const Matrix4& getActivePoseMatrix(); const Matrix4& getActivePoseMatrix();
const Matrix4& getInverseBindPoseMatrix(); const Matrix4& getInverseBindPoseMatrix();
enum node_attribute_type { enum node_attribute_type
{
KRENGINE_NODE_ATTRIBUTE_NONE, KRENGINE_NODE_ATTRIBUTE_NONE,
KRENGINE_NODE_ATTRIBUTE_TRANSLATE_X, KRENGINE_NODE_ATTRIBUTE_TRANSLATE_X,
KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Y, KRENGINE_NODE_ATTRIBUTE_TRANSLATE_Y,

View File

@@ -36,7 +36,8 @@
class KRNode; class KRNode;
class KROctree { class KROctree
{
public: public:
KROctree(); KROctree();
~KROctree(); ~KROctree();

View File

@@ -37,7 +37,9 @@ KROctreeNode::KROctreeNode(KROctreeNode *parent, const AABB &bounds) : m_bounds(
{ {
m_parent = parent; m_parent = parent;
for(int i=0; i<8; i++) m_children[i] = NULL; for (int i = 0; i < 8; i++) {
m_children[i] = NULL;
}
m_occlusionQuery = 0; m_occlusionQuery = 0;
m_occlusionTested = false; m_occlusionTested = false;
@@ -49,7 +51,9 @@ KROctreeNode::KROctreeNode(KROctreeNode *parent, const AABB &bounds, int iChild,
// This constructor is used when expanding the octree and replacing the root node with a new root that encapsulates it // This constructor is used when expanding the octree and replacing the root node with a new root that encapsulates it
m_parent = parent; m_parent = parent;
for(int i=0; i<8; i++) m_children[i] = NULL; for (int i = 0; i < 8; i++) {
m_children[i] = NULL;
}
m_children[iChild] = pChild; m_children[iChild] = pChild;
pChild->m_parent = this; pChild->m_parent = this;

View File

@@ -36,7 +36,8 @@
class KRNode; class KRNode;
class KROctreeNode { class KROctreeNode
{
public: public:
KROctreeNode(KROctreeNode* parent, const AABB& bounds); KROctreeNode(KROctreeNode* parent, const AABB& bounds);
KROctreeNode(KROctreeNode* parent, const AABB& bounds, int iChild, KROctreeNode* pChild); KROctreeNode(KROctreeNode* parent, const AABB& bounds, int iChild, KROctreeNode* pChild);

View File

@@ -33,7 +33,8 @@
#include "KRNode.h" #include "KRNode.h"
class KRParticleSystem : public KRNode { class KRParticleSystem : public KRNode
{
public: public:
virtual ~KRParticleSystem(); virtual ~KRParticleSystem();

View File

@@ -78,7 +78,8 @@ bool KRParticleSystemNewtonian::hasPhysics()
return true; return true;
} }
void KRParticleSystemNewtonian::render(RenderInfo& ri) { void KRParticleSystemNewtonian::render(RenderInfo& ri)
{
if (m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return; if (m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;

View File

@@ -33,7 +33,8 @@
#include "KRParticleSystem.h" #include "KRParticleSystem.h"
class KRParticleSystemNewtonian : public KRParticleSystem { class KRParticleSystemNewtonian : public KRParticleSystem
{
public: public:
KRParticleSystemNewtonian(KRScene& scene, std::string name); KRParticleSystemNewtonian(KRScene& scene, std::string name);
virtual ~KRParticleSystemNewtonian(); virtual ~KRParticleSystemNewtonian();

View File

@@ -168,35 +168,27 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
SpvReflectInterfaceVariable& input_var = *reflection->input_variables[i]; SpvReflectInterfaceVariable& input_var = *reflection->input_variables[i];
if (strcmp(input_var.name, "vertex_position") == 0) { if (strcmp(input_var.name, "vertex_position") == 0) {
attribute_locations[KRMesh::KRENGINE_ATTRIB_VERTEX] = input_var.location + 1; attribute_locations[KRMesh::KRENGINE_ATTRIB_VERTEX] = input_var.location + 1;
} } else if (strcmp(input_var.name, "vertex_normal") == 0) {
else if (strcmp(input_var.name, "vertex_normal") == 0) {
attribute_locations[KRMesh::KRENGINE_ATTRIB_NORMAL] = input_var.location + 1; attribute_locations[KRMesh::KRENGINE_ATTRIB_NORMAL] = input_var.location + 1;
} } else if (strcmp(input_var.name, "vertex_tangent") == 0) {
else if (strcmp(input_var.name, "vertex_tangent") == 0) {
attribute_locations[KRMesh::KRENGINE_ATTRIB_TANGENT] = input_var.location + 1; attribute_locations[KRMesh::KRENGINE_ATTRIB_TANGENT] = input_var.location + 1;
} } else if (strcmp(input_var.name, "vertex_uv") == 0) {
else if (strcmp(input_var.name, "vertex_uv") == 0) {
attribute_locations[KRMesh::KRENGINE_ATTRIB_TEXUVA] = input_var.location + 1; attribute_locations[KRMesh::KRENGINE_ATTRIB_TEXUVA] = input_var.location + 1;
} } else if (strcmp(input_var.name, "vertex_lightmap_uv") == 0) {
else if (strcmp(input_var.name, "vertex_lightmap_uv") == 0) {
attribute_locations[KRMesh::KRENGINE_ATTRIB_TEXUVB] = input_var.location + 1; attribute_locations[KRMesh::KRENGINE_ATTRIB_TEXUVB] = input_var.location + 1;
} } else if (strcmp(input_var.name, "bone_indexes") == 0) {
else if (strcmp(input_var.name, "bone_indexes") == 0) {
attribute_locations[KRMesh::KRENGINE_ATTRIB_BONEINDEXES] = input_var.location + 1; attribute_locations[KRMesh::KRENGINE_ATTRIB_BONEINDEXES] = input_var.location + 1;
} } else if (strcmp(input_var.name, "bone_weights") == 0) {
else if (strcmp(input_var.name, "bone_weights") == 0) {
attribute_locations[KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS] = input_var.location + 1; attribute_locations[KRMesh::KRENGINE_ATTRIB_BONEWEIGHTS] = input_var.location + 1;
} }
} }
initPushConstantStage(ShaderStages::vertex, reflection); initPushConstantStage(ShaderStages::vertex, reflection);
} } else if (shader->getSubExtension().compare("frag") == 0) {
else if (shader->getSubExtension().compare("frag") == 0) {
stageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; stageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
initPushConstantStage(ShaderStages::fragment, reflection); initPushConstantStage(ShaderStages::fragment, reflection);
} } else {
else {
// failed! TODO - Error handling // failed! TODO - Error handling
} }
stageInfo.module = shaderModule; stageInfo.module = shaderModule;
@@ -454,7 +446,8 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf
} }
} }
KRPipeline::~KRPipeline() { KRPipeline::~KRPipeline()
{
if (m_graphicsPipeline) { if (m_graphicsPipeline) {
// TODO: vkDestroyPipeline(device, m_graphicsPipeline, nullptr); // TODO: vkDestroyPipeline(device, m_graphicsPipeline, nullptr);
} }
@@ -492,8 +485,7 @@ void KRPipeline::initPushConstantStage(ShaderStages stage, const SpvReflectShade
for (int iUniform = 0; iUniform < kUniformCount; iUniform++) { for (int iUniform = 0; iUniform < kUniformCount; iUniform++) {
for (int iMember = 0; iMember < block.member_count; iMember++) { for (int iMember = 0; iMember < block.member_count; iMember++) {
const SpvReflectBlockVariable& member = block.members[iMember]; const SpvReflectBlockVariable& member = block.members[iMember];
if (stricmp(KRENGINE_UNIFORM_NAMES[iUniform], member.name) == 0) if (stricmp(KRENGINE_UNIFORM_NAMES[iUniform], member.name) == 0) {
{
pushConstants.offset[iUniform] = member.offset; pushConstants.offset[iUniform] = member.offset;
pushConstants.size[iUniform] = member.size; pushConstants.size[iUniform] = member.size;
} }
@@ -785,7 +777,8 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera &camera, const KR
return true; return true;
} }
const char *KRPipeline::getKey() const { const char* KRPipeline::getKey() const
{
return m_szKey; return m_szKey;
} }

View File

@@ -45,14 +45,16 @@ class KRRenderPass;
enum class ModelFormat : __uint8_t; enum class ModelFormat : __uint8_t;
struct SpvReflectShaderModule; struct SpvReflectShaderModule;
enum class CullMode : uint32_t { enum class CullMode : uint32_t
{
kCullBack = 0, kCullBack = 0,
kCullFront, kCullFront,
kCullNone kCullNone
}; };
// Note: RasterMode is likely to be refactored later to a bitfield // Note: RasterMode is likely to be refactored later to a bitfield
enum class RasterMode : uint32_t { enum class RasterMode : uint32_t
{
kOpaque = 0, kOpaque = 0,
/* /*
kOpaque is equivalent to: kOpaque is equivalent to:
@@ -173,7 +175,8 @@ enum class RasterMode : uint32_t {
*/ */
}; };
class PipelineInfo { class PipelineInfo
{
public: public:
const std::string* shader_name; const std::string* shader_name;
KRCamera* pCamera; KRCamera* pCamera;
@@ -204,7 +207,8 @@ public:
KRNode::RenderPass renderPass; KRNode::RenderPass renderPass;
}; };
class KRPipeline : public KRContextObject { class KRPipeline : public KRContextObject
{
public: public:
KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat); KRPipeline(KRContext& context, KRSurface& surface, const PipelineInfo& info, const char* szKey, const std::vector<KRShader*>& shaders, uint32_t vertexAttributes, ModelFormat modelFormat);
@@ -213,7 +217,8 @@ public:
bool bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const Matrix4& matModel, const std::vector<KRPointLight*>* point_lights, const std::vector<KRDirectionalLight*>* directional_lights, const std::vector<KRSpotLight*>* spot_lights, const KRNode::RenderPass& renderPass); bool bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const Matrix4& matModel, const std::vector<KRPointLight*>* point_lights, const std::vector<KRDirectionalLight*>* directional_lights, const std::vector<KRSpotLight*>* spot_lights, const KRNode::RenderPass& renderPass);
enum class Uniform : uint8_t { enum class Uniform : uint8_t
{
material_ambient = 0, material_ambient = 0,
material_diffuse, material_diffuse,
material_specular, material_specular,

View File

@@ -44,20 +44,21 @@
using namespace std; using namespace std;
KRPipelineManager::KRPipelineManager(KRContext &context) : KRContextObject(context) { KRPipelineManager::KRPipelineManager(KRContext& context) : KRContextObject(context)
{
m_active_pipeline = NULL; m_active_pipeline = NULL;
#ifndef ANDROID #ifndef ANDROID
bool success = glslang::InitializeProcess(); bool success = glslang::InitializeProcess();
if (success) { if (success) {
printf("GLSLang Initialized.\n"); printf("GLSLang Initialized.\n");
} } else {
else {
printf("Failed to initialize GLSLang.\n"); printf("Failed to initialize GLSLang.\n");
} }
#endif // ANDROID #endif // ANDROID
} }
KRPipelineManager::~KRPipelineManager() { KRPipelineManager::~KRPipelineManager()
{
#ifndef ANDROID #ifndef ANDROID
glslang::FinalizeProcess(); glslang::FinalizeProcess();
#endif // ANDROID #endif // ANDROID
@@ -294,7 +295,8 @@ KRPipeline *KRPipelineManager::getPipeline(KRSurface& surface, const PipelineInf
} }
*/ */
size_t KRPipelineManager::getPipelineHandlesUsed() { size_t KRPipelineManager::getPipelineHandlesUsed()
{
return m_pipelines.size(); return m_pipelines.size();
} }

View File

@@ -48,7 +48,8 @@ class KRPipeline;
class PipelineInfo; class PipelineInfo;
class KRCamera; class KRCamera;
class KRPipelineManager : public KRContextObject { class KRPipelineManager : public KRContextObject
{
public: public:
KRPipelineManager(KRContext& context); KRPipelineManager(KRContext& context);

View File

@@ -56,11 +56,13 @@ KRPointLight::~KRPointLight()
} }
} }
std::string KRPointLight::getElementName() { std::string KRPointLight::getElementName()
{
return "point_light"; return "point_light";
} }
AABB KRPointLight::getBounds() { AABB KRPointLight::getBounds()
{
float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE); float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE);
if (influence_radius < m_flareOcclusionSize) { if (influence_radius < m_flareOcclusionSize) {
influence_radius = m_flareOcclusionSize; influence_radius = m_flareOcclusionSize;
@@ -104,8 +106,7 @@ void KRPointLight::render(RenderInfo& ri)
info.renderPass = ri.renderPass; info.renderPass = ri.renderPass;
if (bInsideLight) { if (bInsideLight) {
info.rasterMode = bVisualize ? RasterMode::kAdditiveNoTest : RasterMode::kAlphaBlendNoTest; info.rasterMode = bVisualize ? RasterMode::kAdditiveNoTest : RasterMode::kAlphaBlendNoTest;
} } else {
else {
info.rasterMode = bVisualize ? RasterMode::kAdditive : RasterMode::kAlphaBlend; info.rasterMode = bVisualize ? RasterMode::kAdditive : RasterMode::kAlphaBlend;
} }
info.vertexAttributes = bInsideLight ? m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES.getVertexAttributes() : 1 << KRMesh::KRENGINE_ATTRIB_VERTEX; info.vertexAttributes = bInsideLight ? m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES.getVertexAttributes() : 1 << KRMesh::KRENGINE_ATTRIB_VERTEX;
@@ -136,7 +137,8 @@ void KRPointLight::render(RenderInfo& ri)
} }
} }
void KRPointLight::generateMesh() { void KRPointLight::generateMesh()
{
// Create a triangular facet approximation to a sphere // Create a triangular facet approximation to a sphere
// Based on algorithm from Paul Bourke: http://paulbourke.net/miscellaneous/sphere_cylinder/ // Based on algorithm from Paul Bourke: http://paulbourke.net/miscellaneous/sphere_cylinder/
@@ -152,12 +154,15 @@ void KRPointLight::generateMesh() {
m_cVertices = facet_count * 3; m_cVertices = facet_count * 3;
class Facet3 { class Facet3
{
public: public:
Facet3() { Facet3()
{
} }
~Facet3() { ~Facet3()
{
} }
Vector3 p1; Vector3 p1;

View File

@@ -33,8 +33,8 @@
#include "KRLight.h" #include "KRLight.h"
class KRPointLight : public KRLight { class KRPointLight : public KRLight
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);
KRPointLight(KRScene& scene, std::string name); KRPointLight(KRScene& scene, std::string name);

View File

@@ -71,8 +71,7 @@ void KRPresentationThread::run()
std::chrono::microseconds sleep_duration(15000); std::chrono::microseconds sleep_duration(15000);
m_activeState = PresentThreadState::run; m_activeState = PresentThreadState::run;
while (m_requestedState != PresentThreadRequest::stop) while (m_requestedState != PresentThreadRequest::stop) {
{
switch (m_activeState) { switch (m_activeState) {
case PresentThreadState::pause: case PresentThreadState::pause:
case PresentThreadState::stop: case PresentThreadState::stop:

View File

@@ -176,11 +176,13 @@ KRRenderSettings& KRRenderSettings::operator=(const KRRenderSettings &s)
return *this; return *this;
} }
const Vector2 &KRRenderSettings::getViewportSize() { const Vector2& KRRenderSettings::getViewportSize()
{
return m_viewportSize; return m_viewportSize;
} }
void KRRenderSettings::setViewportSize(const Vector2 &size) { void KRRenderSettings::setViewportSize(const Vector2& size)
{
m_viewportSize = size; m_viewportSize = size;
} }

View File

@@ -33,7 +33,8 @@
#include "KREngine-common.h" #include "KREngine-common.h"
class KRRenderSettings { class KRRenderSettings
{
public: public:
KRRenderSettings(); KRRenderSettings();
~KRRenderSettings(); ~KRRenderSettings();
@@ -106,7 +107,8 @@ public:
float perspective_nearz; float perspective_nearz;
float perspective_farz; float perspective_farz;
enum debug_display_type{ enum debug_display_type
{
KRENGINE_DEBUG_DISPLAY_NONE = 0, KRENGINE_DEBUG_DISPLAY_NONE = 0,
KRENGINE_DEBUG_DISPLAY_TIME, KRENGINE_DEBUG_DISPLAY_TIME,
KRENGINE_DEBUG_DISPLAY_MEMORY, KRENGINE_DEBUG_DISPLAY_MEMORY,

View File

@@ -36,7 +36,8 @@
#include "KRResource+blend.h" #include "KRResource+blend.h"
KRScene* KRResource::LoadBlenderScene(KRContext &context, const std::string& path) { KRScene* KRResource::LoadBlenderScene(KRContext& context, const std::string& path)
{
KRScene* pScene = new KRScene(context, KRResource::GetFileBase(path)); KRScene* pScene = new KRScene(context, KRResource::GetFileBase(path));
KRDataBlock data; KRDataBlock data;
@@ -49,7 +50,8 @@ KRScene* KRResource::LoadBlenderScene(KRContext &context, const std::string& pat
} }
KRBlendFile::KRBlendFile(const void *pFile) { KRBlendFile::KRBlendFile(const void* pFile)
{
unsigned char* scan = (unsigned char*)pFile; unsigned char* scan = (unsigned char*)pFile;
readHeader(scan); readHeader(scan);
std::string block_code = ""; std::string block_code = "";
@@ -62,7 +64,8 @@ KRBlendFile::KRBlendFile(const void *pFile) {
} }
} }
void KRBlendFile::readHeader(unsigned char *&scan) { void KRBlendFile::readHeader(unsigned char*& scan)
{
if (strncmp((char*)scan, "BLENDER", 7) != 0) { if (strncmp((char*)scan, "BLENDER", 7) != 0) {
// TODO throw exception // TODO throw exception
} }
@@ -85,7 +88,8 @@ void KRBlendFile::readHeader(unsigned char *&scan) {
scan += 5; // Skip and ignore version scan += 5; // Skip and ignore version
} }
__int32_t KRBlendFile::readInt(unsigned char *&scan) { __int32_t KRBlendFile::readInt(unsigned char*& scan)
{
__int32_t ret = 0; __int32_t ret = 0;
// read a 32-bit integer and increment scan // read a 32-bit integer and increment scan
@@ -104,7 +108,8 @@ __int32_t KRBlendFile::readInt(unsigned char *&scan) {
return ret; return ret;
} }
__int64_t KRBlendFile::readPointer(unsigned char *&scan) { __int64_t KRBlendFile::readPointer(unsigned char*& scan)
{
__int64_t ret = 0; __int64_t ret = 0;
// read a 32-bit integer and increment scan // read a 32-bit integer and increment scan
switch (m_file_type) { switch (m_file_type) {
@@ -131,12 +136,14 @@ __int64_t KRBlendFile::readPointer(unsigned char *&scan) {
return ret; return ret;
} }
KRBlendFile::~KRBlendFile() { KRBlendFile::~KRBlendFile()
{
} }
KRBlendFile::Block::Block(KRBlendFile *blendFile, unsigned char *&scan) { KRBlendFile::Block::Block(KRBlendFile* blendFile, unsigned char*& scan)
{
scan += (__int64_t)scan % 4; // Scan forward until the next 4-byte boundary scan += (__int64_t)scan % 4; // Scan forward until the next 4-byte boundary
char szBlock[5]; char szBlock[5];
szBlock[0] = *scan++; szBlock[0] = *scan++;
@@ -152,15 +159,18 @@ KRBlendFile::Block::Block(KRBlendFile *blendFile, unsigned char *&scan) {
m_data = scan; m_data = scan;
scan += m_dataSize; scan += m_dataSize;
} }
KRBlendFile::Block::~Block() { KRBlendFile::Block::~Block()
{
} }
std::string KRBlendFile::Block::getCode() { std::string KRBlendFile::Block::getCode()
{
return m_code; return m_code;
} }
int KRBlendFile::Block::getDataSize() { int KRBlendFile::Block::getDataSize()
{
return m_dataSize; return m_dataSize;
} }

View File

@@ -31,12 +31,14 @@
#pragma once #pragma once
class KRBlendFile { class KRBlendFile
{
public: public:
KRBlendFile(const void* pFile); KRBlendFile(const void* pFile);
~KRBlendFile(); ~KRBlendFile();
class Block { class Block
{
public: public:
Block(KRBlendFile* blendFile, unsigned char*& scan); Block(KRBlendFile* blendFile, unsigned char*& scan);
~Block(); ~Block();
@@ -53,7 +55,8 @@ public:
}; };
private: private:
enum file_type { enum file_type
{
KRBLEND_LITTLEENDIAN_32BIT, KRBLEND_LITTLEENDIAN_32BIT,
KRBLEND_LITTLEENDIAN_64BIT, KRBLEND_LITTLEENDIAN_64BIT,
KRBLEND_BIGENDIAN_32BIT, KRBLEND_BIGENDIAN_32BIT,

View File

@@ -206,10 +206,8 @@ void KRResource::LoadFbx(KRContext &context, const std::string& path)
// ----====---- Import Scene Graph Nodes ----====---- // ----====---- Import Scene Graph Nodes ----====----
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Loading scene graph..."); KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Loading scene graph...");
if(pNode) if (pNode) {
{ for (int i = 0; i < pNode->GetChildCount(); i++) {
for(int i = 0; i < pNode->GetChildCount(); i++)
{
LoadNode(pFbxScene, pScene->getRootNode(), pGeometryConverter, pNode->GetChild(i)); LoadNode(pFbxScene, pScene->getRootNode(), pGeometryConverter, pNode->GetChild(i));
} }
} }
@@ -226,8 +224,7 @@ void InitializeSdkObjects(FbxManager*& pSdkManager, FbxScene*& pScene)
// object allocator for almost all the classes in the SDK. // object allocator for almost all the classes in the SDK.
pSdkManager = FbxManager::Create(); pSdkManager = FbxManager::Create();
if (!pSdkManager) if (!pSdkManager) {
{
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Unable to create the FBX SDK manager"); KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Unable to create the FBX SDK manager");
exit(0); exit(0);
} }
@@ -282,16 +279,14 @@ bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilena
const bool lImportStatus = lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings()); const bool lImportStatus = lImporter->Initialize(pFilename, -1, pSdkManager->GetIOSettings());
lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision); lImporter->GetFileVersion(lFileMajor, lFileMinor, lFileRevision);
if( !lImportStatus ) if (!lImportStatus) {
{
FbxStatus& status = lImporter->GetStatus(); FbxStatus& status = lImporter->GetStatus();
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Call to KFbxImporter::Initialize() failed.\nError returned: %s", status.GetErrorString()); KRContext::Log(KRContext::LOG_LEVEL_ERROR, "Call to KFbxImporter::Initialize() failed.\nError returned: %s", status.GetErrorString());
if (status.GetCode() == FbxStatus::EStatusCode::eInvalidFileVersion) if (status.GetCode() == FbxStatus::EStatusCode::eInvalidFileVersion) {
{
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "FBX version number for this FBX SDK is %d.%d.%d", lSDKMajor, lSDKMinor, lSDKRevision); KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "FBX version number for this FBX SDK is %d.%d.%d", lSDKMajor, lSDKMinor, lSDKRevision);
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "FBX version number for file %s is %d.%d.%d", pFilename, lFileMajor, lFileMinor, lFileRevision); KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "FBX version number for file %s is %d.%d.%d", pFilename, lFileMajor, lFileMinor, lFileRevision);
} }
@@ -333,8 +328,7 @@ bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilena
// Import the scene. // Import the scene.
lStatus = lImporter->Import(pScene); lStatus = lImporter->Import(pScene);
if(lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) if (lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) {
{
printf("Please enter password: "); printf("Please enter password: ");
lPassword[0] = '\0'; lPassword[0] = '\0';
@@ -347,8 +341,7 @@ bool LoadScene(FbxManager* pSdkManager, FbxDocument* pScene, const char* pFilena
lStatus = lImporter->Import(pScene); lStatus = lImporter->Import(pScene);
if(lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) if (lStatus == false && lImporter->GetStatus().GetCode() == FbxStatus::EStatusCode::ePasswordError) {
{
printf("\nPassword is wrong, import aborted.\n"); printf("\nPassword is wrong, import aborted.\n");
} }
} }
@@ -600,7 +593,8 @@ KRAnimationLayer *LoadAnimationLayer(KRContext &context, FbxAnimLayer *pAnimLaye
// } // }
//} //}
void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode) { void LoadNode(FbxScene* pFbxScene, KRNode* parent_node, FbxGeometryConverter* pGeometryConverter, FbxNode* pNode)
{
FbxVector4 lTmpVector; FbxVector4 lTmpVector;
pNode->UpdatePropertiesFromPivotsAndLimits(); pNode->UpdatePropertiesFromPivotsAndLimits();
@@ -977,8 +971,7 @@ void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pG
AABB reference_bounds; AABB reference_bounds;
// Create a lod_group node for each fbx child node // Create a lod_group node for each fbx child node
int child_count = pNode->GetChildCount(); int child_count = pNode->GetChildCount();
for(int i = 0; i < child_count; i++) for (int i = 0; i < child_count; i++) {
{
float min_distance = 0; float min_distance = 0;
float max_distance = 0; // 0 for max_distance means infinity float max_distance = 0; // 0 for max_distance means infinity
FbxLODGroup::EDisplayLevel display_level; FbxLODGroup::EDisplayLevel display_level;
@@ -1097,15 +1090,15 @@ void LoadNode(FbxScene* pFbxScene, KRNode *parent_node, FbxGeometryConverter *pG
parent_node->addChild(new_node); parent_node->addChild(new_node);
// Load child nodes // Load child nodes
for(int i = 0; i < pNode->GetChildCount(); i++) for (int i = 0; i < pNode->GetChildCount(); i++) {
{
LoadNode(pFbxScene, new_node, pGeometryConverter, pNode->GetChild(i)); LoadNode(pFbxScene, new_node, pGeometryConverter, pNode->GetChild(i));
} }
} }
} }
} }
void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) { void LoadMaterial(KRContext& context, FbxSurfaceMaterial* pMaterial)
{
//printf(" %s: %i - %i\n", pMaterial->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1); //printf(" %s: %i - %i\n", pMaterial->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1);
// ----====---- Output Material File ----====---- // ----====---- Output Material File ----====----
@@ -1280,11 +1273,13 @@ void LoadMaterial(KRContext &context, FbxSurfaceMaterial *pMaterial) {
void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxMesh* pMesh) { void LoadMesh(KRContext& context, FbxScene* pFbxScene, FbxGeometryConverter* pGeometryConverter, FbxMesh* pMesh)
{
KRMesh::mesh_info mi; KRMesh::mesh_info mi;
mi.format = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; mi.format = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES;
typedef struct { typedef struct
{
float weights[KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX]; float weights[KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX];
int bone_indexes[KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX]; int bone_indexes[KRENGINE_MAX_BONE_WEIGHTS_PER_VERTEX];
} control_point_weight_info_t; } control_point_weight_info_t;
@@ -1435,8 +1430,7 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
} else { } else {
// ----====---- Read SubMesh / Material Mapping ----====---- // ----====---- Read SubMesh / Material Mapping ----====----
int iNewMaterial = -1; int iNewMaterial = -1;
for (int l = 0; l < elementmaterial_count; l++) for (int l = 0; l < elementmaterial_count; l++) {
{
FbxGeometryElementMaterial* leMat = pMesh->GetElementMaterial(l); FbxGeometryElementMaterial* leMat = pMesh->GetElementMaterial(l);
if (leMat) { if (leMat) {
if (leMat->GetReferenceMode() == FbxGeometryElement::eIndex || leMat->GetReferenceMode() == FbxGeometryElement::eIndexToDirect) { if (leMat->GetReferenceMode() == FbxGeometryElement::eIndex || leMat->GetReferenceMode() == FbxGeometryElement::eIndexToDirect) {
@@ -1565,7 +1559,8 @@ void LoadMesh(KRContext &context, FbxScene* pFbxScene, FbxGeometryConverter *pGe
context.getMeshManager()->addModel(new_mesh); context.getMeshManager()->addModel(new_mesh);
} }
KRNode *LoadMesh(KRNode *parent_node, FbxScene* pFbxScene, FbxGeometryConverter *pGeometryConverter, FbxNode* pNode) { KRNode* LoadMesh(KRNode* parent_node, FbxScene* pFbxScene, FbxGeometryConverter* pGeometryConverter, FbxNode* pNode)
{
std::string name = GetFbxObjectName(pNode); std::string name = GetFbxObjectName(pNode);
FbxMesh* pSourceMesh = (FbxMesh*)pNode->GetNodeAttribute(); FbxMesh* pSourceMesh = (FbxMesh*)pNode->GetNodeAttribute();
@@ -1613,7 +1608,8 @@ KRNode *LoadMesh(KRNode *parent_node, FbxScene* pFbxScene, FbxGeometryConverter
} }
KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) { KRNode* LoadSkeleton(KRNode* parent_node, FbxScene* pFbxScene, FbxNode* pNode)
{
std::string name = GetFbxObjectName(pNode); std::string name = GetFbxObjectName(pNode);
KRBone* new_bone = new KRBone(parent_node->getScene(), name.c_str()); KRBone* new_bone = new KRBone(parent_node->getScene(), name.c_str());
@@ -1627,7 +1623,8 @@ KRNode *LoadSkeleton(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) {
return new_bone; return new_bone;
} }
KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) { KRNode* LoadLocator(KRNode* parent_node, FbxScene* pFbxScene, FbxNode* pNode)
{
std::string name = GetFbxObjectName(pNode); std::string name = GetFbxObjectName(pNode);
KRLocator* new_locator = new KRLocator(parent_node->getScene(), name.c_str()); KRLocator* new_locator = new KRLocator(parent_node->getScene(), name.c_str());
@@ -1676,7 +1673,8 @@ KRNode *LoadLocator(KRNode *parent_node, FbxScene* pFbxScene, FbxNode* pNode) {
return new_locator; return new_locator;
} }
KRNode *LoadCamera(KRNode *parent_node, FbxNode* pNode) { KRNode* LoadCamera(KRNode* parent_node, FbxNode* pNode)
{
FbxCamera* camera = (FbxCamera*)pNode->GetNodeAttribute(); FbxCamera* camera = (FbxCamera*)pNode->GetNodeAttribute();
const char* szName = pNode->GetName(); const char* szName = pNode->GetName();
@@ -1684,7 +1682,8 @@ KRNode *LoadCamera(KRNode *parent_node, FbxNode* pNode) {
return new_camera; return new_camera;
} }
KRNode *LoadLight(KRNode *parent_node, FbxNode* pNode) { KRNode* LoadLight(KRNode* parent_node, FbxNode* pNode)
{
const float PI = 3.14159265; const float PI = 3.14159265;
const float d2r = PI * 2 / 360; const float d2r = PI * 2 / 360;

View File

@@ -34,11 +34,13 @@
#include "KRBundle.h" #include "KRBundle.h"
#include "KRContext.h" #include "KRContext.h"
KRResource::KRResource(KRContext &context, std::string name) : KRContextObject(context) { KRResource::KRResource(KRContext& context, std::string name) : KRContextObject(context)
{
m_name = name; m_name = name;
context.addResource(this, name); context.addResource(this, name);
} }
KRResource::~KRResource() { KRResource::~KRResource()
{
m_pContext->removeResource(this); m_pContext->removeResource(this);
} }

View File

@@ -37,7 +37,8 @@
#include "KRContextObject.h" #include "KRContextObject.h"
#include "KRDataBlock.h" #include "KRDataBlock.h"
class KRResourceManager : public KRContextObject { class KRResourceManager : public KRContextObject
{
public: public:
KRResourceManager(KRContext& context); KRResourceManager(KRContext& context);
virtual ~KRResourceManager(); virtual ~KRResourceManager();

View File

@@ -47,14 +47,13 @@ KRReverbZone::KRReverbZone(KRScene &scene, std::string name) : KRNode(scene, nam
m_reverb = ""; m_reverb = "";
m_reverb_gain = 1.0f; m_reverb_gain = 1.0f;
m_gradient_distance = 0.25f; m_gradient_distance = 0.25f;
} }
KRReverbZone::~KRReverbZone() KRReverbZone::~KRReverbZone()
{ {}
}
std::string KRReverbZone::getElementName() { std::string KRReverbZone::getElementName()
{
return "reverb_zone"; return "reverb_zone";
} }
@@ -161,7 +160,8 @@ void KRReverbZone::setGradientDistance(float gradient_distance)
m_gradient_distance = gradient_distance; m_gradient_distance = gradient_distance;
} }
AABB KRReverbZone::getBounds() { AABB KRReverbZone::getBounds()
{
// Reverb zones always have a -1, -1, -1 to 1, 1, 1 bounding box // Reverb zones always have a -1, -1, -1 to 1, 1, 1 bounding box
return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix()); return AABB::Create(-Vector3::One(), Vector3::One(), getModelMatrix());
} }

View File

@@ -35,7 +35,8 @@
#include "KRNode.h" #include "KRNode.h"
#include "KRTexture.h" #include "KRTexture.h"
class KRReverbZone : public KRNode { class KRReverbZone : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -42,18 +42,21 @@
const long KRENGINE_OCCLUSION_TEST_EXPIRY = 10; const long KRENGINE_OCCLUSION_TEST_EXPIRY = 10;
KRScene::KRScene(KRContext &context, std::string name) : KRResource(context, name) { KRScene::KRScene(KRContext& context, std::string name) : KRResource(context, name)
{
m_pFirstLight = NULL; m_pFirstLight = NULL;
m_pRootNode = new KRNode(*this, "scene_root"); m_pRootNode = new KRNode(*this, "scene_root");
notify_sceneGraphCreate(m_pRootNode); notify_sceneGraphCreate(m_pRootNode);
} }
KRScene::~KRScene() { KRScene::~KRScene()
{
delete m_pRootNode; delete m_pRootNode;
m_pRootNode = NULL; m_pRootNode = NULL;
} }
void KRScene::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface, float deltaTime) { void KRScene::renderFrame(VkCommandBuffer& commandBuffer, KRSurface& surface, float deltaTime)
{
getContext().startFrame(deltaTime); getContext().startFrame(deltaTime);
KRCamera* camera = find<KRCamera>("default_camera"); KRCamera* camera = find<KRCamera>("default_camera");
if (camera == NULL) { if (camera == NULL) {
@@ -96,7 +99,8 @@ std::set<KRLight *> &KRScene::getLights()
return m_lights; return m_lights;
} }
void KRScene::render(VkCommandBuffer& commandBuffer, KRSurface& surface, KRCamera *pCamera, unordered_map<AABB, int> &visibleBounds, const KRViewport &viewport, KRNode::RenderPass renderPass, bool new_frame) { void KRScene::render(VkCommandBuffer& commandBuffer, KRSurface& surface, KRCamera* pCamera, unordered_map<AABB, int>& visibleBounds, const KRViewport& viewport, KRNode::RenderPass renderPass, bool new_frame)
{
if (new_frame) { if (new_frame) {
// Expire cached occlusion test results. // Expire cached occlusion test results.
// Cached "failed" results are expired on the next frame (marked with .second of -1) // Cached "failed" results are expired on the next frame (marked with .second of -1)
@@ -369,15 +373,18 @@ void KRScene::render(KRNode::RenderInfo& ri, KROctreeNode* pOctreeNode, unordere
// fprintf(stderr, "Octree culled: (%f, %f, %f) - (%f, %f, %f)\n", pOctreeNode->getBounds().min.x, pOctreeNode->getBounds().min.y, pOctreeNode->getBounds().min.z, pOctreeNode->getBounds().max.x, pOctreeNode->getBounds().max.y, pOctreeNode->getBounds().max.z); // fprintf(stderr, "Octree culled: (%f, %f, %f) - (%f, %f, %f)\n", pOctreeNode->getBounds().min.x, pOctreeNode->getBounds().min.y, pOctreeNode->getBounds().min.z, pOctreeNode->getBounds().max.x, pOctreeNode->getBounds().max.y, pOctreeNode->getBounds().max.z);
} }
std::string KRScene::getExtension() { std::string KRScene::getExtension()
{
return "krscene"; return "krscene";
} }
KRNode *KRScene::getRootNode() { KRNode* KRScene::getRootNode()
{
return m_pRootNode; return m_pRootNode;
} }
bool KRScene::save(KRDataBlock &data) { bool KRScene::save(KRDataBlock& data)
{
tinyxml2::XMLDocument doc; tinyxml2::XMLDocument doc;
tinyxml2::XMLElement* scene_node = doc.NewElement("scene"); tinyxml2::XMLElement* scene_node = doc.NewElement("scene");
doc.InsertEndChild(scene_node); doc.InsertEndChild(scene_node);

View File

@@ -48,7 +48,8 @@ class KRSurface;
using std::vector; using std::vector;
class KRScene : public KRResource { class KRScene : public KRResource
{
public: public:
KRScene(KRContext& context, std::string name); KRScene(KRContext& context, std::string name);
virtual ~KRScene(); virtual ~KRScene();

View File

@@ -32,10 +32,11 @@
#include "KRSceneManager.h" #include "KRSceneManager.h"
#include "KRScene.h" #include "KRScene.h"
KRSceneManager::KRSceneManager(KRContext &context) : KRResourceManager(context){ KRSceneManager::KRSceneManager(KRContext& context) : KRResourceManager(context)
} {}
KRSceneManager::~KRSceneManager() { KRSceneManager::~KRSceneManager()
{
for (unordered_map<std::string, KRScene*>::iterator itr = m_scenes.begin(); itr != m_scenes.end(); ++itr) { for (unordered_map<std::string, KRScene*>::iterator itr = m_scenes.begin(); itr != m_scenes.end(); ++itr) {
delete (*itr).second; delete (*itr).second;
} }
@@ -58,7 +59,8 @@ KRResource* KRSceneManager::getResource(const std::string& name, const std::stri
return nullptr; return nullptr;
} }
KRScene *KRSceneManager::loadScene(const std::string &name, KRDataBlock *data) { KRScene* KRSceneManager::loadScene(const std::string& name, KRDataBlock* data)
{
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
std::string lowerName = name; std::string lowerName = name;
std::transform(lowerName.begin(), lowerName.end(), std::transform(lowerName.begin(), lowerName.end(),
@@ -87,7 +89,8 @@ void KRSceneManager::add(KRScene *scene)
m_scenes[lowerName] = scene; m_scenes[lowerName] = scene;
} }
KRScene *KRSceneManager::getScene(const std::string &name) { KRScene* KRSceneManager::getScene(const std::string& name)
{
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
std::string lowerName = name; std::string lowerName = name;
std::transform(lowerName.begin(), lowerName.end(), std::transform(lowerName.begin(), lowerName.end(),
@@ -101,7 +104,8 @@ KRScene *KRSceneManager::getScene(const std::string &name) {
} }
} }
KRScene *KRSceneManager::getFirstScene() { KRScene* KRSceneManager::getFirstScene()
{
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
unordered_map<std::string, KRScene*>::iterator scene_itr = m_scenes.begin(); unordered_map<std::string, KRScene*>::iterator scene_itr = m_scenes.begin();
if (scene_itr != m_scenes.end()) { if (scene_itr != m_scenes.end()) {
@@ -111,7 +115,8 @@ KRScene *KRSceneManager::getFirstScene() {
} }
} }
unordered_map<std::string, KRScene *> &KRSceneManager::getScenes() { unordered_map<std::string, KRScene*>& KRSceneManager::getScenes()
{
return m_scenes; return m_scenes;
} }

View File

@@ -39,8 +39,8 @@
class KRScene; class KRScene;
class KRSceneManager : public KRResourceManager
class KRSceneManager : public KRResourceManager { {
public: public:
KRSceneManager(KRContext& context); KRSceneManager(KRContext& context);
virtual ~KRSceneManager(); virtual ~KRSceneManager();

View File

@@ -37,8 +37,8 @@
#include "KRResource.h" #include "KRResource.h"
#include "spirv_reflect.h" #include "spirv_reflect.h"
class KRShader : public KRResource { class KRShader : public KRResource
{
public: public:
KRShader(KRContext& context, std::string name, std::string extension); KRShader(KRContext& context, std::string name, std::string extension);
KRShader(KRContext& context, std::string name, std::string extension, KRDataBlock* data); KRShader(KRContext& context, std::string name, std::string extension, KRDataBlock* data);

View File

@@ -327,8 +327,7 @@ bool KRShaderManager::compileAll(KRBundle* outputBundle, KRUnknown* logResource)
} }
std::string shader_name; std::string shader_name;
switch (stage) switch (stage) {
{
case EShLangVertex: case EShLangVertex:
shader_name = vertSourceName; shader_name = vertSourceName;
break; break;

View File

@@ -41,7 +41,8 @@
class KRUnknown; class KRUnknown;
class KRShaderManager : public KRResourceManager { class KRShaderManager : public KRResourceManager
{
public: public:
KRShaderManager(KRContext& context); KRShaderManager(KRContext& context);
virtual ~KRShaderManager(); virtual ~KRShaderManager();

View File

@@ -36,7 +36,8 @@
#include "KRDataBlock.h" #include "KRDataBlock.h"
#include "KRResource.h" #include "KRResource.h"
class KRSource : public KRResource { class KRSource : public KRResource
{
public: public:
KRSource(KRContext& context, std::string name, std::string extension); KRSource(KRContext& context, std::string name, std::string extension);

View File

@@ -38,7 +38,8 @@
#include "KRContextObject.h" #include "KRContextObject.h"
#include "KRDataBlock.h" #include "KRDataBlock.h"
class KRSourceManager : public KRResourceManager { class KRSourceManager : public KRResourceManager
{
public: public:
KRSourceManager(KRContext& context); KRSourceManager(KRContext& context);
virtual ~KRSourceManager(); virtual ~KRSourceManager();

View File

@@ -51,7 +51,8 @@ KRSpotLight::~KRSpotLight()
} }
std::string KRSpotLight::getElementName() { std::string KRSpotLight::getElementName()
{
return "spot_light"; return "spot_light";
} }
@@ -63,27 +64,33 @@ tinyxml2::XMLElement *KRSpotLight::saveXML( tinyxml2::XMLNode *parent)
return e; return e;
} }
void KRSpotLight::loadXML(tinyxml2::XMLElement *e) { void KRSpotLight::loadXML(tinyxml2::XMLElement* e)
{
KRLight::loadXML(e); KRLight::loadXML(e);
e->QueryFloatAttribute("inner_angle", &m_innerAngle); e->QueryFloatAttribute("inner_angle", &m_innerAngle);
e->QueryFloatAttribute("outer_angle", &m_outerAngle); e->QueryFloatAttribute("outer_angle", &m_outerAngle);
} }
float KRSpotLight::getInnerAngle() { float KRSpotLight::getInnerAngle()
{
return m_innerAngle; return m_innerAngle;
} }
float KRSpotLight::getOuterAngle() { float KRSpotLight::getOuterAngle()
{
return m_outerAngle; return m_outerAngle;
} }
void KRSpotLight::setInnerAngle(float innerAngle) { void KRSpotLight::setInnerAngle(float innerAngle)
{
m_innerAngle = innerAngle; m_innerAngle = innerAngle;
} }
void KRSpotLight::setOuterAngle(float outerAngle) { void KRSpotLight::setOuterAngle(float outerAngle)
{
m_outerAngle = outerAngle; m_outerAngle = outerAngle;
} }
AABB KRSpotLight::getBounds() { AABB KRSpotLight::getBounds()
{
float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE); float influence_radius = m_decayStart - sqrt(m_intensity * 0.01f) / sqrt(KRLIGHT_MIN_INFLUENCE);
if (influence_radius < m_flareOcclusionSize) { if (influence_radius < m_flareOcclusionSize) {
influence_radius = m_flareOcclusionSize; influence_radius = m_flareOcclusionSize;

View File

@@ -33,7 +33,8 @@
#include "KRLight.h" #include "KRLight.h"
class KRSpotLight : public KRLight { class KRSpotLight : public KRLight
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -59,10 +59,10 @@ KRSprite::KRSprite(KRScene &scene, std::string name) : KRNode(scene, name)
} }
KRSprite::~KRSprite() KRSprite::~KRSprite()
{ {}
}
std::string KRSprite::getElementName() { std::string KRSprite::getElementName()
{
return "sprite"; return "sprite";
} }
@@ -74,7 +74,8 @@ tinyxml2::XMLElement *KRSprite::saveXML( tinyxml2::XMLNode *parent)
return e; return e;
} }
void KRSprite::loadXML(tinyxml2::XMLElement *e) { void KRSprite::loadXML(tinyxml2::XMLElement* e)
{
KRNode::loadXML(e); KRNode::loadXML(e);
if (e->QueryFloatAttribute("sprite_alpha", &m_spriteAlpha) != tinyxml2::XML_SUCCESS) { if (e->QueryFloatAttribute("sprite_alpha", &m_spriteAlpha) != tinyxml2::XML_SUCCESS) {
@@ -90,7 +91,8 @@ void KRSprite::loadXML(tinyxml2::XMLElement *e) {
m_pSpriteTexture = NULL; m_pSpriteTexture = NULL;
} }
void KRSprite::setSpriteTexture(std::string sprite_texture) { void KRSprite::setSpriteTexture(std::string sprite_texture)
{
m_spriteTexture = sprite_texture; m_spriteTexture = sprite_texture;
m_pSpriteTexture = NULL; m_pSpriteTexture = NULL;
} }
@@ -105,12 +107,14 @@ float KRSprite::getSpriteAlpha() const
return m_spriteAlpha; return m_spriteAlpha;
} }
AABB KRSprite::getBounds() { AABB KRSprite::getBounds()
{
return AABB::Create(-Vector3::One() * 0.5f, Vector3::One() * 0.5f, getModelMatrix()); return AABB::Create(-Vector3::One() * 0.5f, Vector3::One() * 0.5f, getModelMatrix());
} }
void KRSprite::render(RenderInfo& ri) { void KRSprite::render(RenderInfo& ri)
{
if (m_lod_visible >= LOD_VISIBILITY_PRESTREAM && ri.renderPass == KRNode::RENDER_PASS_PRESTREAM) { if (m_lod_visible >= LOD_VISIBILITY_PRESTREAM && ri.renderPass == KRNode::RENDER_PASS_PRESTREAM) {
// Pre-stream sprites, even if the alpha is zero // Pre-stream sprites, even if the alpha is zero

View File

@@ -35,7 +35,8 @@
#include "KRNode.h" #include "KRNode.h"
#include "KRTexture.h" #include "KRTexture.h"
class KRSprite : public KRNode { class KRSprite : public KRNode
{
public: public:
static void InitNodeInfo(KrNodeInfo* nodeInfo); static void InitNodeInfo(KrNodeInfo* nodeInfo);

View File

@@ -79,8 +79,7 @@ void KRStreamerThread::run()
std::chrono::microseconds sleep_duration(15000); std::chrono::microseconds sleep_duration(15000);
while(!m_stop) while (!m_stop) {
{
m_context.doStreaming(); m_context.doStreaming();
std::this_thread::sleep_for(sleep_duration); std::this_thread::sleep_for(sleep_duration);
} }

View File

@@ -35,8 +35,7 @@
KRSurfaceManager::KRSurfaceManager(KRContext& context) KRSurfaceManager::KRSurfaceManager(KRContext& context)
: KRContextObject(context) : KRContextObject(context)
, m_topSurfaceHandle(0) , m_topSurfaceHandle(0)
{ {}
}
KRSurfaceManager::~KRSurfaceManager() KRSurfaceManager::~KRSurfaceManager()
{ {

View File

@@ -85,8 +85,7 @@ KrResult KRSwapchain::create(KRDevice& device, VkSurfaceKHR& surface, VkSurfaceF
swapChainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; swapChainCreateInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
swapChainCreateInfo.queueFamilyIndexCount = 0; swapChainCreateInfo.queueFamilyIndexCount = 0;
swapChainCreateInfo.pQueueFamilyIndices = nullptr; swapChainCreateInfo.pQueueFamilyIndices = nullptr;
} } else {
else {
swapChainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT; swapChainCreateInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
swapChainCreateInfo.queueFamilyIndexCount = 2; swapChainCreateInfo.queueFamilyIndexCount = 2;
swapChainCreateInfo.pQueueFamilyIndices = queueFamilyIndices; swapChainCreateInfo.pQueueFamilyIndices = queueFamilyIndices;

Some files were not shown because too many files have changed in this diff Show More