rk_engine/cpp/render.hpp

211 lines
5.3 KiB
C++
Raw Normal View History

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"
extern rk_vec3 rk_view_origin;
extern rk_vec3 rk_view_lookat;
extern rk_mat4 rk_view;
extern rk_mat4 rk_view_km; //TODO: remove from engine
extern float rk_projection_hfov;
extern float rk_projection_ratio;
extern float rk_projection_near;
extern float rk_projection_far;
extern rk_mat4 rk_projection;
typedef rk_handle_t rk_window_t;
typedef rk_handle_t rk_shader_t;
typedef rk_handle_t rk_input_t;
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;
#define RK_FLAG(bit) (1 << (bit))
enum rk_input_mode : rk_uint {
RK_INPUT_IDENTITY = 0,
RK_INPUT_VIEW_POSITION = 1,
RK_INPUT_VIEW_ORIENTATION = 2
};
enum rk_texture_format : rk_uint {
RK_TEXTURE_FORMAT_SRGB8_A8 = 0,
RK_TEXTURE_FORMAT_RGBA8 = 1,
RK_TEXTURE_FORMAT_RGB10_A2 = 2,
RK_TEXTURE_FORMAT_32F = 3
};
enum rk_texture_flags : rk_uint {
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),
};
enum rk_vertex_format : rk_ubyte {
RK_VERTEX_FORMAT_END = 0,
RK_VERTEX_FORMAT_VEC2_FLOAT = 1,
RK_VERTEX_FORMAT_VEC2_USHORT = 2,
RK_VERTEX_FORMAT_VEC3_FLOAT = 3,
RK_VERTEX_FORMAT_VEC3_INT10 = 4,
};
enum rk_instance_flags : rk_ubyte {
RK_INSTANCE_FLAG_SPAWNED = RK_FLAG(0),
RK_INSTANCE_FLAG_VISIBLE = RK_FLAG(1)
};
enum : rk_ubyte { RK_INSTANCE_FLAGS_SPAWNED_VISIBLE = RK_INSTANCE_FLAG_SPAWNED | RK_INSTANCE_FLAG_VISIBLE };
enum : rk_uint { RK_BATCH_MAX_SIZE = 65536 };
enum rk_batch_translation_format : rk_uint {
RK_BATCH_TRANSLATION_FORMAT_FLOAT = 0,
RK_BATCH_TRANSLATION_FORMAT_SHORT = 1
};
enum rk_batch_orientation_format : rk_uint {
RK_BATCH_ORIENTATION_FORMAT_NONE = 0,
RK_BATCH_ORIENTATION_FORMAT_FLOAT = 1,
RK_BATCH_ORIENTATION_FORMAT_INT10 = 2
};
union rk_mesh {
rk_uint packed;
struct {
rk_ushort offset;
rk_ushort count;
};
};
RK_EXPORT rk_window_t rk_initialize(
char const * name,
rk_uint width,
rk_uint height);
2022-08-28 04:23:13 +02:00
RK_EXPORT rk_shader_t rk_load_shader(
char const * name);
RK_EXPORT void rk_select_shader(
rk_shader_t _shader);
RK_EXPORT rk_input_t rk_resolve_input(
char const * name);
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_input_mode mode);
RK_EXPORT rk_texture_t rk_create_texture(
rk_uint slot,
char const * input,
rk_texture_format format,
rk_uint width,
rk_uint height,
rk_uint nlevels,
rk_texture_flags flags,
void const * pixels);
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,
void const * vertices,
rk_uint nindices,
rk_ushort const * indices);
RK_EXPORT rk_batch_t rk_create_batch(
rk_uint max_size,
rk_batch_translation_format translation_format,
rk_batch_orientation_format orientation_format);
//TODO: export math function and take a projection matrix instead of its parameters
RK_EXPORT void rk_set_projection(
float hfov,
float ratio,
float near,
float far);
//TODO: export math function and take a view matrix instead of its parameters
RK_EXPORT void rk_set_view(
rk_vec3 const & position,
rk_vec3 const & lookat);
RK_EXPORT void rk_begin_frame();
RK_EXPORT void rk_select_texture(
rk_texture_t texture);
RK_EXPORT void rk_draw_triangles(
rk_triangles_t triangles);
RK_EXPORT void rk_select_vertices(
rk_vertices_t vertices);
RK_EXPORT void rk_draw_batch(
rk_batch_t batch,
rk_uint size,
rk_instance_flags const * flags,
rk_ushort const * texlevels,
rk_mesh const * meshes,
rk_vec3 const * translations,
rk_vec3 const * orientations);
RK_EXPORT void rk_unselect_vertices(
rk_vertices_t vertices);
RK_EXPORT void rk_unselect_texture(
rk_texture_t texture);
RK_EXPORT void rk_unselect_shader(
rk_shader_t shader);
RK_EXPORT void rk_end_frame();
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);
RK_EXPORT void rk_terminate();
#endif // _RK_ENGINE_RENDER_H