glerminal/source/glerminal-private.h

88 lines
2.3 KiB
C++

#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
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 = 4;
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;
constexpr unsigned int LAYER_COUNT = 256;
class glerminal
{
public:
glerminal(glerminal_init_cb init, glerminal_main_cb main);
~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;
void offset(unsigned char x, unsigned char y, unsigned char layer, float x_offset, float y_offset);
void update_sprite(unsigned char id, glerminal_sprite sprite);
void update_palette_color(unsigned char id, unsigned int color);
private:
GLFWwindow* m_window;
unsigned int m_vbo;
unsigned int m_sprites_instance_vbo;
unsigned int m_offsets_instance_vbo;
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];
float m_offsets[GRID_AREA * LAYER_COUNT * 2];
unsigned char m_sprites[CELL_SIZE * CELL_SIZE * 256];
float m_palette[256 * 4];
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
void init_glfw();
void init_gl();
void deinit_glfw();
void deinit_gl();
void update_sprites();
void update_palette();
};
}
#endif//TERMG_PRIVATE_H