1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +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) {
DrawBuffer::~DrawBuffer() {
if (vao) {
glDeleteVertexArrays(1, &vao);
}
}
void DrawBuffer::addGeometry(GeometryBuffer* gbuff)
{
if(vao == 0) {
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()) {
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));
glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride,
reinterpret_cast<GLvoid*>(at.offset));
}
}

View File

@ -12,19 +12,22 @@ class DrawBuffer {
GLuint vao;
GLenum facetype;
public:
public:
DrawBuffer();
~DrawBuffer();
GLuint getVAOName() const
{ return vao; }
GLuint getVAOName() const {
return vao;
}
void setFaceType(GLenum ft)
{ facetype = ft; }
void setFaceType(GLenum ft) {
facetype = ft;
}
GLenum getFaceType() const
{ return facetype; }
GLenum getFaceType() const {
return facetype;
}
/**
* Adds a Geometry Buffer to the Draw Buffer.

View File

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

View File

@ -24,13 +24,10 @@ struct AttributeIndex {
GLsizei offset;
GLenum type;
AttributeIndex(AttributeSemantic s,
GLsizei sz,
GLsizei strd,
GLsizei offs,
AttributeIndex(AttributeSemantic s, GLsizei sz, GLsizei strd, GLsizei offs,
GLenum type = GL_FLOAT)
: sem(s), size(sz), stride(strd), offset(offs), type(type)
{}
: sem(s), size(sz), stride(strd), offset(offs), type(type) {
}
};
typedef std::vector<AttributeIndex> AttributeList;
@ -43,22 +40,23 @@ class GeometryBuffer {
GLsizei num;
AttributeList attributes;
public:
public:
GeometryBuffer();
template<class T> GeometryBuffer(const std::vector<T>& data)
: vbo(0), num(0)
{
template <class T>
GeometryBuffer(const std::vector<T>& data) : vbo(0), num(0) {
uploadVertices(data);
}
~GeometryBuffer();
GLuint getVBOName() const
{ return vbo; }
GLuint getVBOName() const {
return vbo;
}
GLsizei getCount() const
{ return num; }
GLsizei getCount() const {
return num;
}
/**
* Uploads Vertex Buffer data from an STL vector
@ -66,8 +64,9 @@ public:
* 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());
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();
}
@ -77,10 +76,12 @@ public:
*/
void uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem);
const AttributeList& getDataAttributes() const
{ return attributes; }
AttributeList& getDataAttributes()
{ return attributes; }
const AttributeList& getDataAttributes() const {
return attributes;
}
AttributeList& getDataAttributes() {
return attributes;
}
};
#endif

View File

@ -7,24 +7,29 @@
/**
* 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) { }
: texName(name), size(dims), hasAlpha(alpha) {
}
GLuint getName() const { return texName; }
GLuint getName() const {
return texName;
}
const glm::ivec2& getSize() const { return size; }
const glm::ivec2& getSize() const {
return size;
}
bool isTransparent() const { return hasAlpha; }
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 ) );
static Handle create(GLuint name, const glm::ivec2& size,
bool transparent) {
return Handle(new TextureData(name, size, transparent));
}
private: