started implementing vao and vbo classes
This commit is contained in:
parent
c901b1b720
commit
f03042b6e9
2
Makefile
2
Makefile
|
@ -69,7 +69,7 @@ $(SB_SRC_DIR)Box.o : $(addprefix $(SB_SRC_DIR),extension.hpp Segment.hpp)
|
|||
$(SB_SRC_DIR)Segment.o : $(addprefix $(SB_SRC_DIR),extension.hpp Box.hpp)
|
||||
$(SB_SRC_DIR)Pixels.o : $(addprefix $(SB_SRC_DIR),Box.hpp extension.hpp)
|
||||
$(SB_SRC_DIR)Audio.o : $(addprefix $(SB_SRC_DIR),Node.hpp Display.hpp Configuration.hpp Box.hpp filesystem.hpp extension.hpp)
|
||||
$(SB_SRC_DIR)Texture.o : $(addprefix $(SB_SRC_DIR),GLObject.cpp filesystem.hpp Game.hpp)
|
||||
$(SB_SRC_DIR)Texture.o : $(addprefix $(SB_SRC_DIR),GLObject.hpp filesystem.hpp Game.hpp)
|
||||
$(SRC_DIR)Item.o : $(addprefix $(SB_SRC_DIR),extension.hpp Node.hpp Texture.hpp)
|
||||
$(SRC_DIR)Pudding.o : $(SRC_H_FILES) $(SB_H_FILES)
|
||||
%.o : %.cpp %.hpp
|
||||
|
|
2
lib/sb
2
lib/sb
|
@ -1 +1 @@
|
|||
Subproject commit 6adac9806faba1483da80895de4d9edb783cdb1f
|
||||
Subproject commit f03d58dae13d673f4db26af88710e541a892cb77
|
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
|
@ -161,10 +161,9 @@ void Pudding::load_gl_context()
|
|||
{
|
||||
log("could not create capture frame thread context");
|
||||
}
|
||||
/* Allocate a vertex array object, bind it as current, doesn't need to be a member var because the same one is always bound */
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
/* Generate a vertex array object ID, bind it as current */
|
||||
vao.generate();
|
||||
vao.bind();
|
||||
/* 2D vertices for any texture that is a plane spanning the screen */
|
||||
std::array<glm::vec2, 6> rectangle_vertices = {{
|
||||
{-1.0f, 1.0f}, {1.0f, 1.0f}, {-1.0f, -1.0f},
|
||||
|
@ -178,9 +177,8 @@ void Pudding::load_gl_context()
|
|||
/* Generate one vertex buffer object to hold all vertices and rectangle UV map. Since we're using one buffer, data
|
||||
* will be copied in one after the other, offset to after the previous data location. The same buffer offset will
|
||||
* be passed to the vertex attributes for each data. */
|
||||
GLuint vbo;
|
||||
glGenBuffers(1, &vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
vbo.generate();
|
||||
vbo.bind();
|
||||
/* allocate space for vertices, UV and colors, and copy rectangle vertices in at initialization */
|
||||
GLsizeiptr vbo_size = (rectangle_vertices.size() + rectangle_uv.size() + pudding_uv.size()) * sizeof(glm::vec2) +
|
||||
(pudding_vertices.size() + pudding_colors.size()) * sizeof(glm::vec3);
|
||||
|
@ -855,3 +853,49 @@ void Pudding::update()
|
|||
previous_barcode = current_barcode;
|
||||
}
|
||||
}
|
||||
|
||||
VAO::VAO() : GLObject(vao_deleter) {}
|
||||
|
||||
/* Bind this VAO to the current GL context */
|
||||
void VAO::bind() const
|
||||
{
|
||||
glBindVertexArray(id());
|
||||
}
|
||||
|
||||
/* Forward the GL VAO generate function to the base class */
|
||||
void VAO::generate()
|
||||
{
|
||||
GLObject::generate(glGenVertexArrays);
|
||||
}
|
||||
|
||||
/* This function gets passed to the abstract base class for deleting the VAO data when the ID
|
||||
* pointer goes out of scope (when all instances of this VAO and its copies are out of scope) */
|
||||
void vao_deleter(GLuint* id)
|
||||
{
|
||||
/* not sure why SDL_Log works here on program exit but SDL_LogDebug and SDL_LogInfo don't */
|
||||
SDL_Log("destroying VAO ID %i", *id);
|
||||
glDeleteVertexArrays(1, id);
|
||||
}
|
||||
|
||||
VBO::VBO() : GLObject(vbo_deleter) {}
|
||||
|
||||
/* Bind this VBO to the current GL context */
|
||||
void VBO::bind() const
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, id());
|
||||
}
|
||||
|
||||
/* Forward the GL buffer generate function to the base class */
|
||||
void VBO::generate()
|
||||
{
|
||||
GLObject::generate(glGenBuffers);
|
||||
}
|
||||
|
||||
/* This function gets passed to the abstract base class for deleting the VBO data when the ID
|
||||
* pointer goes out of scope (when all instances of this VBO and its copies are out of scope) */
|
||||
void vbo_deleter(GLuint* id)
|
||||
{
|
||||
/* not sure why SDL_Log works here on program exit but SDL_LogDebug and SDL_LogInfo don't */
|
||||
SDL_Log("destroying VBO ID %i", *id);
|
||||
glDeleteBuffers(1, id);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,33 @@
|
|||
#include "Item.hpp"
|
||||
#include "Animation.hpp"
|
||||
#include "Texture.hpp"
|
||||
#include "GLObject.hpp"
|
||||
|
||||
class VAO : public GLObject
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
VAO();
|
||||
void generate();
|
||||
void bind() const;
|
||||
|
||||
};
|
||||
|
||||
void vao_deleter(GLuint*);
|
||||
|
||||
class VBO : public GLObject
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
VBO();
|
||||
void generate();
|
||||
void bind() const;
|
||||
|
||||
};
|
||||
|
||||
void vbo_deleter(GLuint*);
|
||||
|
||||
class Pudding : public Game
|
||||
{
|
||||
|
@ -79,6 +106,8 @@ private:
|
|||
std::vector<Texture> tiles;
|
||||
Texture capture_texture_front_buffer, capture_texture_back_buffer;
|
||||
Texture& capture_texture = capture_texture_front_buffer;
|
||||
VAO vao;
|
||||
VBO vbo;
|
||||
|
||||
void set_pudding_model(float, float, int, int = 1, float = -1, float = 1, float = 0.3f);
|
||||
void load_gl_context();
|
||||
|
@ -109,43 +138,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
class VAO
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<GLuint> array_id = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
VAO() {};
|
||||
void generate();
|
||||
void id(GLuint);
|
||||
GLuint id() const;
|
||||
void bind() const;
|
||||
static void destroy(GLuint*);
|
||||
|
||||
};
|
||||
|
||||
class Buffer
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<GLuint> buffer_id = nullptr;
|
||||
|
||||
public:
|
||||
|
||||
Buffer() {};
|
||||
void generate();
|
||||
void id(GLuint);
|
||||
|
||||
};
|
||||
|
||||
class VBO : public Buffer
|
||||
{
|
||||
};
|
||||
|
||||
class Attributes
|
||||
{
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue