Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //vao.h
- #ifndef MM_VAO
- #define MM_VAO
- #include <vector>
- #include<map>
- #include "vbo.h"
- #include "program.h"
- namespace mm
- {
- class Vao
- {
- public:
- Vao();
- Vao(GLuint handle_):handle(handle_){};
- Vbo& createAttribute
- (
- Program& prog,std::string name,GLint size, GLenum type,
- GLboolean normalized=GL_FALSE, GLsizei stride=0, const GLvoid * pointer=0
- );//The return value is to be used to populate the vbo
- GLuint getHandle();
- private:
- GLuint handle;
- std::vector<Vbo> vbo_group;
- std::map<std::string,unsigned int> attr_name_map;
- };
- }
- #endif
- //vao.cpp
- #include "vao.h"
- namespace mm
- {
- Vao::Vao()
- {
- glGenVertexArrays(1,&handle);
- }
- Vbo& Vao::createAttribute
- (
- Program& prog, std::string name, GLint size, GLenum type,
- GLboolean normalized, GLsizei stride, const GLvoid* pointer
- )
- {
- GLuint attr_location = vbo_group.size();
- attr_name_map[name]=attr_location;
- glBindVertexArray(handle);
- GLuint vbo_handle;
- glGenBuffers(1,&vbo_handle);
- auto vbo= new Vbo(vbo_handle);
- vbo_group.push_back(*vbo);
- vbo->setParent(handle);
- glVertexAttribPointer(attr_location,size,type,normalized,stride,pointer);
- glEnableVertexAttribArray(attr_location);
- glBindAttribLocation(prog.getHandle(),attr_location,name.c_str());
- glBindVertexArray(0);
- return *vbo;
- }
- GLuint Vao::getHandle()
- {
- return handle;
- }
- }
- //vbo.h
- #ifndef MM_VBO
- #define MM_VBO
- #include <GL/glew.h>
- namespace mm
- {
- class Vbo
- {
- public:
- Vbo();
- Vbo(GLuint handle_):handle(handle_){};
- void bufferData(GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
- // void bufferSubData(/**/);///TODO
- GLuint getHandle();
- void setParent(GLuint handle_);//DangerousDontEverUse
- private:
- GLuint handle;
- GLuint parent_vao;
- };
- }
- #endif
- //vbo.cpp
- #include "vbo.h"
- namespace mm
- {
- void Vbo::setParent(GLuint handle_)
- {
- parent_vao = handle_;
- }
- GLuint Vbo::getHandle()
- {
- return handle;
- }
- void Vbo::bufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
- {
- glBindVertexArray(parent_vao);
- glBindBuffer(target,handle);
- glBufferData(target,size,data,usage);
- // glBindBuffer(target,0);
- glBindVertexArray(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment