rk_engine/cpp/render/render_opengles.hpp

113 lines
2.7 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 <GLES3/gl32.h>
#include <GLES3/gl3ext.h>
#include <GLES3/gl3platform.h>
static_assert(sizeof(rk_vertex_output) == 4);
struct rk_shader {
GLuint vertex;
GLuint fragment;
GLuint program;
};
struct rk_texture {
unsigned nlevels;
GLuint texture;
};
struct rk_triangles {
unsigned size;
GLuint array;
GLuint vertices;
};
struct rk_vertices {
unsigned nvertices;
unsigned nindices;
unsigned nmeshes;
rk_vertex_format * format;
rk_ubyte * vertices;
rk_vertex_index * indices;
rk_mesh * meshes;
GLuint vertices_buffer;
GLuint indices_buffer;
};
struct rk_command {
GLuint nvertices;
GLuint ninstances;
GLuint base_index;
GLint base_vertex;
GLuint base_instance;
};
typedef void (*rk_packer)(
unsigned const, // count
rk_instance_index const * const __restrict, // indices
rk_vertex_output * __restrict, // dst
rk_vertex_input const * const __restrict); // src
struct rk_parameter {
mutable bool dirty;
unsigned binding;
unsigned offset;
unsigned src_size;
unsigned src_len;
unsigned dst_size;
unsigned dst_len;
rk_vertex_input * source;
rk_packer packer;
};
struct rk_bucket {
unsigned size;
unsigned count;
rk_instance_index * indices;
};
enum rk_batch_state {
RK_BATCH_STATE_EMPTY = 0,
RK_BATCH_STATE_FILLED = 1,
RK_BATCH_STATE_SORTED = 2,
RK_BATCH_STATE_PACKED = 3
};
struct rk_batch {
mutable rk_batch_state state;
mutable unsigned count;
mutable unsigned ninstances;
mutable unsigned ncommands;
unsigned max_size;
unsigned nparams;
rk_vertices const * vertices;
rk_instance_flags * flags;
rk_mesh_index * meshes;
rk_instance_index * indices;
rk_command * commands;
rk_parameter * params;
GLuint vertex_array;
GLuint commands_buffer;
GLuint params_buffer;
};
#endif // _RK_ENGINE_RENDER_OPENGLES_H