uint GLBuffer::buffer() { if (m_buffer == 0) { m_buffer = generateBuffer(); } return m_buffer; }
RenderBatch* RenderBatch_new(unsigned int objectSize, Texture* texture, unsigned int initialSize) { RenderBatch* ret = (RenderBatch*)malloc(sizeof(RenderBatch)); ret->data = BatchData_new(initialSize); ret->objectSize = objectSize; ret->dataSize = 0; ret->texture = texture; ret->drawables = LinkedList_new(); generateBuffer(&ret->vertexBufferIndex); generateBuffer(&ret->colorBufferIndex); generateBuffer(&ret->textureBufferIndex); return ret; }
ElementBufferObject::ElementBufferObject( const void* pBufferData, const GLsizei bufferElements, const GLenum target, const GLenum updateTarget ) : BufferObject( bufferElements, 1, sizeof( GLuint ), target, updateTarget ) { generateBuffer( pBufferData ); }
void GLHelper::bufferVertexColor(const std::vector<glm::vec4> &colors, GLuint &vao, GLuint &vbo, const GLuint attachPointer) { vbo = generateBuffer(1); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(glm::vec4), colors.data(), GL_STATIC_DRAW); glBindVertexArray(vao); glVertexAttribPointer(attachPointer, 4, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(attachPointer); glBindVertexArray(0); checkErrors("bufferVertexColor"); }
void GLHelper::bufferVertexTextureCoordinates(const std::vector<glm::vec2> &textureCoordinates, GLuint &vao, GLuint &vbo, const GLuint attachPointer, GLuint &ebo) { vbo = generateBuffer(1); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, textureCoordinates.size() * sizeof(glm::vec2), textureCoordinates.data(), GL_STATIC_DRAW); glBindVertexArray(vao); glVertexAttribPointer(attachPointer, 2, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(attachPointer); glBindVertexArray(0); checkErrors("bufferVertexTextureCoordinates"); }
void GLHelper::bufferVertexData(const std::vector<glm::vec3> &vertices, const std::vector<glm::mediump_uvec3> &faces, GLuint &vao, GLuint &vbo, const GLuint attachPointer, GLuint &ebo) { // Set up the element array buffer ebo = generateBuffer(1); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, faces.size() * sizeof(glm::mediump_uvec3), faces.data(), GL_STATIC_DRAW); // Set up the vertex attributes glGenVertexArrays(1, &vao); glBindVertexArray(vao); vbo = generateBuffer(1); bufferObjects.push_back(vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), vertices.data(), GL_STATIC_DRAW); //glBufferSubData(GL_ARRAY_BUFFER, 0, vertexSize, vertexData); glVertexAttribPointer(attachPointer, 3, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray(attachPointer); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); checkErrors("bufferVertexData"); }
ALuint _alutPassBufferData (BufferData *bufferData) { ALuint buffer = generateBuffer (); if (buffer == AL_NONE) { return AL_NONE; } if (!passBufferData (bufferData, buffer)) { return AL_NONE; } return buffer; }
/** * This is pretty low performance, but it is used only for debugging physics, so it is good enough */ void GLHelper::drawLine(const glm::vec3 &from, const glm::vec3 &to, const glm::vec3 &fromColor, const glm::vec3 &toColor, bool willTransform) { static GLuint program, viewTransformU, lineInfoU, vao, vbo; static std::map<std::string, Uniform*> uniformMap;//FIXME That map will always be empty, maybe we should overload if (program == 0 || vbo == 0 || vao == 0) { program = initializeProgram("./Data/Shaders/Line/vertex.glsl", "./Data/Shaders/Line/fragment.glsl", uniformMap); lineInfoU = glGetUniformLocation(program, "lineInfo"); viewTransformU = glGetUniformLocation(program, "cameraTransformMatrix"); state->setProgram(program); vbo = generateBuffer(1); glBindBuffer(GL_ARRAY_BUFFER, vbo); std::vector<GLint> indexes; indexes.push_back(0); indexes.push_back(1); glBufferData(GL_ARRAY_BUFFER, indexes.size() * sizeof(GLint), indexes.data(), GL_STATIC_DRAW); //this means the vao is not created yet. glGenVertexArrays(1, &vao); glBindVertexArray(vao); //stride means the space between start of 2 elements. 0 is special, means the space is equal to size. glVertexAttribPointer(0, 1, GL_INT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); } state->setProgram(program); glm::mat4 matrix(glm::vec4(from, 1.0f), glm::vec4(to, 1.0f), glm::vec4(fromColor, 1.0f), glm::vec4(toColor, 1.0f)); glUniformMatrix4fv(lineInfoU, 1, GL_FALSE, glm::value_ptr(matrix)); if (willTransform) { glUniformMatrix4fv(viewTransformU, 1, GL_FALSE, glm::value_ptr(getProjectionMatrix() * getCameraMatrix())); } else { glUniformMatrix4fv(viewTransformU, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0))); } glBindVertexArray(vao); glDrawArrays(GL_LINES, 0, 2); glBindVertexArray(0); //state->setProgram(0); checkErrors("drawLine"); }
IndexBuffer::IndexBuffer(U32 elementCount) : IndexBuffer() { generateBuffer(elementCount); }
void ProceduralTexture::init(int w_in,int h_in) { width = w_in; height = h_in; generateBuffer(); }