glerminal/source/glerminal-private.h

87 lines
2.3 KiB
C
Raw Normal View History

2024-05-09 19:42:12 +00:00
#ifndef TERMG_PRIVATE_H
#define TERMG_PRIVATE_H
#include "glerminal.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <stdexcept>
#ifdef _DEBUG
#include <fstream>
#endif
2024-05-09 19:42:12 +00:00
namespace glerminal
{
constexpr unsigned int SCREEN_WIDTH = 1280;
constexpr unsigned int SCREEN_HEIGHT = 800;
constexpr unsigned int CELL_SIZE = GLERMINAL_CELL_SIZE;
constexpr unsigned int CELL_SCALE = 5;
constexpr unsigned int GRID_WIDTH = SCREEN_WIDTH / (CELL_SIZE * CELL_SCALE);
constexpr unsigned int GRID_HEIGHT = SCREEN_HEIGHT / (CELL_SIZE * CELL_SCALE);
constexpr unsigned int GRID_AREA = GRID_WIDTH * GRID_HEIGHT;
2024-05-15 02:42:49 +00:00
constexpr unsigned int LAYER_COUNT = 8;
2024-05-09 19:42:12 +00:00
class glerminal
{
public:
2024-05-14 21:46:30 +00:00
glerminal(glerminal_init_cb init, glerminal_main_cb main);
2024-05-09 19:42:12 +00:00
~glerminal();
glerminal(const glerminal&) = delete;
glerminal(glerminal&&) = delete;
glerminal& operator=(const glerminal&) = delete;
glerminal& operator=(glerminal&&) = delete;
void run();
void flush();
void set(unsigned char x, unsigned char y, unsigned char layer, unsigned char sprite);
unsigned char get(unsigned char x, unsigned char y, unsigned char layer) const;
2024-05-15 02:42:49 +00:00
void offset(unsigned char x, unsigned char y, unsigned char layer, char x_offset, char y_offset);
2024-05-14 21:46:30 +00:00
void update_sprite(unsigned char id, glerminal_sprite sprite);
void update_palette_color(unsigned char id, unsigned int color);
2024-05-09 19:42:12 +00:00
private:
GLFWwindow* m_window;
unsigned int m_vbo;
2024-05-15 02:42:49 +00:00
unsigned int m_sprites_instance_vbo;
unsigned int m_offsets_instance_vbo;
2024-05-09 19:42:12 +00:00
unsigned int m_vao;
unsigned int m_program;
unsigned int m_screen_vao;
unsigned int m_screen_program;
unsigned int m_sprites_texture;
unsigned int m_framebuffer;
unsigned int m_framebuffer_backing_texture;
unsigned int m_screen_size_uniform_location;
unsigned int m_palette_uniform_location;
unsigned char m_cells[GRID_AREA * LAYER_COUNT];
2024-05-15 02:42:49 +00:00
char m_offsets[GRID_AREA * LAYER_COUNT * 2];
unsigned char m_sprites[CELL_SIZE * CELL_SIZE * 256];
float m_palette[64];
2024-05-09 19:42:12 +00:00
glerminal_main_cb m_main;
#ifdef _DEBUG
mutable std::ofstream m_log;
void log(GLenum type, GLuint id, GLenum severity, const char* message) const;
#endif
2024-05-09 19:42:12 +00:00
void init_glfw();
void init_gl();
void deinit_glfw();
void deinit_gl();
void update_sprites();
void update_palette();
2024-05-09 19:42:12 +00:00
};
}
#endif//TERMG_PRIVATE_H