Files

81 lines
2.1 KiB
C++
Raw Permalink Normal View History

#pragma once
#include "grbl.h"
#include "grbl_machine.h"
#include "glm/ext/matrix_float4x4.hpp"
2023-05-09 14:30:39 +03:00
#include "heightmap.h"
#include <nanogui/opengl.h>
namespace grbl {
class shader_program;
class program_renderer {
public:
void update(const program& pgm, const machine& cnc);
2023-05-07 23:06:12 +03:00
void render(glm::mat4 model, glm::mat4 view, glm::mat4 projection, glm::mat3 normal_mat, glm::vec2 viewport_size);
glm::vec3 get_extents_min() const { return min_pos; };
glm::vec3 get_extents_max() const { return max_pos; };
void update_grid(const grbl::heightmap& grid, float exaggeration_factor);
private:
2023-05-07 23:06:12 +03:00
GLsizei update_model_vbo(const grbl::program& pgm);
void update_model_extents(glm::vec3 point);
GLuint spindle_vbo_id;
GLuint spindle_vao_id;
GLuint vbo_id;
GLuint vao_id;
2023-05-07 11:23:58 +03:00
GLuint extents_vbo_id;
GLuint extents_vao_id;
2023-05-07 23:06:12 +03:00
GLuint heightmap_vbo_id;
GLuint heightmap_vao_id;
shader_program *shader = nullptr;
2023-05-07 23:06:12 +03:00
shader_program *heightmap_shader = nullptr;
bool initialized = false;
glm::vec3 min_pos, max_pos, spindle_pos;
2023-05-07 23:06:12 +03:00
GLsizei vertices_count, spindle_vertices_count, extents_vertices_count, heightmap_vertices_count;
void initialize_program_buffers();
void initialize_spindle_buffers();
2023-05-07 11:23:58 +03:00
void initialize_extents_buffers();
2023-05-07 23:06:12 +03:00
void initialize_heightmap_buffers();
};
class shader_program {
public:
shader_program(const char *vs_content, const char *ps_content);
virtual ~shader_program();
void bind() const;
static void unbind();
GLuint get_id() const { return program_id; }
int get_uniform(const char *name);
void set_mat3(float *value, const char *uniform_name);
void set_mat4(float *value, const char *uniform_name);
void set_vec2(float *value, const char *uniform_name);
void set_vec3(float *value, const char *uniform_name);
void set_vec4(float *value, const char *uniform_name);
void set_float(float value, const char *uniform_name);
void set_int(int value, const char *uniform_name);
private:
GLuint program_id;
GLuint shader_ids[2];
std::map<const char *, int> uniform_cache;
};
}