refactor of graphic system; initial HECL

This commit is contained in:
Jack Andersen 2015-05-14 13:22:42 -10:00
parent 35f2156de1
commit 6ce2472b27
21 changed files with 332 additions and 80 deletions

View File

@ -0,0 +1,20 @@
#ifndef CGFXVERTEXLAYOUTBASE_HPP
#define CGFXVERTEXLAYOUTBASE_HPP
class CGFXVertexLayoutBase
{
unsigned m_uvCount;
unsigned m_weightCount;
public:
CGFXVertexLayoutBase(unsigned uvCount=0, unsigned weightCount=0)
: m_uvCount(uvCount),
m_weightCount(weightCount) {}
virtual ~CGFXVertexLayoutBase() {}
inline unsigned uvCount() {return m_uvCount;}
inline unsigned weightCount() {return m_weightCount;}
inline bool isSkinned() {return m_weightCount > 0;}
};
#endif // CGFXVERTEXLAYOUTBASE_HPP

View File

@ -0,0 +1,5 @@
#ifndef IGFXCOMMANDBUFFER_HPP
#define IGFXCOMMANDBUFFER_HPP
#endif // IGFXCOMMANDBUFFER_HPP

View File

@ -1,13 +1,14 @@
#ifndef IGRAPHICSCONTEXT_HPP
#define IGRAPHICSCONTEXT_HPP
#ifndef IGFXCONTEXT_HPP
#define IGFXCONTEXT_HPP
namespace boo
{
class IGraphicsContext
class IGFXContext
{
friend class CWindowCocoa;
virtual void _setCallback(class IWindowCallback* cb) {(void)cb;};
friend class CWindowXCB;
virtual void _setCallback(class IWindowCallback* cb) {(void)cb;}
public:
@ -33,22 +34,15 @@ public:
PF_RGBAF32_Z24 = 4
};
virtual ~IGraphicsContext() {}
virtual ~IGFXContext() {}
virtual EGraphicsAPI getAPI() const=0;
virtual EPixelFormat getPixelFormat() const=0;
virtual void setPixelFormat(EPixelFormat pf)=0;
virtual void initializeContext()=0;
virtual IGraphicsContext* makeShareContext() const=0;
virtual void makeCurrent()=0;
virtual void clearCurrent()=0;
/* Note: *all* contexts are double-buffered with
* v-sync interval; please call this */
virtual void swapBuffer()=0;
};
}
#endif // IGRAPHICSCONTEXT_HPP
#endif // IGFXCONTEXT_HPP

View File

@ -0,0 +1,5 @@
#ifndef IGFXPIPELINESTATE_HPP
#define IGFXPIPELINESTATE_HPP
#endif // IGFXPIPELINESTATE_HPP

View File

@ -0,0 +1,5 @@
#ifndef IGFXTRANSFORMSET_HPP
#define IGFXTRANSFORMSET_HPP
#endif // IGFXTRANSFORMSET_HPP

View File

@ -0,0 +1,20 @@
#ifndef CHECLLEXER_HPP
#define CHECLLEXER_HPP
#include <string>
#include "graphicsys/CGFXVertexLayoutBase.hpp"
class CHECLLexer
{
const CGFXVertexLayoutBase& m_vertLayout;
public:
CHECLLexer(const CGFXVertexLayoutBase& vertLayout,
const std::string& colorHECL);
CHECLLexer(const CGFXVertexLayoutBase& vertLayout,
const std::string& colorHECL,
const std::string& alphaHECL);
inline const CGFXVertexLayoutBase& getVertLayout() const {return m_vertLayout;}
};
#endif // CHECLLEXER_HPP

View File

@ -0,0 +1,46 @@
#ifndef HECLEXPRESSIONS_HPP
#define HECLEXPRESSIONS_HPP
#include <string>
#include "IHECLBackend.hpp"
class IHECLExpression
{
/* Traverse expression tree and assemble
* backend-specific stage objects */
virtual IHECLBackendStage* recursiveStages(IHECLBackend& backend) const=0;
};
class CHECLNumberLiteral final : IHECLExpression
{
};
class CHECLVector final : IHECLExpression
{
};
class CHECLTextureSample final : IHECLExpression
{
};
class CHECLTextureGatherSample final : IHECLExpression
{
};
class CHECLMulOperation final : IHECLExpression
{
};
class CHECLAddOperation final : IHECLExpression
{
};
class CHECLSubOperation final : IHECLExpression
{
};
class CHECLRoot final : IHECLExpression
{
};
#endif // HECLEXPRESSIONS_HPP

View File

@ -0,0 +1,76 @@
#ifndef IHECLBACKEND_HPP
#define IHECLBACKEND_HPP
#include <string>
#include "CHECLLexer.hpp"
class IHECLBackend;
IHECLBackend* NewHECLBackendOutline(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendGLSL(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendHLSL(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendMetal(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendTEV(const CHECLLexer& lexer);
IHECLBackend* NewHECLBackendGLSLCafe(const CHECLLexer& lexer);
class IHECLBackend
{
public:
enum Type
{
AUTO = 0,
OUTLINE = 1,
GLSL = 2,
HLSL = 3,
METAL = 4,
TEV = 5,
GLSL_CAFE = 6
};
virtual Type getType() const=0;
virtual bool hasVertexSourceForm() const {return false;}
virtual bool hasFragmentSourceForm() const {return false;}
virtual bool hasVertexBinaryForm() const {return false;}
virtual bool hasFragmentBinaryForm() const {return false;}
virtual bool hasBinaryForm() const {return false;}
virtual std::string* emitNewVertexSource() {return NULL;}
virtual std::string* emitNewFragmentSource() {return NULL;}
virtual void* emitNewVertexBinary(size_t& szOut) {szOut = 0;return NULL;}
virtual void* emitNewFragmentBinary(size_t& szOut) {szOut = 0;return NULL;}
virtual void* emitNewBinary(size_t& szOut) {szOut = 0;return NULL;}
static inline IHECLBackend* NewHECLBackend(Type backendType, const CHECLLexer& lexer)
{
switch (backendType)
{
case AUTO:
#if HW_RVL
return NewHECLBackendTEV(lexer);
#elif HW_CAFE
return NewHECLBackendGLSLCafe(lexer);
#elif _WIN32
return NewHECLBackendHLSL(lexer);
#else
return NewHECLBackendGLSL(lexer);
#endif
case OUTLINE:
return NewHECLBackendOutline(lexer);
case GLSL:
return NewHECLBackendGLSL(lexer);
case HLSL:
return NewHECLBackendHLSL(lexer);
case METAL:
return NewHECLBackendMetal(lexer);
case TEV:
return NewHECLBackendTEV(lexer);
case GLSL_CAFE:
return NewHECLBackendGLSLCafe(lexer);
}
return NULL;
}
};
#endif // IHECLBACKEND_HPP

View File

@ -2,7 +2,6 @@ HEADERS += \
$$PWD/include/boo.hpp \
$$PWD/include/IApplication.hpp \
$$PWD/include/windowsys/IWindow.hpp \
$$PWD/include/windowsys/IGraphicsContext.hpp \
$$PWD/include/inputdev/CDolphinSmashAdapter.hpp \
$$PWD/include/inputdev/CRevolutionPad.hpp \
$$PWD/include/inputdev/CCafeProPad.hpp \
@ -13,7 +12,18 @@ HEADERS += \
$$PWD/include/inputdev/CDeviceBase.hpp \
$$PWD/include/inputdev/IHIDListener.hpp \
$$PWD/src/inputdev/IHIDDevice.hpp \
$$PWD/include/inputdev/SDeviceSignature.hpp
$$PWD/include/inputdev/SDeviceSignature.hpp \
$$PWD/include/windowsys/IGFXCommandBuffer.hpp \
$$PWD/include/graphicsys/IGFXCommandBuffer.hpp \
$$PWD/include/graphicsys/IGFXContext.hpp \
$$PWD/include/graphicsys/IGFXPipelineState.hpp \
$$PWD/include/graphicsys/IGFXTransformSet.hpp \
$$PWD/include/graphicsys/hecl/CHECLLexer.hpp \
$$PWD/src/graphicsys/hecl/IHECLBackend.hpp \
$$PWD/src/graphicsys/hecl/HECLExpressions.hpp \
$$PWD/include/graphicsys/CGFXVertexLayoutBase.hpp \
$$PWD/include/graphicsys/hecl/HECLExpressions.hpp \
$$PWD/include/graphicsys/hecl/IHECLBackend.hpp
SOURCES += \
$$PWD/InputDeviceClasses.cpp \
@ -23,7 +33,13 @@ SOURCES += \
$$PWD/src/inputdev/CDualshockPad.cpp \
$$PWD/src/inputdev/CGenericPad.cpp \
$$PWD/src/inputdev/CDeviceBase.cpp \
$$PWD/src/inputdev/SDeviceSignature.cpp
$$PWD/src/inputdev/SDeviceSignature.cpp \
$$PWD/src/graphicsys/hecl/CHECLBackendGLSL.cpp \
$$PWD/src/graphicsys/hecl/CHECLBackendHLSL.cpp \
$$PWD/src/graphicsys/hecl/CHECLBackendMetal.cpp \
$$PWD/src/graphicsys/hecl/CHECLLexer.cpp \
$$PWD/src/graphicsys/hecl/CHECLBackendOutline.cpp \
$$PWD/src/graphicsys/hecl/CHECLBackendTEV.cpp
unix:!macx {
HEADERS += \
@ -33,8 +49,8 @@ unix:!macx {
$$PWD/src/CApplicationUnix.cpp \
$$PWD/src/windowsys/CWindowXCB.cpp \
$$PWD/src/windowsys/CWindowWayland.cpp \
$$PWD/src/windowsys/CGraphicsContextXCB.cpp \
$$PWD/src/windowsys/CGraphicsContextWayland.cpp
$$PWD/src/graphicsys/CGraphicsContextXCB.cpp \
$$PWD/src/graphicsys/CGraphicsContextWayland.cpp
}
linux {
@ -61,7 +77,7 @@ win32 {
$$PWD/src/inputdev/CHIDListenerWinUSB.cpp \
$$PWD/src/inputdev/CHIDDeviceWinUSB.cpp \
$$PWD/src/windowsys/CWindowWin32.cpp \
$$PWD/src/windowsys/CGraphicsContextWin32.cpp
$$PWD/src/graphicsys/CGraphicsContextWin32.cpp
}
INCLUDEPATH += $$PWD/include

View File

@ -274,7 +274,6 @@ public:
dbus_connection_read_write(m_dbus, 0);
while ((msg = dbus_connection_pop_message(m_dbus)))
{
/* check if the message is a signal from the correct interface and with the correct name */
if (dbus_message_is_signal(msg, "boo.signal.FileHandling", "Open"))
{

View File

@ -1,10 +1,10 @@
#include "windowsys/IGraphicsContext.hpp"
#include "graphicsys/IGFXContext.hpp"
#include "windowsys/IWindow.hpp"
namespace boo
{
class CGraphicsContextWayland final : public IGraphicsContext
class CGraphicsContextWayland final : public IGFXContext
{
EGraphicsAPI m_api;
@ -52,29 +52,9 @@ public:
}
IGraphicsContext* makeShareContext() const
{
return NULL;
}
void makeCurrent()
{
}
void clearCurrent()
{
}
void swapBuffer()
{
}
};
IGraphicsContext* _CGraphicsContextWaylandNew(IGraphicsContext::EGraphicsAPI api,
IGFXContext* _CGraphicsContextWaylandNew(IGFXContext::EGraphicsAPI api,
IWindow* parentWindow)
{
return new CGraphicsContextWayland(api, parentWindow);

View File

@ -1,4 +1,4 @@
#include "windowsys/IGraphicsContext.hpp"
#include "graphicsys/IGFXContext.hpp"
#include "windowsys/IWindow.hpp"
#include <xcb/xcb.h>
@ -7,11 +7,12 @@
#include <GL/glcorearb.h>
#include <stdio.h>
#include <stdlib.h>
#include <thread>
namespace boo
{
class CGraphicsContextXCB final : public IGraphicsContext
class CGraphicsContextXCB final : public IGFXContext
{
EGraphicsAPI m_api;
@ -25,6 +26,8 @@ class CGraphicsContextXCB final : public IGraphicsContext
xcb_glx_context_t m_glxCtx = 0;
xcb_glx_context_tag_t m_glxCtxTag = 0;
std::thread* m_commandThread = NULL;
public:
IWindowCallback* m_callback;
@ -34,6 +37,7 @@ public:
m_parentWindow(parentWindow),
m_xcbConn(conn)
{
/* WTF freedesktop?? Fix this awful API and your nonexistant docs */
xcb_glx_get_fb_configs_reply_t* fbconfigs =
xcb_glx_get_fb_configs_reply(m_xcbConn, xcb_glx_get_fb_configs(m_xcbConn, 0), NULL);
@ -137,34 +141,9 @@ public:
m_glxWindow, 0, NULL);
}
IGraphicsContext* makeShareContext() const
{
return NULL;
}
void makeCurrent()
{
xcb_glx_make_context_current_reply_t* reply =
xcb_glx_make_context_current_reply(m_xcbConn,
xcb_glx_make_context_current(m_xcbConn, 0, m_glxWindow, m_glxWindow, m_glxCtx), NULL);
m_glxCtxTag = reply->context_tag;
free(reply);
}
void clearCurrent()
{
xcb_glx_make_context_current(m_xcbConn, m_glxCtxTag, m_glxWindow, m_glxWindow, 0);
m_glxCtxTag = 0;
}
void swapBuffer()
{
xcb_glx_swap_buffers(m_xcbConn, m_glxCtxTag, m_glxWindow);
}
};
IGraphicsContext* _CGraphicsContextXCBNew(IGraphicsContext::EGraphicsAPI api,
IGFXContext* _CGraphicsContextXCBNew(IGFXContext::EGraphicsAPI api,
IWindow* parentWindow, xcb_connection_t* conn,
uint32_t& visualIdOut)
{

View File

@ -0,0 +1,32 @@
#include "graphicsys/hecl/IHECLBackend.hpp"
class CHECLBackendGLSL : public IHECLBackend
{
public:
CHECLBackendGLSL(const CHECLLexer& lexer)
{
}
Type getType() const {return GLSL;}
};
IHECLBackend* NewHECLBackendGLSL(const CHECLLexer& lexer)
{
return new CHECLBackendGLSL(lexer);
}
class CHECLBackendGLSLCafe final : public CHECLBackendGLSL
{
public:
CHECLBackendGLSLCafe(const CHECLLexer& lexer)
: CHECLBackendGLSL(lexer)
{
}
Type getType() const {return GLSL_CAFE;}
};
IHECLBackend* NewHECLBackendGLSLCafe(const CHECLLexer& lexer)
{
return new CHECLBackendGLSLCafe(lexer);
}

View File

@ -0,0 +1,15 @@
#include "graphicsys/hecl/IHECLBackend.hpp"
class CHECLBackendHLSL final : public IHECLBackend
{
public:
CHECLBackendHLSL(const CHECLLexer& lexer)
{
}
Type getType() const {return HLSL;}
};
IHECLBackend* NewHECLBackendHLSL(const CHECLLexer& lexer)
{
return new CHECLBackendHLSL(lexer);
}

View File

@ -0,0 +1,15 @@
#include "graphicsys/hecl/IHECLBackend.hpp"
class CHECLBackendMetal final : public IHECLBackend
{
public:
CHECLBackendMetal(const CHECLLexer& lexer)
{
}
Type getType() const {return METAL;}
};
IHECLBackend* NewHECLBackendMetal(const CHECLLexer& lexer)
{
return new CHECLBackendMetal(lexer);
}

View File

@ -0,0 +1,16 @@
#include "graphicsys/hecl/IHECLBackend.hpp"
class CHECLBackendOutline final : public IHECLBackend
{
public:
CHECLBackendOutline(const CHECLLexer& lexer)
{
}
Type getType() const {return OUTLINE;}
};
IHECLBackend* NewHECLBackendOutline(const CHECLLexer& lexer)
{
return new CHECLBackendOutline(lexer);
}

View File

@ -0,0 +1,15 @@
#include "graphicsys/hecl/IHECLBackend.hpp"
class CHECLBackendTEV final : public IHECLBackend
{
public:
CHECLBackendTEV(const CHECLLexer& lexer)
{
}
Type getType() const {return TEV;}
};
IHECLBackend* NewHECLBackendTEV(const CHECLLexer& lexer)
{
return new CHECLBackendTEV(lexer);
}

View File

@ -0,0 +1,14 @@
#include "graphicsys/hecl/CHECLLexer.hpp"
CHECLLexer::CHECLLexer(const CGFXVertexLayoutBase& vertLayout,
const std::string& colorHECL)
: m_vertLayout(vertLayout)
{
}
CHECLLexer::CHECLLexer(const CGFXVertexLayoutBase& vertLayout,
const std::string& colorHECL,
const std::string& alphaHECL)
: m_vertLayout(vertLayout)
{
}

View File

@ -1,5 +1,5 @@
#include "windowsys/IWindow.hpp"
#include "windowsys/IGraphicsContext.hpp"
#include "graphicsys/IGFXContext.hpp"
#include "IApplication.hpp"
#include <xcb/xcb.h>
@ -145,7 +145,7 @@ static void genFrameDefault(xcb_screen_t* screen, int* xOut, int* yOut, int* wOu
*hOut = height;
}
IGraphicsContext* _CGraphicsContextXCBNew(IGraphicsContext::EGraphicsAPI api,
IGFXContext* _CGraphicsContextXCBNew(IGFXContext::EGraphicsAPI api,
IWindow* parentWindow, xcb_connection_t* conn,
uint32_t& visualIdOut);
@ -153,7 +153,7 @@ class CWindowXCB final : public IWindow
{
xcb_connection_t* m_xcbConn;
xcb_window_t m_windowId;
IGraphicsContext* m_gfxCtx;
IGFXContext* m_gfxCtx;
IWindowCallback* m_callback;
/* Last known input device id (0xffff if not yet set) */
@ -184,7 +184,7 @@ public:
/* Construct graphics context */
uint32_t visualId;
m_gfxCtx = _CGraphicsContextXCBNew(IGraphicsContext::API_OPENGL_3_3, this, m_xcbConn, visualId);
m_gfxCtx = _CGraphicsContextXCBNew(IGFXContext::API_OPENGL_3_3, this, m_xcbConn, visualId);
/* Create colormap */
xcb_colormap_t colormap = xcb_generate_id(m_xcbConn);