glerminal/source/glerminal-private.h

124 lines
3.5 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-07-17 16:08:58 +00:00
#include "miniaudio.h"
2024-05-09 19:42:12 +00:00
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-07-17 16:08:58 +00:00
#include <map>
#include <string>
2024-05-09 19:42:12 +00:00
namespace glerminal
{
2024-05-20 02:46:56 +00:00
constexpr unsigned int CELL_SIZE = 8;
2024-06-01 17:25:20 +00:00
constexpr unsigned int MAX_SPRITES_ROW = 64;
constexpr unsigned int MAX_SPRITES = MAX_SPRITES_ROW * MAX_SPRITES_ROW;
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-07-17 16:08:58 +00:00
constexpr unsigned int SOUND_CHANNELS = 8;
constexpr unsigned int GRID_AREA_2 = (GRID_WIDTH + 2) * (GRID_HEIGHT + 2);
2024-05-09 19:42:12 +00:00
class glerminal
{
public:
2024-06-11 04:40:43 +00:00
explicit glerminal(glerminal_init_params params);
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(int x, int y, int layer, unsigned short sprite);
unsigned short get(int x, int y, int layer) const;
void offset(int x, int y, int layer, float x_offset, float y_offset);
void color(int x, int y, int layer, unsigned int color);
void scale(int x,int y, int 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-07-17 16:08:58 +00:00
bool load_sound(const char* name);
void play_sound(const char* name);
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;
unsigned int m_colors_instance_vbo;
unsigned int m_scales_instance_vbo;
2024-05-17 04:51:45 +00:00
// per-cell data
unsigned short m_cells[GRID_AREA_2 * LAYER_COUNT];
float m_offsets[GRID_AREA_2 * LAYER_COUNT * 2];
unsigned char m_colors[GRID_AREA_2 * LAYER_COUNT * 4];
float m_scales[GRID_AREA_2 * LAYER_COUNT];
2024-05-17 04:51:45 +00:00
// library state
2024-05-09 19:42:12 +00:00
2024-06-02 18:34:07 +00:00
unsigned int m_sprites[(CELL_SIZE + 2) * (CELL_SIZE + 2) * MAX_SPRITES];
2024-05-09 19:42:12 +00:00
glerminal_main_cb m_main;
2024-06-11 04:40:43 +00:00
glerminal_keys_cb m_keypressed, m_keyreleased;
glerminal_mousemoved_cb m_mousemoved;
glerminal_mousepress_cb m_mousepressed, m_mousereleased;
2024-05-09 19:42:12 +00:00
2024-07-17 16:08:58 +00:00
ma_engine m_audio_engine;
std::map<std::string, ma_sound> m_sounds;
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();
2024-07-17 16:08:58 +00:00
void init_audio();
2024-05-09 19:42:12 +00:00
void deinit_glfw();
void deinit_gl();
2024-07-17 16:08:58 +00:00
void deinit_audio();
void update_sprites();
void update_colors();
void update_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-06-11 04:40:43 +00:00
static void glfw_mousemoved_handler(GLFWwindow* window, double x, double y);
static void glfw_mousepress_handler(GLFWwindow* window, int button, int action, int mods);
2024-05-09 19:42:12 +00:00
};
}
2024-05-26 03:16:23 +00:00
#endif//GLERMINAL_PRIVATE_H