Refactoring of streamer code to integrate texture and vbo memory management in progress.

--HG--
branch : nfb
This commit is contained in:
2014-05-13 22:01:19 -07:00
parent 1560c8f19f
commit dc9bec2766
4 changed files with 16 additions and 171 deletions

View File

@@ -1,60 +0,0 @@
//
// KRMeshManager.h
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#ifndef KRMESHSTREAMER_H
#define KRMESHSTREAMER_H
#include "KREngine-common.h"
#include <thread>
#include <atomic>
class KRContext;
class KRMeshStreamer
{
public:
KRMeshStreamer(KRContext &context);
~KRMeshStreamer();
void startStreamer();
private:
KRContext &m_context;
std::thread m_thread;
std::atomic<bool> m_stop;
std::atomic<bool> m_running;
void run();
};
#endif /* defined(KRMESHSTREAMER_H) */

View File

@@ -1,93 +0,0 @@
//
// KRMeshStreamer.cpp
// Kraken
//
// Created by Kearwood Gilbert on 11/1/2013.
// Copyright (c) 2013 Kearwood Software. All rights reserved.
//
#include "KRMeshStreamer.h"
#include "KREngine-common.h"
#include "KRContext.h"
#include <chrono>
#if TARGET_OS_IPHONE
EAGLContext *gMeshStreamerContext = nil;
#elif TARGET_OS_MAC
NSOpenGLContext *gMeshStreamerContext = nil;
#else
#error Unsupported Platform
#endif
KRMeshStreamer::KRMeshStreamer(KRContext &context) : m_context(context)
{
m_running = false;
m_stop = false;
}
void KRMeshStreamer::startStreamer()
{
if(!m_running) {
m_running = true;
#if TARGET_OS_IPHONE
// FIXME: need to add code check for iOS 7 and also this appears to cause crashing
gMeshStreamerContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: [EAGLContext currentContext].sharegroup];
//gMeshStreamerContext.multiThreaded = TRUE;
#elif TARGET_OS_MAC
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
// NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy,
0
};
NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
gMeshStreamerContext = [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext: [NSOpenGLContext currentContext] ];
#else
#error Unsupported Platform
#endif
m_thread = std::thread(&KRMeshStreamer::run, this);
}
}
KRMeshStreamer::~KRMeshStreamer()
{
if(m_running) {
m_stop = true;
m_thread.join();
m_running = false;
}
[gMeshStreamerContext release];
}
void KRMeshStreamer::run()
{
pthread_setname_np("Kraken - Mesh Streamer");
std::chrono::microseconds sleep_duration( 100 );
#if TARGET_OS_IPHONE
[EAGLContext setCurrentContext: gMeshStreamerContext];
#elif TARGET_OS_MAC
[gMeshStreamerContext makeCurrentContext];
#else
#error Unsupported Platform
#endif
while(!m_stop)
{
if(m_context.getStreamingEnabled()) {
}
std::this_thread::sleep_for( sleep_duration );
}
}

View File

@@ -29,8 +29,8 @@
// or implied, of Kearwood Gilbert. // or implied, of Kearwood Gilbert.
// //
#ifndef KRTEXTURESTREAMER_H #ifndef KRSTREAMER_H
#define KRTEXTURESTREAMER_H #define KRSTREAMER_H
#include "KREngine-common.h" #include "KREngine-common.h"
@@ -39,11 +39,11 @@
class KRContext; class KRContext;
class KRTextureStreamer class KRStreamer
{ {
public: public:
KRTextureStreamer(KRContext &context); KRStreamer(KRContext &context);
~KRTextureStreamer(); ~KRStreamer();
void startStreamer(); void startStreamer();
@@ -57,4 +57,4 @@ private:
void run(); void run();
}; };
#endif /* defined(KRTEXTURESTREAMER_H) */ #endif /* defined(KRSTREAMER_H) */

View File

@@ -1,5 +1,5 @@
// //
// KRTextureStreamer.cpp // KRStreamer.cpp
// Kraken // Kraken
// //
// Created by Kearwood Gilbert on 11/1/2013. // Created by Kearwood Gilbert on 11/1/2013.
@@ -8,7 +8,7 @@
#include "KREngine-common.h" #include "KREngine-common.h"
#include "KRTextureStreamer.h" #include "KRStreamer.h"
#include "KRContext.h" #include "KRContext.h"
#include <chrono> #include <chrono>
@@ -27,13 +27,13 @@ NSOpenGLContext *gTextureStreamerContext = nil;
#error Unsupported Platform #error Unsupported Platform
#endif #endif
KRTextureStreamer::KRTextureStreamer(KRContext &context) : m_context(context) KRStreamer::KRStreamer(KRContext &context) : m_context(context)
{ {
m_running = false; m_running = false;
m_stop = false; m_stop = false;
} }
void KRTextureStreamer::startStreamer() void KRStreamer::startStreamer()
{ {
if(!m_running) { if(!m_running) {
m_running = true; m_running = true;
@@ -61,11 +61,11 @@ void KRTextureStreamer::startStreamer()
#error Unsupported Platform #error Unsupported Platform
#endif #endif
m_thread = std::thread(&KRTextureStreamer::run, this); m_thread = std::thread(&KRStreamer::run, this);
} }
} }
KRTextureStreamer::~KRTextureStreamer() KRStreamer::~KRStreamer()
{ {
if(m_running) { if(m_running) {
m_stop = true; m_stop = true;
@@ -76,10 +76,10 @@ KRTextureStreamer::~KRTextureStreamer()
[gTextureStreamerContext release]; [gTextureStreamerContext release];
} }
void KRTextureStreamer::run() void KRStreamer::run()
{ {
pthread_setname_np("Kraken - Texture Streamer"); pthread_setname_np("Kraken - Streamer");
std::chrono::microseconds sleep_duration( 100 ); std::chrono::microseconds sleep_duration( 100 );
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
@@ -92,9 +92,7 @@ void KRTextureStreamer::run()
while(!m_stop) while(!m_stop)
{ {
if(m_context.getStreamingEnabled()) { m_context.doStreaming();
m_context.getTextureManager()->doStreaming();
}
std::this_thread::sleep_for( sleep_duration ); std::this_thread::sleep_for( sleep_duration );
} }
} }