diff options
| -rw-r--r-- | meson.build | 24 | ||||
| -rw-r--r-- | src/context_glfw.cc | 51 | ||||
| -rw-r--r-- | src/context_x11.cc | 46 | ||||
| -rw-r--r-- | src/context_x11.h | 18 | ||||
| -rw-r--r-- | src/engine.cc | 26 | ||||
| -rw-r--r-- | src/engine.h | 5 | ||||
| -rw-r--r-- | src/gl.cc | 3 | ||||
| -rw-r--r-- | src/mauri.cc | 6 | ||||
| -rw-r--r-- | src/objects/object.cc | 8 | ||||
| -rw-r--r-- | src/objects/object.h | 3 | ||||
| -rw-r--r-- | src/objects/pass.cc | 21 | ||||
| -rw-r--r-- | src/objects/scene.cc | 6 | ||||
| -rw-r--r-- | src/objects/scene.h | 3 | ||||
| -rw-r--r-- | src/shader.cc | 17 | ||||
| -rw-r--r-- | src/texture.cc | 2 | ||||
| -rw-r--r-- | src/util.h | 2 | ||||
| -rw-r--r-- | src/visualizer.cc | 2 |
17 files changed, 127 insertions, 116 deletions
diff --git a/meson.build b/meson.build index 0a4b55f..09ffb93 100644 --- a/meson.build +++ b/meson.build @@ -1,21 +1,21 @@ project('mauri', 'cpp', - version : '0.1', - default_options : ['warning_level=3', 'cpp_std=c++20']) + version: '0.1', + default_options: ['warning_level=3', 'cpp_std=c++20']) if get_option('buildtype').startswith('debug') - add_project_arguments('-D_DEBUG_', language : 'cpp') + add_project_arguments('-D_DEBUG_', language: 'cpp') endif -compiler = meson.get_compiler('cpp') +compiler = meson.get_compiler('cpp') cmake = import('cmake') if host_machine.system() == 'linux' - add_project_arguments('-Wno-sign-compare', language : 'cpp') - add_project_arguments('-Wno-unused-parameter', language : 'cpp') - add_project_arguments('-Wno-unused-but-set-variable', language : 'cpp') - add_project_arguments('-Wno-missing-field-initializers', language : 'cpp') - add_project_arguments('-Wno-non-virtual-dtor', language : 'cpp') + add_project_arguments('-Wno-sign-compare', language: 'cpp') + add_project_arguments('-Wno-unused-parameter', language: 'cpp') + add_project_arguments('-Wno-unused-but-set-variable', language: 'cpp') + add_project_arguments('-Wno-missing-field-initializers', language: 'cpp') + add_project_arguments('-Wno-non-virtual-dtor', language: 'cpp') endif mauri_src = [ @@ -60,7 +60,7 @@ mauri_deps += [lz4, glm, json] if glfw.found() mauri_deps += [glfw] mauri_src += 'src/context_glfw.cc' - add_project_arguments('-DBUILD_GLFW', language : 'cpp') + add_project_arguments('-DBUILD_GLFW', language: 'cpp') endif if host_machine.system() == 'linux' @@ -71,7 +71,7 @@ if host_machine.system() == 'linux' if X11.found() and Xrender.found() and Xext.found() and GLX.found() mauri_deps += [X11, Xrender, Xext, GLX] mauri_src += 'src/context_x11.cc' - add_project_arguments('-DBUILD_X11', language : 'cpp') + add_project_arguments('-DBUILD_X11', language: 'cpp') endif endif @@ -82,7 +82,7 @@ if get_option('audio') mauri_src += 'src/visualizer.cc' mauri_deps += [gstreamer, fftw3] - add_project_arguments('-DBUILD_AUDIO', language : 'cpp') + add_project_arguments('-DBUILD_AUDIO', language: 'cpp') endif executable('mauri', mauri_src, diff --git a/src/context_glfw.cc b/src/context_glfw.cc index a5a2f09..63594eb 100644 --- a/src/context_glfw.cc +++ b/src/context_glfw.cc @@ -11,7 +11,7 @@ void ContextGLFW::close_window() glfwSetWindowShouldClose(window, GLFW_TRUE); } -void ContextGLFW::resize_window(int w, int h) +void ContextGLFW::resize_window(s32 w, s32 h) { width = w; height = h; @@ -54,7 +54,7 @@ double ContextGLFW::current_time() return glfwGetTime(); } -ContextGLFW::ContextGLFW(int width, int height, const std::string &name, bool wallpaper) +ContextGLFW::ContextGLFW(s32 width, s32 height, const std::string &name, bool wallpaper) : Context(width, height, name, wallpaper) { if (!glfwInit()) @@ -63,15 +63,52 @@ ContextGLFW::ContextGLFW(int width, int height, const std::string &name, bool wa return; } - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION_MAJOR); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GL_VERSION_MINOR); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + // https://github.com/haasn/libplacebo/blob/master/demos/window_glfw.c#L178 + struct { + s32 api; + s32 major, minor; + s32 glsl_ver; + s32 profile; + } gl_vers[] = { + { GLFW_OPENGL_API, 4, 6, 460, GLFW_OPENGL_CORE_PROFILE }, + { GLFW_OPENGL_API, 4, 5, 450, GLFW_OPENGL_CORE_PROFILE }, + { GLFW_OPENGL_API, 4, 4, 440, GLFW_OPENGL_CORE_PROFILE }, + { GLFW_OPENGL_API, 4, 0, 400, GLFW_OPENGL_CORE_PROFILE }, + { GLFW_OPENGL_API, 3, 3, 330, GLFW_OPENGL_CORE_PROFILE }, + { GLFW_OPENGL_API, 3, 2, 150, GLFW_OPENGL_CORE_PROFILE }, + { GLFW_OPENGL_API, 3, 1, 140, 0 }, + { GLFW_OPENGL_API, 3, 0, 130, 0 }, + }; - glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE); + glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); + glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE); glfwWindowHint(GLFW_SAMPLES, 4); - window = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr); + for (u32 i = 0; i < ARRAY_SIZE(gl_vers); i++) + { + glfwWindowHint(GLFW_CLIENT_API, gl_vers[i].api); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, gl_vers[i].major); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, gl_vers[i].minor); + glfwWindowHint(GLFW_OPENGL_PROFILE, gl_vers[i].profile); +#ifdef __APPLE__ + if (gl_vers[i].profile == GLFW_OPENGL_CORE_PROFILE) + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); +#endif + + window = glfwCreateWindow(width, height, name.c_str(), nullptr, nullptr); + + if (window) + { + break; + } + } + + if (!window) + { + log_error("%s", "could not create opengl context"); + return; + } glfwMakeContextCurrent(window); diff --git a/src/context_x11.cc b/src/context_x11.cc index 225ebd1..3f36aae 100644 --- a/src/context_x11.cc +++ b/src/context_x11.cc @@ -11,16 +11,13 @@ static Atom ATOM_WM_DELETE_WINDOW, ATOM__NET_ACTIVE_WINDOW; void ContextX11::disable_input() { XWMHints wmHint; - wmHint.flags = InputHint | StateHint; wmHint.input = false; wmHint.initial_state = NormalState; - - XSetWMProperties(x11_d, window, NULL, NULL, NULL, - 0, NULL, &wmHint, NULL); + XSetWMProperties(x11_d, window, NULL, NULL, NULL, 0, NULL, &wmHint, NULL); } -ContextX11::ContextX11(int width, int height, const std::string &name, bool wallpaper) +ContextX11::ContextX11(s32 width, s32 height, const std::string &name, bool wallpaper) : Context(width, height, name, wallpaper) { x11_d = XOpenDisplay(NULL); @@ -33,10 +30,10 @@ ContextX11::ContextX11(int width, int height, const std::string &name, bool wall return; } - int screen = XDefaultScreen(x11_d); + s32 screen = XDefaultScreen(x11_d); Window root = RootWindow(x11_d, screen); - static int gl_attrs[] = { + static s32 gl_attrs[] = { GLX_X_RENDERABLE, True, GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, GLX_RENDER_TYPE, GLX_RGBA_BIT, @@ -56,7 +53,7 @@ ContextX11::ContextX11(int width, int height, const std::string &name, bool wall }; // https://github.com/jarcode-foss/glava/blob/master/glava/glx_wcb.c#L383 - int fb_sz, best = -1, samp = -1; + s32 fb_sz, best = -1, samp = -1; GLXFBConfig *fbc = glXChooseFBConfig(x11_d, screen, gl_attrs, &fb_sz); if (!fbc) @@ -67,7 +64,7 @@ ContextX11::ContextX11(int width, int height, const std::string &name, bool wall XVisualInfo* xvi = glXGetVisualFromFBConfig(x11_d, fbc[t]); if (xvi) { - int samp_buf, samples; + s32 samp_buf, samples; glXGetFBConfigAttrib(x11_d, fbc[t], GLX_SAMPLE_BUFFERS, &samp_buf); glXGetFBConfigAttrib(x11_d, fbc[t], GLX_SAMPLES, &samples); XRenderPictFormat* fmt = XRenderFindVisualFormat(x11_d, xvi->visual); @@ -93,11 +90,8 @@ ContextX11::ContextX11(int width, int height, const std::string &name, bool wall XFree(fbc); XVisualInfo *vi = glXGetVisualFromFBConfig(x11_d, config); - Colormap cmap = XCreateColormap(x11_d, root, vi->visual, AllocNone); - XSetWindowAttributes swa; - swa.colormap = cmap; swa.event_mask = ExposureMask | KeyPressMask | StructureNotifyMask | PropertyChangeMask | VisibilityChangeMask; @@ -185,12 +179,11 @@ ContextX11::ContextX11(int width, int height, const std::string &name, bool wall event.xclient.data.l[1] = XInternAtom(x11_d, "_NET_WM_STATE_FULLSCREEN", false); */ - } + } XSetWMProtocols(x11_d, window, &ATOM_WM_DELETE_WINDOW, 1); - XMoveWindow(x11_d, window, 1080, 0); - //XMoveWindow(x11_d, window, 0, 0); + XMoveWindow(x11_d, window, 0, 0); XMapWindow(x11_d, window); XFlush(x11_d); @@ -205,7 +198,7 @@ ContextX11::ContextX11(int width, int height, const std::string &name, bool wall set_draw_enabled(true); } -void ContextX11::resize_window(int w, int h) +void ContextX11::resize_window(s32 w, s32 h) { width = w; height = h; @@ -216,7 +209,8 @@ void ContextX11::swap_buffers() glXSwapBuffers(x11_d, window); } -void ContextX11::raise() { +void ContextX11::raise() +{ XClientMessageEvent ev = { .type = ClientMessage, .serial = 0, @@ -225,16 +219,9 @@ void ContextX11::raise() { .window = window, .message_type = ATOM__NET_ACTIVE_WINDOW, .format = 32, - .data = { .l = { - 1, /* source indication -- `1` when coming from an application */ - 0, /* timestamp -- `0` to (attempt to) ignore */ - (long)window /* requestor's currently active window -- `0` for none */ - } - } + .data = { .l = { 1, 0, (long)window } } }; - /* Send the client message as defined by EWMH standards (usually works) */ - XSendEvent(x11_d, DefaultRootWindow(x11_d), false, StructureNotifyMask, (XEvent*) &ev); - /* Raise the client in the X11 stacking order (sometimes works, can be blocked by the WM) */ + XSendEvent(x11_d, DefaultRootWindow(x11_d), false, StructureNotifyMask, (XEvent *)&ev); XRaiseWindow(x11_d, window); XFlush(x11_d); } @@ -252,8 +239,7 @@ void ContextX11::set_clickthrough() } Window parent, *children = NULL; - unsigned int num_children; - + u32 num_children; if (XQueryTree(x11_d, win, &root, &parent, &children, &num_children)) { if (children) @@ -277,11 +263,9 @@ void ContextX11::cursor_pos(float *x, float *y) s32 root_return_x, root_return_y; s32 win_return_x, win_return_y; Window root_return, child_return; - XQueryPointer(x11_d, window, &root_return, &child_return, &root_return_x, &root_return_y, &win_return_x, &win_return_y, &ret); - *x = (f32)win_return_x; *y = (f32)win_return_y; } @@ -289,11 +273,9 @@ void ContextX11::cursor_pos(float *x, float *y) void ContextX11::process_input() { XEvent xev; - while (XPending(x11_d) > 0) { XNextEvent(x11_d, &xev); - switch (xev.type) { case ClientMessage: diff --git a/src/context_x11.h b/src/context_x11.h index c0e022c..b10cb37 100644 --- a/src/context_x11.h +++ b/src/context_x11.h @@ -17,13 +17,12 @@ #define XWIN_ALL_DESKTOPS 0xFFFFFFFF -#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 - -#define _NET_WM_STATE_REMOVE 0 -#define _NET_WM_STATE_ADD 1 -#define _NET_WM_STATE_TOGGLE 2 +#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define _NET_WM_STATE_REMOVE 0 +#define _NET_WM_STATE_ADD 1 +#define _NET_WM_STATE_TOGGLE 2 typedef GLXContext (*glXCreateContextAttribsARBProc)(Display *, GLXFBConfig, GLXContext, Bool, const s32 *); @@ -53,8 +52,7 @@ class ContextX11 : public Context { f64 current_time() { - std::chrono::duration<f64> diff = (system_clock::now() - start); - return diff.count() * 0.5; + return (system_clock::now() - start).count(); } private: @@ -64,10 +62,10 @@ class ContextX11 : public Context { void raise(); - // make the window shape 0x0 so that its unclickable + // Make the window shape 0x0 so that its unclickable. void set_clickthrough(); - // attempt to disable input by setting window hints + // Attempt to disable input by setting window hints. void disable_input(); Window window; diff --git a/src/engine.cc b/src/engine.cc index 254b06a..29d77f9 100644 --- a/src/engine.cc +++ b/src/engine.cc @@ -53,6 +53,18 @@ Engine::Engine(Scene *scene, Parser *parser, bool audio) view.center(context()->width, context()->height); +#ifdef BUILD_AUDIO + if (audio_enabled) + { + visualizer = new Visualizer(); + } +#else + audio_enabled = false; +#endif + + //rate = 1.f; + rate = 0.55f; + minimal_shader = new Shader(parser, "minimal"); minimal_shader->compile(); @@ -65,15 +77,6 @@ Engine::Engine(Scene *scene, Parser *parser, bool audio) default_model_flipped = glm::scale(default_model, vec3{1.f, -1.f, 1.f}); scene->load(this); - -#ifdef BUILD_AUDIO - if (audio_enabled) - { - visualizer = new Visualizer(); - } -#else - audio_enabled = false; -#endif } Framebuffer *Engine::get_framebuffer(const std::string &name) @@ -160,7 +163,7 @@ void Engine::draw() void Engine::run() { - const f32 TARGET_FPS = 60.f; + const f32 TARGET_FPS = 90.f; time = context()->current_time(); @@ -168,6 +171,7 @@ void Engine::run() { update(); draw(); + context()->swap_buffers(); while (context()->current_time() < time + 1.f / TARGET_FPS) { @@ -175,8 +179,6 @@ void Engine::run() } time = context()->current_time(); - - context()->swap_buffers(); } } diff --git a/src/engine.h b/src/engine.h index de0ff72..214321c 100644 --- a/src/engine.h +++ b/src/engine.h @@ -46,11 +46,8 @@ class Engine ~Engine(); View view; - Scene *scene; - Parser *parser; - #ifdef BUILD_AUDIO Visualizer *visualizer; #endif @@ -58,6 +55,7 @@ class Engine bool audio_enabled; f32 time; + f32 rate; RenderObject *default_object; @@ -67,7 +65,6 @@ class Engine Shader *minimal_shader; Framebuffer *combine_buffer; - std::vector<Framebuffer *> framebuffers; void create_framebuffer(const std::string &name, f32 width, f32 height, f32 scale); @@ -306,7 +306,7 @@ RenderTexture::RenderTexture(bool no_interp, bool clamp_uv, bool filtering, s32 void RenderTexture::upload(byte *data, s32 width, s32 height, s32 level, bool dxt, bool scale) { // Save pixels in RGBA format as a simple utility. - // NOTE: this is pretty wasteful on memory + // NOTE: This is pretty wasteful on memory. if (data != nullptr && level == 0) { pixels.resize(width * height); @@ -468,4 +468,3 @@ void Render::set_viewport(u32 wpad, u32 hpad, u32 width, u32 height) glViewport(wpad, hpad, width, height); } - diff --git a/src/mauri.cc b/src/mauri.cc index 3aa371e..3c9533f 100644 --- a/src/mauri.cc +++ b/src/mauri.cc @@ -30,7 +30,8 @@ s32 main(s32 argc, char *argv[]) gst_init(&argc, &argv); #endif - set_context(new ContextGLFW(1600, 900, "mauri", false)); + set_context(new ContextGLFW(1920, 1080, "mauri", false)); + //set_context(new ContextX11(1920, 1080, "mauri", false)); //set_context(new ContextGLFW(2560, 1440, "mauri", false)); //set_context(new ContextX11(2560, 1440, "mauri", true)); //set_context(new ContextNull(1920, 1080, "mauri", false)); @@ -47,7 +48,8 @@ s32 main(s32 argc, char *argv[]) Scene *scene = new Scene(parser, scene_path); - context()->resize_window(scene->width / 1.75, scene->height / 1.75); + //context()->resize_window(scene->width / 1.75, scene->height / 1.75); + //context()->resize_window(scene->width, scene->height); Engine engine(scene, &parser, true); diff --git a/src/objects/object.cc b/src/objects/object.cc index 4c7273b..833620a 100644 --- a/src/objects/object.cc +++ b/src/objects/object.cc @@ -23,7 +23,6 @@ Object::Object(Parser &p, json &root) // on the scene in order of deps but I'm not sure if that would // break other things. std::vector<s32>::const_iterator it = deps.begin(); - while (it != deps.end()) { bool remove = false; @@ -54,9 +53,7 @@ Object::Object(Parser &p, json &root) //origin[2] = 0.f; p.get_value<s32>(root, "colorBlendMode", &color_blend_mode, 0); - p.get_value<f32>(root, "alpha", &alpha, 1.f); - p.get_value<bool>(root, "visible", &visible, true); auto _image = root["image"]; @@ -72,11 +69,10 @@ Object::Object(Parser &p, json &root) for (auto &effect : root["effects"]) { effects.emplace_back(new Effect(p, effect)); - } } -void Object::get_model(f32 width, f32 height, bool flip) +void Object::get_model(Engine *engine, f32 width, f32 height, bool flip) { model = mat4x4(1.f); @@ -149,7 +145,7 @@ void Object::load(Engine *engine) engine->create_framebuffer(buffer_a, size[0], size[1], 1.f); engine->create_framebuffer(buffer_b, size[0], size[1], 1.f); - get_model(engine->view.width, engine->view.height, effects.size() == 0); + get_model(engine, engine->view.width, engine->view.height, effects.size() == 0); ortho = glm::ortho(-size[0], size[0], -size[1], size[1], 0.f, 1.f); diff --git a/src/objects/object.h b/src/objects/object.h index d4a31a5..37b8bce 100644 --- a/src/objects/object.h +++ b/src/objects/object.h @@ -38,13 +38,12 @@ class Object vec2 size; - void get_model(f32 width, f32 height, bool flip); + void get_model(Engine *engine, f32 width, f32 height, bool flip); mat4x4 ortho; mat4x4 model; RenderObject *gl_uv_object = nullptr; - RenderObject *gl_object = nullptr; RenderObject *gl_object_flipped = nullptr; diff --git a/src/objects/pass.cc b/src/objects/pass.cc index db5084a..feea725 100644 --- a/src/objects/pass.cc +++ b/src/objects/pass.cc @@ -1,3 +1,5 @@ +#include <thread> + #include "../assets.h" #include "../engine.h" #include "../gl.h" @@ -19,46 +21,39 @@ Pass::Pass(Parser &p, json &root, PassStage stage) { case EFFECT0_PASS: { auto _uniforms = root["constantshadervalues"]; - for (auto &value : _uniforms.items()) { uniforms.emplace_back(new UniformOverride({vec4(0.f), value.key()})); p.get_value<vec4>(_uniforms, value.key(), &uniforms.back()->value, vec4(0.f)); } - break; } case EFFECT1_PASS: { auto _material = root["material"]; - if (_material.is_string()) { material = new Material(p, _material); } auto _command = root["command"]; - if (_command.is_string() && _command == "copy") { command = COPY; } auto _target = root["target"]; - if (_target.is_string()) { target = _target; } auto _source = root["source"]; - if (_source.is_string()) { source = _source; } binds[0] = "previous"; - for (auto &bind : root["bind"]) { u32 index = bind["index"]; @@ -74,7 +69,6 @@ Pass::Pass(Parser &p, json &root, PassStage stage) } auto _textures = root["textures"]; - for (auto i = 0u; i < _textures.size(); i++) { auto texture = _textures[i]; @@ -167,18 +161,16 @@ RenderPass::RenderPass(Engine *engine, Pass *pass) command = pass->command; combine = pass->combine; - // This object contains information needed for - // getting previous framebuffer textures and targets. + // This object contains information needed for getting previous + // framebuffer textures and targets. object = pass->object; if (command == COPY) { // Target and source is the only needed information // for a COPY pass. - target = engine->get_framebuffer(pass->target); source = engine->get_framebuffer(pass->source); - return; } @@ -209,7 +201,6 @@ RenderPass::RenderPass(Engine *engine, Pass *pass) // Check if texture is referencing a framebuffer. textures[i] = engine->get_framebuffer_texture(pass->textures[i]); - if (textures[i] == nullptr) { // The texture wasn't a framebuffer so try to load it from an asset. @@ -328,9 +319,7 @@ RenderPass::RenderPass(Engine *engine, Pass *pass) robject = pass->object->gl_object; model = &pass->object->model; } - - // Default everything. - else + else // Default everything. { robject = engine->default_object; model = &engine->default_model; diff --git a/src/objects/scene.cc b/src/objects/scene.cc index 9bdc86c..6df5e02 100644 --- a/src/objects/scene.cc +++ b/src/objects/scene.cc @@ -11,7 +11,6 @@ using namespace Mauri; Scene::Scene(Parser &p, const std::string &path) { auto asset = asset_manager()->get_file(path, NONE); - if (asset->type == ASSET_VOID) { log_error("%s", "failed to open scene.json"); @@ -21,18 +20,17 @@ Scene::Scene(Parser &p, const std::string &path) auto root = json::parse(asset->as_string()); auto camera = root["camera"]; - p.get_value<vec3>(camera, "center", &cam.center, vec3(0.f)); p.get_value<vec3>(camera, "eye", &cam.eye, vec3(0.f)); p.get_value<vec3>(camera, "up", &cam.up, vec3(0.f)); auto general = root["general"]; - p.get_value<bool>(general, "clearenabled", &clear_enabled, true); p.get_value<vec4>(general, "clearcolor", &clear_color, vec4(1.f)); + p.get_value<f32>(general, "nearz", &nearz, 0.f); + p.get_value<f32>(general, "farz", &farz, 1.f); auto ortho = general["orthogonalprojection"]; - p.get_value<f32>(ortho, "width", &width, 0.f); p.get_value<f32>(ortho, "height", &height, 0.f); diff --git a/src/objects/scene.h b/src/objects/scene.h index 7dda288..8f13f3a 100644 --- a/src/objects/scene.h +++ b/src/objects/scene.h @@ -30,6 +30,9 @@ class Scene f32 width; f32 height; + f32 nearz; + f32 farz; + bool clear_enabled; vec4 clear_color; diff --git a/src/shader.cc b/src/shader.cc index ee661fd..4862bb6 100644 --- a/src/shader.cc +++ b/src/shader.cc @@ -114,12 +114,12 @@ void Shader::build_shader_source(Parser *p, const std::string &isource, std::str auto _default = root["default"]; if (!_default.is_null()) - textures[(int)uniform->default_value[0]] = _default; + textures[(s32)uniform->default_value[0]] = _default; auto combo = root["combo"]; if (!combo.is_null()) - texture_combos[(int)uniform->default_value[0]] = combo; + texture_combos[(s32)uniform->default_value[0]] = combo; break; } @@ -259,6 +259,15 @@ void Shader::bind(Engine *engine, Object *object, mat4x4 *model, std::array<Text auto texture_translation = "g_Texture" + index + "Translation"; auto texture_rotation = "g_Texture" + index + "Rotation"; + /* + glm::vec4 resolution = { + object->size[0], + object->size[1], + texture->texture_resolution[2], + texture->texture_resolution[3] + }; + rshader->set_uniform(texture_resolution, TYPE_VEC4, glm::value_ptr(resolution)); + */ rshader->set_uniform(texture_resolution, TYPE_VEC4, glm::value_ptr(texture->texture_resolution)); rshader->set_uniform(texture_translation, TYPE_VEC2, glm::value_ptr(texture->texture_translation)); rshader->set_uniform(texture_rotation, TYPE_VEC4, glm::value_ptr(texture->texture_rotation)); @@ -267,7 +276,8 @@ void Shader::bind(Engine *engine, Object *object, mat4x4 *model, std::array<Text } } - rshader->set_uniform("g_Time", TYPE_FLOAT, &engine->time); + f32 adjusted_time = engine->time * engine->rate; + rshader->set_uniform("g_Time", TYPE_FLOAT, &adjusted_time); rshader->set_uniform("g_TexelSize", TYPE_VEC2, glm::value_ptr(engine->view.texel_size)); rshader->set_uniform("g_TexelSizeHalf", TYPE_VEC2, glm::value_ptr(engine->view.texel_half_size)); @@ -280,7 +290,6 @@ void Shader::bind(Engine *engine, Object *object, mat4x4 *model, std::array<Text } mat4x4 _model, _inverse; - if (!model) _model = mat4x4(1.f); else diff --git a/src/texture.cc b/src/texture.cc index 4eaaf23..8016034 100644 --- a/src/texture.cc +++ b/src/texture.cc @@ -23,7 +23,6 @@ Texture::Texture(Asset *asset) //auto type = asset->reads(9); //auto itype = asset->reads(9); - asset->seek(18); auto format = (TextureFormat)asset->read<u32>(); @@ -171,7 +170,6 @@ Texture::Texture(Asset *asset) delete[] buffer; asset->seek(byte_count); - } } @@ -12,6 +12,8 @@ using namespace glm; #define FRAME_STEP 0 #define UNIFORM_DEBUG 0 +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) + typedef uint32_t u32; typedef int32_t s32; diff --git a/src/visualizer.cc b/src/visualizer.cc index 941ae54..ddffde2 100644 --- a/src/visualizer.cc +++ b/src/visualizer.cc @@ -61,7 +61,7 @@ void Visualizer::monstercat_smoothing(bool right) { if (i == j) continue; - const auto weighted_value = bars[i] / smoothing_factors[(int)(std::abs(i - j))]; + const auto weighted_value = bars[i] / smoothing_factors[(s32)(std::abs(i - j))]; if (bars[j] < weighted_value) { |