less gl state
This commit is contained in:
parent
c68d2967d3
commit
82146468f3
|
@ -5,8 +5,8 @@
|
||||||
|
|
||||||
using Graphics::GL::Texture;
|
using Graphics::GL::Texture;
|
||||||
|
|
||||||
Texture::Texture(int type) {
|
Texture::Texture() {
|
||||||
glCreateTextures(type, 1, &m_handle);
|
glGenTextures(1, &m_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(Texture&& o) : BufferBase(std::move(o)) {
|
Texture::Texture(Texture&& o) : BufferBase(std::move(o)) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "buffer_base.hpp"
|
#include "buffer_base.hpp"
|
||||||
namespace Graphics::GL {
|
namespace Graphics::GL {
|
||||||
struct Texture : BufferBase {
|
struct Texture : BufferBase {
|
||||||
Texture(int type);
|
Texture();
|
||||||
Texture(Texture&& o);
|
Texture(Texture&& o);
|
||||||
~Texture();
|
~Texture();
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,9 +23,9 @@ Particles::Particles() {
|
||||||
glNamedBufferData(m_ubo_info, sizeof(InfoType), nullptr, GL_DYNAMIC_DRAW);
|
glNamedBufferData(m_ubo_info, sizeof(InfoType), nullptr, GL_DYNAMIC_DRAW);
|
||||||
m_particles_mapping = (Type*)glMapNamedBuffer(m_ssbo_particles, GL_READ_WRITE);
|
m_particles_mapping = (Type*)glMapNamedBuffer(m_ssbo_particles, GL_READ_WRITE);
|
||||||
|
|
||||||
auto b = m_vao.bind();
|
glBindVertexArray(m_vao);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_ssbo_vertices);
|
glBindBuffer(GL_ARRAY_BUFFER, m_ssbo_vertices);
|
||||||
Vertex::set_vertex_attribs();
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Particles::update(const Pipeline& pipeline) {
|
void Particles::update(const Pipeline& pipeline) {
|
||||||
|
@ -60,8 +60,9 @@ void Particles::render(const Context& ctx) const {
|
||||||
ctx.set_colour_matrix(glm::mat4(1));
|
ctx.set_colour_matrix(glm::mat4(1));
|
||||||
ctx.set_model_matrix(glm::mat4(1));
|
ctx.set_model_matrix(glm::mat4(1));
|
||||||
|
|
||||||
auto b = m_vao.bind();
|
glBindVertexArray(m_vao);
|
||||||
glDrawArrays(GL_POINTS, 0, m_particles_mapping_size);
|
glDrawArrays(GL_POINTS, 0, m_particles_mapping_size);
|
||||||
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Particles::add(const Type& type) {
|
void Particles::add(const Type& type) {
|
||||||
|
|
|
@ -6,10 +6,13 @@
|
||||||
#include "gl/shader.hpp"
|
#include "gl/shader.hpp"
|
||||||
#include "shader/compile.hpp"
|
#include "shader/compile.hpp"
|
||||||
#include "shader/link.hpp"
|
#include "shader/link.hpp"
|
||||||
|
#include "texture/generate_atlas.hpp"
|
||||||
|
|
||||||
using Graphics::Pipeline;
|
using Graphics::Pipeline;
|
||||||
|
|
||||||
Pipeline::Pipeline() {
|
Pipeline::Pipeline() {
|
||||||
|
Graphics::Texture::generate_atlas(m_generated_atlas);
|
||||||
|
|
||||||
Graphics::GL::Shader model_vert = Graphics::Shader::compile_new(GL_VERTEX_SHADER, "model.vert");
|
Graphics::GL::Shader model_vert = Graphics::Shader::compile_new(GL_VERTEX_SHADER, "model.vert");
|
||||||
Graphics::GL::Shader model_frag = Graphics::Shader::compile_new(GL_FRAGMENT_SHADER, "model.frag");
|
Graphics::GL::Shader model_frag = Graphics::Shader::compile_new(GL_FRAGMENT_SHADER, "model.frag");
|
||||||
Graphics::GL::Shader particles_comp = Graphics::Shader::compile_new(GL_COMPUTE_SHADER, "particles.comp");
|
Graphics::GL::Shader particles_comp = Graphics::Shader::compile_new(GL_COMPUTE_SHADER, "particles.comp");
|
||||||
|
|
|
@ -4,12 +4,14 @@
|
||||||
#include "context.hpp"
|
#include "context.hpp"
|
||||||
#include "gl/program.hpp"
|
#include "gl/program.hpp"
|
||||||
#include "particles.hpp"
|
#include "particles.hpp"
|
||||||
|
#include "texture/generate_atlas.hpp"
|
||||||
#include "window.hpp"
|
#include "window.hpp"
|
||||||
#include "../world/state.hpp"
|
#include "../world/state.hpp"
|
||||||
|
|
||||||
namespace Graphics {
|
namespace Graphics {
|
||||||
struct Pipeline {
|
struct Pipeline {
|
||||||
Window m_window;
|
Window m_window;
|
||||||
|
Texture::GeneratedAtlas m_generated_atlas;
|
||||||
Particles m_particles;
|
Particles m_particles;
|
||||||
GL::Program m_program_model;
|
GL::Program m_program_model;
|
||||||
GL::Program m_program_particles;
|
GL::Program m_program_particles;
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
|
|
||||||
|
#include "generate_atlas.hpp"
|
||||||
#include "../texture.hpp"
|
#include "../texture.hpp"
|
||||||
#include "../shader.hpp"
|
#include "../shader.hpp"
|
||||||
#include "atlas.hpp"
|
#include "atlas.hpp"
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "uv.hpp"
|
#include "uv.hpp"
|
||||||
#include "../gl/array_buffer.hpp"
|
|
||||||
#include "../gl/texture.hpp"
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <stb/stb_rect_pack.h>
|
#include <stb/stb_rect_pack.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
void Graphics::Texture::generate_atlas() {
|
void Graphics::Texture::generate_atlas(GeneratedAtlas& ga) {
|
||||||
int total_area = 0;
|
int total_area = 0;
|
||||||
int min_size = 1;
|
int min_size = 1;
|
||||||
int padding = 0;
|
int padding = 0;
|
||||||
|
@ -71,18 +70,17 @@ void Graphics::Texture::generate_atlas() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Graphics::Shader::SSBO_ATLAS_BUFFER, ga.m_ssbo_id);
|
||||||
|
glNamedBufferData(ga.m_ssbo_id, sizeof(UV) * uvs.size(), uvs.data(), GL_STATIC_DRAW);
|
||||||
|
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, Graphics::Shader::SSBO_ATLAS_BUFFER, ssbo_id);
|
|
||||||
glNamedBufferData(ssbo_id, sizeof(UV) * uvs.size(), uvs.data(), GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glTextureStorage2D(tex_id,
|
|
||||||
glActiveTexture(GL_TEXTURE0 + Graphics::Shader::TEX_ATLAS);
|
glActiveTexture(GL_TEXTURE0 + Graphics::Shader::TEX_ATLAS);
|
||||||
glBindTexture(GL_TEXTURE_2D_ARRAY, tex_id);
|
glBindTexture(GL_TEXTURE_2D_ARRAY, ga.m_tex_id);
|
||||||
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, atlas.m_size.x, atlas.m_size.y, atlas.m_size.z, 0, GL_RGBA, GL_UNSIGNED_BYTE, atlas.m_data.data());
|
glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, atlas.m_size.x, atlas.m_size.y, atlas.m_size.z, 0, GL_RGBA, GL_UNSIGNED_BYTE, atlas.m_data.data());
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,6 @@ namespace Graphics::Texture {
|
||||||
GL::Texture m_tex_id;
|
GL::Texture m_tex_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
GeneratedAtlas generate_atlas();
|
void generate_atlas(GeneratedAtlas& ga);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,12 @@ void Vertex::set_vertex_attribs(unsigned int vao, unsigned int vbo) {
|
||||||
|
|
||||||
glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(v));
|
glVertexArrayVertexBuffer(vao, 0, vbo, 0, sizeof(v));
|
||||||
glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, false, Util::pointer_diff(&v, &v.m_pos));
|
glVertexArrayAttribFormat(vao, 0, 4, GL_FLOAT, false, Util::pointer_diff(&v, &v.m_pos));
|
||||||
glVertexArrayAttribFormat(vao, 1, 4, GL_FLOAT, false, Util::pointer_diff(&v, &v.m_pos));
|
glVertexArrayAttribFormat(vao, 1, 4, GL_FLOAT, false, Util::pointer_diff(&v, &v.m_colour));
|
||||||
glVertexArrayAttribFormat(vao, 2, 2, GL_FLOAT, false, Util::pointer_diff(&v, &v.m_pos));
|
glVertexArrayAttribFormat(vao, 2, 2, GL_FLOAT, false, Util::pointer_diff(&v, &v.m_uv));
|
||||||
glVertexArrayAttribIFormat(vao, 3, 1, GL_UNSIGNED_INT, Util::pointer_diff(&v, &v.m_pos));
|
glVertexArrayAttribIFormat(vao, 3, 1, GL_UNSIGNED_INT, Util::pointer_diff(&v, &v.m_texid));
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
|
glEnableVertexArrayAttrib(vao, i);
|
||||||
glVertexArrayAttribBinding(vao, i, 0);
|
glVertexArrayAttribBinding(vao, i, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
|
|
||||||
#include "graphics/context.hpp"
|
#include "graphics/context.hpp"
|
||||||
#include "graphics/pipeline.hpp"
|
#include "graphics/pipeline.hpp"
|
||||||
#include "graphics/texture.hpp"
|
|
||||||
#include "world/state.hpp"
|
#include "world/state.hpp"
|
||||||
#include <glm/ext/matrix_clip_space.hpp>
|
#include <glm/ext/matrix_clip_space.hpp>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Graphics::Pipeline pipeline;
|
Graphics::Pipeline pipeline;
|
||||||
Graphics::Texture::generate_atlas();
|
|
||||||
World::State state;
|
World::State state;
|
||||||
|
|
||||||
while(!pipeline.should_close()) {
|
while(!pipeline.should_close()) {
|
||||||
|
|
Loading…
Reference in New Issue