2015-11-21 01:14:49 +00:00
|
|
|
#ifndef SPECTER_VIEW_HPP
|
|
|
|
#define SPECTER_VIEW_HPP
|
|
|
|
|
2015-11-21 23:45:02 +00:00
|
|
|
#include <boo/boo.hpp>
|
2015-11-25 01:46:30 +00:00
|
|
|
#include "CVector3f.hpp"
|
|
|
|
#include "CMatrix4f.hpp"
|
|
|
|
#include "CTransform.hpp"
|
|
|
|
#include "CColor.hpp"
|
2015-11-21 23:45:02 +00:00
|
|
|
|
2015-11-26 00:24:01 +00:00
|
|
|
#include <boo/graphicsdev/GL.hpp>
|
|
|
|
#include <boo/graphicsdev/D3D.hpp>
|
|
|
|
#include <boo/graphicsdev/Metal.hpp>
|
|
|
|
|
2015-11-21 01:14:49 +00:00
|
|
|
namespace Specter
|
|
|
|
{
|
2015-12-02 01:32:15 +00:00
|
|
|
class ViewResources;
|
2015-11-29 02:55:30 +00:00
|
|
|
class RootView;
|
2015-11-21 01:14:49 +00:00
|
|
|
|
|
|
|
class View
|
|
|
|
{
|
2015-11-29 02:55:30 +00:00
|
|
|
RootView& m_rootView;
|
|
|
|
View& m_parentView;
|
|
|
|
boo::SWindowRect m_subRect;
|
2015-11-26 00:24:01 +00:00
|
|
|
boo::IGraphicsBufferD* m_bgVertBuf;
|
|
|
|
boo::IGraphicsBufferD* m_bgInstBuf;
|
|
|
|
boo::IVertexFormat* m_bgVtxFmt = nullptr; /* OpenGL only */
|
|
|
|
boo::IShaderDataBinding* m_bgShaderBinding;
|
|
|
|
Zeus::CVector3f m_bgRect[4];
|
|
|
|
Zeus::CColor m_bgColor;
|
2015-11-26 07:35:43 +00:00
|
|
|
int m_bgValidSlots = 0;
|
2015-11-30 00:21:42 +00:00
|
|
|
std::unique_ptr<boo::IGraphicsData> m_gfxData;
|
2015-11-26 07:35:43 +00:00
|
|
|
|
2015-11-29 02:55:30 +00:00
|
|
|
friend class RootView;
|
2015-12-02 01:32:15 +00:00
|
|
|
void buildResources(ViewResources& res);
|
|
|
|
View(ViewResources& res, RootView& parentView);
|
2015-11-29 02:55:30 +00:00
|
|
|
|
2015-11-26 07:35:43 +00:00
|
|
|
protected:
|
|
|
|
struct VertexBlock
|
|
|
|
{
|
|
|
|
Zeus::CMatrix4f m_mv;
|
2015-11-26 23:03:56 +00:00
|
|
|
void setViewRect(const boo::SWindowRect& root, const boo::SWindowRect& sub)
|
|
|
|
{
|
|
|
|
m_mv[0][0] = 2.0f / root.size[0];
|
|
|
|
m_mv[1][1] = 2.0f / root.size[1];
|
|
|
|
m_mv[3][0] = sub.location[0] * m_mv[0][0] - 1.0f;
|
|
|
|
m_mv[3][1] = sub.location[1] * m_mv[1][1] - 1.0f;
|
|
|
|
}
|
2015-11-26 07:35:43 +00:00
|
|
|
} m_viewVertBlock;
|
|
|
|
#define SPECTER_VIEW_VERT_BLOCK_GLSL\
|
|
|
|
"uniform SpecterViewBlock\n"\
|
|
|
|
"{\n"\
|
|
|
|
" mat4 mv;\n"\
|
|
|
|
"};\n"
|
2015-11-27 22:20:22 +00:00
|
|
|
#define SPECTER_VIEW_VERT_BLOCK_HLSL\
|
|
|
|
"cbuffer SpecterViewBlock : register(b0)\n"\
|
|
|
|
"{\n"\
|
|
|
|
" float4x4 mv;\n"\
|
|
|
|
"};\n"
|
2015-11-28 04:05:27 +00:00
|
|
|
#define SPECTER_VIEW_VERT_BLOCK_METAL\
|
|
|
|
"struct SpecterViewBlock\n"\
|
|
|
|
"{\n"\
|
|
|
|
" float4x4 mv;\n"\
|
|
|
|
"};\n"
|
2015-11-26 07:35:43 +00:00
|
|
|
boo::IGraphicsBufferD* m_viewVertBlockBuf;
|
|
|
|
|
2015-11-26 00:24:01 +00:00
|
|
|
public:
|
2015-12-02 01:32:15 +00:00
|
|
|
struct Resources
|
2015-11-26 00:24:01 +00:00
|
|
|
{
|
|
|
|
boo::IShaderPipeline* m_solidShader = nullptr;
|
2015-11-30 00:21:42 +00:00
|
|
|
boo::IVertexFormat* m_solidVtxFmt = nullptr; /* Not OpenGL */
|
|
|
|
|
|
|
|
boo::IShaderPipeline* m_texShader = nullptr;
|
|
|
|
boo::IVertexFormat* m_texVtxFmt = nullptr; /* Not OpenGL */
|
2015-11-26 00:24:01 +00:00
|
|
|
|
|
|
|
void init(boo::GLDataFactory* factory);
|
|
|
|
#if _WIN32
|
|
|
|
void init(boo::ID3DDataFactory* factory);
|
|
|
|
#elif BOO_HAS_METAL
|
|
|
|
void init(boo::MetalDataFactory* factory);
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2015-11-25 01:46:30 +00:00
|
|
|
protected:
|
2015-12-02 01:32:15 +00:00
|
|
|
View(ViewResources& res, View& parentView);
|
|
|
|
void commitResources(ViewResources& res);
|
2015-11-26 00:24:01 +00:00
|
|
|
|
2015-11-21 23:45:02 +00:00
|
|
|
public:
|
2015-11-30 00:21:42 +00:00
|
|
|
virtual ~View() {}
|
2015-11-26 23:03:56 +00:00
|
|
|
View() = delete;
|
2015-11-30 00:21:42 +00:00
|
|
|
View(const View& other) = delete;
|
|
|
|
View& operator=(const View& other) = delete;
|
2015-11-29 02:55:30 +00:00
|
|
|
|
|
|
|
View& parent() {return m_parentView;}
|
|
|
|
RootView& root() {return m_rootView;}
|
2015-11-30 00:21:42 +00:00
|
|
|
const boo::SWindowRect& subRect() const {return m_subRect;}
|
2015-11-29 02:55:30 +00:00
|
|
|
void updateSize();
|
|
|
|
|
2015-11-26 07:35:43 +00:00
|
|
|
void setBackground(Zeus::CColor color) {m_bgColor = color; m_bgValidSlots = 0;}
|
2015-11-30 00:21:42 +00:00
|
|
|
|
|
|
|
virtual void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey) {}
|
|
|
|
virtual void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey) {}
|
|
|
|
virtual void mouseMove(const boo::SWindowCoord&) {}
|
2015-11-26 23:03:56 +00:00
|
|
|
virtual void resized(const boo::SWindowRect &root, const boo::SWindowRect& sub);
|
2015-11-26 00:24:01 +00:00
|
|
|
virtual void draw(boo::IGraphicsCommandQueue* gfxQ);
|
2015-11-21 01:14:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SPECTER_VIEW_HPP
|