From 5218c59ab733f4f721a97fa56a4eef80fabf0618 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 13 Apr 2012 16:34:22 +0000 Subject: [PATCH] gpu: start working on a template-based vertex buffer class. --- src/Makefile.am | 1 + src/core.h | 1 + src/gpu/vertexbuffer.cpp | 31 +++++++++++ src/gpu/vertexbuffer.h | 98 +++++++++++++++++++++++++++++++++++ test/tutorial/tut01.cpp | 16 ++++++ win32/lolcore.vcxproj | 2 + win32/lolcore.vcxproj.filters | 6 +++ 7 files changed, 155 insertions(+) create mode 100644 src/gpu/vertexbuffer.cpp create mode 100644 src/gpu/vertexbuffer.h diff --git a/src/Makefile.am b/src/Makefile.am index 7db0c214..8113f3b0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,6 +30,7 @@ liblol_a_SOURCES = \ \ gpu/shader.cpp gpu/shader.h \ gpu/vbo.cpp gpu/vbo.h \ + gpu/vertexbuffer.cpp gpu/vertexbuffer.h \ \ image/image.cpp image/image.h image/image-private.h \ image/codec/gdiplus-image.cpp \ diff --git a/src/core.h b/src/core.h index d0f6a26d..f4848f94 100644 --- a/src/core.h +++ b/src/core.h @@ -99,6 +99,7 @@ static inline int isnan(float f) #include "layer.h" #include "gpu/shader.h" #include "gpu/vbo.h" +#include "gpu/vertexbuffer.h" #include "image/image.h" #include "application/application.h" diff --git a/src/gpu/vertexbuffer.cpp b/src/gpu/vertexbuffer.cpp new file mode 100644 index 00000000..8a8156ab --- /dev/null +++ b/src/gpu/vertexbuffer.cpp @@ -0,0 +1,31 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include "core.h" +#include "lolgl.h" + +using namespace std; + +namespace lol +{ + +void VertexBuffer::Initialize() +{ +#if defined _XBOX || defined USE_D3D9 + +#endif +} + +} /* namespace lol */ + diff --git a/src/gpu/vertexbuffer.h b/src/gpu/vertexbuffer.h new file mode 100644 index 00000000..ba954407 --- /dev/null +++ b/src/gpu/vertexbuffer.h @@ -0,0 +1,98 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2012 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The GpuVbo class +// ---------------- +// + +#if !defined __LOL_VERTEXBUFFER_H__ +#define __LOL_VERTEXBUFFER_H__ + +namespace lol +{ + +class VertexBuffer +{ +public: + VertexBuffer(VertexBuffer const& that) + { + memcpy(this, &that, sizeof(*this)); + + /* Now call the platform-specific initialisation code */ + Initialize(); + } + + ~VertexBuffer() {} + +protected: + VertexBuffer() {} + + enum StreamType + { + VBO_TYPE_VOID, + VBO_TYPE_FLOAT, + VBO_TYPE_VEC2, + VBO_TYPE_VEC3, + VBO_TYPE_VEC4, + VBO_TYPE_I16VEC4, + VBO_TYPE_U8VEC4, + }; + + template static StreamType GetType(); + + struct { StreamType stream_type; int index; } m_streams[12 + 1]; + +private: + void Initialize(); +}; + +template<> VertexBuffer::StreamType VertexBuffer::GetType() { return VBO_TYPE_VOID; } +template<> VertexBuffer::StreamType VertexBuffer::GetType() { return VBO_TYPE_FLOAT; } +template<> VertexBuffer::StreamType VertexBuffer::GetType() { return VBO_TYPE_VEC2; } +template<> VertexBuffer::StreamType VertexBuffer::GetType() { return VBO_TYPE_VEC3; } +template<> VertexBuffer::StreamType VertexBuffer::GetType() { return VBO_TYPE_VEC4; } +template<> VertexBuffer::StreamType VertexBuffer::GetType() { return VBO_TYPE_I16VEC4; } +template<> VertexBuffer::StreamType VertexBuffer::GetType() { return VBO_TYPE_U8VEC4; } + +template +class VertexDeclaration : public VertexBuffer +{ +public: + /* Arguments are the stream index; default to zero */ + VertexDeclaration(int s1 = 0, int s2 = 0, int s3 = 0, + int s4 = 0, int s5 = 0, int s6 = 0, + int s7 = 0, int s8 = 0, int s9 = 0, + int s10 = 0, int s11 = 0, int s12 = 0) + { + for (int i = 0; i < 12 + 1; i++) + m_streams[i].stream_type = VBO_TYPE_VOID; + + AddStream(0, s1); AddStream(1, s2); AddStream(2, s3); + AddStream(3, s4); AddStream(4, s5); AddStream(5, s6); + AddStream(6, s7); AddStream(7, s8); AddStream(8, s9); + AddStream(9, s10); AddStream(10, s11); AddStream(11, s12); + } + +private: + template void AddStream(int index, int stream) + { + m_streams[index].stream_type = GetType(); + m_streams[index].index = index; + } +}; + +} /* namespace lol */ + +#endif // __LOL_VERTEXBUFFER_H__ + diff --git a/test/tutorial/tut01.cpp b/test/tutorial/tut01.cpp index 0158ed8a..4ee38278 100644 --- a/test/tutorial/tut01.cpp +++ b/test/tutorial/tut01.cpp @@ -61,6 +61,22 @@ public: if (!m_ready) { + VertexBuffer vb(VertexDeclaration(0, 0, 1)); + + + + + + + + + + + + + + + m_shader = Shader::Create( #if !defined __CELLOS_LV2__ && !defined _XBOX && !defined USE_D3D9 "#version 120\n" diff --git a/win32/lolcore.vcxproj b/win32/lolcore.vcxproj index 36cf7b77..e4529a3a 100644 --- a/win32/lolcore.vcxproj +++ b/win32/lolcore.vcxproj @@ -87,6 +87,7 @@ + @@ -140,6 +141,7 @@ + diff --git a/win32/lolcore.vcxproj.filters b/win32/lolcore.vcxproj.filters index 0ff6e8ef..8292dc7b 100644 --- a/win32/lolcore.vcxproj.filters +++ b/win32/lolcore.vcxproj.filters @@ -166,6 +166,9 @@ src\gpu + + src\gpu + src\application @@ -339,6 +342,9 @@ src\gpu + + src\gpu + src\thread