1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-26 04:12:41 +01:00

clang-format files in rwlib/source/gl

This commit is contained in:
Daniel Evans 2016-09-09 21:13:21 +01:00
parent 4308a55ee8
commit c4bb714e54
5 changed files with 143 additions and 146 deletions

View File

@ -4,37 +4,29 @@
/* TODO: Come up with a more elegant solution to "WHICH ARRAY IS IT?" */
std::map<AttributeSemantic, GLuint> semantic_to_attrib_array = {
{ATRS_Position, 0},
{ATRS_Normal, 1},
{ATRS_Colour, 2},
{ATRS_TexCoord, 3}
};
DrawBuffer::DrawBuffer()
: vao(0)
{
{ATRS_Position, 0}, {ATRS_Normal, 1}, {ATRS_Colour, 2}, {ATRS_TexCoord, 3}};
DrawBuffer::DrawBuffer() : vao(0) {
}
DrawBuffer::~DrawBuffer()
{
if(vao) {
glDeleteVertexArrays(1, &vao);
}
DrawBuffer::~DrawBuffer() {
if (vao) {
glDeleteVertexArrays(1, &vao);
}
}
void DrawBuffer::addGeometry(GeometryBuffer* gbuff)
{
if(vao == 0) {
glGenVertexArrays(1, &vao);
}
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, gbuff->getVBOName());
// Iterate the attributes present in the gbuff
for(const AttributeIndex& at : gbuff->getDataAttributes()) {
GLuint vaoindex = semantic_to_attrib_array[at.sem];
glEnableVertexAttribArray(vaoindex);
glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride, reinterpret_cast<GLvoid*>(at.offset));
}
void DrawBuffer::addGeometry(GeometryBuffer* gbuff) {
if (vao == 0) {
glGenVertexArrays(1, &vao);
}
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, gbuff->getVBOName());
// Iterate the attributes present in the gbuff
for (const AttributeIndex& at : gbuff->getDataAttributes()) {
GLuint vaoindex = semantic_to_attrib_array[at.sem];
glEnableVertexAttribArray(vaoindex);
glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride,
reinterpret_cast<GLvoid*>(at.offset));
}
}

View File

@ -1,35 +1,38 @@
#pragma once
#pragma once
#ifndef _DRAWBUFFER_HPP_
#define _DRAWBUFFER_HPP_
#include <gl/gl_core_3_3.h>
class GeometryBuffer;
/**
* DrawBuffer stores VAO state
/**
* DrawBuffer stores VAO state
*/
class DrawBuffer {
GLuint vao;
GLenum facetype;
GLuint vao;
GLenum facetype;
public:
DrawBuffer();
~DrawBuffer();
GLuint getVAOName() const
{ return vao; }
void setFaceType(GLenum ft)
{ facetype = ft; }
GLenum getFaceType() const
{ return facetype; }
/**
* Adds a Geometry Buffer to the Draw Buffer.
*/
void addGeometry(GeometryBuffer* gbuff);
DrawBuffer();
~DrawBuffer();
GLuint getVAOName() const {
return vao;
}
void setFaceType(GLenum ft) {
facetype = ft;
}
GLenum getFaceType() const {
return facetype;
}
/**
* Adds a Geometry Buffer to the Draw Buffer.
*/
void addGeometry(GeometryBuffer* gbuff);
};
#endif
#endif

View File

@ -1,24 +1,20 @@
#include <gl/GeometryBuffer.hpp>
GeometryBuffer::GeometryBuffer()
: vbo(0), num(0)
{
GeometryBuffer::GeometryBuffer() : vbo(0), num(0) {
}
GeometryBuffer::~GeometryBuffer()
{
if(vbo != 0) {
glDeleteBuffers(1, &vbo);
}
GeometryBuffer::~GeometryBuffer() {
if (vbo != 0) {
glDeleteBuffers(1, &vbo);
}
}
void GeometryBuffer::uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem)
{
if(vbo == 0) {
glGenBuffers(1, &vbo);
}
this->num = num;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, size, mem, GL_STATIC_DRAW);
void GeometryBuffer::uploadVertices(GLsizei num, GLsizeiptr size,
const GLvoid* mem) {
if (vbo == 0) {
glGenBuffers(1, &vbo);
}
this->num = num;
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, size, mem, GL_STATIC_DRAW);
}

View File

@ -8,79 +8,80 @@
* Enum used to determine which shader input an attribute maps to
*/
enum AttributeSemantic {
ATRS_Position,
ATRS_Normal,
ATRS_Colour,
ATRS_TexCoord
ATRS_Position,
ATRS_Normal,
ATRS_Colour,
ATRS_TexCoord
};
/**
* Stores Vertex Attribute data
*/
struct AttributeIndex {
AttributeSemantic sem;
GLsizei size;
GLsizei stride;
GLsizei offset;
GLenum type;
AttributeSemantic sem;
GLsizei size;
GLsizei stride;
GLsizei offset;
GLenum type;
AttributeIndex(AttributeSemantic s,
GLsizei sz,
GLsizei strd,
GLsizei offs,
GLenum type = GL_FLOAT)
: sem(s), size(sz), stride(strd), offset(offs), type(type)
{}
AttributeIndex(AttributeSemantic s, GLsizei sz, GLsizei strd, GLsizei offs,
GLenum type = GL_FLOAT)
: sem(s), size(sz), stride(strd), offset(offs), type(type) {
}
};
typedef std::vector<AttributeIndex> AttributeList;
/**
/**
* GeometryBuffer stores a set of vertex attribute data
*/
class GeometryBuffer {
GLuint vbo;
GLsizei num;
AttributeList attributes;
GLuint vbo;
GLsizei num;
AttributeList attributes;
public:
GeometryBuffer();
template <class T>
GeometryBuffer(const std::vector<T>& data) : vbo(0), num(0) {
uploadVertices(data);
}
GeometryBuffer();
template<class T> GeometryBuffer(const std::vector<T>& data)
: vbo(0), num(0)
{
uploadVertices(data);
}
~GeometryBuffer();
~GeometryBuffer();
GLuint getVBOName() const {
return vbo;
}
GLuint getVBOName() const
{ return vbo; }
GLsizei getCount() const
{ return num; }
/**
* Uploads Vertex Buffer data from an STL vector
*
* vertex_attributes() is assumed to exist so that vertex types
* can implicitly declare the strides and offsets for their data.
*/
template<class T> void uploadVertices(const std::vector<T>& data) {
uploadVertices(data.size(), data.size()*sizeof(T), data.data());
// Assume T has a static method for attributes;
attributes = T::vertex_attributes();
}
/**
* Uploads raw memory into the buffer.
*/
void uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem);
const AttributeList& getDataAttributes() const
{ return attributes; }
AttributeList& getDataAttributes()
{ return attributes; }
GLsizei getCount() const {
return num;
}
/**
* Uploads Vertex Buffer data from an STL vector
*
* vertex_attributes() is assumed to exist so that vertex types
* can implicitly declare the strides and offsets for their data.
*/
template <class T>
void uploadVertices(const std::vector<T>& data) {
uploadVertices(data.size(), data.size() * sizeof(T), data.data());
// Assume T has a static method for attributes;
attributes = T::vertex_attributes();
}
/**
* Uploads raw memory into the buffer.
*/
void uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem);
const AttributeList& getDataAttributes() const {
return attributes;
}
AttributeList& getDataAttributes() {
return attributes;
}
};
#endif

View File

@ -7,28 +7,33 @@
/**
* Stores a handle and metadata about a loaded texture.
*/
class TextureData
{
class TextureData {
public:
TextureData(GLuint name, const glm::ivec2& dims, bool alpha)
: texName( name ), size( dims ), hasAlpha(alpha) { }
GLuint getName() const { return texName; }
const glm::ivec2& getSize() const { return size; }
bool isTransparent() const { return hasAlpha; }
typedef std::shared_ptr<TextureData> Handle;
static Handle create(GLuint name, const glm::ivec2& size, bool transparent)
{
return Handle( new TextureData( name, size, transparent ) );
}
TextureData(GLuint name, const glm::ivec2& dims, bool alpha)
: texName(name), size(dims), hasAlpha(alpha) {
}
GLuint getName() const {
return texName;
}
const glm::ivec2& getSize() const {
return size;
}
bool isTransparent() const {
return hasAlpha;
}
typedef std::shared_ptr<TextureData> Handle;
static Handle create(GLuint name, const glm::ivec2& size,
bool transparent) {
return Handle(new TextureData(name, size, transparent));
}
private:
GLuint texName;
glm::ivec2 size;
bool hasAlpha;
GLuint texName;
glm::ivec2 size;
bool hasAlpha;
};