8#include <entt/locator/locator.hpp>
11#include "galaxy/graphics/gl/GLEnums.hpp"
12#include "galaxy/graphics/gl/Sampler.hpp"
13#include "galaxy/graphics/gl/Shader.hpp"
14#include "galaxy/graphics/gl/ShaderBuffer.hpp"
15#include "galaxy/graphics/gl/Texture.hpp"
16#include "galaxy/graphics/gl/TextureView.hpp"
17#include "galaxy/graphics/gl/Vertex.hpp"
18#include "galaxy/graphics/gl/VertexBuffer.hpp"
19#include "galaxy/graphics/gl/VertexArray.hpp"
21#include "galaxy/graphics/Camera.hpp"
22#include "galaxy/graphics/Colour.hpp"
23#include "galaxy/graphics/Enums.hpp"
24#include "galaxy/graphics/RenderCommand.hpp"
25#include "galaxy/graphics/RenderData.hpp"
26#include "galaxy/graphics/Renderer.hpp"
27#include "galaxy/graphics/RenderPass.hpp"
28#include "galaxy/graphics/RenderPipeline.hpp"
29#include "galaxy/graphics/VertexBatch.hpp"
35 void Lua::inject_graphics() noexcept
37 auto& lua = entt::locator<sol::state>::value();
40 lua.new_enum<GLDrawHint>(
43 {
"STATIC_DRAW", GLDrawHint::STATIC_DRAW},
44 {
"DYNAMIC_DRAW", GLDrawHint::DYNAMIC_DRAW},
45 {
"STREAM_DRAW", GLDrawHint::STREAM_DRAW}
48 lua.new_enum<GLTextureMode>(
51 {
"REPEAT", GLTextureMode::REPEAT},
52 {
"MIRRORED_REPEAT", GLTextureMode::MIRRORED_REPEAT},
53 {
"CLAMP_TO_EDGE", GLTextureMode::CLAMP_TO_EDGE},
54 {
"CLAMP_TO_BORDER", GLTextureMode::CLAMP_TO_BORDER}
57 lua.new_enum<GLRenderMode>(
60 {
"QUADS", GLRenderMode::QUADS},
61 {
"TRIANGLES", GLRenderMode::TRIANGLES},
62 {
"LINES", GLRenderMode::LINES},
63 {
"LINE_LOOP", GLRenderMode::LINE_LOOP},
64 {
"POINTS", GLRenderMode::POINTS}
67 lua.new_enum<GLAttributeBinding>(
70 {
"POSITION_POINT", GLAttributeBinding::POSITION_POINT},
71 {
"TEXEL_POINT", GLAttributeBinding::TEXEL_POINT},
72 {
"INDEX_POINT", GLAttributeBinding::INDEX_POINT}
75 lua.new_enum<GLBufferLocation>(
78 {
"VERTEX_BUFFER_POINT", GLBufferLocation::VERTEX_BUFFER_POINT}
81 lua.new_enum<GLBufferBinding>(
84 {
"TEXTURE_HANDLES", GLBufferBinding::TEXTURE_HANDLES},
85 {
"CAMERA", GLBufferBinding::CAMERA},
86 {
"UNIFORMS", GLBufferBinding::UNIFORMS}
89 lua.new_enum<GLTextureFilter>(
92 {
"NEAREST", GLTextureFilter::NEAREST},
93 {
"BILINEAR", GLTextureFilter::BILINEAR},
94 {
"TRILINEAR", GLTextureFilter::TRILINEAR}
99 auto sampler_type = lua.new_usertype<Sampler>(
"Sampler", sol::constructors<Colour()>());
100 sampler_type[
"set"] = &Sampler::set;
101 sampler_type[
"setf"] = &Sampler::setf;
102 sampler_type[
"bind"] = &Sampler::bind;
103 sampler_type[
"unbind"] = &Sampler::unbind;
104 sampler_type[
"id"] = &Sampler::id;
106 auto shader_type = lua.new_usertype<Shader>(
"Shader", sol::constructors<Shader()>());
107 shader_type[
"bind"] = &Shader::bind;
108 shader_type[
"compile"] = &Shader::compile;
109 shader_type[
"destroy"] = &Shader::destroy;
110 shader_type[
"id"] = &Shader::id;
111 shader_type[
"load"] = sol::resolve<bool(const std::string&, const std::string&)>(&Shader::load);
112 shader_type[
"load_combined"] = sol::resolve<bool(const std::string&)>(&Shader::load);
113 shader_type[
"parse"] = sol::resolve<bool(const std::string&, const std::string&)>(&Shader::parse);
114 shader_type[
"parse_combined"] = sol::resolve<bool(const std::string&)>(&Shader::parse);
115 shader_type[
"unbind"] = &Shader::unbind;
116 shader_type[
"set_uniform_bool"] = &Shader::set_uniform<bool>;
117 shader_type[
"set_uniform_int"] = &Shader::set_uniform<int>;
118 shader_type[
"set_uniform_uint"] = &Shader::set_uniform<unsigned int>;
119 shader_type[
"set_uniform_float"] = &Shader::set_uniform<float>;
120 shader_type[
"set_uniform_double"] = &Shader::set_uniform<double>;
121 shader_type[
"set_uniform_mat4"] = &Shader::set_uniform<glm::mat4>;
122 shader_type[
"set_uniform_vec2"] = &Shader::set_uniform<glm::vec2>;
123 shader_type[
"set_uniform_vec3"] = &Shader::set_uniform<glm::vec3>;
124 shader_type[
"set_uniform_vec4"] = &Shader::set_uniform<glm::vec4>;
125 shader_type[
"set_uniform_colour"] = &Shader::set_uniform<Colour>;
127 auto shaderbuffer_type = lua.new_usertype<ShaderBuffer>(
"ShaderBuffer", sol::constructors<ShaderBuffer(), ShaderBuffer(const GLBufferBinding)>());
128 shaderbuffer_type[
"bind"] = &ShaderBuffer::bind;
129 shaderbuffer_type[
"clear"] = &ShaderBuffer::clear;
130 shaderbuffer_type[
"destroy"] = &ShaderBuffer::destroy;
131 shaderbuffer_type[
"id"] = &ShaderBuffer::id;
132 shaderbuffer_type[
"set_index"] = &ShaderBuffer::set_index;
133 shaderbuffer_type[
"unbind"] = &ShaderBuffer::unbind;
137 auto texture_type = lua.new_usertype<Texture>(
"Texture", sol::constructors<Texture()>());
138 texture_type[
"bind"] = &Texture::bind;
139 texture_type[
"destroy"] = &Texture::destroy;
140 texture_type[
"handle"] = &Texture::handle;
141 texture_type[
"height"] = &Texture::height;
142 texture_type[
"id"] = &Texture::id;
143 texture_type[
"load"] = &Texture::load;
144 texture_type[
"load_mem"] = &Texture::load_mem;
145 texture_type[
"save"] = &Texture::save;
146 texture_type[
"unbind"] = &Texture::unbind;
147 texture_type[
"width"] = &Texture::width;
148 texture_type[
"get_view"] = &Texture::get_view;
150 auto textureview_type = lua.new_usertype<TextureView>(
152 sol::constructors<TextureView(const unsigned int, const unsigned int, const unsigned int, const unsigned int, const unsigned int)>()
154 textureview_type[
"id"] = &TextureView::id;
156 auto vertex_type = lua.new_usertype<Vertex>(
"Vertex", sol::constructors<Vertex()>());
157 vertex_type[
"pos"] = &Vertex::m_pos;
158 vertex_type[
"texels"] = &Vertex::m_texels;
159 vertex_type[
"index"] = &Vertex::m_index;
161 lua.set_function(
"gen_quad_vertices", &graphics::gen_quad_vertices);
162 lua.set_function(
"gen_default_indices", &graphics::gen_default_indices);
163 lua.set_function(
"map_x_texel", &graphics::map_x_texel<int>);
164 lua.set_function(
"map_y_texel", &graphics::map_y_texel<int>);
165 lua.set_function(
"map_x_texelf", &graphics::map_x_texel<float>);
166 lua.set_function(
"map_y_texelf", &graphics::map_y_texel<float>);
168 auto vertexbuffer_type = lua.new_usertype<VertexBuffer>(
"VertexBuffer", sol::constructors<VertexBuffer()>());
169 vertexbuffer_type[
"clear"] = &VertexBuffer::clear;
170 vertexbuffer_type[
"count"] = &VertexBuffer::count;
171 vertexbuffer_type[
"id"] = &VertexBuffer::id;
172 vertexbuffer_type[
"offset"] = &VertexBuffer::offset;
173 vertexbuffer_type[
"sub_buffer"] = &VertexBuffer::sub_buffer;
174 vertexbuffer_type[
"buffer"] = &VertexBuffer::buffer;
175 vertexbuffer_type[
"erase"] = &VertexBuffer::erase;
176 vertexbuffer_type[
"reserve"] = &VertexBuffer::reserve;
177 vertexbuffer_type[
"sub_buffer_indices"] = &VertexBuffer::sub_buffer_indices;
178 vertexbuffer_type[
"sub_buffer_vertices"] = &VertexBuffer::sub_buffer_vertices;
180 auto vertexarray_type = lua.new_usertype<VertexArray>(
"VertexArray", sol::constructors<VertexArray()>());
181 vertexarray_type[
"bind"] = &VertexArray::bind;
182 vertexarray_type[
"count"] = &VertexArray::count;
183 vertexarray_type[
"id"] = &VertexArray::id;
184 vertexarray_type[
"offset"] = &VertexArray::offset;
185 vertexarray_type[
"sub_buffer"] = &VertexArray::sub_buffer;
186 vertexarray_type[
"unbind"] = &VertexArray::unbind;
187 vertexarray_type[
"vbo"] = &VertexArray::vbo;
188 vertexarray_type[
"buffer"] = &VertexArray::buffer;
189 vertexarray_type[
"clear"] = &VertexArray::clear;
190 vertexarray_type[
"erase"] = &VertexArray::erase;
191 vertexarray_type[
"reserve"] = &VertexArray::reserve;
192 vertexarray_type[
"sub_buffer_indices"] = &VertexArray::sub_buffer_indices;
193 vertexarray_type[
"sub_buffer_vertices"] = &VertexArray::sub_buffer_vertices;
195 auto cameradata_type = lua.new_usertype<Camera::Data>(
"CameraData", sol::no_constructor);
196 cameradata_type[
"model_view"] = &Camera::Data::m_model_view;
197 cameradata_type[
"projection"] = &Camera::Data::m_projection;
199 auto camera_type = lua.new_usertype<Camera>(
"Camera", sol::constructors<Camera()>());
200 camera_type[
"get_data"] = &Camera::get_data;
201 camera_type[
"get_model_view"] = &Camera::get_model_view;
202 camera_type[
"get_origin"] = &Camera::get_origin;
203 camera_type[
"get_pos"] = &Camera::get_pos;
204 camera_type[
"get_proj"] = &Camera::get_proj;
205 camera_type[
"get_rotation"] = &Camera::get_rotation;
206 camera_type[
"get_scale"] = &Camera::get_scale;
207 camera_type[
"get_transform"] = &Camera::get_transform;
208 camera_type[
"rotation_speed"] = &Camera::m_rotation_speed;
209 camera_type[
"translation_speed"] = &Camera::m_translation_speed;
210 camera_type[
"allow_rotation"] = &Camera::m_allow_rotation;
211 camera_type[
"reset"] = &Camera::reset;
212 camera_type[
"rotate"] = &Camera::rotate;
213 camera_type[
"scale"] = &Camera::scale;
214 camera_type[
"set_rotation"] = &Camera::set_rotation;
215 camera_type[
"set_origin"] = &Camera::set_origin;
216 camera_type[
"set_scale_horizontal"] = &Camera::set_scale_horizontal;
217 camera_type[
"set_scale_vertical"] = &Camera::set_scale_vertical;
218 camera_type[
"move"] = &Camera::move;
219 camera_type[
"move_x"] = &Camera::move_x;
220 camera_type[
"move_y"] = &Camera::move_y;
221 camera_type[
"set_positon"] = &Camera::set_positon;
222 camera_type[
"set_positon_horizontal"] = &Camera::set_positon_horizontal;
223 camera_type[
"set_positon_vertical"] = &Camera::set_positon_vertical;
224 camera_type[
"set_projection"] = &Camera::set_projection;
227 lua.new_usertype<Colour>(
"Colour", sol::constructors<Colour(), Colour(const std::uint8_t, const std::uint8_t, const std::uint8_t, const std::uint8_t)>());
228 colour_type[
"array"] = &Colour::array;
229 colour_type[
"normalize"] = &Colour::normalize;
230 colour_type[
"set_from_norm"] = &Colour::set_from_norm;
231 colour_type[
"set_r"] = sol::resolve<void(const std::uint8_t)>(&Colour::r);
232 colour_type[
"set_g"] = sol::resolve<void(const std::uint8_t)>(&Colour::g);
233 colour_type[
"set_b"] = sol::resolve<void(const std::uint8_t)>(&Colour::b);
234 colour_type[
"set_a"] = sol::resolve<void(const std::uint8_t)>(&Colour::a);
235 colour_type[
"get_r"] = sol::resolve<std::uint8_t() const>(&Colour::r);
236 colour_type[
"get_g"] = sol::resolve<std::uint8_t() const>(&Colour::g);
237 colour_type[
"get_b"] = sol::resolve<std::uint8_t() const>(&Colour::b);
238 colour_type[
"get_a"] = sol::resolve<std::uint8_t() const>(&Colour::a);
239 lua.set(
"GALAXY_COL_OPAQUE", Colour::OPAQUE);
240 lua.set(
"GALAXY_COL_TRANSPARENT", Colour::TRANSPARENT);
241 lua.set(
"GALAXY_COL_OFFSET", Colour::OFFSET);
242 lua.set(
"GALAXY_COL_LOWER", Colour::LOWER);
243 lua.set(
"GALAXY_COL_UPPER", Colour::UPPER);
245 auto rendercmd_type = lua.new_usertype<RenderCmd>(
"RenderCmd", sol::constructors<RenderCmd()>());
246 rendercmd_type[
"type"] = &RenderCmd::type;
247 rendercmd_type[
"vertices"] = &RenderCmd::vertices;
248 rendercmd_type[
"vao"] = &RenderCmd::vao;
249 rendercmd_type[
"data"] = &RenderCmd::data;
251 auto renderdata_type = lua.new_usertype<RenderData>(
"RenderData", sol::constructors<RenderData()>());
252 renderdata_type[
"transform"] = &RenderData::transform;
253 renderdata_type[
"colour"] = &RenderData::colour;
254 renderdata_type[
"entity"] = &RenderData::entity;
255 renderdata_type[
"point"] = &RenderData::point;
256 renderdata_type[
"handle"] = &RenderData::handle;
258 auto renderer_type = lua.new_usertype<Renderer>(
"Renderer", sol::no_constructor);
259 renderer_type[
"begin_pass"] = &Renderer::begin_pass;
260 renderer_type[
"bind_pipeline"] = &Renderer::bind_pipeline;
261 renderer_type[
"end_pass"] = &Renderer::end_pass;
262 renderer_type[
"prepare"] = &Renderer::prepare;
263 renderer_type[
"push_cmd"] = &Renderer::push_cmd;
265 auto renderpipe_type = lua.new_usertype<RenderPipeline>(
"RenderPipeline", sol::constructors<RenderPipeline()>());
266 renderpipe_type[
"enabled"] = &RenderPipeline::enabled;
267 renderpipe_type[
"disabled"] = &RenderPipeline::disabled;
268 renderpipe_type[
"blend_equation"] = &RenderPipeline::blend_equation;
269 renderpipe_type[
"blend_function"] = &RenderPipeline::blend_function;
270 renderpipe_type[
"cull_face"] = &RenderPipeline::cull_face;
271 renderpipe_type[
"depth_func"] = &RenderPipeline::depth_func;
272 renderpipe_type[
"shader"] = &RenderPipeline::shader;
274 auto vertexbatch_type = lua.new_usertype<VertexBatch>(
"VertexBatch", sol::constructors<VertexBatch(
const int,
const int,
const std::vector<unsigned int>&)>());
275 vertexbatch_type[
"bind"] = &VertexBatch::bind;
276 vertexbatch_type[
"count"] = &VertexBatch::count;
277 vertexbatch_type[
"flush"] = &VertexBatch::flush;
278 vertexbatch_type[
"offset"] = &VertexBatch::offset;
279 vertexbatch_type[
"prepare"] = &VertexBatch::prepare;
280 vertexbatch_type[
"push"] = &VertexBatch::push;
281 vertexbatch_type[
"vao"] = &VertexBatch::vao;