Windows implementation WIP

This commit is contained in:
Kearwood Gilbert
2016-07-10 03:33:58 -07:00
parent 16b731cea9
commit 3a7c1ba0eb
156 changed files with 86861 additions and 75 deletions

View File

@@ -232,11 +232,11 @@ bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const
if(v1.c[i] < min.c[i]) {
quadrant[i] = LEFT;
candidatePlane[i] = min.c[i];
inside = FALSE;
inside = false;
}else if (v1.c[i] > max.c[i]) {
quadrant[i] = RIGHT;
candidatePlane[i] = max.c[i];
inside = FALSE;
inside = false;
}else {
quadrant[i] = MIDDLE;
}
@@ -275,7 +275,7 @@ bool KRAABB::intersectsRay(const KRVector3 &v1, const KRVector3 &dir) const
} else {
coord[i] = candidatePlane[i];
}
}
}
return true; /* ray hits box */
}

View File

@@ -35,8 +35,7 @@
#include "KRContext.h"
#include "KRNode.h"
#include "KRAnimationCurve.h"
#include "tinyxml2.h"
#include "KREngine-common.h"
KRAnimation::KRAnimation(KRContext &context, std::string name) : KRResource(context, name)
{

View File

@@ -34,7 +34,6 @@
#include "KRContextObject.h"
#include "KREngine-common.h"
#include "tinyxml2.h"
#include "KRNode.h"
#include "KRAnimationCurve.h"

View File

@@ -34,9 +34,13 @@
#include "KRContextObject.h"
#include "KREngine-common.h"
#include "tinyxml2.h"
#include "KRAnimationAttribute.h"
namespace tinyxml2 {
class XMLNode;
class XMLAttribute;
}
class KRAnimationLayer : public KRContextObject {
public:
KRAnimationLayer(KRContext &context);

View File

@@ -162,7 +162,7 @@ void KRAudioManager::setListenerScene(KRScene *scene)
void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData)
{
uint64_t start_time = mach_absolute_time();
// uint64_t start_time = mach_absolute_time();
AudioUnitSampleType *outA = (AudioUnitSampleType *)ioData->mBuffers[0].mData;
@@ -213,7 +213,7 @@ void KRAudioManager::renderAudio(UInt32 inNumberFrames, AudioBufferList *ioData)
}
uint64_t end_time = mach_absolute_time();
// uint64_t end_time = mach_absolute_time();
// uint64_t duration = (end_time - start_time) * m_timebase_info.numer / m_timebase_info.denom; // Nanoseconds
// double ms = duration;
// ms = ms / 1000000.0;

View File

@@ -34,7 +34,6 @@
#include "KREngine-common.h"
#include "KRAudioSample.h"
#include "KRContextObject.h"
#include "KRDataBlock.h"
#include "KRMat4.h"

View File

@@ -9,7 +9,6 @@
#ifndef KRBEHAVIOR_H
#define KRBEHAVIOR_H
#include "tinyxml2.h"
#include <map>
/*
@@ -20,6 +19,9 @@
class KRBehavior;
class KRNode;
namespace tinyxml2 {
class XMLElement;
} // namespace tinyxml2
typedef KRBehavior *(*KRBehaviorFactoryFunction)(std::map<std::string, std::string> attributes);
typedef std::map<std::string, KRBehaviorFactoryFunction> KRBehaviorFactoryFunctionMap;

View File

@@ -931,7 +931,7 @@ std::string KRCamera::getDebugText()
case KRRenderSettings::KRENGINE_DEBUG_DISPLAY_MEMORY: // ----====---- Memory Utilization ----=====----
{
#if defined(__APPLE__)
// ---- CPU Memory ----
struct task_basic_info info;
@@ -965,7 +965,8 @@ std::string KRCamera::getDebugText()
stream << (vm_stat.free_count * pagesize / 1024 / 1024) << " MB\t";
stream << ((vm_stat.wire_count + vm_stat.active_count + vm_stat.inactive_count) * pagesize / 1024 / 1024) << " MB";
}
#endif // defined(__APPLE__)
// ---- GPU Memory ----
int texture_count_active = m_pContext->getTextureManager()->getActiveTextures().size();
int texture_count = texture_count_active;

View File

@@ -10,6 +10,8 @@
#include "KRContext.h"
#include "KRCamera.h"
#include "KRAudioManager.h"
#include "KRAudioSample.h"
int KRContext::KRENGINE_MAX_SHADER_HANDLES;
int KRContext::KRENGINE_GPU_MEM_MAX;
@@ -23,6 +25,7 @@ int KRContext::KRENGINE_PRESTREAM_DISTANCE;
#elif TARGET_OS_MAC
#elif defined(_WIN32) || defined(_WIN64)
#else
@@ -327,10 +330,13 @@ void KRContext::setStreamingEnabled(bool enable)
m_streamingEnabled = enable;
}
#if TARGET_OS_IPHONE || TARGET_OS_MAC
void KRContext::getMemoryStats(long &free_memory)
{
free_memory = 0;
#if TARGET_OS_IPHONE || TARGET_OS_MAC
mach_port_t host_port = mach_host_self();
mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
vm_size_t pagesize = 0;
@@ -345,11 +351,10 @@ void KRContext::getMemoryStats(long &free_memory)
free_memory = (vm_stat.free_count + vm_stat.inactive_count) * pagesize;
}
#else
#error Unsupported Platform
#endif
}
#endif
void KRContext::doStreaming()
{
if(m_streamingEnabled) {

View File

@@ -18,10 +18,11 @@
#include "KRMeshManager.h"
#include "KRAnimationManager.h"
#include "KRAnimationCurveManager.h"
#include "KRAudioManager.h"
#include "KRUnknownManager.h"
#include "KRStreamer.h"
class KRAudioManager;
class KRContext {
public:
static int KRENGINE_MAX_SHADER_HANDLES;
@@ -72,8 +73,11 @@ public:
bool getStreamingEnabled();
void setStreamingEnabled(bool enable);
#if TARGET_OS_IPHONE || TARGET_OS_MAC
// XXX This doesn't belong here, and might not actually be needed at all
void getMemoryStats(long &free_memory);
#endif
typedef enum {
LOG_LEVEL_INFORMATION,
LOG_LEVEL_WARNING,
@@ -115,8 +119,10 @@ private:
long m_last_fully_streamed_frame; // TODO - Does this need to be atomic?
float m_absolute_time;
#ifdef __APPLE__
mach_timebase_info_data_t m_timebase_info;
#endif
std::atomic<bool> m_streamingEnabled;

View File

@@ -44,8 +44,8 @@ int KRDirectionalLight::configureShadowBufferViewports(const KRViewport &viewpor
const float KRENGINE_SHADOW_BOUNDS_EXTRA_SCALE = 1.25f; // Scale to apply to view frustrum bounds so that we don't need to refresh shadows on every frame
int cShadows = 1;
for(int iShadow=0; iShadow < cShadows; iShadow++) {
GLfloat shadowMinDepths[3][3] = {{0.0, 0.0, 0.0},{0.0, 0.0, 0.0},{0.0, 0.05, 0.3}};
GLfloat shadowMaxDepths[3][3] = {{0.0, 0.0, 1.0},{0.1, 0.0, 0.0},{0.1, 0.3, 1.0}};
GLfloat shadowMinDepths[3][3] = {{0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f},{0.0f, 0.05f, 0.3f}};
GLfloat shadowMaxDepths[3][3] = {{0.0f, 0.0f, 1.0f},{0.1f, 0.0f, 0.0f},{0.1f, 0.3f, 1.0f}};
float min_depth = 0.0f;
float max_depth = 1.0f;

View File

@@ -30,26 +30,53 @@ float const D2R = PI * 2 / 360;
#include <fstream>
#include <stdint.h>
#include <stdio.h>
#if defined(_WIN32) || defined(_WIN64)
#include "../3rdparty/tinyxml2/tinyxml2.h"
#else
#include <sys/mman.h>
#include <unistd.h>
#include <pthread.h>
#include <Accelerate/Accelerate.h>
#include <AudioToolbox/AudioToolbox.h>
#include <AudioToolbox/AudioFile.h>
#include <AudioToolbox/ExtendedAudioFile.h>
#include <AudioToolbox/AUGraph.h>
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#if TARGET_OS_IPHONE
#include <OpenAL/oalMacOSX_OALExtensions.h>
#else
#include <OpenAL/MacOSX_OALExtensions.h>
#endif
#include "tinyxml2.h"
#endif
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/signals2/mutex.hpp>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <time.h>
#include <limits>
#include <unistd.h>
#include <iostream>
#include <math.h>
#include <pthread.h>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/signals2/mutex.hpp>
#include <iostream>
// _USE_MATH_DEFINES must be defined to get M_PI in Windows
#define _USE_MATH_DEFINES
#include <math.h>
#include <atomic>
#include <thread>
#include "tinyxml2.h"
using std::vector;
@@ -84,18 +111,41 @@ using std::unordered_map;
using std::unordered_multimap;
using std::hash;
#if TARGET_OS_IPHONE
#if defined(_WIN32) || defined(_WIN64)
#include <mutex>
#include <cstdint>
typedef int64_t __int64_t;
typedef uint64_t __uint64_t;
typedef int32_t __int32_t;
typedef uint32_t __uint32_t;
typedef int16_t __int16_t;
typedef uint16_t __uint16_t;
typedef int8_t __int8_t;
typedef uint8_t __uint8_t;
#include <GL/glew.h>
// OpenGL ES 2.0 mapping to OpenGL 3.2
#define glDeleteQueriesEXT glDeleteQueries
#define glGenQueriesEXT glGenQueries
#define glBeginQueryEXT glBeginQuery
#define glEndQueryEXT glEndQuery
#define glGetQueryObjectuivEXT glGetQueryObjectuiv
#define glTexStorage2DEXT glTexStorage2D
#define GL_ANY_SAMPLES_PASSED_EXT GL_ANY_SAMPLES_PASSED
#define GL_QUERY_RESULT_EXT GL_QUERY_RESULT
#elif TARGET_OS_IPHONE
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#else
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
// OpenGL ES 2.0 mapping to OpenGL 3.2 mappings
// OpenGL ES 2.0 mapping to OpenGL 3.2
#define glDepthRangef glDepthRange
#define glClearDepthf glClearDepth
#define glDeleteQueriesEXT glDeleteQueries
@@ -119,21 +169,7 @@ using std::hash;
#endif
#include <Accelerate/Accelerate.h>
#include <AudioToolbox/AudioToolbox.h>
#include <AudioToolbox/AudioFile.h>
#include <AudioToolbox/ExtendedAudioFile.h>
#include <AudioToolbox/AUGraph.h>
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#if TARGET_OS_IPHONE
#include <OpenAL/oalMacOSX_OALExtensions.h>
#else
#include <OpenAL/MacOSX_OALExtensions.h>
#endif
#if DEBUG
#if defined(DEBUG) || defined(_DEBUG)
#define GLDEBUG(x) \
x; \
{ \
@@ -148,7 +184,7 @@ fprintf(stderr, "Error at line number %d, in file %s. glGetError() returned %i f
#endif
#if DEBUG
#if defined(DEBUG) || defined(_DEBUG)
#define ALDEBUG(x) \
x; \
{ \
@@ -162,7 +198,7 @@ fprintf(stderr, "Error at line number %d, in file %s. alGetError() returned %i f
#define ALDEBUG(x) x;
#endif
#if DEBUG
#if defined(DEBUG) || defined(_DEBUG)
#define OSDEBUG(x) \
{ \
OSStatus e = x; \
@@ -176,7 +212,7 @@ fprintf(stderr, "Error at line number %d, in file %s. Returned %d for call %s\n"
#endif
#if GL_EXT_debug_marker && DEBUG
#if defined(GL_EXT_debug_marker) && (defined(DEBUG) || defined(_DEBUG))
#define GL_PUSH_GROUP_MARKER(x) glPushGroupMarkerEXT(0, x)
#define GL_POP_GROUP_MARKER glPopGroupMarkerEXT()

View File

@@ -39,7 +39,11 @@
#include "KRShader.h"
#include "KRShaderManager.h"
#include "KRContext.h"
#if defined(_WIN32) || defined(_WIN64)
#include "../3rdparty/forsyth/forsyth.h"
#else
#include "forsyth.h"
#endif
KRMesh::KRMesh(KRContext &context, std::string name) : KRResource(context, name) {
@@ -1454,7 +1458,7 @@ void KRMesh::convertToIndexed()
delete szKey;
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Convert to indexed, before: %i after: %i \(%.2f%% saving)", getHeader()->vertex_count, mi.vertices.size(), ((float)getHeader()->vertex_count - (float)mi.vertices.size()) / (float)getHeader()->vertex_count * 100.0f);
KRContext::Log(KRContext::LOG_LEVEL_INFORMATION, "Convert to indexed, before: %i after: %i (%.2f%% saving)", getHeader()->vertex_count, mi.vertices.size(), ((float)getHeader()->vertex_count - (float)mi.vertices.size()) / (float)getHeader()->vertex_count * 100.0f);
mi.format = KRENGINE_MODEL_FORMAT_INDEXED_TRIANGLES;

View File

@@ -85,7 +85,7 @@ tinyxml2::XMLElement *KRModel::saveXML( tinyxml2::XMLNode *parent)
return e;
}
void KRModel::setRimColor(const const KRVector3 &rim_color)
void KRModel::setRimColor(const KRVector3 &rim_color)
{
m_rim_color = rim_color;
}

View File

@@ -12,7 +12,6 @@
#include "KRResource.h"
#include "KRVector3.h"
#include "KRViewport.h"
#include "tinyxml2.h"
#include "KROctreeNode.h"
#include "KRBehavior.h"
@@ -29,6 +28,10 @@ class KRNode;
class KRPointLight;
class KRSpotLight;
class KRDirectionalLight;
namespace tinyxml2 {
class XMLNode;
class XMLAttribute;
}
class KRNode : public KRContextObject
{

View File

@@ -32,7 +32,6 @@
#include "KREngine-common.h"
#include "KRVector3.h"
#include "KRMat4.h"
#include "tinyxml2.h"
#include "KRLight.h"
@@ -43,6 +42,7 @@
#include "KRSpotLight.h"
#include "KRPointLight.h"
#include "KRQuaternion.h"
#include "KRAudioManager.h"
const long KRENGINE_OCCLUSION_TEST_EXPIRY = 10;

View File

@@ -557,7 +557,7 @@ bool KRShader::bind(KRCamera &camera, const KRViewport &viewport, const KRMat4 &
setUniform(KRENGINE_UNIFORM_RENDER_FRAME, 1);
setUniform(KRENGINE_UNIFORM_VOLUMETRIC_ENVIRONMENT_FRAME, 2);
#if DEBUG
#if defined(DEBUG)
if(shander_changed) { // FINDME!! KIP!! HACK!!
GLint logLength;

View File

@@ -34,7 +34,7 @@
#include "KREngine-common.h"
Byte _KTXFileIdentifier[12] = {
__uint8_t _KTXFileIdentifier[12] = {
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
};
@@ -97,18 +97,18 @@ KRTextureKTX::KRTextureKTX(KRContext &context, std::string name, GLenum internal
m_header.pixelDepth = 0;
m_header.numberOfArrayElements = 0;
m_header.numberOfFaces = 1;
m_header.numberOfMipmapLevels = (UInt32)blocks.size();
m_header.numberOfMipmapLevels = (__uint32_t)blocks.size();
m_header.bytesOfKeyValueData = 0;
m_pData->append(&m_header, sizeof(m_header));
for(auto block_itr = blocks.begin(); block_itr != blocks.end(); block_itr++) {
KRDataBlock *source_block = *block_itr;
UInt32 block_size = (UInt32)source_block->getSize();
__uint32_t block_size = (__uint32_t)source_block->getSize();
m_pData->append(&block_size, 4);
m_pData->append(*source_block);
m_blocks.push_back(m_pData->getSubBlock((int)m_pData->getSize() - (int)block_size, (int)block_size));
size_t alignment_padding_size = KRALIGN(m_pData->getSize()) - m_pData->getSize();
Byte alignment_padding[4] = {0, 0, 0, 0};
__uint8_t alignment_padding[4] = {0, 0, 0, 0};
if(alignment_padding_size > 0) {
m_pData->append(&alignment_padding, alignment_padding_size);
}

View File

@@ -29,20 +29,20 @@ protected:
typedef struct _KTXHeader
{
Byte identifier[12];
UInt32 endianness;
UInt32 glType;
UInt32 glTypeSize;
UInt32 glFormat;
UInt32 glInternalFormat;
UInt32 glBaseInternalFormat;
UInt32 pixelWidth;
UInt32 pixelHeight;
UInt32 pixelDepth;
UInt32 numberOfArrayElements;
UInt32 numberOfFaces;
UInt32 numberOfMipmapLevels;
UInt32 bytesOfKeyValueData;
__uint8_t identifier[12];
__uint32_t endianness;
__uint32_t glType;
__uint32_t glTypeSize;
__uint32_t glFormat;
__uint32_t glInternalFormat;
__uint32_t glBaseInternalFormat;
__uint32_t pixelWidth;
__uint32_t pixelHeight;
__uint32_t pixelDepth;
__uint32_t numberOfArrayElements;
__uint32_t numberOfFaces;
__uint32_t numberOfMipmapLevels;
__uint32_t bytesOfKeyValueData;
} KTXHeader;
KTXHeader m_header;

View File

@@ -11,6 +11,8 @@
#include "KRContext.h"
#include "KRTextureKTX.h"
#if defined(_WIN32) || defined(_WIN64)
#pragma pack(1)
typedef struct {
char idlength;
char colourmaptype;
@@ -24,7 +26,24 @@ typedef struct {
short height;
char bitsperpixel;
char imagedescriptor;
} TGA_HEADER;
#pragma pack()
#else
typedef struct {
char idlength;
char colourmaptype;
char imagetype;
short int colourmaporigin;
short int colourmaplength;
char colourmapdepth;
short int x_origin;
short int y_origin;
short width;
short height;
char bitsperpixel;
char imagedescriptor;
} __attribute__((packed)) TGA_HEADER;
#endif
KRTextureTGA::KRTextureTGA(KRContext &context, KRDataBlock *data, std::string name) : KRTexture2D(context, data, name)

View File

@@ -31,7 +31,6 @@
#include "KREngine-common.h"
#include "KRVector3.h"
#include "tinyxml2.h"
const KRVector3 KRVECTOR3_ZERO(0.0f, 0.0f, 0.0f);