Refactor - rename KRDataBlock to mimir::Block
This commit is contained in:
@@ -3,6 +3,7 @@ add_subdirectory(public)
|
|||||||
set(KRAKEN_PUBLIC_HEADERS "${KRAKEN_PUBLIC_HEADERS}" PARENT_SCOPE)
|
set(KRAKEN_PUBLIC_HEADERS "${KRAKEN_PUBLIC_HEADERS}" PARENT_SCOPE)
|
||||||
|
|
||||||
# Private Implementation
|
# Private Implementation
|
||||||
|
add_sources(block.cpp)
|
||||||
add_sources(kraken.cpp)
|
add_sources(kraken.cpp)
|
||||||
add_sources(KRAmbientZone.cpp)
|
add_sources(KRAmbientZone.cpp)
|
||||||
add_sources(KRAnimation.cpp)
|
add_sources(KRAnimation.cpp)
|
||||||
@@ -41,7 +42,6 @@ IF(APPLE)
|
|||||||
ENDIF()
|
ENDIF()
|
||||||
ENDIF (APPLE)
|
ENDIF (APPLE)
|
||||||
add_sources(KRContextObject.cpp)
|
add_sources(KRContextObject.cpp)
|
||||||
add_sources(KRDataBlock.cpp)
|
|
||||||
add_sources(KRDirectionalLight.cpp)
|
add_sources(KRDirectionalLight.cpp)
|
||||||
IF(APPLE)
|
IF(APPLE)
|
||||||
add_sources(KRDSP_vDSP.cpp)
|
add_sources(KRDSP_vDSP.cpp)
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
#include "KRAnimationCurve.h"
|
#include "KRAnimationCurve.h"
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRAnimation::KRAnimation(KRContext& context, std::string name) : KRResource(context, name)
|
KRAnimation::KRAnimation(KRContext& context, std::string name) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_auto_play = false;
|
m_auto_play = false;
|
||||||
@@ -61,7 +63,7 @@ void KRAnimation::addLayer(KRAnimationLayer* layer)
|
|||||||
m_layers[layer->getName()] = layer;
|
m_layers[layer->getName()] = layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRAnimation::save(KRDataBlock& data)
|
bool KRAnimation::save(Block& data)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
tinyxml2::XMLElement* animation_node = doc.NewElement("animation");
|
tinyxml2::XMLElement* animation_node = doc.NewElement("animation");
|
||||||
@@ -82,7 +84,7 @@ bool KRAnimation::save(KRDataBlock& data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRAnimation* KRAnimation::Load(KRContext& context, const std::string& name, KRDataBlock* data)
|
KRAnimation* KRAnimation::Load(KRContext& context, const std::string& name, Block* data)
|
||||||
{
|
{
|
||||||
std::string xml_string = data->getString();
|
std::string xml_string = data->getString();
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
#include "KRAnimationLayer.h"
|
#include "KRAnimationLayer.h"
|
||||||
|
|
||||||
@@ -46,9 +46,9 @@ public:
|
|||||||
virtual ~KRAnimation();
|
virtual ~KRAnimation();
|
||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
static KRAnimation* Load(KRContext& context, const std::string& name, KRDataBlock* data);
|
static KRAnimation* Load(KRContext& context, const std::string& name, mimir::Block* data);
|
||||||
|
|
||||||
void addLayer(KRAnimationLayer* layer);
|
void addLayer(KRAnimationLayer* layer);
|
||||||
unordered_map<std::string, KRAnimationLayer*>& getLayers();
|
unordered_map<std::string, KRAnimationLayer*>& getLayers();
|
||||||
|
|||||||
@@ -31,11 +31,13 @@
|
|||||||
|
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "KRAnimationCurve.h"
|
#include "KRAnimationCurve.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRAnimationCurve::KRAnimationCurve(KRContext& context, const std::string& name) : KRResource(context, name)
|
KRAnimationCurve::KRAnimationCurve(KRContext& context, const std::string& name) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = new KRDataBlock();
|
m_pData = new Block();
|
||||||
m_pData->expand(sizeof(animation_curve_header));
|
m_pData->expand(sizeof(animation_curve_header));
|
||||||
m_pData->lock();
|
m_pData->lock();
|
||||||
animation_curve_header* header = (animation_curve_header*)m_pData->getStart();
|
animation_curve_header* header = (animation_curve_header*)m_pData->getStart();
|
||||||
@@ -51,7 +53,7 @@ KRAnimationCurve::~KRAnimationCurve()
|
|||||||
m_pData->unload();
|
m_pData->unload();
|
||||||
delete m_pData;
|
delete m_pData;
|
||||||
}
|
}
|
||||||
bool KRAnimationCurve::load(KRDataBlock* data)
|
bool KRAnimationCurve::load(Block* data)
|
||||||
{
|
{
|
||||||
m_pData->unload();
|
m_pData->unload();
|
||||||
delete m_pData;
|
delete m_pData;
|
||||||
@@ -69,13 +71,13 @@ 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(Block& data)
|
||||||
{
|
{
|
||||||
data.append(*m_pData);
|
data.append(*m_pData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRAnimationCurve* KRAnimationCurve::Load(KRContext& context, const std::string& name, KRDataBlock* data)
|
KRAnimationCurve* KRAnimationCurve::Load(KRContext& context, const std::string& name, Block* data)
|
||||||
{
|
{
|
||||||
KRAnimationCurve* new_animation_curve = new KRAnimationCurve(context, name);
|
KRAnimationCurve* new_animation_curve = new KRAnimationCurve(context, name);
|
||||||
if (new_animation_curve->load(data)) {
|
if (new_animation_curve->load(data)) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
|
|
||||||
class KRAnimationCurve : public KRResource
|
class KRAnimationCurve : public KRResource
|
||||||
@@ -45,8 +45,8 @@ public:
|
|||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
virtual bool save(const std::string& path);
|
virtual bool save(const std::string& path);
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
virtual bool load(KRDataBlock* data);
|
virtual bool load(mimir::Block* data);
|
||||||
|
|
||||||
float getFrameRate();
|
float getFrameRate();
|
||||||
void setFrameRate(float frame_rate);
|
void setFrameRate(float frame_rate);
|
||||||
@@ -59,7 +59,7 @@ public:
|
|||||||
void setValue(int frame_number, float value);
|
void setValue(int frame_number, float value);
|
||||||
|
|
||||||
|
|
||||||
static KRAnimationCurve* Load(KRContext& context, const std::string& name, KRDataBlock* data);
|
static KRAnimationCurve* Load(KRContext& context, const std::string& name, mimir::Block* data);
|
||||||
|
|
||||||
bool valueChanges(float start_time, float duration);
|
bool valueChanges(float start_time, float duration);
|
||||||
bool valueChanges(int start_frame, int frame_count);
|
bool valueChanges(int start_frame, int frame_count);
|
||||||
@@ -71,7 +71,7 @@ public:
|
|||||||
void _unlockData();
|
void _unlockData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ void KRAnimationCurveManager::deleteAnimationCurve(KRAnimationCurve* curve)
|
|||||||
delete curve;
|
delete curve;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRAnimationCurveManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRAnimationCurveManager::loadResource(const std::string& name, const std::string& extension, mimir::Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("kranimationcurve") == 0) {
|
if (extension.compare("kranimationcurve") == 0) {
|
||||||
return loadAnimationCurve(name, data);
|
return loadAnimationCurve(name, data);
|
||||||
@@ -65,7 +65,7 @@ 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, mimir::Block* data)
|
||||||
{
|
{
|
||||||
KRAnimationCurve* pAnimationCurve = KRAnimationCurve::Load(*m_pContext, name, data);
|
KRAnimationCurve* pAnimationCurve = KRAnimationCurve::Load(*m_pContext, name, data);
|
||||||
if (pAnimationCurve) {
|
if (pAnimationCurve) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#include "KRAnimationCurve.h"
|
#include "KRAnimationCurve.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
|
|
||||||
@@ -47,10 +47,10 @@ public:
|
|||||||
KRAnimationCurveManager(KRContext& context);
|
KRAnimationCurveManager(KRContext& context);
|
||||||
virtual ~KRAnimationCurveManager();
|
virtual ~KRAnimationCurveManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
KRAnimationCurve* loadAnimationCurve(const std::string& name, KRDataBlock* data);
|
KRAnimationCurve* loadAnimationCurve(const std::string& name, mimir::Block* data);
|
||||||
KRAnimationCurve* getAnimationCurve(const std::string& name);
|
KRAnimationCurve* getAnimationCurve(const std::string& name);
|
||||||
void addAnimationCurve(KRAnimationCurve* new_animation_curve);
|
void addAnimationCurve(KRAnimationCurve* new_animation_curve);
|
||||||
unordered_map<std::string, KRAnimationCurve*>& getAnimationCurves();
|
unordered_map<std::string, KRAnimationCurve*>& getAnimationCurves();
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ void KRAnimationManager::endFrame(float deltaTime)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRAnimationManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRAnimationManager::loadResource(const std::string& name, const std::string& extension, mimir::Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("kranimation") == 0) {
|
if (extension.compare("kranimation") == 0) {
|
||||||
return loadAnimation(name.c_str(), data);
|
return loadAnimation(name.c_str(), data);
|
||||||
@@ -97,7 +97,7 @@ 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, mimir::Block* data)
|
||||||
{
|
{
|
||||||
KRAnimation* pAnimation = KRAnimation::Load(*m_pContext, szName, data);
|
KRAnimation* pAnimation = KRAnimation::Load(*m_pContext, szName, data);
|
||||||
addAnimation(pAnimation);
|
addAnimation(pAnimation);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#include "KRAnimation.h"
|
#include "KRAnimation.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -47,10 +47,10 @@ public:
|
|||||||
KRAnimationManager(KRContext& context);
|
KRAnimationManager(KRContext& context);
|
||||||
virtual ~KRAnimationManager();
|
virtual ~KRAnimationManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
KRAnimation* loadAnimation(const char* szName, KRDataBlock* data);
|
KRAnimation* loadAnimation(const char* szName, mimir::Block* data);
|
||||||
KRAnimation* getAnimation(const char* szName);
|
KRAnimation* getAnimation(const char* szName);
|
||||||
void addAnimation(KRAnimation* new_animation);
|
void addAnimation(KRAnimation* new_animation);
|
||||||
unordered_map<std::string, KRAnimation*>& getAnimations();
|
unordered_map<std::string, KRAnimation*>& getAnimations();
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
class KRAudioManager;
|
class KRAudioManager;
|
||||||
class KRAudioSample;
|
class KRAudioSample;
|
||||||
@@ -56,7 +56,7 @@ private:
|
|||||||
int m_frameCount;
|
int m_frameCount;
|
||||||
int m_frameRate;
|
int m_frameRate;
|
||||||
int m_bytesPerFrame;
|
int m_bytesPerFrame;
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
|
|
||||||
KRAudioSample* m_audioSample;
|
KRAudioSample* m_audioSample;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,12 +32,14 @@
|
|||||||
#include "KRAudioManager.h"
|
#include "KRAudioManager.h"
|
||||||
#include "KRAudioSample.h"
|
#include "KRAudioSample.h"
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRAudioBuffer.h"
|
#include "KRAudioBuffer.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "KRCollider.h"
|
#include "KRCollider.h"
|
||||||
#include "KRDSP.h"
|
#include "KRDSP.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRAudioManager::KRAudioManager(KRContext& context)
|
KRAudioManager::KRAudioManager(KRContext& context)
|
||||||
: KRResourceManager(context)
|
: KRResourceManager(context)
|
||||||
, m_initialized(false)
|
, m_initialized(false)
|
||||||
@@ -1199,7 +1201,7 @@ void KRAudioManager::destroy()
|
|||||||
|
|
||||||
cleanupAudio();
|
cleanupAudio();
|
||||||
|
|
||||||
for (std::vector<KRDataBlock*>::iterator itr = m_bufferPoolIdle.begin(); itr != m_bufferPoolIdle.end(); itr++) {
|
for (std::vector<Block*>::iterator itr = m_bufferPoolIdle.begin(); itr != m_bufferPoolIdle.end(); itr++) {
|
||||||
delete* itr;
|
delete* itr;
|
||||||
}
|
}
|
||||||
m_bufferPoolIdle.clear();
|
m_bufferPoolIdle.clear();
|
||||||
@@ -1257,7 +1259,7 @@ void KRAudioManager::add(KRAudioSample* sound)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRAudioManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRAudioManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("mtl") == 0 ||
|
if (extension.compare("mtl") == 0 ||
|
||||||
extension.compare("mp3") == 0 ||
|
extension.compare("mp3") == 0 ||
|
||||||
@@ -1276,7 +1278,7 @@ KRResource* KRAudioManager::getResource(const std::string& name, const std::stri
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRAudioSample* KRAudioManager::load(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRAudioSample* KRAudioManager::load(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
KRAudioSample* Sound = new KRAudioSample(getContext(), name, extension, data);
|
KRAudioSample* Sound = new KRAudioSample(getContext(), name, extension, data);
|
||||||
if (Sound) add(Sound);
|
if (Sound) add(Sound);
|
||||||
@@ -1290,23 +1292,23 @@ KRAudioSample* KRAudioManager::get(const std::string& name)
|
|||||||
return m_sounds[lower_name];
|
return m_sounds[lower_name];
|
||||||
}
|
}
|
||||||
|
|
||||||
KRDataBlock* KRAudioManager::getBufferData(int size)
|
Block* KRAudioManager::getBufferData(int size)
|
||||||
{
|
{
|
||||||
KRDataBlock* data;
|
Block* data;
|
||||||
// Note: We only store and recycle buffers with a size of CIRCA_AUDIO_MAX_BUFFER_SIZE
|
// Note: We only store and recycle buffers with a size of CIRCA_AUDIO_MAX_BUFFER_SIZE
|
||||||
if (size == KRENGINE_AUDIO_MAX_BUFFER_SIZE && m_bufferPoolIdle.size() > 0) {
|
if (size == KRENGINE_AUDIO_MAX_BUFFER_SIZE && m_bufferPoolIdle.size() > 0) {
|
||||||
// Recycle a buffer from the pool
|
// Recycle a buffer from the pool
|
||||||
data = m_bufferPoolIdle.back();
|
data = m_bufferPoolIdle.back();
|
||||||
m_bufferPoolIdle.pop_back();
|
m_bufferPoolIdle.pop_back();
|
||||||
} else {
|
} else {
|
||||||
data = new KRDataBlock();
|
data = new Block();
|
||||||
data->expand(size);
|
data->expand(size);
|
||||||
}
|
}
|
||||||
data->lock();
|
data->lock();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRAudioManager::recycleBufferData(KRDataBlock* data)
|
void KRAudioManager::recycleBufferData(Block* data)
|
||||||
{
|
{
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
data->unlock();
|
data->unlock();
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
#include "KRResourceManager.h"
|
#include "KRResourceManager.h"
|
||||||
|
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRAudioSource.h"
|
#include "KRAudioSource.h"
|
||||||
#include "KRDSP.h"
|
#include "KRDSP.h"
|
||||||
|
|
||||||
@@ -100,14 +100,14 @@ public:
|
|||||||
virtual ~KRAudioManager();
|
virtual ~KRAudioManager();
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
unordered_map<std::string, KRAudioSample*>& getSounds();
|
unordered_map<std::string, KRAudioSample*>& getSounds();
|
||||||
|
|
||||||
void add(KRAudioSample* Sound);
|
void add(KRAudioSample* Sound);
|
||||||
|
|
||||||
KRAudioSample* load(const std::string& name, const std::string& extension, KRDataBlock* data);
|
KRAudioSample* load(const std::string& name, const std::string& extension, mimir::Block* data);
|
||||||
KRAudioSample* get(const std::string& name);
|
KRAudioSample* get(const std::string& name);
|
||||||
|
|
||||||
// Listener position and orientation
|
// Listener position and orientation
|
||||||
@@ -132,8 +132,8 @@ public:
|
|||||||
|
|
||||||
void makeCurrentContext();
|
void makeCurrentContext();
|
||||||
|
|
||||||
KRDataBlock* getBufferData(int size);
|
mimir::Block* getBufferData(int size);
|
||||||
void recycleBufferData(KRDataBlock* data);
|
void recycleBufferData(mimir::Block* data);
|
||||||
|
|
||||||
void activateAudioSource(KRAudioSource* audioSource);
|
void activateAudioSource(KRAudioSource* audioSource);
|
||||||
void deactivateAudioSource(KRAudioSource* audioSource);
|
void deactivateAudioSource(KRAudioSource* audioSource);
|
||||||
@@ -180,7 +180,7 @@ private:
|
|||||||
|
|
||||||
unordered_map<std::string, KRAudioSample*> m_sounds;
|
unordered_map<std::string, KRAudioSample*> m_sounds;
|
||||||
|
|
||||||
std::vector<KRDataBlock*> m_bufferPoolIdle;
|
std::vector<mimir::Block*> m_bufferPoolIdle;
|
||||||
|
|
||||||
std::vector<KRAudioBuffer*> m_bufferCache;
|
std::vector<KRAudioBuffer*> m_bufferCache;
|
||||||
|
|
||||||
|
|||||||
@@ -31,14 +31,16 @@
|
|||||||
|
|
||||||
#include "KRAudioSample.h"
|
#include "KRAudioSample.h"
|
||||||
#include "KRAudioManager.h"
|
#include "KRAudioManager.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRAudioBuffer.h"
|
#include "KRAudioBuffer.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "KRDSP.h"
|
#include "KRDSP.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = new KRDataBlock();
|
m_pData = new Block();
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@@ -54,7 +56,7 @@ KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string e
|
|||||||
m_last_frame_used = 0;
|
m_last_frame_used = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string extension, KRDataBlock* data) : KRResource(context, name)
|
KRAudioSample::KRAudioSample(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = data;
|
m_pData = data;
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
@@ -329,7 +331,7 @@ std::string KRAudioSample::getExtension()
|
|||||||
return m_extension;
|
return m_extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRAudioSample::save(KRDataBlock& data)
|
bool KRAudioSample::save(Block& data)
|
||||||
{
|
{
|
||||||
data.append(*m_pData);
|
data.append(*m_pData);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
|
|
||||||
class KRAudioBuffer;
|
class KRAudioBuffer;
|
||||||
@@ -43,12 +43,12 @@ class KRAudioSample : public KRResource
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
KRAudioSample(KRContext& context, std::string name, std::string extension);
|
KRAudioSample(KRContext& context, std::string name, std::string extension);
|
||||||
KRAudioSample(KRContext& context, std::string name, std::string extension, KRDataBlock* data);
|
KRAudioSample(KRContext& context, std::string name, std::string extension, mimir::Block* data);
|
||||||
virtual ~KRAudioSample();
|
virtual ~KRAudioSample();
|
||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
|
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
float getDuration();
|
float getDuration();
|
||||||
KRAudioBuffer* getBuffer(int index);
|
KRAudioBuffer* getBuffer(int index);
|
||||||
@@ -66,7 +66,7 @@ private:
|
|||||||
__int64_t m_last_frame_used;
|
__int64_t m_last_frame_used;
|
||||||
|
|
||||||
std::string m_extension;
|
std::string m_extension;
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// Apple Audio Toolbox
|
// Apple Audio Toolbox
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
const int KRENGINE_KRBUNDLE_HEADER_SIZE = 512;
|
const int KRENGINE_KRBUNDLE_HEADER_SIZE = 512;
|
||||||
|
|
||||||
typedef struct _tar_header
|
typedef struct _tar_header
|
||||||
@@ -49,7 +51,7 @@ typedef struct _tar_header
|
|||||||
|
|
||||||
} tar_header_type;
|
} tar_header_type;
|
||||||
|
|
||||||
KRBundle::KRBundle(KRContext& context, std::string name, KRDataBlock* pData) : KRResource(context, name)
|
KRBundle::KRBundle(KRContext& context, std::string name, Block* pData) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = pData;
|
m_pData = pData;
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ KRBundle::KRBundle(KRContext& context, std::string name, KRDataBlock* pData) : K
|
|||||||
file_pos += 512; // Skip past the header to the file contents
|
file_pos += 512; // Skip past the header to the file contents
|
||||||
if (file_header.file_name[0] != '\0' && file_header.file_name[0] != '.') {
|
if (file_header.file_name[0] != '\0' && file_header.file_name[0] != '.') {
|
||||||
// We ignore the last two records in the tar file, which are zero'ed out tar_header structures
|
// We ignore the last two records in the tar file, which are zero'ed out tar_header structures
|
||||||
KRDataBlock* pFileData = pData->getSubBlock((int)file_pos, (int)file_size);
|
Block* pFileData = pData->getSubBlock((int)file_pos, (int)file_size);
|
||||||
context.loadResource(file_header.file_name, pFileData);
|
context.loadResource(file_header.file_name, pFileData);
|
||||||
}
|
}
|
||||||
file_pos += RoundUpSize(file_size);
|
file_pos += RoundUpSize(file_size);
|
||||||
@@ -71,7 +73,7 @@ KRBundle::KRBundle(KRContext& context, std::string name, KRDataBlock* pData) : K
|
|||||||
KRBundle::KRBundle(KRContext& context, std::string name) : KRResource(context, name)
|
KRBundle::KRBundle(KRContext& context, std::string name) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
// Create an empty krbundle (tar) file, initialized with two zero-ed out file headers, which terminate it.
|
// Create an empty krbundle (tar) file, initialized with two zero-ed out file headers, which terminate it.
|
||||||
m_pData = new KRDataBlock();
|
m_pData = new Block();
|
||||||
m_pData->expand(KRENGINE_KRBUNDLE_HEADER_SIZE * 2);
|
m_pData->expand(KRENGINE_KRBUNDLE_HEADER_SIZE * 2);
|
||||||
m_pData->lock();
|
m_pData->lock();
|
||||||
memset(m_pData->getStart(), 0, m_pData->getSize());
|
memset(m_pData->getStart(), 0, m_pData->getSize());
|
||||||
@@ -106,7 +108,7 @@ 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(Block& 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
|
||||||
@@ -115,10 +117,10 @@ bool KRBundle::save(KRDataBlock& data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRDataBlock* KRBundle::append(KRResource& resource)
|
Block* KRBundle::append(KRResource& resource)
|
||||||
{
|
{
|
||||||
// Serialize resource to binary representation
|
// Serialize resource to binary representation
|
||||||
KRDataBlock resource_data;
|
Block resource_data;
|
||||||
resource.save(resource_data);
|
resource.save(resource_data);
|
||||||
|
|
||||||
std::string file_name = resource.getName() + "." + resource.getExtension();
|
std::string file_name = resource.getName() + "." + resource.getExtension();
|
||||||
@@ -165,6 +167,6 @@ KRDataBlock* KRBundle::append(KRResource& resource)
|
|||||||
|
|
||||||
m_pData->unlock();
|
m_pData->unlock();
|
||||||
|
|
||||||
KRDataBlock* pFileData = m_pData->getSubBlock((int)resource_data_start, (int)resource_data.getSize());
|
Block* pFileData = m_pData->getSubBlock((int)resource_data_start, (int)resource_data.getSize());
|
||||||
return pFileData;
|
return pFileData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,21 +32,21 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.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, mimir::Block* pData);
|
||||||
KRBundle(KRContext& context, std::string name);
|
KRBundle(KRContext& context, std::string name);
|
||||||
virtual ~KRBundle();
|
virtual ~KRBundle();
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
virtual bool save(const std::string& path);
|
virtual bool save(const std::string& path);
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
KRDataBlock* append(KRResource& resource);
|
mimir::Block* append(KRResource& resource);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
static size_t RoundUpSize(size_t s);
|
static size_t RoundUpSize(size_t s);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ KRBundleManager::~KRBundleManager()
|
|||||||
m_bundles.clear();
|
m_bundles.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRBundleManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRBundleManager::loadResource(const std::string& name, const std::string& extension, mimir::Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("krbundle") == 0) {
|
if (extension.compare("krbundle") == 0) {
|
||||||
return loadBundle(name.c_str(), data);
|
return loadBundle(name.c_str(), data);
|
||||||
@@ -61,7 +61,7 @@ KRResource* KRBundleManager::getResource(const std::string& name, const std::str
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRBundle* KRBundleManager::loadBundle(const char* szName, KRDataBlock* pData)
|
KRBundle* KRBundleManager::loadBundle(const char* szName, mimir::Block* pData)
|
||||||
{
|
{
|
||||||
KRBundle* pBundle = new KRBundle(*m_pContext, szName, pData);
|
KRBundle* pBundle = new KRBundle(*m_pContext, szName, pData);
|
||||||
m_bundles[szName] = pBundle;
|
m_bundles[szName] = pBundle;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
class KRContext;
|
class KRContext;
|
||||||
class KRBundle;
|
class KRBundle;
|
||||||
@@ -46,10 +46,10 @@ public:
|
|||||||
KRBundleManager(KRContext& context);
|
KRBundleManager(KRContext& context);
|
||||||
~KRBundleManager();
|
~KRBundleManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
KRBundle* loadBundle(const char* szName, KRDataBlock* pData);
|
KRBundle* loadBundle(const char* szName, mimir::Block* pData);
|
||||||
KRBundle* getBundle(const char* szName);
|
KRBundle* getBundle(const char* szName);
|
||||||
KRBundle* createBundle(const char* szName);
|
KRBundle* createBundle(const char* szName);
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
#include "KRRenderPass.h"
|
#include "KRRenderPass.h"
|
||||||
#include "KRPipeline.h"
|
#include "KRPipeline.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo)
|
void KRCamera::InitNodeInfo(KrNodeInfo* nodeInfo)
|
||||||
{
|
{
|
||||||
@@ -778,7 +780,7 @@ void KRCamera::renderPost(VkCommandBuffer& commandBuffer, KRSurface& surface)
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (m_debug_text_vertices.getSize() > 0) {
|
if (m_debug_text_vertices.getSize() > 0) {
|
||||||
m_debug_text_vertices = KRDataBlock();
|
m_debug_text_vertices = Block();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ private:
|
|||||||
float v;
|
float v;
|
||||||
} DebugTextVertexData;
|
} DebugTextVertexData;
|
||||||
|
|
||||||
KRDataBlock m_debug_text_vertices;
|
mimir::Block m_debug_text_vertices;
|
||||||
KRMeshManager::KRVBOData m_debug_text_vbo_data;
|
KRMeshManager::KRVBOData m_debug_text_vbo_data;
|
||||||
|
|
||||||
// std::string getDebugText();
|
// std::string getDebugText();
|
||||||
|
|||||||
@@ -48,6 +48,8 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
// TODO - Make values dynamic after Vulkan conversion:
|
// TODO - Make values dynamic after Vulkan conversion:
|
||||||
int KRContext::KRENGINE_MAX_PIPELINE_HANDLES = 4000;
|
int KRContext::KRENGINE_MAX_PIPELINE_HANDLES = 4000;
|
||||||
int KRContext::KRENGINE_GPU_MEM_MAX = 256000000;
|
int KRContext::KRENGINE_GPU_MEM_MAX = 256000000;
|
||||||
@@ -325,7 +327,7 @@ 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, Block* 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);
|
||||||
@@ -394,7 +396,7 @@ 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;
|
||||||
}
|
}
|
||||||
KRDataBlock* data = new KRDataBlock();
|
Block* data = new Block();
|
||||||
if (!data->load(loadResourceInfo->pResourcePath)) {
|
if (!data->load(loadResourceInfo->pResourcePath)) {
|
||||||
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KRContext::loadResource - Failed to open file: %s", loadResourceInfo->pResourcePath);
|
KRContext::Log(KRContext::LOG_LEVEL_ERROR, "KRContext::loadResource - Failed to open file: %s", loadResourceInfo->pResourcePath);
|
||||||
delete data;
|
delete data;
|
||||||
@@ -457,7 +459,7 @@ KrResult KRContext::unmapResource(const KrUnmapResourceInfo* unmapResourceInfo)
|
|||||||
KrResult KRContext::getResourceData(const KrGetResourceDataInfo* getResourceDataInfo, KrGetResourceDataCallback callback)
|
KrResult KRContext::getResourceData(const KrGetResourceDataInfo* getResourceDataInfo, KrGetResourceDataCallback callback)
|
||||||
{
|
{
|
||||||
// TODO - This will be asynchronous... The function will always succeed, but the asynchronous result could report a failure
|
// TODO - This will be asynchronous... The function will always succeed, but the asynchronous result could report a failure
|
||||||
KRDataBlock data;
|
Block data;
|
||||||
KrGetResourceDataResult result = {};
|
KrGetResourceDataResult result = {};
|
||||||
|
|
||||||
KRResource* resource = nullptr;
|
KRResource* resource = nullptr;
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ public:
|
|||||||
}
|
}
|
||||||
// -=-=-=- End: Helper functions for Public API Entry Points
|
// -=-=-=- End: Helper functions for Public API Entry Points
|
||||||
|
|
||||||
KRResource* loadResource(const std::string& file_name, KRDataBlock* data);
|
KRResource* loadResource(const std::string& file_name, mimir::Block* data);
|
||||||
|
|
||||||
|
|
||||||
KRBundleManager* getBundleManager();
|
KRBundleManager* getBundleManager();
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include "KRDevice.h"
|
#include "KRDevice.h"
|
||||||
#include "KRDeviceManager.h"
|
#include "KRDeviceManager.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRDevice::KRDevice(KRContext& context, const VkPhysicalDevice& device)
|
KRDevice::KRDevice(KRContext& context, const VkPhysicalDevice& device)
|
||||||
: KRContextObject(context)
|
: KRContextObject(context)
|
||||||
, m_device(device)
|
, m_device(device)
|
||||||
@@ -713,14 +715,14 @@ void KRDevice::streamStart()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRDevice::streamUpload(KRDataBlock& data, VkBuffer destination)
|
void KRDevice::streamUpload(Block& data, VkBuffer destination)
|
||||||
{
|
{
|
||||||
data.lock();
|
data.lock();
|
||||||
streamUpload(data.getStart(), data.getSize(), destination);
|
streamUpload(data.getStart(), data.getSize(), destination);
|
||||||
data.unlock();
|
data.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRDevice::graphicsUpload(VkCommandBuffer& commandBuffer, KRDataBlock& data, VkBuffer destination)
|
void KRDevice::graphicsUpload(VkCommandBuffer& commandBuffer, Block& data, VkBuffer destination)
|
||||||
{
|
{
|
||||||
data.lock();
|
data.lock();
|
||||||
graphicsUpload(commandBuffer, data.getStart(), data.getSize(), destination);
|
graphicsUpload(commandBuffer, data.getStart(), data.getSize(), destination);
|
||||||
@@ -779,7 +781,7 @@ void KRDevice::streamUpload(void* data, size_t size, Vector3i dimensions, VkImag
|
|||||||
streamUploadImpl(size, dimensions, destination, 0, 1);
|
streamUploadImpl(size, dimensions, destination, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRDevice::streamUpload(KRDataBlock& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount)
|
void KRDevice::streamUpload(Block& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount)
|
||||||
{
|
{
|
||||||
checkFlushStreamBuffer(size);
|
checkFlushStreamBuffer(size);
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class KRDataBlock;
|
namespace mimir {
|
||||||
|
class Block;
|
||||||
|
}
|
||||||
|
|
||||||
class KRDevice : public KRContextObject
|
class KRDevice : public KRContextObject
|
||||||
{
|
{
|
||||||
@@ -69,13 +71,13 @@ public:
|
|||||||
KrResult selectPresentMode(VkSurfaceKHR& surface, VkPresentModeKHR& selectedPresentMode) const;
|
KrResult selectPresentMode(VkSurfaceKHR& surface, VkPresentModeKHR& selectedPresentMode) const;
|
||||||
|
|
||||||
void streamStart();
|
void streamStart();
|
||||||
void streamUpload(KRDataBlock& data, VkBuffer destination);
|
void streamUpload(mimir::Block& data, VkBuffer destination);
|
||||||
void streamUpload(KRDataBlock& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount);
|
void streamUpload(mimir::Block& data, VkImage destination, size_t offset, size_t size, Vector3i dimensions, uint32_t baseMipLevel, uint32_t levelCount);
|
||||||
void streamUpload(void* data, size_t size, VkBuffer destination);
|
void streamUpload(void* data, size_t size, VkBuffer destination);
|
||||||
void streamUpload(void* data, size_t size, Vector3i dimensions, VkImage destination);
|
void streamUpload(void* data, size_t size, Vector3i dimensions, VkImage destination);
|
||||||
void streamEnd();
|
void streamEnd();
|
||||||
|
|
||||||
void graphicsUpload(VkCommandBuffer& commandBuffer, KRDataBlock& data, VkBuffer destination);
|
void graphicsUpload(VkCommandBuffer& commandBuffer, mimir::Block& data, VkBuffer destination);
|
||||||
void graphicsUpload(VkCommandBuffer& commandBuffer, void* data, size_t size, VkBuffer destination);
|
void graphicsUpload(VkCommandBuffer& commandBuffer, void* data, size_t size, VkBuffer destination);
|
||||||
|
|
||||||
void createDescriptorSets(const std::vector<VkDescriptorSetLayout>& layouts, std::vector<VkDescriptorSet>& descriptorSets);
|
void createDescriptorSets(const std::vector<VkDescriptorSetLayout>& layouts, std::vector<VkDescriptorSet>& descriptorSets);
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
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;
|
||||||
@@ -83,7 +85,7 @@ bool KRMaterial::needsVertexTangents()
|
|||||||
return m_normalMap.size() > 0;
|
return m_normalMap.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRMaterial::save(KRDataBlock& data)
|
bool KRMaterial::save(Block& data)
|
||||||
{
|
{
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
stream.precision(std::numeric_limits<long double>::digits10);
|
stream.precision(std::numeric_limits<long double>::digits10);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
virtual ~KRMaterial();
|
virtual ~KRMaterial();
|
||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
|
|
||||||
void setAmbientMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset);
|
void setAmbientMap(std::string texture_name, Vector2 texture_scale, Vector2 texture_offset);
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRMaterialManager.h"
|
#include "KRMaterialManager.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
|
|
||||||
KRMaterialManager::KRMaterialManager(KRContext& context, KRTextureManager* pTextureManager, KRPipelineManager* pPipelineManager) : KRResourceManager(context)
|
KRMaterialManager::KRMaterialManager(KRContext& context, KRTextureManager* pTextureManager, KRPipelineManager* pPipelineManager) : KRResourceManager(context)
|
||||||
{
|
{
|
||||||
@@ -44,7 +46,7 @@ KRMaterialManager::~KRMaterialManager()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRMaterialManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRMaterialManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("mtl") == 0) {
|
if (extension.compare("mtl") == 0) {
|
||||||
return load(name.c_str(), data);
|
return load(name.c_str(), data);
|
||||||
@@ -95,7 +97,7 @@ 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, Block* data)
|
||||||
{
|
{
|
||||||
KRMaterial* pMaterial = NULL;
|
KRMaterial* pMaterial = NULL;
|
||||||
char szSymbol[16][256];
|
char szSymbol[16][256];
|
||||||
|
|||||||
@@ -49,10 +49,10 @@ public:
|
|||||||
KRMaterialManager(KRContext& context, KRTextureManager* pTextureManager, KRPipelineManager* pPipelineManager);
|
KRMaterialManager(KRContext& context, KRTextureManager* pTextureManager, KRPipelineManager* pPipelineManager);
|
||||||
virtual ~KRMaterialManager();
|
virtual ~KRMaterialManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
KRMaterial* load(const char* szName, KRDataBlock* data);
|
KRMaterial* load(const char* szName, mimir::Block* data);
|
||||||
void add(KRMaterial* new_material);
|
void add(KRMaterial* new_material);
|
||||||
KRMaterial* getMaterial(const std::string& name);
|
KRMaterial* getMaterial(const std::string& name);
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,8 @@
|
|||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "../3rdparty/forsyth/forsyth.h"
|
#include "../3rdparty/forsyth/forsyth.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRMesh::KRMesh(KRContext& context, std::string name) : KRResource(context, name)
|
KRMesh::KRMesh(KRContext& context, std::string name) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
setName(name);
|
setName(name);
|
||||||
@@ -50,7 +52,7 @@ 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, Block* data) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
setName(name);
|
setName(name);
|
||||||
|
|
||||||
@@ -149,13 +151,13 @@ 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(Block& data)
|
||||||
{
|
{
|
||||||
data.append(*m_pData);
|
data.append(*m_pData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMesh::loadPack(KRDataBlock* data)
|
void KRMesh::loadPack(Block* data)
|
||||||
{
|
{
|
||||||
releaseData();
|
releaseData();
|
||||||
|
|
||||||
@@ -377,8 +379,8 @@ void KRMesh::createDataBlocks(KRMeshManager::KRVBOData::vbo_type t)
|
|||||||
getIndexedRange(index_group++, start_index_offset, start_vertex_offset, index_count, vertex_count);
|
getIndexedRange(index_group++, start_index_offset, start_vertex_offset, index_count, vertex_count);
|
||||||
|
|
||||||
if ((int)mesh.vertex_data_blocks.size() <= vbo_index) {
|
if ((int)mesh.vertex_data_blocks.size() <= vbo_index) {
|
||||||
KRDataBlock* vertex_data_block = m_pData->getSubBlock(vertex_data_offset + start_vertex_offset * m_vertex_size, vertex_count * m_vertex_size);
|
Block* vertex_data_block = m_pData->getSubBlock(vertex_data_offset + start_vertex_offset * m_vertex_size, vertex_count * m_vertex_size);
|
||||||
KRDataBlock* index_data_block = m_pData->getSubBlock(index_data_offset + start_index_offset * 2, index_count * 2);
|
Block* index_data_block = m_pData->getSubBlock(index_data_offset + start_index_offset * 2, index_count * 2);
|
||||||
mesh.vbo_data_blocks.emplace_back(std::make_shared<KRMeshManager::KRVBOData>(getContext().getMeshManager(), vertex_data_block, index_data_block, vertex_attrib_flags, true, t
|
mesh.vbo_data_blocks.emplace_back(std::make_shared<KRMeshManager::KRVBOData>(getContext().getMeshManager(), vertex_data_block, index_data_block, vertex_attrib_flags, true, t
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, m_lodBaseName.c_str()
|
, m_lodBaseName.c_str()
|
||||||
@@ -406,8 +408,8 @@ void KRMesh::createDataBlocks(KRMeshManager::KRVBOData::vbo_type t)
|
|||||||
int vertex_size = m_vertex_size;
|
int vertex_size = m_vertex_size;
|
||||||
|
|
||||||
if ((int)mesh.vertex_data_blocks.size() <= vbo_index) {
|
if ((int)mesh.vertex_data_blocks.size() <= vbo_index) {
|
||||||
KRDataBlock* index_data_block = NULL;
|
Block* index_data_block = NULL;
|
||||||
KRDataBlock* vertex_data_block = m_pData->getSubBlock(vertex_data_offset + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes);
|
Block* vertex_data_block = m_pData->getSubBlock(vertex_data_offset + iBuffer * MAX_VBO_SIZE * vertex_size, vertex_size * cBufferVertexes);
|
||||||
mesh.vbo_data_blocks.emplace_back(std::make_shared<KRMeshManager::KRVBOData>(getContext().getMeshManager(), vertex_data_block, index_data_block, vertex_attrib_flags, true, t
|
mesh.vbo_data_blocks.emplace_back(std::make_shared<KRMeshManager::KRVBOData>(getContext().getMeshManager(), vertex_data_block, index_data_block, vertex_attrib_flags, true, t
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, m_lodBaseName.c_str()
|
, m_lodBaseName.c_str()
|
||||||
@@ -619,7 +621,7 @@ void KRMesh::LoadData(const KRMesh::mesh_info& mi, bool calculate_normals, bool
|
|||||||
size_t vertex_count = mi.vertices.size();
|
size_t vertex_count = mi.vertices.size();
|
||||||
size_t bone_count = mi.bone_names.size();
|
size_t bone_count = mi.bone_names.size();
|
||||||
size_t new_file_size = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(pack_bone) * bone_count + KRALIGN(2 * index_count) + KRALIGN(8 * index_base_count) + vertex_size * vertex_count;
|
size_t new_file_size = sizeof(pack_header) + sizeof(pack_material) * submesh_count + sizeof(pack_bone) * bone_count + KRALIGN(2 * index_count) + KRALIGN(8 * index_base_count) + vertex_size * vertex_count;
|
||||||
m_pData = new KRDataBlock();
|
m_pData = new Block();
|
||||||
m_pMetaData = m_pData;
|
m_pMetaData = m_pData;
|
||||||
m_pData->expand(new_file_size);
|
m_pData->expand(new_file_size);
|
||||||
m_pData->lock();
|
m_pData->lock();
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ 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);
|
||||||
|
|
||||||
KRMesh(KRContext& context, std::string name, KRDataBlock* data);
|
KRMesh(KRContext& context, std::string name, mimir::Block* data);
|
||||||
KRMesh(KRContext& context, std::string name);
|
KRMesh(KRContext& context, std::string name);
|
||||||
virtual ~KRMesh();
|
virtual ~KRMesh();
|
||||||
|
|
||||||
@@ -124,10 +124,10 @@ public:
|
|||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
virtual bool save(const std::string& path);
|
virtual bool save(const std::string& path);
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
void LoadData(const mesh_info& mi, bool calculate_normals, bool calculate_tangents);
|
void LoadData(const mesh_info& mi, bool calculate_normals, bool calculate_tangents);
|
||||||
void loadPack(KRDataBlock* data);
|
void loadPack(mimir::Block* data);
|
||||||
|
|
||||||
void convertToIndexed();
|
void convertToIndexed();
|
||||||
void optimize();
|
void optimize();
|
||||||
@@ -160,8 +160,8 @@ public:
|
|||||||
int start_vertex;
|
int start_vertex;
|
||||||
int vertex_count;
|
int vertex_count;
|
||||||
char szMaterialName[KRENGINE_MAX_NAME_LENGTH];
|
char szMaterialName[KRENGINE_MAX_NAME_LENGTH];
|
||||||
vector<KRDataBlock*> vertex_data_blocks;
|
vector<mimir::Block*> vertex_data_blocks;
|
||||||
vector<KRDataBlock*> index_data_blocks;
|
vector<mimir::Block*> index_data_blocks;
|
||||||
// KRMeshManager depends on the address of KRVBOData's being constant
|
// KRMeshManager depends on the address of KRVBOData's being constant
|
||||||
// after allocation, enforced by deleted copy constructors.
|
// after allocation, enforced by deleted copy constructors.
|
||||||
// As std::vector requires copy constuctors, we wrap these in shared_ptr.
|
// As std::vector requires copy constuctors, we wrap these in shared_ptr.
|
||||||
@@ -239,9 +239,9 @@ protected:
|
|||||||
bool m_constant; // TRUE if this should be always loaded and should not be passed through the streamer
|
bool m_constant; // TRUE if this should be always loaded and should not be passed through the streamer
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
KRDataBlock* m_pMetaData;
|
mimir::Block* m_pMetaData;
|
||||||
KRDataBlock* m_pIndexBaseData;
|
mimir::Block* m_pIndexBaseData;
|
||||||
|
|
||||||
void getSubmeshes();
|
void getSubmeshes();
|
||||||
void getMaterials();
|
void getMaterials();
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
#include "KRMeshQuad.h"
|
#include "KRMeshQuad.h"
|
||||||
#include "KRMeshSphere.h"
|
#include "KRMeshSphere.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRMeshManager::KRMeshManager(KRContext& context)
|
KRMeshManager::KRMeshManager(KRContext& context)
|
||||||
: KRResourceManager(context)
|
: KRResourceManager(context)
|
||||||
, m_currentVBO(NULL)
|
, m_currentVBO(NULL)
|
||||||
@@ -117,7 +119,7 @@ KRMeshManager::~KRMeshManager()
|
|||||||
m_models.clear();
|
m_models.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRMeshManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRMeshManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("krmesh") == 0) {
|
if (extension.compare("krmesh") == 0) {
|
||||||
return loadModel(name.c_str(), data);
|
return loadModel(name.c_str(), data);
|
||||||
@@ -140,7 +142,7 @@ 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, Block* pData)
|
||||||
{
|
{
|
||||||
KRMesh* pModel = new KRMesh(*m_pContext, szName, pData);
|
KRMesh* pModel = new KRMesh(*m_pContext, szName, pData);
|
||||||
addModel(pModel);
|
addModel(pModel);
|
||||||
@@ -326,7 +328,7 @@ long KRMeshManager::getMemUsed()
|
|||||||
long KRMeshManager::getMemActive()
|
long KRMeshManager::getMemActive()
|
||||||
{
|
{
|
||||||
long mem_active = 0;
|
long mem_active = 0;
|
||||||
for (unordered_map<KRDataBlock*, KRVBOData*>::iterator itr = m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) {
|
for (unordered_map<Block*, KRVBOData*>::iterator itr = m_vbosActive.begin(); itr != m_vbosActive.end(); itr++) {
|
||||||
mem_active += (*itr).second->getSize();
|
mem_active += (*itr).second->getSize();
|
||||||
}
|
}
|
||||||
return mem_active;
|
return mem_active;
|
||||||
@@ -475,7 +477,7 @@ KRMeshManager::KRVBOData::KRVBOData()
|
|||||||
memset(m_allocations, 0, sizeof(AllocationInfo) * KRENGINE_MAX_GPU_COUNT);
|
memset(m_allocations, 0, sizeof(AllocationInfo) * KRENGINE_MAX_GPU_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRMeshManager::KRVBOData::KRVBOData(KRMeshManager* manager, KRDataBlock* data, KRDataBlock* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
|
KRMeshManager::KRVBOData::KRVBOData(KRMeshManager* manager, Block* data, Block* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, const char* debug_label
|
, const char* debug_label
|
||||||
#endif
|
#endif
|
||||||
@@ -492,7 +494,7 @@ KRMeshManager::KRVBOData::KRVBOData(KRMeshManager* manager, KRDataBlock* data, K
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMeshManager::KRVBOData::init(KRMeshManager* manager, KRDataBlock* data, KRDataBlock* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
|
void KRMeshManager::KRVBOData::init(KRMeshManager* manager, Block* data, Block* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, const char* debug_label
|
, const char* debug_label
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#include "KRResourceManager.h"
|
#include "KRResourceManager.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRNode.h"
|
#include "KRNode.h"
|
||||||
|
|
||||||
class KRContext;
|
class KRContext;
|
||||||
@@ -51,13 +51,13 @@ public:
|
|||||||
void init();
|
void init();
|
||||||
virtual ~KRMeshManager();
|
virtual ~KRMeshManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
void startFrame(float deltaTime);
|
void startFrame(float deltaTime);
|
||||||
void endFrame(float deltaTime);
|
void endFrame(float deltaTime);
|
||||||
|
|
||||||
KRMesh* loadModel(const char* szName, KRDataBlock* pData);
|
KRMesh* loadModel(const char* szName, mimir::Block* pData);
|
||||||
std::vector<KRMesh*> getModel(const char* szName);
|
std::vector<KRMesh*> getModel(const char* szName);
|
||||||
KRMesh* getMaxLODModel(const char* szName);
|
KRMesh* getMaxLODModel(const char* szName);
|
||||||
void addModel(KRMesh* model);
|
void addModel(KRMesh* model);
|
||||||
@@ -84,12 +84,12 @@ public:
|
|||||||
} vbo_type;
|
} vbo_type;
|
||||||
|
|
||||||
KRVBOData();
|
KRVBOData();
|
||||||
KRVBOData(KRMeshManager* manager, KRDataBlock* data, KRDataBlock* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
|
KRVBOData(KRMeshManager* manager, mimir::Block* data, mimir::Block* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, const char* debug_label
|
, const char* debug_label
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
void init(KRMeshManager* manager, KRDataBlock* data, KRDataBlock* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
|
void init(KRMeshManager* manager, mimir::Block* data, mimir::Block* index_data, int vertex_attrib_flags, bool static_vbo, vbo_type t
|
||||||
#if KRENGINE_DEBUG_GPU_LABELS
|
#if KRENGINE_DEBUG_GPU_LABELS
|
||||||
, const char* debug_label
|
, const char* debug_label
|
||||||
#endif
|
#endif
|
||||||
@@ -97,8 +97,8 @@ public:
|
|||||||
~KRVBOData();
|
~KRVBOData();
|
||||||
|
|
||||||
|
|
||||||
KRDataBlock* m_data;
|
mimir::Block* m_data;
|
||||||
KRDataBlock* m_index_data;
|
mimir::Block* m_index_data;
|
||||||
|
|
||||||
bool isVBOLoaded()
|
bool isVBOLoaded()
|
||||||
{
|
{
|
||||||
@@ -211,9 +211,9 @@ public:
|
|||||||
void doStreaming(long& memoryRemaining, long& memoryRemainingThisFrame);
|
void doStreaming(long& memoryRemaining, long& memoryRemainingThisFrame);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
KRDataBlock KRENGINE_VBO_3D_CUBE_VERTICES;
|
mimir::Block KRENGINE_VBO_3D_CUBE_VERTICES;
|
||||||
__int32_t KRENGINE_VBO_3D_CUBE_ATTRIBS;
|
__int32_t KRENGINE_VBO_3D_CUBE_ATTRIBS;
|
||||||
KRDataBlock KRENGINE_VBO_2D_SQUARE_VERTICES;
|
mimir::Block KRENGINE_VBO_2D_SQUARE_VERTICES;
|
||||||
__int32_t KRENGINE_VBO_2D_SQUARE_ATTRIBS;
|
__int32_t KRENGINE_VBO_2D_SQUARE_ATTRIBS;
|
||||||
|
|
||||||
unordered_multimap<std::string, KRMesh*> m_models; // Multiple models with the same name/key may be inserted, representing multiple LOD levels of the model
|
unordered_multimap<std::string, KRMesh*> m_models; // Multiple models with the same name/key may be inserted, representing multiple LOD levels of the model
|
||||||
@@ -221,12 +221,12 @@ private:
|
|||||||
long m_vboMemUsed;
|
long m_vboMemUsed;
|
||||||
KRVBOData* m_currentVBO;
|
KRVBOData* m_currentVBO;
|
||||||
|
|
||||||
unordered_map<KRDataBlock*, KRVBOData*> m_vbosActive;
|
unordered_map<mimir::Block*, KRVBOData*> m_vbosActive;
|
||||||
std::vector<std::pair<float, KRVBOData*> > m_activeVBOs_streamer;
|
std::vector<std::pair<float, KRVBOData*> > m_activeVBOs_streamer;
|
||||||
std::vector<std::pair<float, KRVBOData*> > m_activeVBOs_streamer_copy;
|
std::vector<std::pair<float, KRVBOData*> > m_activeVBOs_streamer_copy;
|
||||||
|
|
||||||
KRDataBlock m_randomParticleVertexData;
|
mimir::Block m_randomParticleVertexData;
|
||||||
KRDataBlock m_volumetricLightingVertexData;
|
mimir::Block m_volumetricLightingVertexData;
|
||||||
|
|
||||||
long m_memoryTransferredThisFrame;
|
long m_memoryTransferredThisFrame;
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
|
|
||||||
#include "KRCamera.h"
|
#include "KRCamera.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRNode.h"
|
#include "KRNode.h"
|
||||||
#include "KRSurface.h"
|
#include "KRSurface.h"
|
||||||
#include "KRMesh.h"
|
#include "KRMesh.h"
|
||||||
|
|||||||
@@ -35,12 +35,14 @@
|
|||||||
#include "KRScene.h"
|
#include "KRScene.h"
|
||||||
#include "KRResource+blend.h"
|
#include "KRResource+blend.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
|
|
||||||
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;
|
Block data;
|
||||||
|
|
||||||
if (data.load(path)) {
|
if (data.load(path)) {
|
||||||
//KRBlendFile blend_file = KRBlendFile(pFile);
|
//KRBlendFile blend_file = KRBlendFile(pFile);
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
#include "KRMesh.h"
|
#include "KRMesh.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
||||||
{
|
{
|
||||||
KRMesh* new_mesh = new KRMesh(context, KRResource::GetFileBase(path));
|
KRMesh* new_mesh = new KRMesh(context, KRResource::GetFileBase(path));
|
||||||
@@ -42,7 +44,7 @@ KRMesh* KRResource::LoadObj(KRContext& context, const std::string& path)
|
|||||||
|
|
||||||
std::vector<std::string> material_names_t;
|
std::vector<std::string> material_names_t;
|
||||||
|
|
||||||
KRDataBlock data;
|
Block data;
|
||||||
|
|
||||||
char szSymbol[500][256];
|
char szSymbol[500][256];
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
#include "KRBundle.h"
|
#include "KRBundle.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRResource::KRResource(KRContext& context, std::string name) : KRContextObject(context)
|
KRResource::KRResource(KRContext& context, std::string name) : KRContextObject(context)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
@@ -89,7 +91,7 @@ std::string KRResource::GetFilePath(const std::string& name)
|
|||||||
|
|
||||||
bool KRResource::save(const std::string& path)
|
bool KRResource::save(const std::string& path)
|
||||||
{
|
{
|
||||||
KRDataBlock data;
|
Block data;
|
||||||
if (save(data)) {
|
if (save(data)) {
|
||||||
return data.save(path);
|
return data.save(path);
|
||||||
} else {
|
} else {
|
||||||
@@ -99,11 +101,11 @@ bool KRResource::save(const std::string& path)
|
|||||||
|
|
||||||
KrResult KRResource::moveToBundle(KRBundle* bundle)
|
KrResult KRResource::moveToBundle(KRBundle* bundle)
|
||||||
{
|
{
|
||||||
KRDataBlock* data = bundle->append(*this);
|
Block* data = bundle->append(*this);
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
return KR_ERROR_UNEXPECTED;
|
return KR_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
// TODO(kearwood) - We must re-attach the KRResource to the returned KRDataBlock
|
// TODO(kearwood) - We must re-attach the KRResource to the returned Block
|
||||||
delete data;
|
delete data;
|
||||||
return KR_SUCCESS;
|
return KR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
class KRBundle;
|
class KRBundle;
|
||||||
class KRScene;
|
class KRScene;
|
||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
std::string getName();
|
std::string getName();
|
||||||
virtual std::string getExtension() = 0;
|
virtual std::string getExtension() = 0;
|
||||||
virtual bool save(const std::string& path);
|
virtual bool save(const std::string& path);
|
||||||
virtual bool save(KRDataBlock& data) = 0;
|
virtual bool save(mimir::Block& data) = 0;
|
||||||
|
|
||||||
KrResult moveToBundle(KRBundle* bundle);
|
KrResult moveToBundle(KRBundle* bundle);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
class KRResourceManager : public KRContextObject
|
class KRResourceManager : public KRContextObject
|
||||||
{
|
{
|
||||||
@@ -43,6 +43,6 @@ public:
|
|||||||
KRResourceManager(KRContext& context);
|
KRResourceManager(KRContext& context);
|
||||||
virtual ~KRResourceManager();
|
virtual ~KRResourceManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) = 0;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) = 0;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) = 0;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
|
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
using std::map;
|
using std::map;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|||||||
@@ -40,6 +40,8 @@
|
|||||||
#include "KRPointLight.h"
|
#include "KRPointLight.h"
|
||||||
#include "KRAudioManager.h"
|
#include "KRAudioManager.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
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)
|
||||||
@@ -383,7 +385,7 @@ KRNode* KRScene::getRootNode()
|
|||||||
return m_pRootNode;
|
return m_pRootNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRScene::save(KRDataBlock& data)
|
bool KRScene::save(Block& data)
|
||||||
{
|
{
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
tinyxml2::XMLElement* scene_node = doc.NewElement("scene");
|
tinyxml2::XMLElement* scene_node = doc.NewElement("scene");
|
||||||
@@ -397,7 +399,7 @@ bool KRScene::save(KRDataBlock& data)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRScene* KRScene::Load(KRContext& context, const std::string& name, KRDataBlock* data)
|
KRScene* KRScene::Load(KRContext& context, const std::string& name, Block* data)
|
||||||
{
|
{
|
||||||
std::string xml_string = data->getString();
|
std::string xml_string = data->getString();
|
||||||
delete data;
|
delete data;
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
static KRScene* Load(KRContext& context, const std::string& name, KRDataBlock* data);
|
static KRScene* Load(KRContext& context, const std::string& name, mimir::Block* data);
|
||||||
|
|
||||||
KRNode* getRootNode();
|
KRNode* getRootNode();
|
||||||
KRLight* getFirstLight();
|
KRLight* getFirstLight();
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include "KRSceneManager.h"
|
#include "KRSceneManager.h"
|
||||||
#include "KRScene.h"
|
#include "KRScene.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRSceneManager::KRSceneManager(KRContext& context) : KRResourceManager(context)
|
KRSceneManager::KRSceneManager(KRContext& context) : KRResourceManager(context)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ KRSceneManager::~KRSceneManager()
|
|||||||
m_scenes.clear();
|
m_scenes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRSceneManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRSceneManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("krscene") == 0) {
|
if (extension.compare("krscene") == 0) {
|
||||||
return loadScene(name, data);
|
return loadScene(name, data);
|
||||||
@@ -59,7 +61,7 @@ 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, Block* 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;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
|
|
||||||
#include "KRResourceManager.h"
|
#include "KRResourceManager.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
class KRScene;
|
class KRScene;
|
||||||
|
|
||||||
@@ -45,13 +45,13 @@ public:
|
|||||||
KRSceneManager(KRContext& context);
|
KRSceneManager(KRContext& context);
|
||||||
virtual ~KRSceneManager();
|
virtual ~KRSceneManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
KRScene* createScene(const std::string& name);
|
KRScene* createScene(const std::string& name);
|
||||||
|
|
||||||
void add(KRScene* scene);
|
void add(KRScene* scene);
|
||||||
KRScene* loadScene(const std::string& name, KRDataBlock* data);
|
KRScene* loadScene(const std::string& name, mimir::Block* data);
|
||||||
|
|
||||||
KRScene* getScene(const std::string& name);
|
KRScene* getScene(const std::string& name);
|
||||||
KRScene* getFirstScene();
|
KRScene* getFirstScene();
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include "KRShader.h"
|
#include "KRShader.h"
|
||||||
#include "spirv_reflect.h"
|
#include "spirv_reflect.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
ShaderStage getShaderStageFromExtension(const char* extension)
|
ShaderStage getShaderStageFromExtension(const char* extension)
|
||||||
{
|
{
|
||||||
if (strcmp(extension, "vert") == 0) {
|
if (strcmp(extension, "vert") == 0) {
|
||||||
@@ -104,7 +106,7 @@ VkShaderStageFlagBits getShaderStageFlagBitsFromShaderStage(ShaderStage stage)
|
|||||||
|
|
||||||
KRShader::KRShader(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
KRShader::KRShader(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = new KRDataBlock();
|
m_pData = new Block();
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
m_subExtension = KRResource::GetFileExtension(name);
|
m_subExtension = KRResource::GetFileExtension(name);
|
||||||
m_stage = getShaderStageFromExtension(m_subExtension.c_str());
|
m_stage = getShaderStageFromExtension(m_subExtension.c_str());
|
||||||
@@ -113,7 +115,7 @@ KRShader::KRShader(KRContext& context, std::string name, std::string extension)
|
|||||||
getReflection();
|
getReflection();
|
||||||
}
|
}
|
||||||
|
|
||||||
KRShader::KRShader(KRContext& context, std::string name, std::string extension, KRDataBlock* data) : KRResource(context, name)
|
KRShader::KRShader(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = data;
|
m_pData = data;
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
@@ -138,13 +140,13 @@ std::string& KRShader::getSubExtension()
|
|||||||
return m_subExtension;
|
return m_subExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRShader::save(KRDataBlock& data)
|
bool KRShader::save(Block& data)
|
||||||
{
|
{
|
||||||
data.append(*m_pData);
|
data.append(*m_pData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRDataBlock* KRShader::getData()
|
Block* KRShader::getData()
|
||||||
{
|
{
|
||||||
return m_pData;
|
return m_pData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
#include "spirv_reflect.h"
|
#include "spirv_reflect.h"
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ 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, mimir::Block* data);
|
||||||
virtual ~KRShader();
|
virtual ~KRShader();
|
||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
@@ -74,9 +74,9 @@ public:
|
|||||||
|
|
||||||
bool createShaderModule(VkDevice& device, VkShaderModule& module);
|
bool createShaderModule(VkDevice& device, VkShaderModule& module);
|
||||||
|
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
KRDataBlock* getData();
|
mimir::Block* getData();
|
||||||
const SpvReflectShaderModule* getReflection();
|
const SpvReflectShaderModule* getReflection();
|
||||||
ShaderStage getShaderStage() const;
|
ShaderStage getShaderStage() const;
|
||||||
VkShaderStageFlagBits getShaderStageFlagBits() const;
|
VkShaderStageFlagBits getShaderStageFlagBits() const;
|
||||||
@@ -86,7 +86,7 @@ private:
|
|||||||
|
|
||||||
std::string m_extension;
|
std::string m_extension;
|
||||||
std::string m_subExtension;
|
std::string m_subExtension;
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
SpvReflectShaderModule m_reflection;
|
SpvReflectShaderModule m_reflection;
|
||||||
bool m_reflectionValid;
|
bool m_reflectionValid;
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
#include "KRUnknownManager.h"
|
#include "KRUnknownManager.h"
|
||||||
#include "KRUnknown.h"
|
#include "KRUnknown.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRShaderManager::KRShaderManager(KRContext& context) : KRResourceManager(context)
|
KRShaderManager::KRShaderManager(KRContext& context) : KRResourceManager(context)
|
||||||
, m_initializedGlslang(false)
|
, m_initializedGlslang(false)
|
||||||
, m_includer(&context)
|
, m_includer(&context)
|
||||||
@@ -55,7 +57,7 @@ KRShaderManager::~KRShaderManager()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRShaderManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRShaderManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("spv") == 0) {
|
if (extension.compare("spv") == 0) {
|
||||||
return load(name, extension, data);
|
return load(name, extension, data);
|
||||||
@@ -98,7 +100,7 @@ void KRShaderManager::add(KRShader* shader)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KRShader* KRShaderManager::load(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRShader* KRShaderManager::load(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
KRShader* shader = new KRShader(getContext(), name, extension, data);
|
KRShader* shader = new KRShader(getContext(), name, extension, data);
|
||||||
if (shader) add(shader);
|
if (shader) add(shader);
|
||||||
@@ -347,7 +349,7 @@ bool KRShaderManager::compileAll(KRBundle* outputBundle, KRUnknown* logResource)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!shader_name.empty()) {
|
if (!shader_name.empty()) {
|
||||||
KRDataBlock* data = new KRDataBlock();
|
Block* data = new Block();
|
||||||
data->append(static_cast<void*>(spirv.data()), spirv.size() * sizeof(unsigned int));
|
data->append(static_cast<void*>(spirv.data()), spirv.size() * sizeof(unsigned int));
|
||||||
KRShader* shader = new KRShader(getContext(), shader_name, "spv", data);
|
KRShader* shader = new KRShader(getContext(), shader_name, "spv", data);
|
||||||
add(shader);
|
add(shader);
|
||||||
@@ -393,7 +395,7 @@ glslang::TShader::Includer::IncludeResult* KRShaderManager::Includer::includeLoc
|
|||||||
if (!source) {
|
if (!source) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
KRDataBlock* data = source->getData();
|
Block* data = source->getData();
|
||||||
data->lock();
|
data->lock();
|
||||||
const char* sourceString = static_cast<const char*>(data->getStart());
|
const char* sourceString = static_cast<const char*>(data->getStart());
|
||||||
return new IncludeResult(std::string(headerName), sourceString, data->getSize(), static_cast<void*>(data));
|
return new IncludeResult(std::string(headerName), sourceString, data->getSize(), static_cast<void*>(data));
|
||||||
@@ -401,6 +403,6 @@ glslang::TShader::Includer::IncludeResult* KRShaderManager::Includer::includeLoc
|
|||||||
|
|
||||||
void KRShaderManager::Includer::releaseInclude(IncludeResult* includeResult)
|
void KRShaderManager::Includer::releaseInclude(IncludeResult* includeResult)
|
||||||
{
|
{
|
||||||
KRDataBlock* data = static_cast<KRDataBlock*>(includeResult->userData);
|
Block* data = static_cast<Block*>(includeResult->userData);
|
||||||
data->unlock();
|
data->unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#include "KRShader.h"
|
#include "KRShader.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
class KRUnknown;
|
class KRUnknown;
|
||||||
|
|
||||||
@@ -47,12 +47,12 @@ public:
|
|||||||
KRShaderManager(KRContext& context);
|
KRShaderManager(KRContext& context);
|
||||||
virtual ~KRShaderManager();
|
virtual ~KRShaderManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
void add(KRShader* shader);
|
void add(KRShader* shader);
|
||||||
|
|
||||||
KRShader* load(const std::string& name, const std::string& extension, KRDataBlock* data);
|
KRShader* load(const std::string& name, const std::string& extension, mimir::Block* data);
|
||||||
KRShader* get(const std::string& name, const std::string& extension);
|
KRShader* get(const std::string& name, const std::string& extension);
|
||||||
|
|
||||||
bool compileAll(KRBundle* outputBundle, KRUnknown* logResource);
|
bool compileAll(KRBundle* outputBundle, KRUnknown* logResource);
|
||||||
|
|||||||
@@ -31,13 +31,15 @@
|
|||||||
|
|
||||||
#include "KRSource.h"
|
#include "KRSource.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRSource::KRSource(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
KRSource::KRSource(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = new KRDataBlock();
|
m_pData = new Block();
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRSource::KRSource(KRContext& context, std::string name, std::string extension, KRDataBlock* data) : KRResource(context, name)
|
KRSource::KRSource(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = data;
|
m_pData = data;
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
@@ -53,13 +55,13 @@ std::string KRSource::getExtension()
|
|||||||
return m_extension;
|
return m_extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRSource::save(KRDataBlock& data)
|
bool KRSource::save(Block& data)
|
||||||
{
|
{
|
||||||
data.append(*m_pData);
|
data.append(*m_pData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRDataBlock* KRSource::getData()
|
Block* KRSource::getData()
|
||||||
{
|
{
|
||||||
return m_pData;
|
return m_pData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
|
|
||||||
class KRSource : public KRResource
|
class KRSource : public KRResource
|
||||||
@@ -41,17 +41,17 @@ class KRSource : public KRResource
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
KRSource(KRContext& context, std::string name, std::string extension);
|
KRSource(KRContext& context, std::string name, std::string extension);
|
||||||
KRSource(KRContext& context, std::string name, std::string extension, KRDataBlock* data);
|
KRSource(KRContext& context, std::string name, std::string extension, mimir::Block* data);
|
||||||
virtual ~KRSource();
|
virtual ~KRSource();
|
||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
|
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
KRDataBlock* getData();
|
mimir::Block* getData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string m_extension;
|
std::string m_extension;
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRShader.h"
|
#include "KRShader.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRSourceManager::KRSourceManager(KRContext& context) : KRResourceManager(context)
|
KRSourceManager::KRSourceManager(KRContext& context) : KRResourceManager(context)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ void KRSourceManager::add(KRSource* source)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRSourceManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRSourceManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
if (getShaderStageFromExtension(extension.c_str()) != ShaderStage::Invalid ||
|
if (getShaderStageFromExtension(extension.c_str()) != ShaderStage::Invalid ||
|
||||||
extension.compare("glsl") == 0 ||
|
extension.compare("glsl") == 0 ||
|
||||||
@@ -95,7 +97,7 @@ KRResource* KRSourceManager::getResource(const std::string& name, const std::str
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRSource* KRSourceManager::load(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRSource* KRSourceManager::load(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
KRSource* source = new KRSource(getContext(), name, extension, data);
|
KRSource* source = new KRSource(getContext(), name, extension, data);
|
||||||
if (source) add(source);
|
if (source) add(source);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
#include "KRResourceManager.h"
|
#include "KRResourceManager.h"
|
||||||
#include "KRSource.h"
|
#include "KRSource.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
class KRSourceManager : public KRResourceManager
|
class KRSourceManager : public KRResourceManager
|
||||||
{
|
{
|
||||||
@@ -44,12 +44,12 @@ public:
|
|||||||
KRSourceManager(KRContext& context);
|
KRSourceManager(KRContext& context);
|
||||||
virtual ~KRSourceManager();
|
virtual ~KRSourceManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
void add(KRSource* source);
|
void add(KRSource* source);
|
||||||
|
|
||||||
KRSource* load(const std::string& name, const std::string& extension, KRDataBlock* data);
|
KRSource* load(const std::string& name, const std::string& extension, mimir::Block* data);
|
||||||
KRSource* get(const std::string& name, const std::string& extension);
|
KRSource* get(const std::string& name, const std::string& extension);
|
||||||
|
|
||||||
const unordered_map<std::string, KRSource*>& get(const std::string& extension);
|
const unordered_map<std::string, KRSource*>& get(const std::string& extension);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRTexture.h"
|
#include "KRTexture.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "KRTextureManager.h"
|
#include "KRTextureManager.h"
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,9 @@
|
|||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
|
|
||||||
class KRDataBlock;
|
namespace mimir {
|
||||||
|
class Block;
|
||||||
|
}
|
||||||
class KRCamera;
|
class KRCamera;
|
||||||
class KRDeviceManager;
|
class KRDeviceManager;
|
||||||
class KRDevice;
|
class KRDevice;
|
||||||
|
|||||||
@@ -33,7 +33,9 @@
|
|||||||
#include "KRTexture2D.h"
|
#include "KRTexture2D.h"
|
||||||
#include "KRTextureManager.h"
|
#include "KRTextureManager.h"
|
||||||
|
|
||||||
KRTexture2D::KRTexture2D(KRContext& context, KRDataBlock* data, std::string name) : KRTexture(context, name)
|
using namespace mimir;
|
||||||
|
|
||||||
|
KRTexture2D::KRTexture2D(KRContext& context, Block* data, std::string name) : KRTexture(context, name)
|
||||||
{
|
{
|
||||||
m_pData = data;
|
m_pData = data;
|
||||||
}
|
}
|
||||||
@@ -114,7 +116,7 @@ bool KRTexture2D::save(const std::string& path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRTexture2D::save(KRDataBlock& data)
|
bool KRTexture2D::save(Block& data)
|
||||||
{
|
{
|
||||||
if (m_pData) {
|
if (m_pData) {
|
||||||
data.append(*m_pData);
|
data.append(*m_pData);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
using std::list;
|
using std::list;
|
||||||
|
|
||||||
@@ -43,16 +43,16 @@ class KRDevice;
|
|||||||
class KRTexture2D : public KRTexture
|
class KRTexture2D : public KRTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KRTexture2D(KRContext& context, KRDataBlock* data, std::string name);
|
KRTexture2D(KRContext& context, mimir::Block* data, std::string name);
|
||||||
virtual ~KRTexture2D();
|
virtual ~KRTexture2D();
|
||||||
virtual bool save(const std::string& path);
|
virtual bool save(const std::string& path);
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
virtual bool uploadTexture(KRDevice& device, VkImage& image, int lod_max_dim, int& current_lod_max_dim, bool premultiply_alpha = false) = 0;
|
virtual bool uploadTexture(KRDevice& device, VkImage& image, int lod_max_dim, int& current_lod_max_dim, bool premultiply_alpha = false) = 0;
|
||||||
virtual Vector2i getDimensions() const = 0;
|
virtual Vector2i getDimensions() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
|
|
||||||
bool createGPUTexture(int lod_max_dim) override;
|
bool createGPUTexture(int lod_max_dim) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ bool KRTextureAnimated::save(const std::string& path)
|
|||||||
return true; // Animated textures are just references; there are no files to output
|
return true; // Animated textures are just references; there are no files to output
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRTextureAnimated::save(KRDataBlock& data)
|
bool KRTextureAnimated::save(Block& data)
|
||||||
{
|
{
|
||||||
return true; // Animated textures are just references; there are no files to output
|
return true; // Animated textures are just references; there are no files to output
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
#include "KRTexture.h"
|
#include "KRTexture.h"
|
||||||
#include "KRTexture2D.h"
|
#include "KRTexture2D.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
class KRTextureAnimated : public KRTexture
|
class KRTextureAnimated : public KRTexture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -41,7 +43,7 @@ public:
|
|||||||
virtual ~KRTextureAnimated();
|
virtual ~KRTextureAnimated();
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
virtual bool save(const std::string& path);
|
virtual bool save(const std::string& path);
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(Block& data);
|
||||||
|
|
||||||
virtual long getMemRequiredForSize(int max_dim);
|
virtual long getMemRequiredForSize(int max_dim);
|
||||||
virtual void resetPoolExpiry(float lodCoverage, texture_usage_t textureUsage);
|
virtual void resetPoolExpiry(float lodCoverage, texture_usage_t textureUsage);
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
#include "KRTexture2D.h"
|
#include "KRTexture2D.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRTextureCube::KRTextureCube(KRContext& context, std::string name) : KRTexture(context, name)
|
KRTextureCube::KRTextureCube(KRContext& context, std::string name) : KRTexture(context, name)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -163,7 +165,7 @@ bool KRTextureCube::save(const std::string& path)
|
|||||||
return true; // Cube maps are just references; there are no files to output
|
return true; // Cube maps are just references; there are no files to output
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRTextureCube::save(KRDataBlock& data)
|
bool KRTextureCube::save(Block& data)
|
||||||
{
|
{
|
||||||
return true; // Cube maps are just references; there are no files to output
|
return true; // Cube maps are just references; there are no files to output
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
virtual ~KRTextureCube();
|
virtual ~KRTextureCube();
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
virtual bool save(const std::string& path);
|
virtual bool save(const std::string& path);
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
virtual long getMemRequiredForSize(int max_dim);
|
virtual long getMemRequiredForSize(int max_dim);
|
||||||
virtual void resetPoolExpiry(float lodCoverage, texture_usage_t textureUsage);
|
virtual void resetPoolExpiry(float lodCoverage, texture_usage_t textureUsage);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ __uint8_t _KTXFileIdentifier[12] = {
|
|||||||
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
|
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
|
||||||
};
|
};
|
||||||
|
|
||||||
KRTextureKTX::KRTextureKTX(KRContext& context, KRDataBlock* data, std::string name) : KRTexture2D(context, data, name)
|
KRTextureKTX::KRTextureKTX(KRContext& context, Block* data, std::string name) : KRTexture2D(context, data, name)
|
||||||
{
|
{
|
||||||
m_pData->copy(&m_header, 0, sizeof(KTXHeader));
|
m_pData->copy(&m_header, 0, sizeof(KTXHeader));
|
||||||
if (memcmp(_KTXFileIdentifier, m_header.identifier, 12) != 0) {
|
if (memcmp(_KTXFileIdentifier, m_header.identifier, 12) != 0) {
|
||||||
@@ -84,7 +84,7 @@ KRTextureKTX::KRTextureKTX(KRContext& context, KRDataBlock* data, std::string na
|
|||||||
m_min_lod_max_dim = KRMAX(width, height);
|
m_min_lod_max_dim = KRMAX(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<KRDataBlock*>& blocks) : KRTexture2D(context, new KRDataBlock(), name)
|
KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<Block*>& blocks) : KRTexture2D(context, new Block(), name)
|
||||||
{
|
{
|
||||||
memcpy(m_header.identifier, _KTXFileIdentifier, 12);
|
memcpy(m_header.identifier, _KTXFileIdentifier, 12);
|
||||||
m_header.endianness = 0x04030201;
|
m_header.endianness = 0x04030201;
|
||||||
@@ -103,7 +103,7 @@ KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int in
|
|||||||
|
|
||||||
m_pData->append(&m_header, sizeof(m_header));
|
m_pData->append(&m_header, sizeof(m_header));
|
||||||
for (auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) {
|
for (auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) {
|
||||||
KRDataBlock* source_block = *block_itr;
|
Block* source_block = *block_itr;
|
||||||
__uint32_t block_size = (__uint32_t)source_block->getSize();
|
__uint32_t block_size = (__uint32_t)source_block->getSize();
|
||||||
m_pData->append(&block_size, 4);
|
m_pData->append(&block_size, 4);
|
||||||
m_pData->append(*source_block);
|
m_pData->append(*source_block);
|
||||||
@@ -118,8 +118,8 @@ KRTextureKTX::KRTextureKTX(KRContext& context, std::string name, unsigned int in
|
|||||||
|
|
||||||
KRTextureKTX::~KRTextureKTX()
|
KRTextureKTX::~KRTextureKTX()
|
||||||
{
|
{
|
||||||
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
||||||
KRDataBlock* block = *itr;
|
Block* block = *itr;
|
||||||
delete block;
|
delete block;
|
||||||
}
|
}
|
||||||
m_blocks.clear();
|
m_blocks.clear();
|
||||||
@@ -370,8 +370,8 @@ long KRTextureKTX::getMemRequiredForSize(int max_dim)
|
|||||||
int height = m_header.pixelHeight;
|
int height = m_header.pixelHeight;
|
||||||
long memoryRequired = 0;
|
long memoryRequired = 0;
|
||||||
|
|
||||||
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
||||||
KRDataBlock* block = *itr;
|
Block* block = *itr;
|
||||||
if (width <= target_dim && height <= target_dim) {
|
if (width <= target_dim && height <= target_dim) {
|
||||||
memoryRequired += (long)block->getSize();
|
memoryRequired += (long)block->getSize();
|
||||||
}
|
}
|
||||||
@@ -408,8 +408,8 @@ bool KRTextureKTX::uploadTexture(KRDevice& device, VkImage& image, int lod_max_d
|
|||||||
// Upload texture data
|
// Upload texture data
|
||||||
int destination_level = 0;
|
int destination_level = 0;
|
||||||
int source_level = 0;
|
int source_level = 0;
|
||||||
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
||||||
KRDataBlock* block = *itr;
|
Block* block = *itr;
|
||||||
if (width <= target_dim && height <= target_dim) {
|
if (width <= target_dim && height <= target_dim) {
|
||||||
|
|
||||||
if (width > current_lod_max_dim) {
|
if (width > current_lod_max_dim) {
|
||||||
|
|||||||
@@ -33,11 +33,13 @@
|
|||||||
|
|
||||||
#include "KRTexture2D.h"
|
#include "KRTexture2D.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
class KRTextureKTX : public KRTexture2D
|
class KRTextureKTX : public KRTexture2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KRTextureKTX(KRContext& context, KRDataBlock* data, std::string name);
|
KRTextureKTX(KRContext& context, Block* data, std::string name);
|
||||||
KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<KRDataBlock*>& blocks);
|
KRTextureKTX(KRContext& context, std::string name, unsigned int internal_format, unsigned int base_internal_format, int width, int height, const std::list<Block*>& blocks);
|
||||||
virtual ~KRTextureKTX();
|
virtual ~KRTextureKTX();
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::list<KRDataBlock*> m_blocks;
|
std::list<Block*> m_blocks;
|
||||||
|
|
||||||
typedef struct _KTXHeader
|
typedef struct _KTXHeader
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,11 +34,13 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
__uint8_t _KTX2FileIdentifier[12] = {
|
__uint8_t _KTX2FileIdentifier[12] = {
|
||||||
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
|
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
|
||||||
};
|
};
|
||||||
|
|
||||||
KRTextureKTX2::KRTextureKTX2(KRContext& context, KRDataBlock* data, std::string name) : KRTexture2D(context, data, name)
|
KRTextureKTX2::KRTextureKTX2(KRContext& context, Block* data, std::string name) : KRTexture2D(context, data, name)
|
||||||
{
|
{
|
||||||
m_pData->copy(&m_header, 0, sizeof(KTX2Header));
|
m_pData->copy(&m_header, 0, sizeof(KTX2Header));
|
||||||
if (memcmp(_KTX2FileIdentifier, m_header.identifier, 12) != 0) {
|
if (memcmp(_KTX2FileIdentifier, m_header.identifier, 12) != 0) {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
class KRTextureKTX2 : public KRTexture2D
|
class KRTextureKTX2 : public KRTexture2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KRTextureKTX2(KRContext& context, KRDataBlock* data, std::string name);
|
KRTextureKTX2(KRContext& context, mimir::Block* data, std::string name);
|
||||||
virtual ~KRTextureKTX2();
|
virtual ~KRTextureKTX2();
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ void KRTextureManager::setMaxAnisotropy(float max_anisotropy)
|
|||||||
m_maxAnisotropy = max_anisotropy;
|
m_maxAnisotropy = max_anisotropy;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRResource* KRTextureManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRTextureManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
if (extension.compare("pvr") == 0 ||
|
if (extension.compare("pvr") == 0 ||
|
||||||
extension.compare("ktx") == 0 ||
|
extension.compare("ktx") == 0 ||
|
||||||
@@ -95,7 +95,7 @@ KRResource* KRTextureManager::getResource(const std::string& name, const std::st
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRTexture* KRTextureManager::loadTexture(const char* szName, const char* szExtension, KRDataBlock* data)
|
KRTexture* KRTextureManager::loadTexture(const char* szName, const char* szExtension, Block* data)
|
||||||
{
|
{
|
||||||
KRTexture* pTexture = NULL;
|
KRTexture* pTexture = NULL;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
#include "KRTexture.h"
|
#include "KRTexture.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
#include "KRStreamerThread.h"
|
#include "KRStreamerThread.h"
|
||||||
|
|
||||||
@@ -49,12 +49,12 @@ public:
|
|||||||
virtual ~KRTextureManager();
|
virtual ~KRTextureManager();
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
bool selectTexture(unsigned int target, int iTextureUnit, int iTextureHandle);
|
bool selectTexture(unsigned int target, int iTextureUnit, int iTextureHandle);
|
||||||
|
|
||||||
KRTexture* loadTexture(const char* szName, const char* szExtension, KRDataBlock* data);
|
KRTexture* loadTexture(const char* szName, const char* szExtension, mimir::Block* data);
|
||||||
KRTexture* getTextureCube(const char* szName);
|
KRTexture* getTextureCube(const char* szName);
|
||||||
KRTexture* getTexture(const std::string& name);
|
KRTexture* getTexture(const std::string& name);
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,8 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
|
|
||||||
#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff
|
#define PVR_TEXTURE_FLAG_TYPE_MASK 0xff
|
||||||
|
|
||||||
@@ -62,7 +64,7 @@ typedef struct _PVRTexHeader
|
|||||||
uint32_t numSurfs;
|
uint32_t numSurfs;
|
||||||
} PVRTexHeader;
|
} PVRTexHeader;
|
||||||
|
|
||||||
KRTexturePVR::KRTexturePVR(KRContext& context, KRDataBlock* data, std::string name) : KRTexture2D(context, data, name)
|
KRTexturePVR::KRTexturePVR(KRContext& context, Block* data, std::string name) : KRTexture2D(context, data, name)
|
||||||
{
|
{
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
@@ -139,8 +141,8 @@ KRTexturePVR::KRTexturePVR(KRContext& context, KRDataBlock* data, std::string na
|
|||||||
|
|
||||||
KRTexturePVR::~KRTexturePVR()
|
KRTexturePVR::~KRTexturePVR()
|
||||||
{
|
{
|
||||||
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
||||||
KRDataBlock* block = *itr;
|
Block* block = *itr;
|
||||||
delete block;
|
delete block;
|
||||||
}
|
}
|
||||||
m_blocks.clear();
|
m_blocks.clear();
|
||||||
@@ -179,8 +181,8 @@ long KRTexturePVR::getMemRequiredForSize(int max_dim)
|
|||||||
int height = m_iHeight;
|
int height = m_iHeight;
|
||||||
long memoryRequired = 0;
|
long memoryRequired = 0;
|
||||||
|
|
||||||
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
||||||
KRDataBlock* block = *itr;
|
Block* block = *itr;
|
||||||
if (width <= target_dim && height <= target_dim) {
|
if (width <= target_dim && height <= target_dim) {
|
||||||
memoryRequired += (long)block->getSize();
|
memoryRequired += (long)block->getSize();
|
||||||
}
|
}
|
||||||
@@ -216,8 +218,8 @@ bool KRTexturePVR::uploadTexture(KRDevice& device, VkImage& image, int lod_max_d
|
|||||||
// Upload texture data
|
// Upload texture data
|
||||||
int destination_level = 0;
|
int destination_level = 0;
|
||||||
int source_level = 0;
|
int source_level = 0;
|
||||||
for (std::list<KRDataBlock*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
for (std::list<Block*>::iterator itr = m_blocks.begin(); itr != m_blocks.end(); itr++) {
|
||||||
KRDataBlock* block = *itr;
|
Block* block = *itr;
|
||||||
if (width <= target_dim && height <= target_dim) {
|
if (width <= target_dim && height <= target_dim) {
|
||||||
|
|
||||||
if (width > current_lod_max_dim) {
|
if (width > current_lod_max_dim) {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
class KRTexturePVR : public KRTexture2D
|
class KRTexturePVR : public KRTexture2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KRTexturePVR(KRContext& context, KRDataBlock* data, std::string name);
|
KRTexturePVR(KRContext& context, mimir::Block* data, std::string name);
|
||||||
virtual ~KRTexturePVR();
|
virtual ~KRTexturePVR();
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
|
|
||||||
@@ -54,5 +54,5 @@ protected:
|
|||||||
unsigned int m_internalFormat;
|
unsigned int m_internalFormat;
|
||||||
bool m_bHasAlpha;
|
bool m_bHasAlpha;
|
||||||
|
|
||||||
std::list<KRDataBlock*> m_blocks;
|
std::list<mimir::Block*> m_blocks;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ typedef struct
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
KRTextureTGA::KRTextureTGA(KRContext& context, KRDataBlock* data, std::string name) : KRTexture2D(context, data, name)
|
KRTextureTGA::KRTextureTGA(KRContext& context, Block* data, std::string name) : KRTexture2D(context, data, name)
|
||||||
{
|
{
|
||||||
data->lock();
|
data->lock();
|
||||||
TGA_HEADER* pHeader = (TGA_HEADER*)data->getStart();
|
TGA_HEADER* pHeader = (TGA_HEADER*)data->getStart();
|
||||||
@@ -329,7 +329,7 @@ KRTexture* KRTextureTGA::compress(bool premultiply_alpha)
|
|||||||
|
|
||||||
m_pData->lock();
|
m_pData->lock();
|
||||||
|
|
||||||
std::list<KRDataBlock *> blocks;
|
std::list<Block *> blocks;
|
||||||
|
|
||||||
getContext().getTextureManager()->_setActiveTexture(0);
|
getContext().getTextureManager()->_setActiveTexture(0);
|
||||||
|
|
||||||
@@ -370,7 +370,7 @@ KRTexture* KRTextureTGA::compress(bool premultiply_alpha)
|
|||||||
while(lod_width > 1) {
|
while(lod_width > 1) {
|
||||||
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_WIDTH, &lod_width));
|
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_WIDTH, &lod_width));
|
||||||
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_size));
|
GLDEBUG(glGetTexLevelParameteriv(GL_TEXTURE_2D, lod_level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compressed_size));
|
||||||
KRDataBlock *new_block = new KRDataBlock();
|
Block *new_block = new Block();
|
||||||
new_block->expand(compressed_size);
|
new_block->expand(compressed_size);
|
||||||
new_block->lock();
|
new_block->lock();
|
||||||
GLDEBUG(glGetCompressedTexImage(GL_TEXTURE_2D, lod_level, new_block->getStart()));
|
GLDEBUG(glGetCompressedTexImage(GL_TEXTURE_2D, lod_level, new_block->getStart()));
|
||||||
@@ -390,7 +390,7 @@ KRTexture* KRTextureTGA::compress(bool premultiply_alpha)
|
|||||||
m_pData->unlock();
|
m_pData->unlock();
|
||||||
|
|
||||||
for(auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) {
|
for(auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) {
|
||||||
KRDataBlock *block = *block_itr;
|
Block *block = *block_itr;
|
||||||
delete block;
|
delete block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,10 +33,12 @@
|
|||||||
|
|
||||||
#include "KRTexture2D.h"
|
#include "KRTexture2D.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
class KRTextureTGA : public KRTexture2D
|
class KRTextureTGA : public KRTexture2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KRTextureTGA(KRContext& context, KRDataBlock* data, std::string name);
|
KRTextureTGA(KRContext& context, Block* data, std::string name);
|
||||||
virtual ~KRTextureTGA();
|
virtual ~KRTextureTGA();
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
|
|
||||||
|
|||||||
@@ -31,13 +31,15 @@
|
|||||||
|
|
||||||
#include "KRUnknown.h"
|
#include "KRUnknown.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = new KRDataBlock();
|
m_pData = new Block();
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension, KRDataBlock* data) : KRResource(context, name)
|
KRUnknown::KRUnknown(KRContext& context, std::string name, std::string extension, Block* data) : KRResource(context, name)
|
||||||
{
|
{
|
||||||
m_pData = data;
|
m_pData = data;
|
||||||
m_extension = extension;
|
m_extension = extension;
|
||||||
@@ -53,13 +55,13 @@ std::string KRUnknown::getExtension()
|
|||||||
return m_extension;
|
return m_extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KRUnknown::save(KRDataBlock& data)
|
bool KRUnknown::save(Block& data)
|
||||||
{
|
{
|
||||||
data.append(*m_pData);
|
data.append(*m_pData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRDataBlock* KRUnknown::getData()
|
Block* KRUnknown::getData()
|
||||||
{
|
{
|
||||||
return m_pData;
|
return m_pData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
|
|
||||||
class KRUnknown : public KRResource
|
class KRUnknown : public KRResource
|
||||||
@@ -41,17 +41,17 @@ class KRUnknown : public KRResource
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
KRUnknown(KRContext& context, std::string name, std::string extension);
|
KRUnknown(KRContext& context, std::string name, std::string extension);
|
||||||
KRUnknown(KRContext& context, std::string name, std::string extension, KRDataBlock* data);
|
KRUnknown(KRContext& context, std::string name, std::string extension, mimir::Block* data);
|
||||||
virtual ~KRUnknown();
|
virtual ~KRUnknown();
|
||||||
|
|
||||||
virtual std::string getExtension();
|
virtual std::string getExtension();
|
||||||
|
|
||||||
virtual bool save(KRDataBlock& data);
|
virtual bool save(mimir::Block& data);
|
||||||
|
|
||||||
KRDataBlock* getData();
|
mimir::Block* getData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string m_extension;
|
std::string m_extension;
|
||||||
KRDataBlock* m_pData;
|
mimir::Block* m_pData;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include "KRUnknownManager.h"
|
#include "KRUnknownManager.h"
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
|
|
||||||
|
using namespace mimir;
|
||||||
|
|
||||||
KRUnknownManager::KRUnknownManager(KRContext& context) : KRResourceManager(context)
|
KRUnknownManager::KRUnknownManager(KRContext& context) : KRResourceManager(context)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ void KRUnknownManager::add(KRUnknown* unknown)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KRResource* KRUnknownManager::loadResource(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRResource* KRUnknownManager::loadResource(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
// KRUnknown's can have any extension
|
// KRUnknown's can have any extension
|
||||||
return load(name, extension, data);
|
return load(name, extension, data);
|
||||||
@@ -87,7 +89,7 @@ KRResource* KRUnknownManager::getResource(const std::string& name, const std::st
|
|||||||
return get(name, extension);
|
return get(name, extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRUnknown* KRUnknownManager::load(const std::string& name, const std::string& extension, KRDataBlock* data)
|
KRUnknown* KRUnknownManager::load(const std::string& name, const std::string& extension, Block* data)
|
||||||
{
|
{
|
||||||
KRUnknown* unknown = new KRUnknown(getContext(), name, extension, data);
|
KRUnknown* unknown = new KRUnknown(getContext(), name, extension, data);
|
||||||
if (unknown) add(unknown);
|
if (unknown) add(unknown);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
#include "KRUnknown.h"
|
#include "KRUnknown.h"
|
||||||
#include "KRContextObject.h"
|
#include "KRContextObject.h"
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
|
|
||||||
class KRUnknownManager : public KRResourceManager
|
class KRUnknownManager : public KRResourceManager
|
||||||
{
|
{
|
||||||
@@ -45,12 +45,12 @@ public:
|
|||||||
KRUnknownManager(KRContext& context);
|
KRUnknownManager(KRContext& context);
|
||||||
virtual ~KRUnknownManager();
|
virtual ~KRUnknownManager();
|
||||||
|
|
||||||
virtual KRResource* loadResource(const std::string& name, const std::string& extension, KRDataBlock* data) override;
|
virtual KRResource* loadResource(const std::string& name, const std::string& extension, mimir::Block* data) override;
|
||||||
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
virtual KRResource* getResource(const std::string& name, const std::string& extension) override;
|
||||||
|
|
||||||
void add(KRUnknown* unknown);
|
void add(KRUnknown* unknown);
|
||||||
|
|
||||||
KRUnknown* load(const std::string& name, const std::string& extension, KRDataBlock* data);
|
KRUnknown* load(const std::string& name, const std::string& extension, mimir::Block* data);
|
||||||
KRUnknown* get(const std::string& name, const std::string& extension);
|
KRUnknown* get(const std::string& name, const std::string& extension);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// KRDataBlock.cpp
|
// block.cpp
|
||||||
// Kraken Engine
|
// Kraken Engine
|
||||||
//
|
//
|
||||||
// Copyright 2023 Kearwood Gilbert. All rights reserved.
|
// Copyright 2023 Kearwood Gilbert. All rights reserved.
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
// or implied, of Kearwood Gilbert.
|
// or implied, of Kearwood Gilbert.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "KRDataBlock.h"
|
#include "block.h"
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
#include "KRResource.h"
|
#include "KRResource.h"
|
||||||
#include "KRContext.h"
|
#include "KRContext.h"
|
||||||
@@ -40,6 +40,7 @@
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define KRENGINE_MIN_MMAP 32768
|
||||||
#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY - 1))
|
#define KRAKEN_MEM_ROUND_DOWN_PAGE(x) ((x) & ~(KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY - 1))
|
||||||
#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY - 1)) + KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY)
|
#define KRAKEN_MEM_ROUND_UP_PAGE(x) ((((x) - 1) & ~(KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY - 1)) + KRContext::KRENGINE_SYS_ALLOCATION_GRANULARITY)
|
||||||
|
|
||||||
@@ -47,7 +48,9 @@ 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()
|
namespace mimir {
|
||||||
|
|
||||||
|
Block::Block()
|
||||||
{
|
{
|
||||||
m_data = NULL;
|
m_data = NULL;
|
||||||
m_data_size = 0;
|
m_data_size = 0;
|
||||||
@@ -66,7 +69,7 @@ KRDataBlock::KRDataBlock()
|
|||||||
m_bReadOnly = false;
|
m_bReadOnly = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
KRDataBlock::KRDataBlock(void* data, size_t size)
|
Block::Block(void* data, size_t size)
|
||||||
{
|
{
|
||||||
m_data = NULL;
|
m_data = NULL;
|
||||||
m_data_size = 0;
|
m_data_size = 0;
|
||||||
@@ -86,13 +89,13 @@ KRDataBlock::KRDataBlock(void* data, size_t size)
|
|||||||
load(data, size);
|
load(data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRDataBlock::~KRDataBlock()
|
Block::~Block()
|
||||||
{
|
{
|
||||||
unload();
|
unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unload a file, releasing any mmap'ed file handles or malloc'ed ram that was in use
|
// Unload a file, releasing any mmap'ed file handles or malloc'ed ram that was in use
|
||||||
void KRDataBlock::unload()
|
void Block::unload()
|
||||||
{
|
{
|
||||||
assert(m_lockCount == 0);
|
assert(m_lockCount == 0);
|
||||||
|
|
||||||
@@ -130,7 +133,7 @@ void KRDataBlock::unload()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Encapsulate a pointer. Note - The pointer will not be free'ed
|
// Encapsulate a pointer. Note - The pointer will not be free'ed
|
||||||
bool KRDataBlock::load(void* data, size_t size)
|
bool Block::load(void* data, size_t size)
|
||||||
{
|
{
|
||||||
unload();
|
unload();
|
||||||
m_data = data;
|
m_data = data;
|
||||||
@@ -141,7 +144,7 @@ bool KRDataBlock::load(void* data, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load a file into memory using mmap. The data pointer will be protected as read-only until append() or expand() is called
|
// Load a file into memory using mmap. The data pointer will be protected as read-only until append() or expand() is called
|
||||||
bool KRDataBlock::load(const std::string& path)
|
bool Block::load(const std::string& path)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
unload();
|
unload();
|
||||||
@@ -180,10 +183,10 @@ bool KRDataBlock::load(const std::string& path)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a KRDataBlock encapsulating a sub-region of this block. The caller is responsible to free the object.
|
// Create a Block encapsulating a sub-region of this block. The caller is responsible to free the object.
|
||||||
KRDataBlock* KRDataBlock::getSubBlock(int start, int length)
|
Block* Block::getSubBlock(int start, int length)
|
||||||
{
|
{
|
||||||
KRDataBlock* new_block = new KRDataBlock();
|
Block* new_block = new Block();
|
||||||
|
|
||||||
new_block->m_data_size = length;
|
new_block->m_data_size = length;
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
@@ -206,27 +209,27 @@ 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* Block::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* Block::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 Block::getSize() const
|
||||||
{
|
{
|
||||||
return m_data_size;
|
return m_data_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expand the data block, and switch it to read-write mode. Note - this may result in a mmap'ed file being copied to malloc'ed ram and then closed
|
// Expand the data block, and switch it to read-write mode. Note - this may result in a mmap'ed file being copied to malloc'ed ram and then closed
|
||||||
void KRDataBlock::expand(size_t size)
|
void Block::expand(size_t size)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
if (m_data == NULL && m_hPackFile == INVALID_HANDLE_VALUE) {
|
if (m_data == NULL && m_hPackFile == INVALID_HANDLE_VALUE) {
|
||||||
@@ -265,7 +268,7 @@ 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 Block::append(void* data, size_t size)
|
||||||
{
|
{
|
||||||
// Expand the data block
|
// Expand the data block
|
||||||
expand(size);
|
expand(size);
|
||||||
@@ -278,13 +281,13 @@ 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 Block::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 Block::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) {
|
||||||
@@ -321,7 +324,7 @@ 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 Block::append(Block & data)
|
||||||
{
|
{
|
||||||
data.lock();
|
data.lock();
|
||||||
append(data.getStart(), data.getSize());
|
append(data.getStart(), data.getSize());
|
||||||
@@ -329,7 +332,7 @@ void KRDataBlock::append(KRDataBlock & data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Append string to the end of the block, increasing the size of the block and making it read-write. The resulting datablock includes a terminating character
|
// Append string to the end of the block, increasing the size of the block and making it read-write. The resulting datablock includes a terminating character
|
||||||
void KRDataBlock::append(const std::string & s)
|
void Block::append(const std::string & s)
|
||||||
{
|
{
|
||||||
const char* szText = s.c_str();
|
const char* szText = s.c_str();
|
||||||
size_t text_length = strlen(szText);
|
size_t text_length = strlen(szText);
|
||||||
@@ -349,7 +352,7 @@ 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 Block::save(const std::string & path)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -429,9 +432,9 @@ bool KRDataBlock::save(const std::string & path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get contents as a string
|
// Get contents as a string
|
||||||
std::string KRDataBlock::getString()
|
std::string Block::getString()
|
||||||
{
|
{
|
||||||
KRDataBlock b;
|
Block b;
|
||||||
b.append(*this);
|
b.append(*this);
|
||||||
b.append((void*)"\0", 1); // Ensure data is null terminated, to read as a string safely
|
b.append((void*)"\0", 1); // Ensure data is null terminated, to read as a string safely
|
||||||
b.lock();
|
b.lock();
|
||||||
@@ -471,7 +474,7 @@ void ReportWindowsLastError(LPCTSTR lpszFunction)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Lock the memory, forcing it to be loaded into a contiguous block of address space
|
// Lock the memory, forcing it to be loaded into a contiguous block of address space
|
||||||
void KRDataBlock::lock()
|
void Block::lock()
|
||||||
{
|
{
|
||||||
if (m_lockCount == 0) {
|
if (m_lockCount == 0) {
|
||||||
|
|
||||||
@@ -503,7 +506,7 @@ void KRDataBlock::lock()
|
|||||||
}
|
}
|
||||||
assert(m_mmapData != NULL);
|
assert(m_mmapData != NULL);
|
||||||
#elif defined(__APPLE__) || defined(ANDROID)
|
#elif defined(__APPLE__) || defined(ANDROID)
|
||||||
//fprintf(stderr, "KRDataBlock::lock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
|
//fprintf(stderr, "Block::lock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
|
||||||
// Round m_data_offset down to the next memory page, as required by mmap
|
// Round m_data_offset down to the next memory page, as required by mmap
|
||||||
|
|
||||||
if ((m_mmapData = mmap(0, m_data_size + alignment_offset, m_bReadOnly ? PROT_READ : PROT_WRITE, MAP_SHARED, m_fdPackFile, m_data_offset - alignment_offset)) == (caddr_t)-1) {
|
if ((m_mmapData = mmap(0, m_data_size + alignment_offset, m_bReadOnly ? PROT_READ : PROT_WRITE, MAP_SHARED, m_fdPackFile, m_data_offset - alignment_offset)) == (caddr_t)-1) {
|
||||||
@@ -551,7 +554,7 @@ m_lockCount++;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unlock the memory, releasing the address space for use by other allocations
|
// Unlock the memory, releasing the address space for use by other allocations
|
||||||
void KRDataBlock::unlock()
|
void Block::unlock()
|
||||||
{
|
{
|
||||||
// We expect that the data block was previously locked
|
// We expect that the data block was previously locked
|
||||||
assertLocked();
|
assertLocked();
|
||||||
@@ -571,7 +574,7 @@ void KRDataBlock::unlock()
|
|||||||
free(m_data);
|
free(m_data);
|
||||||
m_data = NULL;
|
m_data = NULL;
|
||||||
} else {
|
} else {
|
||||||
//fprintf(stderr, "KRDataBlock::unlock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
|
//fprintf(stderr, "Block::unlock - \"%s\" (%i)\n", m_fileOwnerDataBlock->m_fileName.c_str(), m_lockCount);
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
if (m_mmapData != NULL) {
|
if (m_mmapData != NULL) {
|
||||||
UnmapViewOfFile(m_mmapData);
|
UnmapViewOfFile(m_mmapData);
|
||||||
@@ -599,7 +602,9 @@ m_lockCount--;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Assert if not locked
|
// Assert if not locked
|
||||||
void KRDataBlock::assertLocked()
|
void Block::assertLocked()
|
||||||
{
|
{
|
||||||
assert(m_lockCount > 0);
|
assert(m_lockCount > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace mimir
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// KRDataBlock.h
|
// block.h
|
||||||
// Kraken Engine
|
// Kraken Engine
|
||||||
//
|
//
|
||||||
// Copyright 2023 Kearwood Gilbert. All rights reserved.
|
// Copyright 2023 Kearwood Gilbert. All rights reserved.
|
||||||
@@ -31,20 +31,20 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include "KREngine-common.h"
|
#include "KREngine-common.h"
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define KRENGINE_MIN_MMAP 32768
|
namespace mimir {
|
||||||
|
class Block
|
||||||
class KRDataBlock
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KRDataBlock();
|
Block();
|
||||||
KRDataBlock(void* data, size_t size);
|
Block(void* data, size_t size);
|
||||||
~KRDataBlock();
|
~Block();
|
||||||
|
|
||||||
// Encapsulate a pointer. Note - The pointer will not be free'ed
|
// Encapsulate a pointer. Note - The pointer will not be free'ed
|
||||||
bool load(void* data, size_t size);
|
bool load(void* data, size_t size);
|
||||||
@@ -55,14 +55,14 @@ public:
|
|||||||
// Save the data to a file.
|
// Save the data to a file.
|
||||||
bool save(const std::string& path);
|
bool save(const std::string& path);
|
||||||
|
|
||||||
// Create a KRDataBlock encapsulating a sub-region of this block. The caller is responsible to free the object.
|
// Create a Block encapsulating a sub-region of this block. The caller is responsible to free the object.
|
||||||
KRDataBlock* getSubBlock(int start, int length);
|
Block* getSubBlock(int start, int length);
|
||||||
|
|
||||||
// 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 append(void* data, size_t size);
|
void append(void* data, 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 append(KRDataBlock& data);
|
void append(Block& data);
|
||||||
|
|
||||||
// Append string to the end of the block, increasing the size of the block and making it read-write. The null terminating character is included
|
// Append string to the end of the block, increasing the size of the block and making it read-write. The null terminating character is included
|
||||||
void append(const std::string& s);
|
void append(const std::string& s);
|
||||||
@@ -111,7 +111,7 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string m_fileName;
|
std::string m_fileName;
|
||||||
KRDataBlock* m_fileOwnerDataBlock;
|
Block* m_fileOwnerDataBlock;
|
||||||
void* m_mmapData;
|
void* m_mmapData;
|
||||||
|
|
||||||
// For malloc'ed objects:
|
// For malloc'ed objects:
|
||||||
@@ -127,3 +127,5 @@ private:
|
|||||||
void assertLocked();
|
void assertLocked();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
} // namespace mimir
|
||||||
|
|
||||||
Reference in New Issue
Block a user