134 lines
3.4 KiB
C++
134 lines
3.4 KiB
C++
// 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_OPENGLES_H
|
|
#define _RK_ENGINE_RENDER_OPENGLES_H
|
|
|
|
#include "../render.hpp"
|
|
#include "render_context.hpp"
|
|
#include <GLES3/gl32.h>
|
|
#include <GLES3/gl3ext.h>
|
|
#include <GLES3/gl3platform.h>
|
|
|
|
enum : rk_uint {
|
|
RK_VERTICES_BINDING = 0,
|
|
RK_PARAMS_BINDING = 1
|
|
};
|
|
|
|
struct rk_shader {
|
|
GLuint vertex;
|
|
GLuint fragment;
|
|
GLuint program;
|
|
};
|
|
|
|
struct rk_texture {
|
|
rk_uint slot;
|
|
rk_uint nlevels;
|
|
GLint sampler;
|
|
GLuint texture;
|
|
};
|
|
|
|
struct rk_triangles {
|
|
rk_uint size;
|
|
GLuint array;
|
|
GLuint vertices;
|
|
};
|
|
|
|
struct rk_vertices {
|
|
rk_uint vertex_size;
|
|
rk_uint layout;
|
|
GLuint array;
|
|
GLuint vertices;
|
|
GLuint indices;
|
|
};
|
|
|
|
struct rk_command {
|
|
GLuint count;
|
|
GLuint ninstances;
|
|
GLuint base_index;
|
|
GLint base_vertex;
|
|
GLuint base_instance;
|
|
};
|
|
|
|
struct rk_batch {
|
|
rk_uint size;
|
|
rk_batch_translation_format translation_format;
|
|
rk_batch_orientation_format orientation_format;
|
|
rk_uint params_size;
|
|
rk_ushort * indices;
|
|
rk_ubyte * params;
|
|
rk_command * commands;
|
|
GLuint params_buffer;
|
|
GLuint commands_buffer;
|
|
};
|
|
|
|
struct rk_translation_float {
|
|
rk_vec3 xyz;
|
|
|
|
inline void set(rk_vec3 const & translation) {
|
|
xyz = translation;
|
|
}
|
|
};
|
|
|
|
struct rk_translation_short {
|
|
rk_short x;
|
|
rk_short y;
|
|
rk_short z;
|
|
rk_short pad;
|
|
|
|
inline void set(rk_vec3 const & translation) {
|
|
x = static_cast<rk_short>(translation.x);
|
|
y = static_cast<rk_short>(translation.y);
|
|
z = static_cast<rk_short>(translation.z);
|
|
pad = 0;
|
|
}
|
|
};
|
|
|
|
struct rk_orientation_float {
|
|
rk_vec3 xyz;
|
|
|
|
inline void set(rk_vec3 const & orientation) {
|
|
xyz = orientation;
|
|
}
|
|
};
|
|
|
|
struct rk_orientation_int10 {
|
|
rk_uint xyz;
|
|
|
|
inline void set(rk_vec3 const & orientation) {
|
|
#define _pack_10(x) static_cast<rk_uint>(static_cast<rk_int>((x) * ((x) < 0.f ? 512.f : 511.f)) & 1023)
|
|
xyz = _pack_10(orientation.x) << 20 | _pack_10(orientation.y) << 10 | _pack_10(orientation.z);
|
|
#undef _pack_10
|
|
}
|
|
};
|
|
|
|
template < typename _translation_t, typename _orientation_t >
|
|
struct rk_params {
|
|
_translation_t translation;
|
|
_orientation_t orientation;
|
|
|
|
inline void set(rk_vec3 const & translation, rk_vec3 const & orientation) {
|
|
this->translation.set(translation);
|
|
this->orientation.set(orientation);
|
|
}
|
|
};
|
|
|
|
typedef rk_params<rk_translation_float, rk_orientation_float> rk_params_float_float;
|
|
typedef rk_params<rk_translation_float, rk_orientation_int10> rk_params_float_int10;
|
|
typedef rk_params<rk_translation_short, rk_orientation_float> rk_params_short_float;
|
|
typedef rk_params<rk_translation_short, rk_orientation_int10> rk_params_short_int10;
|
|
|
|
#endif // _RK_ENGINE_RENDER_OPENGLES_H
|