Skip to content

Commit

Permalink
shaders, window close event, audio destroy bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mtiapko committed Jan 7, 2019
1 parent 8e1eb8d commit b88a726
Show file tree
Hide file tree
Showing 33 changed files with 565 additions and 139 deletions.
1 change: 1 addition & 0 deletions include/audio/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class core

public:
static status create() noexcept;
static void destroy() noexcept;
};

}
Expand Down
2 changes: 1 addition & 1 deletion include/audio/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define __DK_AUDIO_DEBUG_H__

#include <AL/al.h>
#include "log.h"
#include "containers/string_view.h"
#include "log.h"

#define AL_CALL(func) \
func, \
Expand Down
7 changes: 4 additions & 3 deletions include/audio/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#define __DK_AUDIO_SOUND_H__

#include <AL/al.h>
#include "audio/source_data.h"
#include "audio/sound_data.h"

namespace dk::audio
{

class sound
class sound final: public resource
{
private:
ALuint m_id;
Expand All @@ -16,10 +16,11 @@ class sound

public:
sound() noexcept;
~sound() noexcept;
~sound() noexcept override;

ALuint id() const noexcept { return m_id; }

status create(string_view file_path, sound_data_fmt fmt = sound_data_fmt::AUTO) noexcept;
status create(const sound_data& data) noexcept;
void destroy() noexcept;
};
Expand Down
6 changes: 3 additions & 3 deletions include/audio/source_data.h → include/audio/sound_data.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __DK_AUDIO_SOUND_DATA_H__
#define __DK_AUDIO_SOUND_DATA_H__

#include "status.h"
#include "resource.h"
#include "containers/string_view.h"

namespace dk::audio
Expand All @@ -13,7 +13,7 @@ enum class sound_data_fmt
WAVE
};

class sound_data
class sound_data final: public resource
{
private:
uint8_t* m_data;
Expand All @@ -26,7 +26,7 @@ class sound_data

public:
sound_data() noexcept;
~sound_data() noexcept;
~sound_data() noexcept override;

const uint8_t* data() const noexcept { return m_data; }
size_t size() const noexcept { return m_size; }
Expand Down
3 changes: 2 additions & 1 deletion include/audio/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class source
void pause() const noexcept;
void stop() const noexcept;

void set_sound(const sound& snd) const noexcept;
void set(const sound& snd) const noexcept;
void remove_sound() const noexcept;

void set_pitch(float val) const noexcept;
Expand All @@ -39,6 +39,7 @@ class source
bool looping() const noexcept;

status create() noexcept;
void destroy() noexcept;
};

}
Expand Down
4 changes: 4 additions & 0 deletions include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ namespace dk
class core
{
private:
static bool s_running;
static graph::renderer s_active_renderer;

public:
template<typename T> static T* active() noexcept;

static status run(application* app) noexcept;
static void stop() noexcept;

// TODO: enum create all, only audio, only net, ... (multi using overloaded AND '&&')
static status create() noexcept;
static void destroy() noexcept;
};

}
Expand Down
27 changes: 27 additions & 0 deletions include/graph/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef __DK_GRAPH_DEBUG_H__
#define __DK_GRAPH_DEBUG_H__

#include <GL/gl.h>
#include "containers/string_view.h"
#include "log.h"

#define GL_CALL(func) \
func, \
[](string_view func_name) { \
if(auto err = glGetError(); err != GL_NO_ERROR) \
DK_LOG_ERROR_IMPL(__FILE__, func_name, __LINE__, \
"OpenGL function '", #func, "' failed: ", debug::code_to_str(err)); \
}(__func__)

namespace dk::graph
{

class debug
{
public:
static string_view code_to_str(GLenum code) noexcept;
};

}

#endif // !__DK_AUDIO_DEBUG_H__
37 changes: 37 additions & 0 deletions include/graph/shader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef __DK_GRAPH_SHADER_H__
#define __DK_GRAPH_SHADER_H__

#include <GL/gl.h>
#include "graph/shader_data.h"

namespace dk::graph
{

enum class shader_type
{
VERTEX = 0,
GEOMETRY,
FRAGMENT
};

class shader final: public resource
{
private:
GLuint m_id;

static GLenum convert_to_gl_type(shader_type type) noexcept;

public:
shader() noexcept;
~shader() noexcept override;

GLuint id() const noexcept { return m_id; }

status create(string_view file_path, shader_type type) noexcept;
status create(const shader_data& data, shader_type type) noexcept;
void destroy() noexcept;
};

}

#endif // !__DK_GRAPH_SHADER_H__
29 changes: 29 additions & 0 deletions include/graph/shader_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef __DK_GRAPH_SHADER_DATA_H__
#define __DK_GRAPH_SHADER_DATA_H__

#include "resource.h"
#include "containers/string.h"
#include "containers/string_view.h"

namespace dk::graph
{

class shader_data final: public resource
{
private:
string m_data;
string_view m_file_path;

public:
shader_data() noexcept = default;
~shader_data() noexcept override = default;

const string& data() const noexcept { return m_data; }
string_view file_path() const noexcept { return m_file_path; }

status create(string_view path) noexcept;
};

}

#endif // !__DK_GRAPH_SHADER_DATA_H__
31 changes: 31 additions & 0 deletions include/graph/shader_program.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef __DK_GRAPH_SHADER_PROGRAM_H__
#define __DK_GRAPH_SHADER_PROGRAM_H__

#include "graph/shader.h"

namespace dk::graph
{

class shader_program : public resource
{
private:
GLuint m_id;

public:
~shader_program() noexcept override;

void enable() const noexcept;
void disable() const noexcept;

status add(string_view file_path, shader_type type) const noexcept;
status add(const shader& inst) const noexcept;
status remove_shaders() const noexcept;

status create() noexcept;
status link() const noexcept;
void destroy() noexcept;
};

}

#endif // !__DK_GRAPH_SHADER_PROGRAM_H__
13 changes: 10 additions & 3 deletions include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
#include "status.h"
#include "util/term.h"

#define DK_LOG_COLOR(color, txt) dk::util::term_text_color::color, dk::util::term_text_attrib::BOLD, txt, dk::util::term_text_attrib::DEFAULT
#define DK_LOG_COLOR(color, ...) \
dk::util::term_text_color::color, dk::util::term_text_attrib::BOLD, \
__VA_ARGS__, \
dk::util::term_text_attrib::DEFAULT

#define DK_LOG_HEADER(color, title, file, func, line) "[", DK_LOG_COLOR(color, title), "] ", dk::log_timestamp{}, " - ", file, "::", func, " (", line, ") - "
#define DK_LOG_PRINT(color, title, file, func, line, ...) dk::log::print(DK_LOG_HEADER(color, title, file, func, line), __VA_ARGS__)
#define DK_LOG_HEADER(color, title, file, func, line) \
"[", DK_LOG_COLOR(color, title), "] ", \
DK_LOG_COLOR(GRAY, dk::log_timestamp{}, " - ", file, "::", func, " (", line, ") - ")

#define DK_LOG_PRINT(color, title, file, func, line, ...) \
dk::log::print(DK_LOG_HEADER(color, title, file, func, line), __VA_ARGS__)

#define DK_LOG_IMPL(file, func, line, ...) DK_LOG_PRINT(LIGHT_BLUE, " MSG ", file, func, line, __VA_ARGS__, '\n')
#define DK_LOG_OK_IMPL(file, func, line, ...) DK_LOG_PRINT(LIGHT_GREEN, " OK! ", file, func, line, __VA_ARGS__, '\n')
Expand Down
17 changes: 17 additions & 0 deletions include/resource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __DK_RESOURCE_H__
#define __DK_RESOURCE_H__

#include "status.h"

namespace dk
{

class resource
{
public:
virtual ~resource() noexcept = default;
};

}

#endif // !__DK_RESOURCE_H__
13 changes: 0 additions & 13 deletions include/sys/events/create_event.h

This file was deleted.

13 changes: 0 additions & 13 deletions include/sys/events/destroy_event.h

This file was deleted.

13 changes: 0 additions & 13 deletions include/sys/events/render_event.h

This file was deleted.

22 changes: 0 additions & 22 deletions include/sys/events/update_event.h

This file was deleted.

13 changes: 13 additions & 0 deletions include/sys/events/window_close_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __DK_SYS_WINDOW_CLOSE_EVENT_H__
#define __DK_SYS_WINDOW_CLOSE_EVENT_H__

#include "sys/event.h"

namespace dk::sys
{

class window_close_event : public event {};

}

#endif // !__DK_SYS_WINDOW_CLOSE_EVENT_H__
Loading

0 comments on commit b88a726

Please sign in to comment.