From 82502743e5c19cd61096b0a931de164848027a28 Mon Sep 17 00:00:00 2001 From: rachytski Date: Thu, 22 Nov 2012 18:04:02 +0300 Subject: [PATCH] added platform-independent VertexDecl. --- graphics/area_renderer.hpp | 6 +++--- graphics/blitter.cpp | 10 +++++++++ graphics/blitter.hpp | 9 ++++++--- graphics/geometry_batcher.hpp | 6 +++--- graphics/vertex_decl.cpp | 29 ++++++++++++++++++++++++++ graphics/vertex_decl.hpp | 38 +++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 graphics/vertex_decl.cpp create mode 100644 graphics/vertex_decl.hpp diff --git a/graphics/area_renderer.hpp b/graphics/area_renderer.hpp index 4323935e21..615cd65dc1 100644 --- a/graphics/area_renderer.hpp +++ b/graphics/area_renderer.hpp @@ -1,10 +1,10 @@ #pragma once -#include "blitter.hpp" +#include "geometry_batcher.hpp" namespace graphics { - class AreaRenderer : public Blitter + class AreaRenderer : public GeometryBatcher { private: @@ -14,7 +14,7 @@ namespace graphics public: - typedef Blitter base_t; + typedef GeometryBatcher base_t; struct Params : base_t::Params { diff --git a/graphics/blitter.cpp b/graphics/blitter.cpp index 1d8f544ff2..25524db925 100644 --- a/graphics/blitter.cpp +++ b/graphics/blitter.cpp @@ -22,6 +22,16 @@ namespace graphics { } + void Blitter::beginFrame() + { + base_t::beginFrame(); + } + + void Blitter::endFrame() + { + base_t::endFrame(); + } + void Blitter::blit(shared_ptr const & srcSurface, ScreenBase const & from, ScreenBase const & to, diff --git a/graphics/blitter.hpp b/graphics/blitter.hpp index fbd45470d8..0a967e9ab6 100644 --- a/graphics/blitter.hpp +++ b/graphics/blitter.hpp @@ -2,7 +2,7 @@ #include "opengl/storage.hpp" -#include "geometry_batcher.hpp" +#include "display_list_renderer.hpp" #include "../geometry/point2d.hpp" #include "../geometry/rect2d.hpp" @@ -30,7 +30,7 @@ namespace graphics m2::RectU m_texRect; }; - class Blitter : public GeometryBatcher + class Blitter : public DisplayListRenderer { private: @@ -38,7 +38,7 @@ namespace graphics protected: - typedef GeometryBatcher base_t; + typedef DisplayListRenderer base_t; void calcPoints(m2::RectI const & srcRect, m2::RectU const & texRect, @@ -52,6 +52,9 @@ namespace graphics Blitter(base_t::Params const & params); ~Blitter(); + void beginFrame(); + void endFrame(); + /// Immediate mode rendering functions. /// they doesn't buffer any data as other functions do, but immediately renders it /// @{ diff --git a/graphics/geometry_batcher.hpp b/graphics/geometry_batcher.hpp index 03bcf05a16..bc969340a5 100644 --- a/graphics/geometry_batcher.hpp +++ b/graphics/geometry_batcher.hpp @@ -6,7 +6,7 @@ #include "opengl/framebuffer.hpp" #include "opengl/storage.hpp" -#include "display_list_renderer.hpp" +#include "blitter.hpp" #include "skin_page.hpp" #include "resource_manager.hpp" @@ -28,7 +28,7 @@ namespace graphics { class Skin; - class GeometryBatcher : public DisplayListRenderer + class GeometryBatcher : public Blitter { public: @@ -36,7 +36,7 @@ namespace graphics private: - typedef DisplayListRenderer base_t; + typedef Blitter base_t; shared_ptr m_skin; diff --git a/graphics/vertex_decl.cpp b/graphics/vertex_decl.cpp new file mode 100644 index 0000000000..ba0eb6f0ae --- /dev/null +++ b/graphics/vertex_decl.cpp @@ -0,0 +1,29 @@ +#include "vertex_decl.hpp" + +namespace graphics +{ + VertexAttrib::VertexAttrib(size_t offset, + EDataType elemType, + size_t elemCount, + size_t stride) + : m_offset(offset), + m_elemType(elemType), + m_elemCount(elemCount), + m_stride(stride) + {} + + VertexDecl::VertexDecl(VertexAttrib const * attrs, size_t cnt) + { + copy(attrs, attrs + cnt, back_inserter(m_attrs)); + } + + VertexAttrib const * VertexDecl::getAttr(size_t i) const + { + return &m_attrs[i]; + } + + size_t VertexDecl::size() const + { + return m_attrs.size(); + } +} diff --git a/graphics/vertex_decl.hpp b/graphics/vertex_decl.hpp new file mode 100644 index 0000000000..f71a4a2985 --- /dev/null +++ b/graphics/vertex_decl.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include "defines.hpp" + +#include "../std/vector.hpp" +#include "../std/string.hpp" + +namespace graphics +{ + /// Single attribute of vertex. + struct VertexAttrib + { + size_t m_offset; + EDataType m_elemType; + size_t m_elemCount; + size_t m_stride; + string m_name; + + VertexAttrib(size_t offset, + EDataType elemType, + size_t elemCount, + size_t stride); + }; + + /// Vertex structure declaration. + class VertexDecl + { + private: + vector m_attrs; + public: + /// constructor. + VertexDecl(VertexAttrib const * attrs, size_t cnt); + /// get the number of attributes. + size_t size() const; + /// get vertex attribute. + VertexAttrib const * getAttr(size_t i) const; + }; +}