Add a bunch more debug_print calls
This commit is contained in:
parent
f66e20aa3d
commit
20b3a47aba
@ -25,6 +25,7 @@
|
|||||||
#include "util/sequence.hpp"
|
#include "util/sequence.hpp"
|
||||||
#include "detail.hpp"
|
#include "detail.hpp"
|
||||||
#include "error.hpp"
|
#include "error.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
namespace sfx{
|
namespace sfx{
|
||||||
|
|
||||||
@ -50,7 +51,12 @@ namespace sfx{
|
|||||||
m_err(open_default_stream(&m_stream, in_c, out_c, paFloat32, samplerate, buffersize, m_cb)),
|
m_err(open_default_stream(&m_stream, in_c, out_c, paFloat32, samplerate, buffersize, m_cb)),
|
||||||
m_samplerate(samplerate),
|
m_samplerate(samplerate),
|
||||||
m_in_channels(in_c),
|
m_in_channels(in_c),
|
||||||
m_out_channels(out_c){}
|
m_out_channels(out_c)
|
||||||
|
{
|
||||||
|
if(m_err != paNoError){
|
||||||
|
debug_print_error("Failed to open audio stream\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
~stream();
|
~stream();
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@ namespace gfx{
|
|||||||
|
|
||||||
struct vertex {
|
struct vertex {
|
||||||
math::vec3<float> position;
|
math::vec3<float> position;
|
||||||
math::vec4<float> color;
|
math::vec3<float> normal;
|
||||||
math::vec2<float> tex_coords;
|
math::vec2<float> tex_coords;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,7 @@ namespace gfx{
|
|||||||
GLuint m_tex_id = 0; //handle to texture object
|
GLuint m_tex_id = 0; //handle to texture object
|
||||||
GLsizei m_width = 0;
|
GLsizei m_width = 0;
|
||||||
GLsizei m_height = 0;
|
GLsizei m_height = 0;
|
||||||
GLenum m_format = GL_RGBA;
|
GLenum m_format = 0;
|
||||||
GLenum m_type = GL_UNSIGNED_BYTE;
|
GLenum m_type = GL_UNSIGNED_BYTE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -38,18 +38,17 @@ private:
|
|||||||
"void main(){"
|
"void main(){"
|
||||||
"gl_Position = vp_mat * model_mat * vec4(position, 1.0);"
|
"gl_Position = vp_mat * model_mat * vec4(position, 1.0);"
|
||||||
"frag_tex_coords = tex_coords;"
|
"frag_tex_coords = tex_coords;"
|
||||||
"frag_vertex_color = color;"
|
|
||||||
"}";
|
"}";
|
||||||
static constexpr char s_fragment_shader_text[] = "#version 430 core\n"
|
static constexpr char s_fragment_shader_text[] = "#version 430 core\n"
|
||||||
"out vec4 FragColor;"
|
"out vec4 FragColor;"
|
||||||
|
|
||||||
"in vec2 frag_tex_coords;"
|
"in vec2 frag_tex_coords;"
|
||||||
"in vec4 frag_vertex_color;"
|
|
||||||
|
|
||||||
"uniform sampler2D texture1;"
|
"uniform sampler2D texture1;"
|
||||||
|
"uniform vec4 model_color;"
|
||||||
|
|
||||||
"void main(){"
|
"void main(){"
|
||||||
"FragColor = texture(texture1, frag_tex_coords);"
|
"FragColor = mix(texture(texture1, frag_tex_coords), model_color, model_color.a);"
|
||||||
"}";
|
"}";
|
||||||
public:
|
public:
|
||||||
sprite_shader();
|
sprite_shader();
|
||||||
|
|||||||
@ -39,6 +39,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
gfx::model* m_model;
|
gfx::model* m_model;
|
||||||
value m_active_value = value::BLANK;
|
value m_active_value = value::BLANK;
|
||||||
|
math::vec4<float> m_color_filter = {};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
square(gfx::model* model);
|
square(gfx::model* model);
|
||||||
@ -46,6 +47,8 @@ public:
|
|||||||
void set_value(value v);
|
void set_value(value v);
|
||||||
value get_value()const;
|
value get_value()const;
|
||||||
|
|
||||||
|
void set_color(const math::vec4<float>& color);
|
||||||
|
|
||||||
void render(gfx::shader_program&)override;
|
void render(gfx::shader_program&)override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -65,12 +65,14 @@ namespace sfx::impl{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void channel::resize_buffer(size_t newsize){
|
void channel::resize_buffer(size_t newsize){
|
||||||
|
debug_print_warn("Resizing audio channel buffer size. Pausing channel in audio thread\n");
|
||||||
bool was_paused = m_paused.load(std::memory_order_acquire);
|
bool was_paused = m_paused.load(std::memory_order_acquire);
|
||||||
pause();
|
pause();
|
||||||
wait_for_consumer();
|
wait_for_consumer();
|
||||||
m_data.resize(newsize);
|
m_data.resize(newsize);
|
||||||
if(!was_paused)
|
if(!was_paused)
|
||||||
resume();
|
resume();
|
||||||
|
debug_print("Audio channel resuming\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void channel::play(const mixdata& m){
|
void channel::play(const mixdata& m){
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
#include "audio/impl/mixer.hpp"
|
#include "audio/impl/mixer.hpp"
|
||||||
#include "audio/impl/channel.hpp"
|
#include "audio/impl/channel.hpp"
|
||||||
#include "audio/mixdata.hpp"
|
#include "audio/mixdata.hpp"
|
||||||
|
#include "audio/error.hpp"
|
||||||
|
|
||||||
namespace sfx::impl{
|
namespace sfx::impl{
|
||||||
|
|
||||||
@ -30,7 +31,10 @@ namespace sfx::impl{
|
|||||||
m_lk(m_copy_lock, std::defer_lock),
|
m_lk(m_copy_lock, std::defer_lock),
|
||||||
m_output_sink(0, output_channels, samplerate, 0, callback, *this)
|
m_output_sink(0, output_channels, samplerate, 0, callback, *this)
|
||||||
{
|
{
|
||||||
m_output_sink.start();
|
if(m_output_sink.last_error() != sfx::error::NONE)
|
||||||
|
m_output_sink.start();
|
||||||
|
else
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
mixer::~mixer(){
|
mixer::~mixer(){
|
||||||
exit();
|
exit();
|
||||||
@ -55,8 +59,10 @@ namespace sfx::impl{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mixer::lock(){
|
void mixer::lock(){
|
||||||
|
debug_print_warn("Locking mixer\n");
|
||||||
m_lk.lock();
|
m_lk.lock();
|
||||||
consumer_lock();
|
consumer_lock();
|
||||||
|
debug_print("Unlocking mixer\n");
|
||||||
}
|
}
|
||||||
void mixer::consumer_lock(){
|
void mixer::consumer_lock(){
|
||||||
pause();
|
pause();
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "engine/game_state.hpp"
|
#include "engine/game_state.hpp"
|
||||||
#include "engine/input.hpp"
|
#include "engine/input.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
#include <queue> //queue
|
#include <queue> //queue
|
||||||
#include <memory> //unique_ptr
|
#include <memory> //unique_ptr
|
||||||
@ -25,18 +26,21 @@
|
|||||||
namespace egn{
|
namespace egn{
|
||||||
|
|
||||||
void game_state_manager::push_state(std::unique_ptr<game_state_iface>&& state){
|
void game_state_manager::push_state(std::unique_ptr<game_state_iface>&& state){
|
||||||
|
debug_print("Pushing new state onto game state stack\n");
|
||||||
if(!m_state_stack.empty())
|
if(!m_state_stack.empty())
|
||||||
m_state_stack.top()->leave();
|
m_state_stack.top()->leave();
|
||||||
m_state_stack.push (std::move(state));
|
m_state_stack.push (std::move(state));
|
||||||
m_state_stack.top()->enter();
|
m_state_stack.top()->enter();
|
||||||
}
|
}
|
||||||
void game_state_manager::pop_state(){
|
void game_state_manager::pop_state(){
|
||||||
|
debug_print("Poping state from game state stack\n");
|
||||||
m_state_stack.top()->leave();
|
m_state_stack.top()->leave();
|
||||||
m_state_stack.pop();
|
m_state_stack.pop();
|
||||||
if(!m_state_stack.empty())
|
if(!m_state_stack.empty())
|
||||||
m_state_stack.top()->enter();
|
m_state_stack.top()->enter();
|
||||||
}
|
}
|
||||||
void game_state_manager::replace_state(std::unique_ptr<game_state_iface>&& state){
|
void game_state_manager::replace_state(std::unique_ptr<game_state_iface>&& state){
|
||||||
|
debug_print("Replacing top state of game state stack\n");
|
||||||
m_state_stack.top()->leave();
|
m_state_stack.top()->leave();
|
||||||
m_state_stack.top() = std::move(state);
|
m_state_stack.top() = std::move(state);
|
||||||
m_state_stack.top()->enter();
|
m_state_stack.top()->enter();
|
||||||
@ -49,12 +53,19 @@ namespace egn{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void game_state_manager::update(double time_diff){
|
void game_state_manager::update(double time_diff){
|
||||||
if(!m_state_stack.empty())
|
if(!m_state_stack.empty()){
|
||||||
m_state_stack.top()->update(time_diff);
|
m_state_stack.top()->update(time_diff);
|
||||||
|
}else{
|
||||||
|
debug_print_warn("Running update without an active game state\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
void game_state_manager::render(){
|
void game_state_manager::render(){
|
||||||
if(!m_state_stack.empty())
|
if(!m_state_stack.empty()){
|
||||||
m_state_stack.top()->render();
|
m_state_stack.top()->render();
|
||||||
|
}else{
|
||||||
|
debug_print_warn("Running render without an active game state\n");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,9 @@ namespace gfx{
|
|||||||
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
|
#ifdef OUR_DICK_ENABLE_DEBUG_OUTPUT
|
||||||
glfwSetErrorCallback(our_dick_glfw_error_callback);
|
glfwSetErrorCallback(our_dick_glfw_error_callback);
|
||||||
#endif
|
#endif
|
||||||
|
if(s_status){
|
||||||
|
debug_print_warn("Call to glfwInit after already initialized\n");
|
||||||
|
}
|
||||||
s_status = glfwInit();
|
s_status = glfwInit();
|
||||||
}
|
}
|
||||||
glfw_system& glfw_system::instance(){
|
glfw_system& glfw_system::instance(){
|
||||||
|
|||||||
@ -60,7 +60,7 @@ namespace gfx{
|
|||||||
attrib.enable();
|
attrib.enable();
|
||||||
|
|
||||||
attrib = m_vao.get_attribute(2);
|
attrib = m_vao.get_attribute(2);
|
||||||
attrib.set_float_array(4, offsetof(vertex, color));
|
attrib.set_float_array(3, offsetof(vertex, normal));
|
||||||
attrib.associate_with(0);
|
attrib.associate_with(0);
|
||||||
attrib.enable();
|
attrib.enable();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -528,6 +528,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[2])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[2])){
|
||||||
glProgramUniform2fv(m_shader_id, loc, count, reinterpret_cast<const GLfloat*>(v_arr));
|
glProgramUniform2fv(m_shader_id, loc, count, reinterpret_cast<const GLfloat*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 2]);
|
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 2]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -543,6 +544,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[3])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[3])){
|
||||||
glProgramUniform3fv(m_shader_id, loc, count, reinterpret_cast<const GLfloat*>(v_arr));
|
glProgramUniform3fv(m_shader_id, loc, count, reinterpret_cast<const GLfloat*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 3]);
|
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 3]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -559,6 +561,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[4])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLfloat[4])){
|
||||||
glProgramUniform4fv(m_shader_id, loc, count, reinterpret_cast<const GLfloat*>(v_arr));
|
glProgramUniform4fv(m_shader_id, loc, count, reinterpret_cast<const GLfloat*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 4]);
|
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 4]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -621,6 +624,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[2])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[2])){
|
||||||
glProgramUniform2iv(m_shader_id, loc, count, reinterpret_cast<const GLint*>(v_arr));
|
glProgramUniform2iv(m_shader_id, loc, count, reinterpret_cast<const GLint*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLint[]> arr(new GLint[count * 2]);
|
std::unique_ptr<GLint[]> arr(new GLint[count * 2]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -636,6 +640,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[3])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[3])){
|
||||||
glProgramUniform3iv(m_shader_id, loc, count, reinterpret_cast<const GLint*>(v_arr));
|
glProgramUniform3iv(m_shader_id, loc, count, reinterpret_cast<const GLint*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLint[]> arr(new GLint[count * 3]);
|
std::unique_ptr<GLint[]> arr(new GLint[count * 3]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -652,6 +657,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[4])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLint[4])){
|
||||||
glProgramUniform4iv(m_shader_id, loc, count, reinterpret_cast<const GLint*>(v_arr));
|
glProgramUniform4iv(m_shader_id, loc, count, reinterpret_cast<const GLint*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLint[]> arr(new GLint[count * 4]);
|
std::unique_ptr<GLint[]> arr(new GLint[count * 4]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -714,6 +720,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[2])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[2])){
|
||||||
glProgramUniform2uiv(m_shader_id, loc, count, reinterpret_cast<const GLuint*>(v_arr));
|
glProgramUniform2uiv(m_shader_id, loc, count, reinterpret_cast<const GLuint*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLuint[]> arr(new GLuint[count * 2]);
|
std::unique_ptr<GLuint[]> arr(new GLuint[count * 2]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -729,6 +736,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[3])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[3])){
|
||||||
glProgramUniform3uiv(m_shader_id, loc, count, reinterpret_cast<const GLuint*>(v_arr));
|
glProgramUniform3uiv(m_shader_id, loc, count, reinterpret_cast<const GLuint*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLuint[]> arr(new GLuint[count * 3]);
|
std::unique_ptr<GLuint[]> arr(new GLuint[count * 3]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -745,6 +753,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[4])){
|
if constexpr(sizeof(v_arr[0]) == sizeof(GLuint[4])){
|
||||||
glProgramUniform4uiv(m_shader_id, loc, count, reinterpret_cast<const GLuint*>(v_arr));
|
glProgramUniform4uiv(m_shader_id, loc, count, reinterpret_cast<const GLuint*>(v_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLuint[]> arr(new GLuint[count * 4]);
|
std::unique_ptr<GLuint[]> arr(new GLuint[count * 4]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = v_arr[i].get(0);
|
arr[i] = v_arr[i].get(0);
|
||||||
@ -807,6 +816,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[4])){
|
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[4])){
|
||||||
glProgramUniformMatrix2fv(m_shader_id, loc, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
|
glProgramUniformMatrix2fv(m_shader_id, loc, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 4]);
|
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 4]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = m_arr[i].get(0);
|
arr[i] = m_arr[i].get(0);
|
||||||
@ -824,6 +834,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[9])){
|
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[9])){
|
||||||
glProgramUniformMatrix3fv(m_shader_id, loc, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
|
glProgramUniformMatrix3fv(m_shader_id, loc, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 9]);
|
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 9]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = m_arr[i].get(0);
|
arr[i] = m_arr[i].get(0);
|
||||||
@ -846,6 +857,7 @@ namespace gfx{
|
|||||||
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[16])){
|
if constexpr(sizeof(m_arr[0]) == sizeof(GLfloat[16])){
|
||||||
glProgramUniformMatrix4fv(m_shader_id, loc, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
|
glProgramUniformMatrix4fv(m_shader_id, loc, count, GL_FALSE, reinterpret_cast<const GLfloat*>(m_arr));
|
||||||
}else{
|
}else{
|
||||||
|
debug_print_warn("Using inefficient uniform initialization\n");
|
||||||
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 16]);
|
std::unique_ptr<GLfloat[]> arr(new GLfloat[count * 16]);
|
||||||
for(GLsizei i = 0; i < count; ++i){
|
for(GLsizei i = 0; i < count; ++i){
|
||||||
arr[i] = m_arr[i].get(0);
|
arr[i] = m_arr[i].get(0);
|
||||||
|
|||||||
@ -23,6 +23,22 @@
|
|||||||
|
|
||||||
namespace gfx{
|
namespace gfx{
|
||||||
|
|
||||||
|
static bool is_format_compatible(GLenum format, int channel_count){
|
||||||
|
switch(channel_count){
|
||||||
|
case 1:
|
||||||
|
return format == GL_RED;
|
||||||
|
case 2:
|
||||||
|
return format == GL_RG;
|
||||||
|
case 3:
|
||||||
|
return format == GL_RGB;
|
||||||
|
case 4:
|
||||||
|
return format == GL_RGBA;
|
||||||
|
};
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
texture::texture(){
|
texture::texture(){
|
||||||
glCreateTextures(GL_TEXTURE_2D, 1, &m_tex_id);
|
glCreateTextures(GL_TEXTURE_2D, 1, &m_tex_id);
|
||||||
}
|
}
|
||||||
@ -44,6 +60,11 @@ namespace gfx{
|
|||||||
case GL_RGBA:
|
case GL_RGBA:
|
||||||
glTextureStorage2D(m_tex_id, 1, GL_RGBA8, m_width, m_height);
|
glTextureStorage2D(m_tex_id, 1, GL_RGBA8, m_width, m_height);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
debug_print_error("Unsupported format passed to texture constructor\n");
|
||||||
|
glDeleteTextures(1, &m_tex_id);
|
||||||
|
m_tex_id = 0;
|
||||||
|
return;
|
||||||
};
|
};
|
||||||
glTextureSubImage2D(m_tex_id, 0, 0, 0, m_width, m_height, m_format, m_type, data);
|
glTextureSubImage2D(m_tex_id, 0, 0, 0, m_width, m_height, m_format, m_type, data);
|
||||||
glGenerateTextureMipmap(m_tex_id);
|
glGenerateTextureMipmap(m_tex_id);
|
||||||
@ -75,32 +96,35 @@ namespace gfx{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!m_tex_id){
|
if(m_width != i.get_width() || m_height != i.get_height() || !is_format_compatible(m_format, i.get_channels())){
|
||||||
debug_print("Generating texture after texture construction\n");
|
if(m_format != 0){
|
||||||
glCreateTextures(GL_TEXTURE_2D, 1, &m_tex_id);
|
debug_print_warn("Regenerating texture\n");
|
||||||
}
|
glDeleteTextures(1, &m_tex_id);
|
||||||
m_width = i.get_width();
|
glCreateTextures(GL_TEXTURE_2D, 1, &m_tex_id);
|
||||||
m_height = i.get_height();
|
}
|
||||||
switch(i.get_channels()){
|
m_width = i.get_width();
|
||||||
case 1:
|
m_height = i.get_height();
|
||||||
m_format = GL_RED;
|
switch(i.get_channels()){
|
||||||
glTextureStorage2D(m_tex_id, 1, GL_R8, m_width, m_height);
|
case 1:
|
||||||
break;
|
m_format = GL_RED;
|
||||||
case 2:
|
glTextureStorage2D(m_tex_id, 1, GL_R8, m_width, m_height);
|
||||||
m_format = GL_RG;
|
break;
|
||||||
glTextureStorage2D(m_tex_id, 1, GL_RG8, m_width, m_height);
|
case 2:
|
||||||
break;
|
m_format = GL_RG;
|
||||||
case 3:
|
glTextureStorage2D(m_tex_id, 1, GL_RG8, m_width, m_height);
|
||||||
m_format = GL_RGB;
|
break;
|
||||||
glTextureStorage2D(m_tex_id, 1, GL_RGB8, m_width, m_height);
|
case 3:
|
||||||
break;
|
m_format = GL_RGB;
|
||||||
case 4:
|
glTextureStorage2D(m_tex_id, 1, GL_RGB8, m_width, m_height);
|
||||||
m_format = GL_RGBA;
|
break;
|
||||||
glTextureStorage2D(m_tex_id, 1, GL_RGBA8, m_width, m_height);
|
case 4:
|
||||||
break;
|
m_format = GL_RGBA;
|
||||||
default:
|
glTextureStorage2D(m_tex_id, 1, GL_RGBA8, m_width, m_height);
|
||||||
debug_print_error("Invalid format for texture\n");
|
break;
|
||||||
return false;
|
default:
|
||||||
|
debug_print_error("Invalid format for texture\n");
|
||||||
|
return false;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
glTextureSubImage2D(m_tex_id, 0, 0, 0, m_width, m_height, m_format, GL_UNSIGNED_BYTE, i.data());
|
glTextureSubImage2D(m_tex_id, 0, 0, 0, m_width, m_height, m_format, GL_UNSIGNED_BYTE, i.data());
|
||||||
glGenerateTextureMipmap(m_tex_id);
|
glGenerateTextureMipmap(m_tex_id);
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "graphics/vbo.hpp"
|
#include "graphics/vbo.hpp"
|
||||||
#include "util/minmax.hpp"
|
#include "util/minmax.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
#include <utility> //exchange, swap, move
|
#include <utility> //exchange, swap, move
|
||||||
|
|
||||||
@ -117,6 +118,7 @@ namespace gfx{
|
|||||||
scoped_vbo_map<void>::scoped_vbo_map(GLuint bid, vbo::maptype m):
|
scoped_vbo_map<void>::scoped_vbo_map(GLuint bid, vbo::maptype m):
|
||||||
m_buffer(bid)
|
m_buffer(bid)
|
||||||
{
|
{
|
||||||
|
debug_print_verbose("Mapping vertex buffer object %u\n", bid);
|
||||||
m_data = reinterpret_cast<pointer>(glMapNamedBuffer(m_buffer, static_cast<GLenum>(m)));
|
m_data = reinterpret_cast<pointer>(glMapNamedBuffer(m_buffer, static_cast<GLenum>(m)));
|
||||||
}
|
}
|
||||||
scoped_vbo_map<void>::scoped_vbo_map(scoped_vbo_map&& m):
|
scoped_vbo_map<void>::scoped_vbo_map(scoped_vbo_map&& m):
|
||||||
@ -124,6 +126,7 @@ namespace gfx{
|
|||||||
m_buffer(std::exchange(m.m_buffer, 0)){}
|
m_buffer(std::exchange(m.m_buffer, 0)){}
|
||||||
scoped_vbo_map<void>::~scoped_vbo_map(){
|
scoped_vbo_map<void>::~scoped_vbo_map(){
|
||||||
if(m_data){
|
if(m_data){
|
||||||
|
debug_print_verbose("Unmapping vertex buffer object %u\n", m_buffer);
|
||||||
glUnmapNamedBuffer(m_buffer);
|
glUnmapNamedBuffer(m_buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -122,6 +122,7 @@ static void enable_opengl_debug_context(){
|
|||||||
|
|
||||||
static bool has_supported_opengl_version(){
|
static bool has_supported_opengl_version(){
|
||||||
if(GLAD_GL_VERSION_4_5){
|
if(GLAD_GL_VERSION_4_5){
|
||||||
|
debug_print_succ("Opengl 4.5 fully supported\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(GLAD_GL_VERSION_4_3){
|
if(GLAD_GL_VERSION_4_3){
|
||||||
|
|||||||
@ -102,8 +102,9 @@ void play_state::handle_input(const egn::input_event& ev){
|
|||||||
(projected1.y() > (sq_pos.y() - 1.0f) && projected1.y() < (sq_pos.y() + 1.0f)))
|
(projected1.y() > (sq_pos.y() - 1.0f) && projected1.y() < (sq_pos.y() + 1.0f)))
|
||||||
{
|
{
|
||||||
debug_print_succ("Clicked on square %lu\n", i);
|
debug_print_succ("Clicked on square %lu\n", i);
|
||||||
if(sq.get_value() == square::value::BLANK)
|
if(sq.get_value() == square::value::BLANK){
|
||||||
sq.set_value(((++m_current_player) %= 2) ? square::value::O : square::value::X);
|
sq.set_value(((++m_current_player) %= 2) ? square::value::O : square::value::X);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,9 +45,13 @@ void square::set_value(value t){
|
|||||||
auto square::get_value()const -> value{
|
auto square::get_value()const -> value{
|
||||||
return m_active_value;
|
return m_active_value;
|
||||||
}
|
}
|
||||||
|
void square::set_color(const math::vec4<float>& color){
|
||||||
|
m_color_filter = color;
|
||||||
|
}
|
||||||
|
|
||||||
void square::render(gfx::shader_program& shader){
|
void square::render(gfx::shader_program& shader){
|
||||||
shader.set_uniform("model_mat", get_model_matrix());
|
shader.set_uniform("model_mat", get_model_matrix());
|
||||||
|
shader.set_uniform("model_color", m_color_filter);
|
||||||
shader.set_uniform("texture1", *m_model->mesh(0).material().get_material((int)m_active_value));
|
shader.set_uniform("texture1", *m_model->mesh(0).material().get_material((int)m_active_value));
|
||||||
m_model->mesh(0).vertex().render(shader);
|
m_model->mesh(0).vertex().render(shader);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user