From 11fb586a206d7bbc6ed2405fa8abb8ae4a98c679 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 7 Nov 2011 00:36:28 +0000 Subject: [PATCH] gpu: start implementing a vertex buffer object. --- src/Makefile.am | 1 + src/core.h | 1 + src/gpu/vbo.cpp | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gpu/vbo.h | 45 ++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 src/gpu/vbo.cpp create mode 100644 src/gpu/vbo.h diff --git a/src/Makefile.am b/src/Makefile.am index 4435cacd..9de31693 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -22,6 +22,7 @@ liblol_a_SOURCES = \ $(sdl_sources) \ \ shader/shader.cpp shader/shader.h \ + gpu/vbo.cpp gpu/vbo.h \ \ image/image.cpp image/image.h image/image-private.h \ image/codec/android-image.cpp \ diff --git a/src/core.h b/src/core.h index b95d5db3..45fdce5d 100644 --- a/src/core.h +++ b/src/core.h @@ -96,6 +96,7 @@ static inline int isnan(float f) #include "dict.h" #include "map.h" #include "layer.h" +#include "gpu/vbo.h" #include "shader/shader.h" #include "image/image.h" #include "application/application.h" diff --git a/src/gpu/vbo.cpp b/src/gpu/vbo.cpp new file mode 100644 index 00000000..baee78cb --- /dev/null +++ b/src/gpu/vbo.cpp @@ -0,0 +1,100 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 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" +#include "gpu/vbo.h" + +using namespace std; + +namespace lol +{ + +/* + * GpuVbo implementation class + */ + +class GpuVboData +{ + friend class GpuVbo; + + size_t elemsize, elemcount; + uint8_t *alloc_buffer; + + static size_t const GPU_ALIGN = 128; +}; + +/* + * Public GpuVbo class + */ + +GpuVbo::GpuVbo() + : data(new GpuVboData()) +{ + data->elemsize = 0; + data->elemcount = 0; + data->alloc_buffer = 0; +} + +void GpuVbo::SetSize(size_t elemsize, size_t elemcount) +{ + size_t oldsize = data->elemsize * data->elemcount; + size_t newsize = elemsize * elemcount; + + if (newsize == oldsize) + return; + + if (oldsize) + delete[] data->alloc_buffer; + data->alloc_buffer = NULL; + if (newsize) + data->alloc_buffer = new uint8_t[newsize + GpuVboData::GPU_ALIGN - 1]; + + data->elemsize = elemsize; + data->elemcount = elemcount; +} + +size_t GpuVbo::GetSize() +{ + return data->elemsize * data->elemcount; +} + +uint8_t *GpuVbo::GetData() +{ + return (uint8_t *)(((uintptr_t)data->alloc_buffer) + & ~((uintptr_t)GpuVboData::GPU_ALIGN - 1)); +} + +uint8_t const *GpuVbo::GetData() const +{ + return (uint8_t const *)(((uintptr_t)data->alloc_buffer) + & ~((uintptr_t)GpuVboData::GPU_ALIGN - 1)); +} + +void GpuVbo::Bind() +{ +} + +void GpuVbo::Unbind() +{ +} + +GpuVbo::~GpuVbo() +{ + delete[] data->alloc_buffer; + delete data; +} + +} /* namespace lol */ + diff --git a/src/gpu/vbo.h b/src/gpu/vbo.h new file mode 100644 index 00000000..4f8b0c5e --- /dev/null +++ b/src/gpu/vbo.h @@ -0,0 +1,45 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 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_VBO_H__ +#define __LOL_VBO_H__ + +namespace lol +{ + +class GpuVboData; + +class GpuVbo +{ +public: + GpuVbo(); + ~GpuVbo(); + + void SetSize(size_t elemsize, size_t elemcount); + size_t GetSize(); + uint8_t *GetData(); + uint8_t const *GetData() const; + + void Bind(); + void Unbind(); + +private: + GpuVboData *data; +}; + +} /* namespace lol */ + +#endif // __LOL_VBO_H__ +