glerminal/source/glerminal-private.h

108 lines
3.0 KiB
C
Raw Normal View History

2024-05-26 03:16:23 +00:00
#ifndef GLERMINAL_PRIVATE_H
#define GLERMINAL_PRIVATE_H
2024-05-09 19:42:12 +00:00
#include "glerminal.h"
2024-05-20 02:46:56 +00:00
#include <stb_image.h>
2024-05-09 19:42:12 +00:00
#include <glad/glad.h>
#include <GLFW/glfw3.h>
2024-05-26 16:35:15 +00:00
#include <iostream>
#include <fstream>
2024-05-20 02:46:56 +00:00
#include <stdexcept>
2024-05-09 19:42:12 +00:00
namespace glerminal
{
2024-05-20 02:46:56 +00:00
constexpr unsigned int CELL_SIZE = 8;
constexpr unsigned int GRID_WIDTH = ::GRID_WIDTH;
constexpr unsigned int GRID_HEIGHT = ::GRID_HEIGHT;
2024-05-24 01:33:15 +00:00
constexpr unsigned int LAYER_COUNT = ::LAYER_COUNT;
constexpr unsigned int CELL_SCALE = ::CELL_SCALE;
constexpr unsigned int GRID_AREA = GRID_WIDTH * GRID_HEIGHT;
2024-05-24 01:33:15 +00:00
constexpr unsigned int SCREEN_WIDTH = GRID_WIDTH * CELL_SIZE * CELL_SCALE;
constexpr unsigned int SCREEN_HEIGHT = GRID_HEIGHT * CELL_SIZE * CELL_SCALE;
2024-05-09 19:42:12 +00:00
class glerminal
{
public:
2024-05-30 14:57:36 +00:00
glerminal(glerminal_init_cb init, glerminal_main_cb main, glerminal_keys_cb pressed, glerminal_keys_cb released);
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();
2024-05-26 03:16:23 +00:00
void quit();
2024-05-09 19:42:12 +00:00
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;
void offset(unsigned char x, unsigned char y, unsigned char layer, float x_offset, float y_offset);
2024-05-17 04:51:45 +00:00
void layer_color(unsigned char layer, unsigned int color);
void layer_scale(unsigned char layer, float scale);
2024-05-20 02:46:56 +00:00
void load_atlas(unsigned char w, unsigned char h, const unsigned int* data);
2024-05-14 21:46:30 +00:00
2024-05-09 19:42:12 +00:00
private:
2024-05-17 04:51:45 +00:00
// glfw data
2024-05-09 19:42:12 +00:00
GLFWwindow* m_window;
2024-05-17 04:51:45 +00:00
// opengl handles
2024-05-09 19:42:12 +00:00
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_screen_vao;
2024-05-17 04:51:45 +00:00
unsigned int m_program;
unsigned int m_screen_program;
unsigned int m_sprites_texture;
unsigned int m_framebuffer;
unsigned int m_framebuffer_backing_texture;
2024-05-27 17:07:50 +00:00
unsigned int m_screen_framebuffer;
unsigned int m_screen_framebuffer_backing_texture;
2024-05-17 04:51:45 +00:00
unsigned int m_layer_colors_buffer;
unsigned int m_layer_scales_buffer;
unsigned int m_screen_size_uniform_location;
unsigned int m_palette_uniform_location;
2024-05-17 04:51:45 +00:00
// per-cell data
unsigned char m_cells[GRID_AREA * LAYER_COUNT];
float m_offsets[GRID_AREA * LAYER_COUNT * 2];
2024-05-17 04:51:45 +00:00
// per-layer data
float m_layer_colors[LAYER_COUNT * 4];
float m_layer_scales[LAYER_COUNT];
// library state
2024-05-09 19:42:12 +00:00
2024-05-17 04:51:45 +00:00
unsigned int m_sprites[CELL_SIZE * CELL_SIZE * (1 << (8 * sizeof(*m_cells)))];
2024-05-09 19:42:12 +00:00
glerminal_main_cb m_main;
2024-05-30 14:57:36 +00:00
glerminal_keys_cb m_pressed, m_released;
2024-05-09 19:42:12 +00:00
2024-05-26 16:05:29 +00:00
#ifdef GLERMINAL_OPENGL_DEBUG_CONTEXT
mutable std::ofstream m_log;
#endif
void log(GLenum type, GLuint id, GLenum severity, const char* message) const;
2024-05-09 19:42:12 +00:00
void init_glfw();
void init_gl();
void deinit_glfw();
void deinit_gl();
void update_sprites();
2024-05-17 04:51:45 +00:00
void update_layer_colors();
void update_layer_scales();
2024-05-30 14:57:36 +00:00
static void glfw_key_handler(GLFWwindow* window, int key, int scancode, int action, int mods);
2024-05-09 19:42:12 +00:00
};
}
2024-05-26 03:16:23 +00:00
#endif//GLERMINAL_PRIVATE_H