Commit ae3a6b71 authored by Johannes Braun's avatar Johannes Braun
Browse files

Aaand again, further cleanup. Seems okay now.

parent 89eb2e9f
#include "GBuffer.h"
#include "engine/EngineState.h"
#include <util/log.h>
#include <util/files.h>
#include "engine/graphics/Light.h"
#include "LightManager.h"
......@@ -11,8 +12,8 @@ namespace glare
GBuffer::GBuffer(unsigned int width, unsigned int height, unsigned samples) : m_width(width), m_height(height)
{
const std::vector<std::shared_ptr<glare::core::Shader>> shaders = {
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, shader("screenshader/gbuffer/gbuffer.frag"))
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, files::shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, files::shader("screenshader/gbuffer/gbuffer.frag"))
};
m_texture_renderer = std::make_unique<TextureRenderer>(std::make_shared<glare::core::ShaderProgram>(shaders));
......
......@@ -7,11 +7,6 @@ namespace glare
{
namespace core
{
fs::path shader(fs::path path)
{
return fs::path(ASSETS_PATH) / "shaders" / path;
}
Shader::Shader(gl::ShaderType type)
: m_handle(std::move(type))
{}
......
......@@ -16,8 +16,6 @@ namespace glare
{
namespace fs = std::experimental::filesystem;
fs::path shader(fs::path path);
class Shader
{
public:
......
......@@ -100,9 +100,13 @@ namespace glare
auto anim = std::make_shared<core::Animation>();
anim->duration = m_duration;
anim->interpolator = [](double value) {
//quadratic interpolator
return glm::pow(value, 2);
};
anim->on_update = [&](double, double current_value) {
m_animation_progress = float(glm::pow(current_value, 2));
m_animation_progress = float(current_value);
};
anim->on_finish = [&]() {
......
#include "TextureRenderer.h"
#include "engine/EngineState.h"
#include <util/log.h>
#include <util/files.h>
namespace glare
{
......@@ -37,8 +38,8 @@ namespace glare
std::shared_ptr<TextureRenderer> DefaultTextureRenderers::makeSimpleRenderer()
{
const std::vector<std::shared_ptr<glare::core::Shader>> shaders = {
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, shader("screenshader/simple.frag"))
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, files::shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, files::shader("screenshader/simple.frag"))
};
return std::make_shared<TextureRenderer>(std::make_shared<glare::core::ShaderProgram>(shaders));
}
......@@ -46,8 +47,8 @@ namespace glare
std::shared_ptr<TextureRenderer> DefaultTextureRenderers::makeFXAARenderer()
{
const std::vector<std::shared_ptr<glare::core::Shader>> shaders = {
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, shader("screenshader/fxaa/fxaa.frag"))
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, files::shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, files::shader("screenshader/fxaa/fxaa.frag"))
};
return std::make_shared<TextureRenderer>(std::make_shared<glare::core::ShaderProgram>(shaders));
}
......@@ -55,8 +56,8 @@ namespace glare
std::shared_ptr<TextureRenderer> DefaultTextureRenderers::makeMultisampleRenderer()
{
const std::vector<std::shared_ptr<glare::core::Shader>> shaders = {
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, shader("screenshader/multisample/multisample.frag"))
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, files::shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, files::shader("screenshader/multisample/multisample.frag"))
};
return std::make_shared<TextureRenderer>(std::make_shared<glare::core::ShaderProgram>(shaders));
}
......@@ -64,8 +65,8 @@ namespace glare
std::shared_ptr<TextureRenderer> DefaultTextureRenderers::makeCenterTextureRenderer()
{
const std::vector<std::shared_ptr<glare::core::Shader>> shaders = {
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, shader("screenshader/center_texture/center_texture.frag"))
std::make_shared<glare::core::Shader>(gl::ShaderType::eVertex, files::shader("screenshader/screen_triangle.vert")),
std::make_shared<glare::core::Shader>(gl::ShaderType::eFragment, files::shader("screenshader/center_texture/center_texture.frag"))
};
return std::make_shared<TextureRenderer>(std::make_shared<glare::core::ShaderProgram>(shaders));
}
......
#include "AudioUtilities.h"
#include <util/log.h>
namespace glare
{
namespace io
{
bool isNextCorrectTag(std::ifstream &file, uint32_t tag)
{
uint32_t data;
file.read(reinterpret_cast<char*>(&data), sizeof(uint32_t));
return tag == data;
}
AudioUtilities::wav_data_t AudioUtilities::loadWAV(const fs::path &path)
{
wav_data_t wav_data;
wav_data.data_size = -1;
std::ifstream wav_file(path, std::ios::binary | std::ios::in);
if(!isNextCorrectTag(wav_file, tag("RIFF")))
{
Log_Error << "WAV file not compatible: Missing RIFF tag";
return wav_data;
}
read(wav_file, &wav_data.file_size);
if (!isNextCorrectTag(wav_file, tag("WAVE")))
{
Log_Error << "WAV file not compatible: Missing WAVE tag";
return wav_data;
}
if (!isNextCorrectTag(wav_file, tag("fmt ")))
{
Log_Error << "WAV file not compatible: Missing format (fmt) tag";
return wav_data;
}
read(wav_file, &wav_data.chunk_size);
read(wav_file, &wav_data.format);
read(wav_file, &wav_data.channels);
read(wav_file, &wav_data.sample_rate);
read(wav_file, &wav_data.avg_bytes_per_second);
read(wav_file, &wav_data.bytes_per_sample);
read(wav_file, &wav_data.bits_per_sample);
if (!isNextCorrectTag(wav_file, tag("data")))
{
Log_Error << "WAV file not compatible: Missing data tag";
return wav_data;
}
read(wav_file, &wav_data.data_size);
wav_data.data.resize(wav_data.data_size);
wav_file.read(reinterpret_cast<char*>(wav_data.data.data()), wav_data.data.size() * sizeof(char)); //sizeof(char) is 1, but whatever, right?
return wav_data;
}
}
}
#ifndef __AUDIOUTILITIES_H
#define __AUDIOUTILITIES_H
#include <filesystem>
#include <fstream>
#include <vector>
namespace glare
{
namespace io
{
constexpr uint32_t tag(char name[4])
{
return ((uint32_t(name[0]) & 0xFF) | ((uint32_t(name[1]) & 0xFF) << 8) | ((uint32_t(name[2]) & 0xFF) << 16) | ((uint32_t(name[3]) & 0xFF) << 24));
}
namespace fs = std::experimental::filesystem;
template<typename T>
void read(std::ifstream &file, T* target)
{
file.read(reinterpret_cast<char*>(target), sizeof(T));
}
namespace AudioUtilities
{
struct wav_data_t
{
uint32_t chunk_size;
uint16_t format;
uint16_t channels;
uint32_t sample_rate;
uint32_t avg_bytes_per_second;
uint16_t bytes_per_sample;
uint16_t bits_per_sample;
uint32_t file_size;
uint32_t data_size;
std::vector<unsigned char> data;
};
wav_data_t loadWAV(const fs::path &path);
}
}
}
#endif //__AUDIOUTILITIES_H
......@@ -172,7 +172,7 @@ namespace glare
Log_Info << "Compiling construction shader...";
Log_Warn << "Caution: This will influence the construction time by a lot, so don't rely on the next time measurement for performance purposes.";
core::ClockMS compile_timer;
m_construction_shader = core::ShaderProgram::makeUnique(core::shader("/raytracer/linespace_generate.compute").string());
m_construction_shader = core::ShaderProgram::makeUnique(files::shader("/raytracer/linespace_generate.compute").string());
Log_Warn << "Compilation took " << compile_timer.time() << "ms";
}
......@@ -324,9 +324,9 @@ namespace glare
: m_linespace(linespace), m_collector(collector)
{
std::vector<std::shared_ptr<core::Shader>> shaders = {
std::make_shared<core::Shader>(gl::ShaderType::eVertex, "/linespace/visualize/lines.vert"),
std::make_shared<core::Shader>(gl::ShaderType::eGeometry, "/linespace/visualize/lines.geom"),
std::make_shared<core::Shader>(gl::ShaderType::eFragment, "/linespace/visualize/lines.frag")
std::make_shared<core::Shader>(gl::ShaderType::eVertex, files::shader("/linespace/visualize/lines.vert")),
std::make_shared<core::Shader>(gl::ShaderType::eGeometry, files::shader("/linespace/visualize/lines.geom")),
std::make_shared<core::Shader>(gl::ShaderType::eFragment, files::shader("/linespace/visualize/lines.frag"))
};
m_program = std::make_unique<core::ShaderProgram>(shaders);
m_vertex_array = std::make_unique<core::VertexArray>();
......
#include "audio.h"
// --------------- STDLIB ---------------
#include <fstream>
// --------------- EXTERN ---------------
#include <util/files.h>
#include <util/log.h>
// --------------- INTERN ---------------
namespace audio
{
wave_t loadWAV(const fs::path &path)
{
wave_t wave;
wave.data_size = -1;
std::ifstream wav_file(path, std::ios::binary | std::ios::in);
if (files::readOne<uint32_t>(wav_file) != tag("RIFF"))
{
Log_Error << "WAV file not compatible: Missing RIFF tag";
return wave;
}
files::readOne(wav_file, &wave.file_size);
if (files::readOne<uint32_t>(wav_file) != tag("WAVE"))
{
Log_Error << "WAV file not compatible: Missing WAVE tag";
return wave;
}
if (files::readOne<uint32_t>(wav_file) != tag("fmt "))
{
Log_Error << "WAV file not compatible: Missing format (fmt) tag";
return wave;
}
files::readOne(wav_file, &wave.chunk_size);
files::readOne(wav_file, &wave.format);
files::readOne(wav_file, &wave.channels);
files::readOne(wav_file, &wave.sample_rate);
files::readOne(wav_file, &wave.avg_bytes_per_second);
files::readOne(wav_file, &wave.bytes_per_sample);
files::readOne(wav_file, &wave.bits_per_sample);
if (files::readOne<uint32_t>(wav_file) != tag("data"))
{
Log_Error << "WAV file not compatible: Missing data tag";
return wave;
}
files::readOne(wav_file, &wave.data_size);
wave.data.resize(wave.data_size);
wav_file.read(reinterpret_cast<char*>(wave.data.data()), wave.data.size() * sizeof(char));
return wave;
}
}
\ No newline at end of file
#ifndef INCLUDE_AUDIO_H
#define INCLUDE_AUDIO_H
// --------------- STDLIB ---------------
#include <cinttypes>
#include <filesystem>
// --------------- EXTERN ---------------
// --------------- INTERN ---------------
namespace fs = std::experimental::filesystem;
namespace audio
{
constexpr uint32_t tag(char name[4])
{
return ((uint32_t(name[0]) & 0xFF) | ((uint32_t(name[1]) & 0xFF) << 8) | ((uint32_t(name[2]) & 0xFF) << 16) | ((uint32_t(name[3]) & 0xFF) << 24));
}
struct wave_t
{
uint32_t chunk_size;
uint16_t format;
uint16_t channels;
uint32_t sample_rate;
uint32_t avg_bytes_per_second;
uint16_t bytes_per_sample;
uint16_t bits_per_sample;
uint32_t file_size;
uint32_t data_size;
std::vector<unsigned char> data;
};
wave_t loadWAV(const fs::path &path);
}
#endif //INCLUDE_AUDIO_H
......@@ -16,6 +16,20 @@ namespace files
// -- TEXT FILES --
std::string loadText(const fs::path &path);
void saveText(const fs::path& path, const fs::path &content);
template<typename T>
inline void readOne(std::ifstream &file, T* target)
{
file.read(reinterpret_cast<char*>(target), sizeof(T));
}
template<typename T>
inline T readOne(std::ifstream &file)
{
T value;
file.read(reinterpret_cast<char*>(&value), sizeof(T));
return value;
}
}
#endif //__FILES_H
#include "text.h"
// --------------- STDLIB ---------------
// --------------- EXTERN ---------------
// --------------- INTERN ---------------
namespace text
{
std::wstring to_wstring(const std::string &input)
{
//make text unsigned (const char* to const unsigned char*) as it's needed for conversion.
const unsigned char* ch_text = reinterpret_cast<const unsigned char*>(input.data());
return std::wstring(&ch_text[0], &ch_text[input.size()]);
}
bool isLineBreakable(wchar_t character)
{
return (character == ' ' || character == '-' || character == '+' || character == '*' || character == '/');
}
}
\ No newline at end of file
#ifndef INCLUDE_TEXT_H
#define INCLUDE_TEXT_H
// --------------- STDLIB ---------------
#include <string>
// --------------- EXTERN ---------------
// --------------- INTERN ---------------
namespace text
{
std::wstring to_wstring(const std::string &input);
bool isLineBreakable(wchar_t character);
}
#endif //INCLUDE_TEXT_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment