REmove more of the unnecessary GLBacken .h and GPUCOnfig.h include, The gpu::Context is now completely agnostic of the True Backend

This commit is contained in:
Sam Gateau 2015-07-30 15:07:36 -07:00
parent d84e2d31ea
commit 14f4c9c6c0
10 changed files with 63 additions and 36 deletions

View file

@ -772,8 +772,9 @@ void Application::initializeGL() {
} }
#endif #endif
// Where the gpuContext is created and where the TRUE Backend is created and assigned // Where the gpuContext is initialized and where the TRUE Backend is created and assigned
_gpuContext = std::make_shared<gpu::Context>(new gpu::GLBackend()); gpu::Context::init<gpu::GLBackend>();
_gpuContext = std::make_shared<gpu::Context>();
initDisplay(); initDisplay();
qCDebug(interfaceapp, "Initialized Display."); qCDebug(interfaceapp, "Initialized Display.");

View file

@ -13,7 +13,6 @@
#define hifi_GLCanvas_h #define hifi_GLCanvas_h
#include <QDebug> #include <QDebug>
#include <gpu/GPUConfig.h>
#include <QGLWidget> #include <QGLWidget>
#include <QTimer> #include <QTimer>

View file

@ -10,13 +10,16 @@
// //
#include "Context.h" #include "Context.h"
// this include should disappear! as soon as the gpu::Context is in place
#include "GLBackend.h"
using namespace gpu; using namespace gpu;
Context::Context(Backend* backend) : Context::CreateBackend Context::_createBackendCallback = nullptr;
_backend(backend) { Context::MakeProgram Context::_makeProgramCallback = nullptr;
std::once_flag Context::_initialized;
Context::Context() {
if (_createBackendCallback) {
_backend.reset(_createBackendCallback());
}
} }
Context::Context(const Context& context) { Context::Context(const Context& context) {
@ -26,8 +29,8 @@ Context::~Context() {
} }
bool Context::makeProgram(Shader& shader, const Shader::BindingSet& bindings) { bool Context::makeProgram(Shader& shader, const Shader::BindingSet& bindings) {
if (shader.isProgram()) { if (shader.isProgram() && _makeProgramCallback) {
return GLBackend::makeProgram(shader, bindings); return _makeProgramCallback(shader, bindings);
} }
return false; return false;
} }

View file

@ -12,6 +12,7 @@
#define hifi_gpu_Context_h #define hifi_gpu_Context_h
#include <assert.h> #include <assert.h>
#include <mutex>
#include "Batch.h" #include "Batch.h"
@ -26,13 +27,12 @@ namespace gpu {
class Backend { class Backend {
public: public:
virtual~ Backend() {}; virtual~ Backend() {};
virtual void render(Batch& batch) = 0; virtual void render(Batch& batch) = 0;
virtual void syncCache() = 0; virtual void syncCache() = 0;
virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage) = 0; virtual void downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage) = 0;
class TransformObject { class TransformObject {
public: public:
Mat4 _model; Mat4 _model;
@ -118,7 +118,21 @@ protected:
class Context { class Context {
public: public:
Context(Backend* backend); typedef Backend* (*CreateBackend)();
typedef bool (*MakeProgram)(Shader& shader, const Shader::BindingSet& bindings);
// This one call must happen before any context is created or used (Shader::MakeProgram) in order to setup the Backend and any singleton data needed
template <class T>
static void init() {
std::call_once(_initialized, [] {
_createBackendCallback = T::createBackend;
_makeProgramCallback = T::makeProgram;
T::init();
});
}
Context();
~Context(); ~Context();
void render(Batch& batch); void render(Batch& batch);
@ -132,13 +146,17 @@ public:
protected: protected:
Context(const Context& context); Context(const Context& context);
std::unique_ptr<Backend> _backend;
// This function can only be called by "static Shader::makeProgram()" // This function can only be called by "static Shader::makeProgram()"
// makeProgramShader(...) make a program shader ready to be used in a Batch. // makeProgramShader(...) make a program shader ready to be used in a Batch.
// It compiles the sub shaders, link them and defines the Slots and their bindings. // It compiles the sub shaders, link them and defines the Slots and their bindings.
// If the shader passed is not a program, nothing happens. // If the shader passed is not a program, nothing happens.
static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet()); static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings);
std::unique_ptr<Backend> _backend; static CreateBackend _createBackendCallback;
static MakeProgram _makeProgramCallback;
static std::once_flag _initialized;
friend class Shader; friend class Shader;
}; };

View file

@ -63,12 +63,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
(&::gpu::GLBackend::do_glLineWidth), (&::gpu::GLBackend::do_glLineWidth),
}; };
GLBackend::GLBackend() : void GLBackend::init() {
_input(),
_transform(),
_pipeline(),
_output()
{
static std::once_flag once; static std::once_flag once;
std::call_once(once, [] { std::call_once(once, [] {
qCDebug(gpulogging) << "GL Version: " << QString((const char*) glGetString(GL_VERSION)); qCDebug(gpulogging) << "GL Version: " << QString((const char*) glGetString(GL_VERSION));
@ -108,7 +103,18 @@ GLBackend::GLBackend() :
}*/ }*/
#endif #endif
}); });
}
Backend* GLBackend::createBackend() {
return new GLBackend();
}
GLBackend::GLBackend() :
_input(),
_transform(),
_pipeline(),
_output()
{
initInput(); initInput();
initTransform(); initTransform();
} }

View file

@ -22,10 +22,17 @@
namespace gpu { namespace gpu {
class GLBackend : public Backend { class GLBackend : public Backend {
public:
// Context Backend static interface required
friend class Context;
static void init();
static Backend* createBackend();
static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet());
explicit GLBackend(bool syncCache); explicit GLBackend(bool syncCache);
GLBackend(); GLBackend();
public:
virtual ~GLBackend(); virtual ~GLBackend();
virtual void render(Batch& batch); virtual void render(Batch& batch);
@ -47,7 +54,6 @@ public:
static void checkGLStackStable(std::function<void()> f); static void checkGLStackStable(std::function<void()> f);
static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet());
class GLBuffer : public GPUObject { class GLBuffer : public GPUObject {

View file

@ -18,7 +18,6 @@
#include <QMap> #include <QMap>
#include <QQueue> #include <QQueue>
#include <gpu/Batch.h> #include <gpu/Batch.h>
#include <gpu/GPUConfig.h>
#include "RenderUtilsLogging.h" #include "RenderUtilsLogging.h"
static QQueue<gpu::FramebufferPointer> _cachedFramebuffers; static QQueue<gpu::FramebufferPointer> _cachedFramebuffers;

View file

@ -18,10 +18,7 @@
#include <ViewFrustum.h> #include <ViewFrustum.h>
#include <RenderArgs.h> #include <RenderArgs.h>
#include <gpu/Batch.h>
#include <gpu/Context.h> #include <gpu/Context.h>
#include <gpu/GPUConfig.h>
#include <gpu/GPULogging.h>
#include "drawItemBounds_vert.h" #include "drawItemBounds_vert.h"
#include "drawItemBounds_frag.h" #include "drawItemBounds_frag.h"
@ -151,17 +148,17 @@ void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContex
const unsigned int VEC3_ADRESS_OFFSET = 3; const unsigned int VEC3_ADRESS_OFFSET = 3;
for (int i = 0; i < nbItems; i++) { for (int i = 0; i < nbItems; i++) {
batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const GLfloat*) (itemAABox + i)); batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*) (itemAABox + i));
batch._glUniform3fv(_drawItemBoundDimLoc, 1, ((const GLfloat*) (itemAABox + i)) + VEC3_ADRESS_OFFSET); batch._glUniform3fv(_drawItemBoundDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET);
batch.draw(gpu::LINES, 24, 0); batch.draw(gpu::LINES, 24, 0);
} }
batch.setPipeline(getDrawItemStatusPipeline()); batch.setPipeline(getDrawItemStatusPipeline());
for (int i = 0; i < nbItems; i++) { for (int i = 0; i < nbItems; i++) {
batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const GLfloat*) (itemAABox + i)); batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*) (itemAABox + i));
batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const GLfloat*) (itemAABox + i)) + VEC3_ADRESS_OFFSET); batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET);
batch._glUniform4iv(_drawItemStatusValueLoc, 1, (const GLint*) (itemStatus + i)); batch._glUniform4iv(_drawItemStatusValueLoc, 1, (const int*) (itemStatus + i));
batch.draw(gpu::TRIANGLES, 24, 0); batch.draw(gpu::TRIANGLES, 24, 0);
} }

View file

@ -17,9 +17,7 @@
#include <PerfStat.h> #include <PerfStat.h>
#include <RenderArgs.h> #include <RenderArgs.h>
#include <ViewFrustum.h> #include <ViewFrustum.h>
#include <gpu/Batch.h>
#include <gpu/Context.h> #include <gpu/Context.h>
#include <gpu/GPUConfig.h>
using namespace render; using namespace render;

View file

@ -94,7 +94,6 @@ class QTestWindow : public QWindow {
QSize _size; QSize _size;
//TextRenderer* _textRenderer[4]; //TextRenderer* _textRenderer[4];
RateCounter fps; RateCounter fps;
gpu::ContextPointer _gpuContext;
protected: protected:
void renderText(); void renderText();
@ -124,7 +123,8 @@ public:
show(); show();
makeCurrent(); makeCurrent();
_gpuContext.reset(new gpu::Context(new gpu::GLBackend()));
gpu::Context::init<gpu::GLBackend>();