style: apply clang format
This commit is contained in:
@@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
#include "vertex.h"
|
#include "vertex.h"
|
||||||
|
|
||||||
Buffer::Buffer(const std::vector<Vertex>& vertices, const std::vector<uint16_t>& indices)
|
Buffer::Buffer(const std::vector<Vertex>& vertices,
|
||||||
|
const std::vector<uint16_t>& indices)
|
||||||
{
|
{
|
||||||
index_count_ = static_cast<GLsizei>(indices.size());
|
index_count_ = static_cast<GLsizei>(indices.size());
|
||||||
|
|
||||||
@@ -19,12 +20,15 @@ Buffer::Buffer(const std::vector<Vertex>& vertices, const std::vector<uint16_t>&
|
|||||||
glBindVertexArray(vao_);
|
glBindVertexArray(vao_);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo_);
|
||||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), vertices.data(), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex),
|
||||||
|
vertices.data(), GL_STATIC_DRAW);
|
||||||
|
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo_);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(uint16_t), indices.data(), GL_STATIC_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(uint16_t),
|
||||||
|
indices.data(), GL_STATIC_DRAW);
|
||||||
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||||
|
nullptr);
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
class Buffer {
|
class Buffer {
|
||||||
public:
|
public:
|
||||||
Buffer(const std::vector<Vertex>& vertices, const std::vector<uint16_t>& indices);
|
Buffer(const std::vector<Vertex>& vertices,
|
||||||
|
const std::vector<uint16_t>& indices);
|
||||||
~Buffer();
|
~Buffer();
|
||||||
|
|
||||||
void Draw(const Shader& shader) const;
|
void Draw(const Shader& shader) const;
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath)
|
Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath)
|
||||||
{
|
{
|
||||||
const uint32_t vshader = CompileShader(GL_VERTEX_SHADER, vertexPath);
|
const uint32_t vshader = CompileShader(GL_VERTEX_SHADER, vertexPath);
|
||||||
const uint32_t fshader = CompileShader(GL_FRAGMENT_SHADER, fragmentPath);
|
const uint32_t fshader =
|
||||||
|
CompileShader(GL_FRAGMENT_SHADER, fragmentPath);
|
||||||
|
|
||||||
if (vshader == 0 || fshader == 0) {
|
if (vshader == 0 || fshader == 0) {
|
||||||
program_id_ = 0;
|
program_id_ = 0;
|
||||||
@@ -30,7 +31,8 @@ Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath)
|
|||||||
glGetProgramiv(program_id_, GL_LINK_STATUS, &ret);
|
glGetProgramiv(program_id_, GL_LINK_STATUS, &ret);
|
||||||
if (ret == GL_FALSE) {
|
if (ret == GL_FALSE) {
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
glGetProgramInfoLog(program_id_, sizeof(buffer), nullptr, buffer);
|
glGetProgramInfoLog(program_id_, sizeof(buffer), nullptr,
|
||||||
|
buffer);
|
||||||
error_ = buffer;
|
error_ = buffer;
|
||||||
glDeleteProgram(program_id_);
|
glDeleteProgram(program_id_);
|
||||||
program_id_ = 0;
|
program_id_ = 0;
|
||||||
@@ -51,13 +53,17 @@ void Shader::SetupAttribs() const
|
|||||||
int loc = glGetAttribLocation(program_id_, "vpos");
|
int loc = glGetAttribLocation(program_id_, "vpos");
|
||||||
if (loc != -1) {
|
if (loc != -1) {
|
||||||
glEnableVertexAttribArray(loc);
|
glEnableVertexAttribArray(loc);
|
||||||
glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const void*>(offsetof(Vertex, position)));
|
glVertexAttribPointer(
|
||||||
|
loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||||
|
reinterpret_cast<const void*>(offsetof(Vertex, position)));
|
||||||
}
|
}
|
||||||
|
|
||||||
loc = glGetAttribLocation(program_id_, "vcolor");
|
loc = glGetAttribLocation(program_id_, "vcolor");
|
||||||
if (loc != -1) {
|
if (loc != -1) {
|
||||||
glEnableVertexAttribArray(loc);
|
glEnableVertexAttribArray(loc);
|
||||||
glVertexAttribPointer(loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<const void*>(offsetof(Vertex, color)));
|
glVertexAttribPointer(
|
||||||
|
loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),
|
||||||
|
reinterpret_cast<const void*>(offsetof(Vertex, color)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/shader.h
14
src/shader.h
@@ -9,13 +9,20 @@
|
|||||||
|
|
||||||
class Shader {
|
class Shader {
|
||||||
public:
|
public:
|
||||||
Shader(const std::string& vertex_path, const std::string& fragment_path);
|
Shader(const std::string& vertex_path,
|
||||||
|
const std::string& fragment_path);
|
||||||
|
|
||||||
void Use() const;
|
void Use() const;
|
||||||
void SetupAttribs() const;
|
void SetupAttribs() const;
|
||||||
|
|
||||||
uint32_t getId() const { return program_id_; }
|
uint32_t getId() const
|
||||||
const char* getError() const { return error_.c_str(); }
|
{
|
||||||
|
return program_id_;
|
||||||
|
}
|
||||||
|
const char* getError() const
|
||||||
|
{
|
||||||
|
return error_.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
int getLocation(const char* key) const;
|
int getLocation(const char* key) const;
|
||||||
|
|
||||||
@@ -33,5 +40,4 @@ private:
|
|||||||
uint32_t CompileShader(uint32_t type, const std::string& source_path);
|
uint32_t CompileShader(uint32_t type, const std::string& source_path);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SHADER_H_
|
#endif // SHADER_H_
|
||||||
Reference in New Issue
Block a user