Have the first geom shader working that will explode the box.
This commit is contained in:
parent
c4c808f3c5
commit
22c2b78fca
13 changed files with 153 additions and 20 deletions
|
|
@ -5,8 +5,8 @@
|
|||
#include <unordered_map>
|
||||
#include "json.hpp"
|
||||
|
||||
const unsigned int SCR_WIDTH = 800;
|
||||
const unsigned int SCR_HEIGHT = 600;
|
||||
const unsigned int SCR_WIDTH = 1792;
|
||||
const unsigned int SCR_HEIGHT = 1008;
|
||||
|
||||
#define MAX_LIGHTS 4
|
||||
|
||||
|
|
@ -96,9 +96,10 @@ namespace components {
|
|||
struct Shader {
|
||||
std::string vertex_path;
|
||||
std::string frag_path;
|
||||
std::string geometry_path;
|
||||
};
|
||||
|
||||
ENROLL_COMPONENT(Shader, vertex_path, frag_path);
|
||||
ENROLL_COMPONENT(Shader, vertex_path, frag_path, geometry_path);
|
||||
|
||||
struct Scene {
|
||||
components::Shader shader;
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ void Scene::render(GLFWwindow* window) {
|
|||
with_shader.setMat4("view", view);
|
||||
with_shader.setMat4("projection", projection);
|
||||
with_shader.setVec3("cameraPos", camera.position);
|
||||
with_shader.setFloat("time", glfwGetTime());
|
||||
|
||||
for(auto& thing : things) {
|
||||
draw_thing(with_shader, thing);
|
||||
|
|
|
|||
|
|
@ -46,11 +46,11 @@ struct Scene {
|
|||
bool reflect_on = false;
|
||||
|
||||
Scene(components::Scene& config):
|
||||
shader{config.shader.vertex_path, config.shader.frag_path},
|
||||
reflect_shader{config.reflect_shader.vertex_path, config.reflect_shader.frag_path},
|
||||
skybox_shader{config.skybox_shader.vertex_path, config.skybox_shader.frag_path},
|
||||
shader{config.shader},
|
||||
reflect_shader{config.reflect_shader},
|
||||
skybox_shader{config.skybox_shader},
|
||||
skybox_faces{config.skybox_faces},
|
||||
screen{.shader={config.screen_shader.vertex_path, config.screen_shader.frag_path}},
|
||||
screen{.shader={config.screen_shader}},
|
||||
materials{config.materials},
|
||||
camera{
|
||||
.position=config.camera.position,
|
||||
|
|
|
|||
|
|
@ -61,19 +61,33 @@ unsigned int Shader::load_shader(const std::string& filename, GLenum shader_type
|
|||
return shader_id;
|
||||
}
|
||||
|
||||
Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) {
|
||||
unsigned int vertex = load_shader(vertexPath, GL_VERTEX_SHADER);
|
||||
unsigned int fragment = load_shader(fragmentPath, GL_FRAGMENT_SHADER);
|
||||
|
||||
Shader::Shader(components::Shader config) {
|
||||
dbc::log($F("Loading shaders vert={}, frag={}, geom={}", config.vertex_path, config.frag_path, config.geometry_path));
|
||||
|
||||
unsigned int vertex = load_shader(config.vertex_path, GL_VERTEX_SHADER);
|
||||
unsigned int fragment = load_shader(config.frag_path, GL_FRAGMENT_SHADER);
|
||||
unsigned int geometry = UINT_MAX;
|
||||
|
||||
ID = glCreateProgram();
|
||||
dbc::log($F("Created shader program ID: {}", ID));
|
||||
glAttachShader(ID, vertex);
|
||||
glAttachShader(ID, fragment);
|
||||
glLinkProgram(ID);
|
||||
|
||||
if(config.geometry_path != "") {
|
||||
geometry = load_shader(config.geometry_path, GL_GEOMETRY_SHADER);
|
||||
glAttachShader(ID, geometry);
|
||||
}
|
||||
|
||||
glLinkProgram(ID);
|
||||
check_error("link", ID, GL_LINK_STATUS);
|
||||
|
||||
glDeleteShader(vertex);
|
||||
glDeleteShader(fragment);
|
||||
|
||||
if(config.geometry_path != "") {
|
||||
glDeleteShader(geometry);
|
||||
}
|
||||
}
|
||||
|
||||
void Shader::use() const {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ class Shader
|
|||
public:
|
||||
unsigned int ID = UINT_MAX;
|
||||
|
||||
Shader(const std::string& vertexPath, const std::string& fragmentPath);
|
||||
Shader(components::Shader config);
|
||||
|
||||
unsigned int load_shader(const std::string& filename, GLenum shader_type);
|
||||
void use() const;
|
||||
void setBool(const std::string &name, bool value) const;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue