mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add shader class
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Cubed/config.hpp>
|
||||
#include <Cubed/shader.hpp>
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glm/glm.hpp>
|
||||
@@ -16,6 +17,7 @@ public:
|
||||
Renderer(const Camera& camera, World& world, const TextureManager& texture_manager);
|
||||
~Renderer();
|
||||
void init();
|
||||
const Shader& get_shader(const std::string& name) const;
|
||||
void render();
|
||||
void update_proj_matrix(float aspect, float width, float height);
|
||||
private:
|
||||
@@ -35,21 +37,14 @@ private:
|
||||
GLuint m_outline_vbo;
|
||||
GLuint m_ui_vbo;
|
||||
|
||||
GLuint m_sky_program;
|
||||
GLuint m_text_program;
|
||||
GLuint m_outline_program;
|
||||
GLuint m_ui_program;
|
||||
GLuint m_world_program;
|
||||
|
||||
|
||||
glm::mat4 m_ui_proj;
|
||||
glm::mat4 m_ui_m_matrix;
|
||||
|
||||
std::unordered_map<std::size_t, Shader> m_shaders;
|
||||
std::vector<GLuint> m_vao;
|
||||
std::vector<Vertex2D> m_ui;
|
||||
void render_outline();
|
||||
void render_sky();
|
||||
void render_text();
|
||||
void render_ui();
|
||||
|
||||
void render_world();
|
||||
};
|
||||
26
include/Cubed/shader.hpp
Normal file
26
include/Cubed/shader.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <string>
|
||||
class Shader {
|
||||
public:
|
||||
Shader();
|
||||
Shader(const std::string& name, const std::string& v_shader_path, const std::string& f_shader_path);
|
||||
~Shader();
|
||||
Shader(const Shader&) = delete;
|
||||
Shader& operator=(const Shader&) = delete;
|
||||
Shader(Shader&& shader);
|
||||
Shader& operator=(Shader&& shader);
|
||||
|
||||
void create(const std::string& name, const std::string& v_shader_path, const std::string& f_shader_path);
|
||||
std::size_t hash() const;
|
||||
GLuint loc(const std::string& loc) const;
|
||||
const std::string& name() const;
|
||||
void use() const;
|
||||
|
||||
private:
|
||||
GLuint m_program = 0;
|
||||
std::size_t m_hash = 0;
|
||||
std::string m_name = "-1";
|
||||
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
namespace HASH {
|
||||
inline std::size_t str(std::string value) {
|
||||
inline std::size_t str(const std::string& value) {
|
||||
return std::hash<std::string>{}(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@ struct Character {
|
||||
GLuint advance;
|
||||
};
|
||||
|
||||
class Shader;
|
||||
|
||||
class Font {
|
||||
public:
|
||||
Font();
|
||||
~Font();
|
||||
|
||||
static void render_text(GLuint program, const std::string& text, float x, float y, float scale, const glm::vec3& color);
|
||||
static void render_text(const Shader& shader, const std::string& text, float x, float y, float scale, const glm::vec3& color);
|
||||
|
||||
private:
|
||||
FT_Library m_ft;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <SOIL2.h>
|
||||
#include <string>
|
||||
|
||||
namespace Shader {
|
||||
namespace Tools {
|
||||
GLuint create_shader_program(const std::string& v_shader_path, const std::string& f_shader_path);
|
||||
void print_shader_log(GLuint shader);
|
||||
void print_program_info(int prog);
|
||||
|
||||
Reference in New Issue
Block a user