Cleanup: remove projection and views and add setters for mat3 and mat4 instead.
This commit is contained in:
@ -18,7 +18,6 @@
|
||||
|
||||
static rk_shader const * rk_current_shader = nullptr;
|
||||
static rk_vertices const * rk_current_vertices = nullptr;
|
||||
static bool rk_frame = false;
|
||||
|
||||
static void rk_printf(char const * messsage) {
|
||||
printf("[RK_ENGINE] %s\n", messsage);
|
||||
@ -146,10 +145,6 @@ rk_shader_t rk_load_shader(
|
||||
rk_free_shader_source(fragment_source, fragment_length);
|
||||
}
|
||||
|
||||
shader->uniforms.view = glGetUniformLocation(shader->program, "u_view");
|
||||
shader->uniforms.view_km = glGetUniformLocation(shader->program, "u_view_km");
|
||||
shader->uniforms.projection = glGetUniformLocation(shader->program, "u_projection");
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
@ -159,17 +154,6 @@ void rk_select_shader(
|
||||
if (shader) {
|
||||
rk_current_shader = shader;
|
||||
glUseProgram(shader->program);
|
||||
if (rk_frame) {
|
||||
if (shader->uniforms.view > -1) {
|
||||
glUniformMatrix4fv(shader->uniforms.view, 1, GL_FALSE, glm::value_ptr(rk_view));
|
||||
}
|
||||
if (shader->uniforms.view_km > -1) {
|
||||
glUniformMatrix4fv(shader->uniforms.view_km, 1, GL_FALSE, glm::value_ptr(rk_view_km));
|
||||
}
|
||||
if (shader->uniforms.projection > -1) {
|
||||
glUniformMatrix4fv(shader->uniforms.projection, 1, GL_FALSE, glm::value_ptr(rk_projection));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,23 +177,28 @@ void rk_set_input_float(
|
||||
|
||||
void rk_set_input_vec3(
|
||||
rk_input_t _input,
|
||||
rk_vec3 const & value,
|
||||
rk_input_mode mode) {
|
||||
rk_vec3 const & value) {
|
||||
GLint const input = reinterpret_cast<intptr_t>(_input) - 1;
|
||||
if (rk_current_shader && input > -1) {
|
||||
switch (mode) {
|
||||
case RK_INPUT_IDENTITY:
|
||||
glUniform3fv(input, 1, glm::value_ptr(value));
|
||||
break;
|
||||
case RK_INPUT_VIEW_POSITION: {
|
||||
glUniform3fv(input, 1, glm::value_ptr(rk_view * rk_vec4(value, 1.0)));
|
||||
break;
|
||||
}
|
||||
case RK_INPUT_VIEW_ORIENTATION: {
|
||||
glUniform3fv(input, 1, glm::value_ptr(rk_view * rk_vec4(value, 0.0)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
glUniform3fv(input, 1, glm::value_ptr(value));
|
||||
}
|
||||
}
|
||||
|
||||
void rk_set_input_mat3(
|
||||
rk_input_t _input,
|
||||
rk_mat3 const & value) {
|
||||
GLint const input = reinterpret_cast<intptr_t>(_input) - 1;
|
||||
if (rk_current_shader && input > -1) {
|
||||
glUniformMatrix3fv(input, 1, GL_FALSE, glm::value_ptr(value));
|
||||
}
|
||||
}
|
||||
|
||||
void rk_set_input_mat4(
|
||||
rk_input_t _input,
|
||||
rk_mat4 const & value) {
|
||||
GLint const input = reinterpret_cast<intptr_t>(_input) - 1;
|
||||
if (rk_current_shader && input > -1) {
|
||||
glUniformMatrix4fv(input, 1, GL_FALSE, glm::value_ptr(value));
|
||||
}
|
||||
}
|
||||
|
||||
@ -490,7 +479,6 @@ rk_batch_t rk_create_batch(
|
||||
}
|
||||
|
||||
void rk_begin_frame() {
|
||||
rk_frame = true;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@ -721,7 +709,6 @@ void rk_unselect_shader(
|
||||
|
||||
void rk_end_frame() {
|
||||
rk_swap_buffers();
|
||||
rk_frame = false;
|
||||
}
|
||||
|
||||
void rk_destroy_batch(
|
||||
|
@ -27,17 +27,10 @@ enum : rk_uint {
|
||||
RK_PARAMS_BINDING = 1
|
||||
};
|
||||
|
||||
struct rk_uniforms {
|
||||
GLint view;
|
||||
GLint view_km;
|
||||
GLint projection;
|
||||
};
|
||||
|
||||
struct rk_shader {
|
||||
GLuint vertex;
|
||||
GLuint fragment;
|
||||
GLuint program;
|
||||
rk_uniforms uniforms;
|
||||
};
|
||||
|
||||
struct rk_texture {
|
||||
|
@ -1,48 +0,0 @@
|
||||
// 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/>.
|
||||
|
||||
#include "render.hpp"
|
||||
|
||||
rk_vec3 rk_view_origin;
|
||||
rk_vec3 rk_view_lookat;
|
||||
rk_mat4 rk_view;
|
||||
rk_mat4 rk_view_km;
|
||||
|
||||
float rk_projection_hfov;
|
||||
float rk_projection_ratio;
|
||||
float rk_projection_near;
|
||||
float rk_projection_far;
|
||||
rk_mat4 rk_projection;
|
||||
|
||||
void rk_set_projection(
|
||||
float hfov,
|
||||
float ratio,
|
||||
float near,
|
||||
float far) {
|
||||
rk_projection_hfov = hfov;
|
||||
rk_projection_ratio = ratio;
|
||||
rk_projection_near = near;
|
||||
rk_projection_far = far;
|
||||
rk_projection = glm::perspectiveRH(hfov, ratio, near, far);
|
||||
}
|
||||
|
||||
extern void rk_set_view(
|
||||
rk_vec3 const & position,
|
||||
rk_vec3 const & lookat) {
|
||||
rk_view_origin = position;
|
||||
rk_view_lookat = lookat;
|
||||
rk_view = glm::lookAtRH(position, lookat, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
rk_view_km = glm::lookAtRH(position * 0.001f, lookat * 0.001f, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
}
|
@ -19,17 +19,6 @@
|
||||
#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;
|
||||
@ -40,12 +29,6 @@ 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,
|
||||
@ -118,8 +101,15 @@ RK_EXPORT void rk_set_input_float(
|
||||
|
||||
RK_EXPORT void rk_set_input_vec3(
|
||||
rk_input_t input,
|
||||
rk_vec3 const & value,
|
||||
rk_input_mode mode);
|
||||
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 rk_texture_t rk_create_texture(
|
||||
rk_uint slot,
|
||||
|
Reference in New Issue
Block a user