2022-08-28 04:23:13 +02:00
|
|
|
// Copyright (C) 2022 RozK
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#ifndef _RK_ENGINE_RENDER_H
|
|
|
|
#define _RK_ENGINE_RENDER_H
|
|
|
|
|
|
|
|
#include "types.hpp"
|
|
|
|
#include "math.hpp"
|
|
|
|
|
|
|
|
typedef rk_handle_t rk_shader_t;
|
|
|
|
typedef rk_handle_t rk_input_t;
|
2022-12-18 03:39:34 +01:00
|
|
|
typedef rk_handle_t rk_param_t;
|
2022-08-28 04:23:13 +02:00
|
|
|
typedef rk_handle_t rk_texture_t;
|
|
|
|
typedef rk_handle_t rk_triangles_t;
|
|
|
|
typedef rk_handle_t rk_vertices_t;
|
|
|
|
typedef rk_handle_t rk_batch_t;
|
|
|
|
|
2023-01-04 09:33:49 +01:00
|
|
|
typedef rk_uint rk_texture_format;
|
|
|
|
|
|
|
|
enum : rk_uint {
|
2022-08-28 04:23:13 +02:00
|
|
|
RK_TEXTURE_FORMAT_SRGB8_A8 = 0,
|
|
|
|
RK_TEXTURE_FORMAT_RGBA8 = 1,
|
|
|
|
RK_TEXTURE_FORMAT_RGB10_A2 = 2,
|
2022-12-25 04:20:19 +01:00
|
|
|
RK_TEXTURE_FORMAT_FLOAT_32 = 3
|
2022-08-28 04:23:13 +02:00
|
|
|
};
|
|
|
|
|
2023-01-04 09:33:49 +01:00
|
|
|
typedef rk_uint rk_texture_flags;
|
|
|
|
|
|
|
|
enum : rk_uint {
|
2022-08-28 04:23:13 +02:00
|
|
|
RK_TEXTURE_FLAG_3D = RK_FLAG(0),
|
|
|
|
RK_TEXTURE_FLAG_MIPMAPS = RK_FLAG(1),
|
|
|
|
RK_TEXTURE_FLAG_MIN_NEAREST = 0,
|
|
|
|
RK_TEXTURE_FLAG_MIN_LINEAR = RK_FLAG(2),
|
|
|
|
RK_TEXTURE_FLAG_MAG_NEAREST = 0,
|
|
|
|
RK_TEXTURE_FLAG_MAG_LINEAR = RK_FLAG(3),
|
|
|
|
};
|
|
|
|
|
2023-01-04 09:33:49 +01:00
|
|
|
typedef rk_ubyte rk_vertex_format;
|
|
|
|
|
|
|
|
enum : rk_ubyte {
|
2022-12-05 05:50:04 +01:00
|
|
|
RK_VERTEX_FORMAT_VEC3_FLOAT = 1,
|
|
|
|
RK_VERTEX_FORMAT_VEC3_INT10 = 2,
|
2023-01-04 09:33:49 +01:00
|
|
|
RK_VERTEX_FORMAT_VEC3_UINT10 = 3,
|
|
|
|
RK_VERTEX_FORMAT_NORMALIZE = RK_FLAG(7),
|
|
|
|
RK_VERTEX_FORMAT_MASK = RK_VERTEX_FORMAT_NORMALIZE - 1
|
2022-12-17 04:58:19 +01:00
|
|
|
};
|
|
|
|
|
2023-01-04 09:33:49 +01:00
|
|
|
typedef rk_ubyte rk_param_format;
|
2022-12-05 05:50:04 +01:00
|
|
|
|
2023-01-04 09:33:49 +01:00
|
|
|
enum : rk_ubyte {
|
2022-12-17 04:58:19 +01:00
|
|
|
RK_PARAM_FORMAT_VEC3_FLOAT = 1,
|
|
|
|
RK_PARAM_FORMAT_VEC3_SHORT = 2,
|
2022-12-26 14:05:06 +01:00
|
|
|
RK_PARAM_FORMAT_VEC3_INT10 = 3,
|
|
|
|
RK_PARAM_FORMAT_MAT3_FLOAT = 4,
|
2023-01-04 09:33:49 +01:00
|
|
|
RK_PARAM_FORMAT_MAT3_INT10 = 5,
|
|
|
|
RK_PARAM_FORMAT_NORMALIZE = RK_FLAG(7),
|
|
|
|
RK_PARAM_FORMAT_MASK = RK_PARAM_FORMAT_NORMALIZE - 1
|
2022-08-28 04:23:13 +02:00
|
|
|
};
|
|
|
|
|
2023-01-04 09:33:49 +01:00
|
|
|
typedef rk_ubyte rk_instance_flags;
|
2022-12-17 04:58:19 +01:00
|
|
|
|
2023-01-04 09:33:49 +01:00
|
|
|
enum : rk_ubyte {
|
2022-08-28 04:23:13 +02:00
|
|
|
RK_INSTANCE_FLAG_SPAWNED = RK_FLAG(0),
|
2023-01-04 09:33:49 +01:00
|
|
|
RK_INSTANCE_FLAG_VISIBLE = RK_FLAG(1),
|
|
|
|
RK_INSTANCE_FLAGS_SPAWNED_VISIBLE = RK_INSTANCE_FLAG_SPAWNED | RK_INSTANCE_FLAG_VISIBLE
|
2022-08-28 04:23:13 +02:00
|
|
|
};
|
|
|
|
|
2023-01-04 09:33:49 +01:00
|
|
|
typedef rk_ushort rk_instance_index;
|
|
|
|
|
|
|
|
enum : rk_uint {
|
|
|
|
RK_BATCH_MAX_SIZE = 1 << (sizeof(rk_instance_index) * 8)
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef rk_ushort rk_vertex_index;
|
|
|
|
typedef rk_ushort rk_mesh_index;
|
|
|
|
|
2023-01-04 09:06:13 +01:00
|
|
|
struct rk_mesh {
|
|
|
|
rk_uint base_index;
|
|
|
|
rk_uint ntriangles;
|
2022-08-28 04:23:13 +02:00
|
|
|
};
|
|
|
|
|
2023-01-04 12:41:05 +01:00
|
|
|
// param input types must be size compatible with an array of rk_param_input
|
|
|
|
typedef rk_uint rk_param_input;
|
|
|
|
|
|
|
|
template<typename _input_type>
|
|
|
|
void rk_param_get_input_size(unsigned & _size, unsigned & _len) {
|
|
|
|
static_assert((sizeof(_input_type) % sizeof(rk_param_input)) == 0);
|
|
|
|
_size = sizeof(_input_type);
|
|
|
|
_len = sizeof(_input_type) / sizeof(rk_param_input);
|
|
|
|
}
|
|
|
|
|
2022-12-30 14:11:48 +01:00
|
|
|
RK_EXPORT void rk_render_initialize(
|
|
|
|
rk_bool debug);
|
2022-12-24 11:27:53 +01:00
|
|
|
|
|
|
|
RK_EXPORT void rk_render_terminate();
|
2022-08-28 04:23:13 +02:00
|
|
|
|
2023-01-01 08:09:37 +01:00
|
|
|
RK_EXPORT rk_shader_t rk_create_shader(
|
2022-12-04 01:43:35 +01:00
|
|
|
rk_uint const vert_nlines,
|
2023-01-02 12:14:13 +01:00
|
|
|
rk_char const * const * vert_lines,
|
2022-12-04 01:43:35 +01:00
|
|
|
rk_uint const frag_nlines,
|
2023-01-02 12:14:13 +01:00
|
|
|
rk_char const * const * frag_lines);
|
2022-08-28 04:23:13 +02:00
|
|
|
|
|
|
|
RK_EXPORT rk_input_t rk_resolve_input(
|
2022-12-18 03:39:34 +01:00
|
|
|
rk_shader_t shader,
|
2023-01-02 12:14:13 +01:00
|
|
|
rk_char const * name);
|
2022-08-28 04:23:13 +02:00
|
|
|
|
2022-12-17 16:50:41 +01:00
|
|
|
RK_EXPORT rk_param_t rk_resolve_param(
|
2022-12-18 03:39:34 +01:00
|
|
|
rk_shader_t shader,
|
2023-01-02 12:14:13 +01:00
|
|
|
rk_char const * name);
|
2022-12-17 16:50:41 +01:00
|
|
|
|
2022-08-28 04:23:13 +02:00
|
|
|
RK_EXPORT rk_texture_t rk_create_texture(
|
|
|
|
rk_texture_format format,
|
|
|
|
rk_uint width,
|
|
|
|
rk_uint height,
|
|
|
|
rk_uint nlevels,
|
|
|
|
rk_texture_flags flags,
|
2022-12-31 09:38:18 +01:00
|
|
|
rk_ubyte const * pixels);
|
2022-08-28 04:23:13 +02:00
|
|
|
|
|
|
|
RK_EXPORT rk_triangles_t rk_create_triangles(
|
|
|
|
rk_uint nvertices,
|
|
|
|
rk_vec3 const * vertices);
|
|
|
|
|
|
|
|
RK_EXPORT rk_vertices_t rk_create_vertices(
|
|
|
|
rk_vertex_format const * format,
|
|
|
|
rk_uint nvertices,
|
2022-12-31 09:38:18 +01:00
|
|
|
rk_ubyte const * vertices,
|
2022-08-28 04:23:13 +02:00
|
|
|
rk_uint nindices,
|
2023-01-04 09:33:49 +01:00
|
|
|
rk_vertex_index const * indices,
|
2023-01-03 12:59:07 +01:00
|
|
|
rk_uint nmeshes,
|
|
|
|
rk_mesh const * meshes);
|
2022-08-28 04:23:13 +02:00
|
|
|
|
|
|
|
RK_EXPORT rk_batch_t rk_create_batch(
|
2022-12-18 03:39:34 +01:00
|
|
|
rk_vertices_t vertices,
|
2022-08-28 04:23:13 +02:00
|
|
|
rk_uint max_size,
|
2022-12-17 04:58:19 +01:00
|
|
|
rk_param_format const * params_format);
|
2022-08-28 04:23:13 +02:00
|
|
|
|
2023-01-03 14:05:25 +01:00
|
|
|
RK_EXPORT void rk_fill_batch(
|
|
|
|
rk_batch_t batch,
|
|
|
|
rk_uint count,
|
|
|
|
rk_instance_flags const * flags,
|
2023-01-04 09:33:49 +01:00
|
|
|
rk_mesh_index const * meshes,
|
|
|
|
rk_param_input const * const * params);
|
2023-01-03 14:05:25 +01:00
|
|
|
|
2023-01-01 07:57:10 +01:00
|
|
|
RK_EXPORT void rk_clear_buffer(
|
|
|
|
rk_bool pixels,
|
|
|
|
rk_bool depth,
|
|
|
|
rk_bool stencil);
|
2022-08-28 04:23:13 +02:00
|
|
|
|
2022-12-18 03:39:34 +01:00
|
|
|
RK_EXPORT void rk_select_shader(
|
|
|
|
rk_shader_t _shader);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_set_input_float(
|
|
|
|
rk_input_t input,
|
|
|
|
float value);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_set_input_vec3(
|
|
|
|
rk_input_t input,
|
|
|
|
rk_vec3 const & value);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_set_input_mat3(
|
|
|
|
rk_input_t input,
|
|
|
|
rk_mat3 const & value);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_set_input_mat4(
|
|
|
|
rk_input_t input,
|
|
|
|
rk_mat4 const & value);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_set_param_vec3(
|
|
|
|
rk_param_t param,
|
|
|
|
rk_vec3 const & value);
|
|
|
|
|
2022-12-27 06:20:18 +01:00
|
|
|
RK_EXPORT void rk_set_param_mat3(
|
|
|
|
rk_param_t param,
|
|
|
|
rk_mat3 const & value);
|
|
|
|
|
2022-08-28 04:23:13 +02:00
|
|
|
RK_EXPORT void rk_select_texture(
|
2022-12-19 06:27:34 +01:00
|
|
|
rk_uint slot,
|
2022-12-31 13:36:48 +01:00
|
|
|
rk_texture_t texture);
|
2022-08-28 04:23:13 +02:00
|
|
|
|
|
|
|
RK_EXPORT void rk_draw_triangles(
|
|
|
|
rk_triangles_t triangles);
|
|
|
|
|
2023-01-02 17:01:36 +01:00
|
|
|
RK_EXPORT void rk_draw_batch(
|
|
|
|
rk_batch_t batch);
|
|
|
|
|
2022-08-28 04:23:13 +02:00
|
|
|
RK_EXPORT void rk_unselect_texture(
|
2022-12-19 06:27:34 +01:00
|
|
|
rk_uint slot,
|
2022-08-28 04:23:13 +02:00
|
|
|
rk_texture_t texture);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_unselect_shader(
|
|
|
|
rk_shader_t shader);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_destroy_batch(
|
|
|
|
rk_batch_t batch);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_destroy_triangles(
|
|
|
|
rk_triangles_t triangles);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_destroy_vertices(
|
|
|
|
rk_vertices_t vertices);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_destroy_texture(
|
|
|
|
rk_texture_t texture);
|
|
|
|
|
|
|
|
RK_EXPORT void rk_destroy_shader(
|
|
|
|
rk_shader_t shader);
|
|
|
|
|
|
|
|
#endif // _RK_ENGINE_RENDER_H
|