Browse Source

Adapted to recent meshdata/shader changes.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
faf94c74e2
  1. 4
      src/AbstractShaderProgram.h
  2. 8
      src/DebugTools/ObjectRenderer.cpp
  3. 8
      src/Mesh.h
  4. 24
      src/Text/TextRenderer.cpp
  5. 2
      src/Text/TextRenderer.h

4
src/AbstractShaderProgram.h

@ -46,7 +46,7 @@ functions and properties:
- <strong>%Attribute definitions</strong> with location and type for - <strong>%Attribute definitions</strong> with location and type for
configuring meshes, for example: configuring meshes, for example:
@code @code
typedef Attribute<0, Point3D> Position; typedef Attribute<0, Vector3> Position;
typedef Attribute<1, Vector3> Normal; typedef Attribute<1, Vector3> Normal;
typedef Attribute<2, Vector2> TextureCoordinates; typedef Attribute<2, Vector2> TextureCoordinates;
@endcode @endcode
@ -1371,8 +1371,6 @@ template<std::size_t size_> struct Attribute<Math::Vector<size_, GLdouble>>: Dou
template<class T> struct Attribute<Math::Vector2<T>>: Attribute<Math::Vector<2, T>> {}; template<class T> struct Attribute<Math::Vector2<T>>: Attribute<Math::Vector<2, T>> {};
template<class T> struct Attribute<Math::Vector3<T>>: Attribute<Math::Vector<3, T>> {}; template<class T> struct Attribute<Math::Vector3<T>>: Attribute<Math::Vector<3, T>> {};
template<class T> struct Attribute<Math::Vector4<T>>: Attribute<Math::Vector<4, T>> {}; template<class T> struct Attribute<Math::Vector4<T>>: Attribute<Math::Vector<4, T>> {};
template<class T> struct Attribute<Math::Point2D<T>>: Attribute<Math::Vector3<T>> {};
template<class T> struct Attribute<Math::Point3D<T>>: Attribute<Math::Vector4<T>> {};
template<class T> struct Attribute<Color3<T>>: Attribute<Math::Vector3<T>> {}; template<class T> struct Attribute<Color3<T>>: Attribute<Math::Vector3<T>> {};
template<class T> struct Attribute<Color4<T>>: Attribute<Math::Vector4<T>> {}; template<class T> struct Attribute<Color4<T>>: Attribute<Math::Vector4<T>> {};

8
src/DebugTools/ObjectRenderer.cpp

@ -33,12 +33,12 @@ template<> struct Renderer<2> {
inline static ResourceKey indexBuffer() { return {"object2d-indices"}; } inline static ResourceKey indexBuffer() { return {"object2d-indices"}; }
inline static ResourceKey mesh() { return {"object2d"}; } inline static ResourceKey mesh() { return {"object2d"}; }
static const std::array<Point2D, 8> positions; static const std::array<Vector2, 8> positions;
static const std::array<Color3<>, 8> colors; static const std::array<Color3<>, 8> colors;
static const std::array<std::uint8_t, 12> indices; static const std::array<std::uint8_t, 12> indices;
}; };
const std::array<Point2D, 8> Renderer<2>::positions{{ const std::array<Vector2, 8> Renderer<2>::positions{{
{ 0.0f, 0.0f}, { 0.0f, 0.0f},
{ 1.0f, 0.0f}, /* X axis */ { 1.0f, 0.0f}, /* X axis */
{ 0.9f, 0.1f}, { 0.9f, 0.1f},
@ -78,12 +78,12 @@ template<> struct Renderer<3> {
inline static ResourceKey indexBuffer() { return {"object3d-indices"}; } inline static ResourceKey indexBuffer() { return {"object3d-indices"}; }
inline static ResourceKey mesh() { return {"object3d"}; } inline static ResourceKey mesh() { return {"object3d"}; }
static const std::array<Point3D, 12> positions; static const std::array<Vector3, 12> positions;
static const std::array<Color3<>, 12> colors; static const std::array<Color3<>, 12> colors;
static const std::array<uint8_t, 18> indices; static const std::array<uint8_t, 18> indices;
}; };
const std::array<Point3D, 12> Renderer<3>::positions{{ const std::array<Vector3, 12> Renderer<3>::positions{{
{ 0.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 0.0f},
{ 1.0f, 0.0f, 0.0f}, /* X axis */ { 1.0f, 0.0f, 0.0f}, /* X axis */
{ 0.9f, 0.1f, 0.0f}, { 0.9f, 0.1f, 0.0f},

8
src/Mesh.h

@ -64,7 +64,7 @@ mesh is empty and no draw commands are issued when calling draw().
// Custom shader, needing only position data // Custom shader, needing only position data
class MyShader: public AbstractShaderProgram { class MyShader: public AbstractShaderProgram {
public: public:
typedef Attribute<0, Point3D> Position; typedef Attribute<0, Vector3> Position;
// ... // ...
}; };
@ -72,7 +72,7 @@ Mesh* mesh;
Buffer* vertexBuffer; Buffer* vertexBuffer;
// Fill vertex buffer with position data // Fill vertex buffer with position data
static constexpr Point3D positions[30] = { static constexpr Vector3 positions[30] = {
// ... // ...
}; };
vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); vertexBuffer->setData(positions, Buffer::Usage::StaticDraw);
@ -109,7 +109,7 @@ mesh->setPrimitive(plane.primitive())
// Custom shader // Custom shader
class MyShader: public AbstractShaderProgram { class MyShader: public AbstractShaderProgram {
public: public:
typedef Attribute<0, Point3D> Position; typedef Attribute<0, Vector3> Position;
// ... // ...
}; };
@ -117,7 +117,7 @@ Buffer *vertexBuffer, *indexBuffer;
Mesh* mesh; Mesh* mesh;
// Fill vertex buffer with position data // Fill vertex buffer with position data
static constexpr Point3D positions[300] = { static constexpr Vector3 positions[300] = {
// ... // ...
}; };
vertexBuffer->setData(positions, Buffer::Usage::StaticDraw); vertexBuffer->setData(positions, Buffer::Usage::StaticDraw);

24
src/Text/TextRenderer.cpp

@ -23,8 +23,6 @@
#include <Utility/Unicode.h> #include <Utility/Unicode.h>
#endif #endif
#include "Math/Point2D.h"
#include "Math/Point3D.h"
#include "Context.h" #include "Context.h"
#include "Extensions.h" #include "Extensions.h"
#include "Mesh.h" #include "Mesh.h"
@ -151,30 +149,30 @@ template<class T> void createIndices(void* output, const std::uint32_t glyphCoun
} }
} }
template<std::uint8_t dimensions> typename DimensionTraits<dimensions>::PointType point(const Vector2& vec); template<std::uint8_t dimensions> typename DimensionTraits<dimensions>::VectorType point(const Vector2& vec);
template<> inline Point2D point<2>(const Vector2& vec) { template<> inline Vector2 point<2>(const Vector2& vec) {
return swizzle<'x', 'y', '1'>(vec); return vec;
} }
template<> inline Point3D point<3>(const Vector2& vec) { template<> inline Vector3 point<3>(const Vector2& vec) {
return swizzle<'x', 'y', '0', '1'>(vec); return {vec, 1.0f};
} }
template<std::uint8_t dimensions> struct Vertex { template<std::uint8_t dimensions> struct Vertex {
typename DimensionTraits<dimensions>::PointType position; typename DimensionTraits<dimensions>::VectorType position;
Vector2 texcoords; Vector2 texcoords;
}; };
} }
template<std::uint8_t dimensions> std::tuple<std::vector<typename DimensionTraits<dimensions>::PointType>, std::vector<Vector2>, std::vector<std::uint32_t>, Rectangle> TextRenderer<dimensions>::render(Font& font, GLfloat size, const std::string& text) { template<std::uint8_t dimensions> std::tuple<std::vector<typename DimensionTraits<dimensions>::VectorType>, std::vector<Vector2>, std::vector<std::uint32_t>, Rectangle> TextRenderer<dimensions>::render(Font& font, GLfloat size, const std::string& text) {
TextLayouter layouter(font, size, text); TextLayouter layouter(font, size, text);
const std::uint32_t vertexCount = layouter.glyphCount()*4; const std::uint32_t vertexCount = layouter.glyphCount()*4;
/* Output data */ /* Output data */
std::vector<typename DimensionTraits<dimensions>::PointType> positions; std::vector<typename DimensionTraits<dimensions>::VectorType> positions;
std::vector<Vector2> texcoords; std::vector<Vector2> texcoords;
positions.reserve(vertexCount); positions.reserve(vertexCount);
texcoords.reserve(vertexCount); texcoords.reserve(vertexCount);
@ -210,7 +208,8 @@ template<std::uint8_t dimensions> std::tuple<std::vector<typename DimensionTrait
/* Rendered rectangle */ /* Rendered rectangle */
Rectangle rectangle; Rectangle rectangle;
if(layouter.glyphCount()) rectangle = {positions[1].xy(), positions[positions.size()-2].xy()}; if(layouter.glyphCount()) rectangle =
{swizzle<'x', 'y'>(positions[1]), swizzle<'x', 'y'>(positions[positions.size()-2])};
return std::make_tuple(std::move(positions), std::move(texcoords), std::move(indices), rectangle); return std::make_tuple(std::move(positions), std::move(texcoords), std::move(indices), rectangle);
} }
@ -270,7 +269,8 @@ template<std::uint8_t dimensions> std::tuple<Mesh, Rectangle> TextRenderer<dimen
/* Rendered rectangle */ /* Rendered rectangle */
Rectangle rectangle; Rectangle rectangle;
if(layouter.glyphCount()) rectangle = {vertices[1].position.xy(), vertices[vertices.size()-2].position.xy()}; if(layouter.glyphCount()) rectangle =
{swizzle<'x', 'y'>(vertices[1].position), swizzle<'x', 'y'>(vertices[vertices.size()-2].position)};
/* Configure mesh */ /* Configure mesh */
Mesh mesh; Mesh mesh;

2
src/Text/TextRenderer.h

@ -109,7 +109,7 @@ template<std::uint8_t dimensions> class MAGNUM_TEXT_EXPORT TextRenderer {
* Returns tuple with vertex positions, texture coordinates, indices * Returns tuple with vertex positions, texture coordinates, indices
* and rectangle spanning the rendered text. * and rectangle spanning the rendered text.
*/ */
static std::tuple<std::vector<typename DimensionTraits<dimensions>::PointType>, std::vector<Vector2>, std::vector<std::uint32_t>, Rectangle> render(Font& font, GLfloat size, const std::string& text); static std::tuple<std::vector<typename DimensionTraits<dimensions>::VectorType>, std::vector<Vector2>, std::vector<std::uint32_t>, Rectangle> render(Font& font, GLfloat size, const std::string& text);
/** /**
* @brief Render text * @brief Render text

Loading…
Cancel
Save