mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-18 16:32:32 +02:00
clang-format files in rwlib/source/gl
This commit is contained in:
parent
4308a55ee8
commit
c4bb714e54
@ -4,37 +4,29 @@
|
|||||||
|
|
||||||
/* TODO: Come up with a more elegant solution to "WHICH ARRAY IS IT?" */
|
/* TODO: Come up with a more elegant solution to "WHICH ARRAY IS IT?" */
|
||||||
std::map<AttributeSemantic, GLuint> semantic_to_attrib_array = {
|
std::map<AttributeSemantic, GLuint> semantic_to_attrib_array = {
|
||||||
{ATRS_Position, 0},
|
{ATRS_Position, 0}, {ATRS_Normal, 1}, {ATRS_Colour, 2}, {ATRS_TexCoord, 3}};
|
||||||
{ATRS_Normal, 1},
|
|
||||||
{ATRS_Colour, 2},
|
|
||||||
{ATRS_TexCoord, 3}
|
|
||||||
};
|
|
||||||
|
|
||||||
DrawBuffer::DrawBuffer()
|
|
||||||
: vao(0)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
DrawBuffer::DrawBuffer() : vao(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawBuffer::~DrawBuffer()
|
DrawBuffer::~DrawBuffer() {
|
||||||
{
|
if (vao) {
|
||||||
if(vao) {
|
glDeleteVertexArrays(1, &vao);
|
||||||
glDeleteVertexArrays(1, &vao);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawBuffer::addGeometry(GeometryBuffer* gbuff)
|
void DrawBuffer::addGeometry(GeometryBuffer* gbuff) {
|
||||||
{
|
if (vao == 0) {
|
||||||
if(vao == 0) {
|
glGenVertexArrays(1, &vao);
|
||||||
glGenVertexArrays(1, &vao);
|
}
|
||||||
}
|
|
||||||
|
glBindVertexArray(vao);
|
||||||
glBindVertexArray(vao);
|
glBindBuffer(GL_ARRAY_BUFFER, gbuff->getVBOName());
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, gbuff->getVBOName());
|
// Iterate the attributes present in the gbuff
|
||||||
// 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];
|
||||||
GLuint vaoindex = semantic_to_attrib_array[at.sem];
|
glEnableVertexAttribArray(vaoindex);
|
||||||
glEnableVertexAttribArray(vaoindex);
|
glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride,
|
||||||
glVertexAttribPointer(vaoindex, at.size, at.type, GL_TRUE, at.stride, reinterpret_cast<GLvoid*>(at.offset));
|
reinterpret_cast<GLvoid*>(at.offset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,38 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef _DRAWBUFFER_HPP_
|
#ifndef _DRAWBUFFER_HPP_
|
||||||
#define _DRAWBUFFER_HPP_
|
#define _DRAWBUFFER_HPP_
|
||||||
#include <gl/gl_core_3_3.h>
|
#include <gl/gl_core_3_3.h>
|
||||||
|
|
||||||
class GeometryBuffer;
|
class GeometryBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DrawBuffer stores VAO state
|
* DrawBuffer stores VAO state
|
||||||
*/
|
*/
|
||||||
class DrawBuffer {
|
class DrawBuffer {
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
|
|
||||||
GLenum facetype;
|
GLenum facetype;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
DrawBuffer();
|
||||||
DrawBuffer();
|
~DrawBuffer();
|
||||||
~DrawBuffer();
|
|
||||||
|
GLuint getVAOName() const {
|
||||||
GLuint getVAOName() const
|
return vao;
|
||||||
{ return vao; }
|
}
|
||||||
|
|
||||||
void setFaceType(GLenum ft)
|
void setFaceType(GLenum ft) {
|
||||||
{ facetype = ft; }
|
facetype = ft;
|
||||||
|
}
|
||||||
GLenum getFaceType() const
|
|
||||||
{ return facetype; }
|
GLenum getFaceType() const {
|
||||||
|
return facetype;
|
||||||
/**
|
}
|
||||||
* Adds a Geometry Buffer to the Draw Buffer.
|
|
||||||
*/
|
/**
|
||||||
void addGeometry(GeometryBuffer* gbuff);
|
* Adds a Geometry Buffer to the Draw Buffer.
|
||||||
|
*/
|
||||||
|
void addGeometry(GeometryBuffer* gbuff);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,24 +1,20 @@
|
|||||||
#include <gl/GeometryBuffer.hpp>
|
#include <gl/GeometryBuffer.hpp>
|
||||||
|
|
||||||
GeometryBuffer::GeometryBuffer()
|
GeometryBuffer::GeometryBuffer() : vbo(0), num(0) {
|
||||||
: vbo(0), num(0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GeometryBuffer::~GeometryBuffer()
|
GeometryBuffer::~GeometryBuffer() {
|
||||||
{
|
if (vbo != 0) {
|
||||||
if(vbo != 0) {
|
glDeleteBuffers(1, &vbo);
|
||||||
glDeleteBuffers(1, &vbo);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryBuffer::uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem)
|
void GeometryBuffer::uploadVertices(GLsizei num, GLsizeiptr size,
|
||||||
{
|
const GLvoid* mem) {
|
||||||
if(vbo == 0) {
|
if (vbo == 0) {
|
||||||
glGenBuffers(1, &vbo);
|
glGenBuffers(1, &vbo);
|
||||||
}
|
}
|
||||||
this->num = num;
|
this->num = num;
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||||
glBufferData(GL_ARRAY_BUFFER, size, mem, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, size, mem, GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
@ -8,79 +8,80 @@
|
|||||||
* Enum used to determine which shader input an attribute maps to
|
* Enum used to determine which shader input an attribute maps to
|
||||||
*/
|
*/
|
||||||
enum AttributeSemantic {
|
enum AttributeSemantic {
|
||||||
ATRS_Position,
|
ATRS_Position,
|
||||||
ATRS_Normal,
|
ATRS_Normal,
|
||||||
ATRS_Colour,
|
ATRS_Colour,
|
||||||
ATRS_TexCoord
|
ATRS_TexCoord
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores Vertex Attribute data
|
* Stores Vertex Attribute data
|
||||||
*/
|
*/
|
||||||
struct AttributeIndex {
|
struct AttributeIndex {
|
||||||
AttributeSemantic sem;
|
AttributeSemantic sem;
|
||||||
GLsizei size;
|
GLsizei size;
|
||||||
GLsizei stride;
|
GLsizei stride;
|
||||||
GLsizei offset;
|
GLsizei offset;
|
||||||
GLenum type;
|
GLenum type;
|
||||||
|
|
||||||
AttributeIndex(AttributeSemantic s,
|
AttributeIndex(AttributeSemantic s, GLsizei sz, GLsizei strd, GLsizei offs,
|
||||||
GLsizei sz,
|
GLenum type = GL_FLOAT)
|
||||||
GLsizei strd,
|
: sem(s), size(sz), stride(strd), offset(offs), type(type) {
|
||||||
GLsizei offs,
|
}
|
||||||
GLenum type = GL_FLOAT)
|
|
||||||
: sem(s), size(sz), stride(strd), offset(offs), type(type)
|
|
||||||
{}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<AttributeIndex> AttributeList;
|
typedef std::vector<AttributeIndex> AttributeList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GeometryBuffer stores a set of vertex attribute data
|
* GeometryBuffer stores a set of vertex attribute data
|
||||||
*/
|
*/
|
||||||
class GeometryBuffer {
|
class GeometryBuffer {
|
||||||
GLuint vbo;
|
GLuint vbo;
|
||||||
GLsizei num;
|
GLsizei num;
|
||||||
|
|
||||||
AttributeList attributes;
|
AttributeList attributes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
GeometryBuffer();
|
||||||
|
template <class T>
|
||||||
|
GeometryBuffer(const std::vector<T>& data) : vbo(0), num(0) {
|
||||||
|
uploadVertices(data);
|
||||||
|
}
|
||||||
|
|
||||||
GeometryBuffer();
|
~GeometryBuffer();
|
||||||
template<class T> GeometryBuffer(const std::vector<T>& data)
|
|
||||||
: vbo(0), num(0)
|
|
||||||
{
|
|
||||||
uploadVertices(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
~GeometryBuffer();
|
GLuint getVBOName() const {
|
||||||
|
return vbo;
|
||||||
|
}
|
||||||
|
|
||||||
GLuint getVBOName() const
|
GLsizei getCount() const {
|
||||||
{ return vbo; }
|
return num;
|
||||||
|
}
|
||||||
GLsizei getCount() const
|
|
||||||
{ return num; }
|
/**
|
||||||
|
* Uploads Vertex Buffer data from an STL vector
|
||||||
/**
|
*
|
||||||
* 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.
|
||||||
* 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) {
|
||||||
template<class T> void uploadVertices(const std::vector<T>& data) {
|
uploadVertices(data.size(), data.size() * sizeof(T), data.data());
|
||||||
uploadVertices(data.size(), data.size()*sizeof(T), data.data());
|
// Assume T has a static method for attributes;
|
||||||
// Assume T has a static method for attributes;
|
attributes = T::vertex_attributes();
|
||||||
attributes = T::vertex_attributes();
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Uploads raw memory into the buffer.
|
||||||
* Uploads raw memory into the buffer.
|
*/
|
||||||
*/
|
void uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem);
|
||||||
void uploadVertices(GLsizei num, GLsizeiptr size, const GLvoid* mem);
|
|
||||||
|
const AttributeList& getDataAttributes() const {
|
||||||
const AttributeList& getDataAttributes() const
|
return attributes;
|
||||||
{ return attributes; }
|
}
|
||||||
AttributeList& getDataAttributes()
|
AttributeList& getDataAttributes() {
|
||||||
{ return attributes; }
|
return attributes;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -7,28 +7,33 @@
|
|||||||
/**
|
/**
|
||||||
* Stores a handle and metadata about a loaded texture.
|
* Stores a handle and metadata about a loaded texture.
|
||||||
*/
|
*/
|
||||||
class TextureData
|
class TextureData {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
TextureData(GLuint name, const glm::ivec2& dims, bool alpha)
|
||||||
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; }
|
}
|
||||||
|
|
||||||
bool isTransparent() const { return hasAlpha; }
|
const glm::ivec2& getSize() const {
|
||||||
|
return size;
|
||||||
typedef std::shared_ptr<TextureData> Handle;
|
}
|
||||||
|
|
||||||
static Handle create(GLuint name, const glm::ivec2& size, bool transparent)
|
bool isTransparent() const {
|
||||||
{
|
return hasAlpha;
|
||||||
return Handle( new TextureData( name, size, transparent ) );
|
}
|
||||||
}
|
|
||||||
|
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:
|
private:
|
||||||
GLuint texName;
|
GLuint texName;
|
||||||
glm::ivec2 size;
|
glm::ivec2 size;
|
||||||
bool hasAlpha;
|
bool hasAlpha;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user