diff options
| author | 2020-10-01 05:24:29 -0400 | |
|---|---|---|
| committer | 2020-10-01 05:24:29 -0400 | |
| commit | 5e981cd004ac092f35588ebdc4e58e03131296b3 (patch) | |
| tree | 8dcb262db78fdc5a3a7cde627a7f73f2f34f7c79 /src | |
| parent | 4c200513158ad0b974cda961deffe6192830ecae (diff) | |
| download | mauri-5e981cd004ac092f35588ebdc4e58e03131296b3.tar.gz mauri-5e981cd004ac092f35588ebdc4e58e03131296b3.tar.bz2 mauri-5e981cd004ac092f35588ebdc4e58e03131296b3.zip | |
cleanup 'todo' usage
Diffstat (limited to 'src')
| -rw-r--r-- | src/assets.cc | 96 | ||||
| -rw-r--r-- | src/context.h | 3 | ||||
| -rw-r--r-- | src/context_glfw.cc | 19 | ||||
| -rw-r--r-- | src/context_x11.cc | 3 | ||||
| -rw-r--r-- | src/engine.cc | 72 | ||||
| -rw-r--r-- | src/gl.cc | 90 | ||||
| -rw-r--r-- | src/objects/effect.cc | 32 | ||||
| -rw-r--r-- | src/objects/material.cc | 6 | ||||
| -rw-r--r-- | src/objects/model.cc | 14 | ||||
| -rw-r--r-- | src/objects/object.cc | 120 | ||||
| -rw-r--r-- | src/objects/pass.cc | 170 | ||||
| -rw-r--r-- | src/objects/scene.cc | 57 | ||||
| -rw-r--r-- | src/objects/scene.h | 21 | ||||
| -rw-r--r-- | src/texture.cc | 82 |
14 files changed, 359 insertions, 426 deletions
diff --git a/src/assets.cc b/src/assets.cc index 6b34c03..71a9f26 100644 --- a/src/assets.cc +++ b/src/assets.cc @@ -10,99 +10,73 @@ using namespace Mauri; Asset::Asset() { - this->type = ASSET_VOID; - this->size = 0; - this->pos = 0; - this->data = nullptr; - this->hash = 0; + type = ASSET_VOID; + size = 0; + pos = 0; + data = nullptr; + hash = 0; } static Asset asset_void = Asset(); Asset::Asset(std::string path, byte *begin, byte *end) { - this->type = ASSET_SLICE; - this->size = end - begin; - this->pos = 0; - this->data = begin; - this->hash = std::hash<std::string>{}(path); + type = ASSET_SLICE; + size = end - begin; + pos = 0; + data = begin; + hash = std::hash<std::string>{}(path); } Asset::Asset(std::string path) { - //FILE *file = fopen(path.c_str(), "rb"); - - //if (file == NULL) - // return; - - //this->type = ASSET_FILE; - //this->pos = 0; - //this->hash = std::hash<std::string>{}(path); - - //fseek(file, 0, SEEK_END); - - //this->size = ftell(file); - //this->data = (unsigned char *)malloc(this->size); - - //rewind(file); - - //size_t res = fread(this->data, 1, this->size, file); - - //fclose(file); - - //if (res != this->size) { - // log_error("failed to read file (%s)", path.c_str()); - // free(this->data); - // return; - //} - std::ifstream file(path, std::ios::binary | std::ios::ate); if (file.bad() || file.fail()) { - this->type = ASSET_VOID; + type = ASSET_VOID; file.close(); return; } - this->size = file.tellg(); - this->data = new byte[this->size]; + size = file.tellg(); + data = new byte[size]; file.seekg(0, std::ios::beg); - if (!file.read(reinterpret_cast<char *>(this->data), this->size)) + if (!file.read(reinterpret_cast<char *>(data), size)) { - this->type = ASSET_VOID; + type = ASSET_VOID; file.close(); return; } file.close(); - this->pos = 0; - this->type = ASSET_FILE; + pos = 0; + type = ASSET_FILE; - this->hash = std::hash<std::string>{}(path); + hash = std::hash<std::string>{}(path); } Asset::~Asset() { - if (this->type == ASSET_FILE) + if (type == ASSET_FILE) { - delete[] this->data; + delete[] data; } } bool AssetManager::load_package(std::string path) { - this->pkg = new Asset(path); + pkg = new Asset(path); - if (this->pkg->type == ASSET_VOID) + if (pkg->type == ASSET_VOID) { log_error("failed to load pkg file: (%s)", path.c_str()); return false; }; - auto signature = this->pkg->reads(this->pkg->read<u32>()); + auto signature = pkg->reads(pkg->read<u32>()); if (signature.compare(0, 4, "PKGV") != 0) { @@ -110,7 +84,7 @@ bool AssetManager::load_package(std::string path) return false; } - auto count = this->pkg->read<u32>(); + auto count = pkg->read<u32>(); std::vector<PkgFile> pkg_files; pkg_files.reserve(count); @@ -118,18 +92,18 @@ bool AssetManager::load_package(std::string path) for (auto i = 0; i < count; i++) { pkg_files.emplace_back((PkgFile) { - this->pkg->reads(this->pkg->read<u32>()), - this->pkg->read<u32>(), - this->pkg->read<u32>() + pkg->reads(pkg->read<u32>()), + pkg->read<u32>(), + pkg->read<u32>() }); } for (auto file : pkg_files) { - this->files.push_back( + files.push_back( new Asset(std::string(file.path), - this->pkg->ptr() + file.offset, - this->pkg->ptr() + file.offset + file.length)); + pkg->ptr() + file.offset, + pkg->ptr() + file.offset + file.length)); log_debug("loaded file (%s)", std::string(file.path).c_str()); } @@ -163,7 +137,7 @@ Asset *AssetManager::get_file(std::string path, FileTypeHint hint) u64 hash = std::hash<std::string>{}(path); - for (auto &file : this->files) + for (auto &file : files) { if (file->hash == hash) { @@ -181,18 +155,18 @@ Asset *AssetManager::get_file(std::string path, FileTypeHint hint) return &asset_void; } - this->files.push_back(std::move(asset)); + files.push_back(std::move(asset)); - return this->files.back(); + return files.back(); } AssetManager::~AssetManager() { - for (auto &file : this->files) + for (auto &file : files) { delete file; } - delete this->pkg; + delete pkg; } namespace Mauri diff --git a/src/context.h b/src/context.h index a4f2342..09ba01e 100644 --- a/src/context.h +++ b/src/context.h @@ -13,7 +13,8 @@ namespace Mauri class Context { public: - Context(int width, int height, std::string name, bool wallpaper) {} + Context(int width, int height, std::string name, bool wallpaper) + : width(width), height(height) {} virtual ~Context() {} diff --git a/src/context_glfw.cc b/src/context_glfw.cc index 2900f15..21e2ef3 100644 --- a/src/context_glfw.cc +++ b/src/context_glfw.cc @@ -8,32 +8,32 @@ using namespace Mauri; void ContextGLFW::close_window() { - glfwSetWindowShouldClose(this->window, GLFW_TRUE); + glfwSetWindowShouldClose(window, GLFW_TRUE); } -void ContextGLFW::resize_window(int width, int height) +void ContextGLFW::resize_window(int nwidth, int nheight) { - this->width = width; - this->height = height; - glfwSetWindowSize(this->window, width, height); + width = nwidth; + height = nheight; + glfwSetWindowSize(window, width, height); } bool ContextGLFW::should_close() const { - return glfwWindowShouldClose(this->window); + return glfwWindowShouldClose(window); } void ContextGLFW::cursor_pos(f32 *x, f32 *y) { f64 _x, _y; - glfwGetCursorPos(this->window, &_x, &_y); + glfwGetCursorPos(window, &_x, &_y); *x = (f32)_x; *y = (f32)_y; } void ContextGLFW::swap_buffers() { - glfwSwapBuffers(this->window); + glfwSwapBuffers(window); } void ContextGLFW::process_input() @@ -49,9 +49,6 @@ double ContextGLFW::current_time() ContextGLFW::ContextGLFW(int width, int height, std::string name, bool wallpaper) : Context(width, height, name, wallpaper) { - this->width = width; - this->height = height; - if (!glfwInit()) { log_print("err", "failed to init glfw"); diff --git a/src/context_x11.cc b/src/context_x11.cc index 898aa86..347bbe4 100644 --- a/src/context_x11.cc +++ b/src/context_x11.cc @@ -22,9 +22,6 @@ void ContextX11::disable_input() ContextX11::ContextX11(int width, int height, std::string name, bool wallpaper) : Context(width, height, name, wallpaper) { - this->width = width; - this->height = height; - x11_d = XOpenDisplay(NULL); ATOM_WM_DELETE_WINDOW = XInternAtom(x11_d, "WM_DELETE_WINDOW", true); diff --git a/src/engine.cc b/src/engine.cc index fc76bdd..83bea7d 100644 --- a/src/engine.cc +++ b/src/engine.cc @@ -15,8 +15,8 @@ using namespace Mauri; void View::center_scale(float w1, float h1) { - auto w0 = this->width; - auto h0 = this->height; + auto w0 = width; + auto h0 = height; auto w_scale = w1 / w0; auto h_scale = h1 / h0; @@ -38,53 +38,51 @@ void View::default_viewport(float w0, float h0) } Engine::Engine(Scene *scene, Context *context) + : context(context), scene(scene) { - this->scene = scene; - this->context = context; + view.width = scene->width; + view.height = scene->height; - this->view.width = scene->width; - this->view.height = scene->height; + view.texel_size[0] = 1.f / scene->width; + view.texel_size[1] = 1.f / scene->height; - this->view.texel_size[0] = 1.f / scene->width; - this->view.texel_size[1] = 1.f / scene->height; + view.texel_half_size[0] = .5f / scene->width; + view.texel_half_size[1] = .5f / scene->height; - this->view.texel_half_size[0] = .5f / scene->width; - this->view.texel_half_size[1] = .5f / scene->height; - - this->texture_cache.reserve(100); + //texture_cache.reserve(100); auto combine = std::string("_rt_FullFrameBuffer"); - this->new_framebuffer(combine, this->context->width, this->context->height, 1.f); - this->combine_buffer = this->get_framebuffer(combine); + new_framebuffer(combine, context->width, context->height, 1.f); + combine_buffer = get_framebuffer(combine); - this->default_object = new RenderObject(DEFAULT); - this->identity = mat4x4(1.f); + default_object = new RenderObject(DEFAULT); + identity = mat4x4(1.f); - this->scene->load(this); + scene->load(this); } Framebuffer *Engine::get_framebuffer(std::string name) { - return this->framebuffers[name]; + return framebuffers[name]; } Texture *Engine::get_framebuffer_texture(std::string name) { - return this->framebuffers[name]->texture; + return framebuffers[name]->texture; } void Engine::new_framebuffer(std::string name, f32 width, f32 height, f32 scale) { - this->framebuffers[name] = new Framebuffer(width, height, scale); + framebuffers[name] = new Framebuffer(width, height, scale); } void Engine::update() { - this->context->process_input(); - this->time = this->context->current_time(); + context->process_input(); + time = context->current_time(); - for (auto &object: this->scene->objects) + for (auto &object: scene->objects) { object->update(this); } @@ -92,47 +90,47 @@ void Engine::update() void Engine::draw() { - for (auto& buffer : this->framebuffers) + for (auto& buffer : framebuffers) { if (buffer.second != nullptr) buffer.second->buffer->clear((vec4){0.f, 0.f, 0.f, 0.f}); } - if (this->scene->clear_enabled) - this->combine_buffer->buffer->clear(this->scene->clear_color); + if (scene->clear_enabled) + combine_buffer->buffer->clear(scene->clear_color); - this->scene->draw(this); + scene->draw(this); - this->combine_buffer->buffer->blit(this->context->width, this->context->height); + combine_buffer->buffer->blit(context->width, context->height); } void Engine::run() { const f32 TARGET_FPS = 60.f; - f32 time = this->context->current_time(); + f32 time = context->current_time(); - while (!this->context->should_close()) + while (!context->should_close()) { - this->update(); - this->draw(); + update(); + draw(); - while (this->context->current_time() < time + 1.f / TARGET_FPS) + while (context->current_time() < time + 1.f / TARGET_FPS) { std::this_thread::sleep_for(std::chrono::milliseconds(2)); } - time = this->context->current_time(); + time = context->current_time(); - this->context->swap_buffers(); + context->swap_buffers(); } } Engine::~Engine() { - for (auto &buffer : this->framebuffers) + for (auto &buffer : framebuffers) { delete buffer.second; } - delete this->default_object; + delete default_object; } @@ -15,11 +15,11 @@ void RenderObject::set_data(f32 *vertices, s32 vertex_count) if (!gl_initialized) return; #endif - glGenVertexArrays(1, &this->vao); - glBindVertexArray(this->vao); + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); - glGenBuffers(1, &this->vbo); - glBindBuffer(GL_ARRAY_BUFFER, this->vbo); + glGenBuffers(1, &vbo); + glBindBuffer(GL_ARRAY_BUFFER, vbo); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); @@ -36,8 +36,8 @@ void RenderObject::bind() if (!gl_initialized) return; #endif - glBindVertexArray(this->vao); - glBindBuffer(GL_ARRAY_BUFFER, this->vbo); + glBindVertexArray(vao); + glBindBuffer(GL_ARRAY_BUFFER, vbo); } RenderObject::RenderObject(RenderObjType type, f32 width, f32 height) @@ -57,7 +57,7 @@ RenderObject::RenderObject(RenderObjType type, f32 width, f32 height) 1.f, 1.f, 0.f, 1.f, 1.f, 1.f, -1.f, 0.f, 1.f, 0.f }; - this->set_data(vertices, sizeof(vertices)); + set_data(vertices, sizeof(vertices)); break; } case RenderObjType::UV_SCALE: { @@ -74,7 +74,7 @@ RenderObject::RenderObject(RenderObjType type, f32 width, f32 height) width, height, 0.f, x_scale, y_scale, width, -height, 0.f, x_scale, 0.f }; - this->set_data(vertices, sizeof(vertices)); + set_data(vertices, sizeof(vertices)); break; } case RenderObjType::OBJECT: { @@ -86,7 +86,7 @@ RenderObject::RenderObject(RenderObjType type, f32 width, f32 height) width, -height, 0.f, 1.f, 1.f, width, height, 0.f, 1.f, 0.f }; - this->set_data(vertices, sizeof(vertices)); + set_data(vertices, sizeof(vertices)); break; } } @@ -98,8 +98,8 @@ RenderObject::~RenderObject() if (!gl_initialized) return; #endif - glDeleteVertexArrays(1, &this->vao); - glDeleteBuffers(1, &this->vbo); + glDeleteVertexArrays(1, &vao); + glDeleteBuffers(1, &vbo); } bool RenderShader::compile(u32 program, const char *source, char *error) @@ -131,29 +131,29 @@ RenderShader::RenderShader(std::string vs_source, std::string fs_source) if (!gl_initialized) return; #endif - this->uniform_locations.clear(); - this->program = glCreateProgram(); + uniform_locations.clear(); + program = glCreateProgram(); char error[256]; u32 vs_shader = glCreateShader(GL_VERTEX_SHADER); - if (!this->compile(vs_shader, vs_source.c_str(), error)) + if (!compile(vs_shader, vs_source.c_str(), error)) { log_error("failed to compile vertex shader (%s)", error); return; } u32 fs_shader = glCreateShader(GL_FRAGMENT_SHADER); - if (!this->compile(fs_shader, fs_source.c_str(), error)) + if (!compile(fs_shader, fs_source.c_str(), error)) { log_error("failed to compile fragment shader (%s)", error); return; } - glAttachShader(this->program, vs_shader); - glAttachShader(this->program, fs_shader); + glAttachShader(program, vs_shader); + glAttachShader(program, fs_shader); - glLinkProgram(this->program); + glLinkProgram(program); } void RenderShader::bind() @@ -162,7 +162,7 @@ void RenderShader::bind() if (!gl_initialized) return; #endif - glUseProgram(this->program); + glUseProgram(program); } RenderShader::~RenderShader() @@ -171,7 +171,7 @@ RenderShader::~RenderShader() if (!gl_initialized) return; #endif - glDeleteShader(this->program); + glDeleteShader(program); } s32 RenderShader::uniform_loc(std::string &name) @@ -180,12 +180,12 @@ s32 RenderShader::uniform_loc(std::string &name) if (!gl_initialized) return; #endif - auto loc = this->uniform_locations.find(name); + auto loc = uniform_locations.find(name); - if (loc == this->uniform_locations.end()) + if (loc == uniform_locations.end()) { - this->uniform_locations[name] = glGetUniformLocation(this->program, name.c_str()); - return this->uniform_locations[name]; + uniform_locations[name] = glGetUniformLocation(program, name.c_str()); + return uniform_locations[name]; } else return loc->second; @@ -197,7 +197,7 @@ void RenderShader::set_uniform(std::string name, UniformType type, f32 *value) if (!gl_initialized) return; #endif - auto loc = this->uniform_loc(name); + auto loc = uniform_loc(name); switch (type) { @@ -231,7 +231,7 @@ void RenderTexture::bind(s32 index) #endif glActiveTexture(GL_TEXTURE0 + index); - glBindTexture(GL_TEXTURE_2D, this->id); + glBindTexture(GL_TEXTURE_2D, id); } RenderTexture::RenderTexture(bool interp, bool clamp_uv, s32 mm_count) @@ -240,9 +240,9 @@ RenderTexture::RenderTexture(bool interp, bool clamp_uv, s32 mm_count) if (!gl_initialized) return; #endif - glGenTextures(1, &this->id); + glGenTextures(1, &id); - glBindTexture(GL_TEXTURE_2D, this->id); + glBindTexture(GL_TEXTURE_2D, id); if (interp) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -274,7 +274,7 @@ void RenderTexture::upload(byte *data, s32 width, s32 height, s32 level, u32 for if (!gl_initialized) return; #endif - this->bind(0); + bind(0); if (scale) { @@ -308,27 +308,23 @@ RenderTexture::~RenderTexture() if (!gl_initialized) return; #endif - glDeleteTextures(1, &this->id); + glDeleteTextures(1, &id); } -RenderFramebuffer::RenderFramebuffer(f32 width, f32 height, f32 scale) +RenderFramebuffer::RenderFramebuffer(f32 width0, f32 height0, f32 scale) + : width(width0 / scale), height(height0 / scale) { #ifdef __DEBUG__ if (!gl_initialized) return; #endif - this->width = width / scale; - this->height = height / scale; + texture = new RenderTexture(false, false, 1); + texture->upload(nullptr, width, height, 0, GL_RGBA, false); - this->texture = new RenderTexture(false, false, 1); + glGenFramebuffers(1, &id); + glBindFramebuffer(GL_FRAMEBUFFER, id); - glGenFramebuffers(1, &this->id); - - this->texture->upload(nullptr, this->width, this->height, 0, GL_RGBA, false); - - glBindFramebuffer(GL_FRAMEBUFFER, this->id); - - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, this->texture->id, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture->id, 0); GLenum attatchment[] = {GL_COLOR_ATTACHMENT0}; glDrawBuffers(1, attatchment); @@ -340,19 +336,19 @@ void RenderFramebuffer::bind() if (!gl_initialized) return; #endif - glBindFramebuffer(GL_FRAMEBUFFER, this->id); + glBindFramebuffer(GL_FRAMEBUFFER, id); } void RenderFramebuffer::blit(f32 width, f32 height) { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); - glBindFramebuffer(GL_READ_FRAMEBUFFER, this->id); - glBlitFramebuffer(0, this->height, this->width, 0, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glBindFramebuffer(GL_READ_FRAMEBUFFER, id); + glBlitFramebuffer(0, height, width, 0, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); } void RenderFramebuffer::clear(vec4 color) { - glBindFramebuffer(GL_FRAMEBUFFER, this->id); + glBindFramebuffer(GL_FRAMEBUFFER, id); glClearBufferfv(GL_COLOR, 0, glm::value_ptr(color)); } @@ -362,7 +358,7 @@ RenderFramebuffer::~RenderFramebuffer() if (!gl_initialized) return; #endif - delete this->texture; - glDeleteFramebuffers(1, &this->id); + delete texture; + glDeleteFramebuffers(1, &id); } diff --git a/src/objects/effect.cc b/src/objects/effect.cc index 7f22ef0..cde37e6 100644 --- a/src/objects/effect.cc +++ b/src/objects/effect.cc @@ -18,13 +18,13 @@ using namespace Mauri; Effect::Effect(Json::Value root) { - this->id = root["id"].asInt(); + id = root["id"].asInt(); - this->visible = json_user_value(root.get("visible", true)).asBool(); + visible = json_user_value(root.get("visible", true)).asBool(); for (auto &pass0 : root["passes"]) { - this->passes0.emplace_back(new Pass(pass0, EFFECT0_PASS)); + passes0.emplace_back(new Pass(pass0, EFFECT0_PASS)); } auto asset = asset_manager()->get_file(root["file"].asString(), NONE); @@ -34,43 +34,43 @@ Effect::Effect(Json::Value root) Json::Value file = asset->as_json(); - this->name = file["name"].asString(); + name = file["name"].asString(); for (auto &pass1 : file["passes"]) { - this->passes1.emplace_back(new Pass(pass1, EFFECT1_PASS)); + passes1.emplace_back(new Pass(pass1, EFFECT1_PASS)); } for (auto &fbo : file["fbos"]) { - this->fbos.emplace_back((EffectBuffer) { fbo["name"].asString(), fbo["scale"].asFloat() }); + fbos.emplace_back((EffectBuffer) { fbo["name"].asString(), fbo["scale"].asFloat() }); } } void Effect::load(Engine *engine, Object *object, bool last_effect) { - if (!this->visible) + if (!visible) return; - this->buffer_id = fmt::format("{}_{}", this->id, object->id); + buffer_id = fmt::format("{}_{}", id, object->id); - for (auto &fbo : this->fbos) + for (auto &fbo : fbos) { - fbo.name.append(this->buffer_id); + fbo.name.append(buffer_id); engine->new_framebuffer(fbo.name, object->size[0], object->size[1], fbo.scale); } - for (int i = 0; i < this->passes0.size(); i++) + for (int i = 0; i < passes0.size(); i++) { Pass *pass = new Pass(); - pass->combine = (i == (this->passes0.size() - 1)) && last_effect; + pass->combine = (i == (passes0.size() - 1)) && last_effect; pass->object = object; pass->effect = this; - this->passes0[i]->load(EFFECT0_PASS, pass); - this->passes1[i]->load(EFFECT1_PASS, pass); + passes0[i]->load(EFFECT0_PASS, pass); + passes1[i]->load(EFFECT1_PASS, pass); object->passes.push_back(pass); } @@ -78,12 +78,12 @@ void Effect::load(Engine *engine, Object *object, bool last_effect) Effect::~Effect() { - for (auto &pass0 : this->passes0) + for (auto &pass0 : passes0) { delete pass0; } - for (auto &pass1 : this->passes1) + for (auto &pass1 : passes1) { delete pass1; } diff --git a/src/objects/material.cc b/src/objects/material.cc index 4c61cbc..59ac759 100644 --- a/src/objects/material.cc +++ b/src/objects/material.cc @@ -25,13 +25,13 @@ Material::Material(std::string path) for (auto &pass : root["passes"]) { - this->passes0.push_back(new Pass(pass, MATERIAL_PASS)); + passes0.push_back(new Pass(pass, MATERIAL_PASS)); } } void Material::load(Object *object, MaterialType type, Pass *pass, bool no_effects) { - for (auto &pass0 : this->passes0) + for (auto &pass0 : passes0) { switch (type) { @@ -57,7 +57,7 @@ void Material::load(Object *object, MaterialType type, Pass *pass, bool no_effec Material::~Material() { - for (auto &pass0 : this->passes0) + for (auto &pass0 : passes0) { delete pass0; } diff --git a/src/objects/model.cc b/src/objects/model.cc index 59c1cb3..322c188 100644 --- a/src/objects/model.cc +++ b/src/objects/model.cc @@ -21,20 +21,20 @@ Model::Model(std::string path) Json::Value root = asset->as_json(); - this->autosize = root.get("autosize", true).asBool(); - this->fullscreen = root.get("fullscreen", false).asBool(); - this->passthrough = root.get("passthrough", false).asBool(); + autosize = root.get("autosize", true).asBool(); + fullscreen = root.get("fullscreen", false).asBool(); + passthrough = root.get("passthrough", false).asBool(); - this->material = new Material(root["material"].asString()); + material = new Material(root["material"].asString()); } void Model::load(Object *object, bool no_effects) { - this->material->load(object, MATERIAL_MODEL, NULL, no_effects); + material->load(object, MATERIAL_MODEL, NULL, no_effects); } Model::~Model() { - if (this->material != nullptr) - delete this->material; + if (material != nullptr) + delete material; } diff --git a/src/objects/object.cc b/src/objects/object.cc index a356637..6cc775f 100644 --- a/src/objects/object.cc +++ b/src/objects/object.cc @@ -21,105 +21,105 @@ using namespace Mauri; Object::Object(Json::Value root) { - this->id = root["id"].asInt(); - this->name = root["name"].asString(); + id = root["id"].asInt(); + name = root["name"].asString(); for (auto &id : root["dependencies"]) - this->deps.push_back(id.asInt()); + deps.push_back(id.asInt()); - sscanf_vec3(json_user_value(root.get("angles", "")).asCString(), this->angles); - sscanf_vec3(json_user_value(root.get("colors", "")).asCString(), this->color); - sscanf_vec2(json_user_value(root.get("size", "")).asCString(), this->size); - sscanf_vec3(json_user_value(root.get("scale", "")).asCString(), this->scale); - sscanf_vec3(json_user_value(root.get("origin", "")).asCString(), this->origin); + sscanf_vec3(json_user_value(root.get("angles", "")).asCString(), angles); + sscanf_vec3(json_user_value(root.get("colors", "")).asCString(), color); + sscanf_vec2(json_user_value(root.get("size", "")).asCString(), size); + sscanf_vec3(json_user_value(root.get("scale", "")).asCString(), scale); + sscanf_vec3(json_user_value(root.get("origin", "")).asCString(), origin); - this->color_blend_mode = (BlendMode)root.get("colorblendmode", 0).asInt(); + color_blend_mode = (BlendMode)root.get("colorblendmode", 0).asInt(); - this->visible = json_user_value(root.get("visible", true)).asBool(); + visible = json_user_value(root.get("visible", true)).asBool(); auto _image = root["image"]; if (!_image.isNull()) - this->image = new Model(_image.asString()); + image = new Model(_image.asString()); auto config = root["config"]; if (!config.isNull()) - this->passthrough = config.get("passthrough", false).asBool(); + passthrough = config.get("passthrough", false).asBool(); for (auto &effect : root["effects"]) { - this->effects.emplace_back(new Effect(effect)); + effects.emplace_back(new Effect(effect)); } } void Object::get_model(f32 width, f32 height, bool flip) { - this->model = mat4x4(1.f); + model = mat4x4(1.f); - this->model = glm::translate(this->model, (vec3){-width, -height, 0.f}); - this->model = glm::translate(this->model, this->origin * 2.f); + model = glm::translate(model, (vec3){-width, -height, 0.f}); + model = glm::translate(model, origin * 2.f); - this->model = glm::rotate(this->model, this->angles[0], (vec3){1.f, 0.f, 0.f}); - this->model = glm::rotate(this->model, this->angles[1], (vec3){0.f, 1.f, 0.f}); - this->model = glm::rotate(this->model, this->angles[2], (vec3){0.f, 0.f, 1.f}); + model = glm::rotate(model, angles[0], (vec3){1.f, 0.f, 0.f}); + model = glm::rotate(model, angles[1], (vec3){0.f, 1.f, 0.f}); + model = glm::rotate(model, angles[2], (vec3){0.f, 0.f, 1.f}); - this->model = glm::scale(this->model, this->scale); + model = glm::scale(model, scale); mat4x4 _ortho = glm::ortho(-width, width, height, -height, 0.f, 1.f); if (flip) { - this->model = glm::scale(this->model, (vec3){1.f, -1.f, 1.f}); + model = glm::scale(model, (vec3){1.f, -1.f, 1.f}); } - this->model = _ortho * this->model; + model = _ortho * model; } void Object::load(Engine *engine) { - if (this->loaded || !this->visible) + if (loaded || !visible) return; - f32 width = this->size[0]; - f32 height = this->size[1]; + f32 width = size[0]; + f32 height = size[1]; - this->abuffer = fmt::format("_rt_imageLayerComposite_{}_a", this->id); - this->bbuffer = fmt::format("_rt_imageLayerComposite_{}_b", this->id); + abuffer = fmt::format("_rt_imageLayerComposite_{}_a", this->id); + bbuffer = fmt::format("_rt_imageLayerComposite_{}_b", this->id); - engine->new_framebuffer(this->abuffer, width, height, 1.f); - engine->new_framebuffer(this->bbuffer, width, height, 1.f); + engine->new_framebuffer(abuffer, width, height, 1.f); + engine->new_framebuffer(bbuffer, width, height, 1.f); - this->get_model(engine->view.width, engine->view.height, this->effects.size() == 0); + get_model(engine->view.width, engine->view.height, effects.size() == 0); - this->ortho = glm::ortho(-width, width, -height, height, 0.f, 1.f); + ortho = glm::ortho(-width, width, -height, height, 0.f, 1.f); - this->gl_object = new RenderObject(OBJECT, width, height); - this->gl_uv_object = new RenderObject(UV_SCALE, width, height); + gl_object = new RenderObject(OBJECT, width, height); + gl_uv_object = new RenderObject(UV_SCALE, width, height); - if (this->image) + if (image != nullptr) { - this->image->load(this, this->effects.size() == 0); + image->load(this, effects.size() == 0); - if (this->image->fullscreen) + if (image->fullscreen) { - this->fullscreen = true; - this->size[0] = engine->view.width; - this->size[1] = engine->view.height; - this->origin[0] = this->size[0] / 2.f; - this->origin[1] = this->size[1] / 2.f; + fullscreen = true; + size[0] = engine->view.width; + size[1] = engine->view.height; + origin[0] = size[0] / 2.f; + origin[1] = size[1] / 2.f; } - if (this->image->passthrough) - this->passthrough = true; + if (image->passthrough) + passthrough = true; } - for (int i = 0; i < this->effects.size(); i++) + for (int i = 0; i < effects.size(); i++) { - this->effects[i]->load(engine, this, i == (this->effects.size() - 1)); + effects[i]->load(engine, this, i == (effects.size() - 1)); } - this->loaded = true; + loaded = true; } void Object::update(Engine *engine) @@ -131,10 +131,10 @@ void Object::update(Engine *engine) void Object::draw(Engine *engine) { - if (!this->visible) + if (!visible) return; - for (auto &pass : this->passes) + for (auto &pass : passes) { pass->draw(engine); } @@ -142,32 +142,26 @@ void Object::draw(Engine *engine) std::string Object::get_target_buffer() const { - if (this->buffer_switch) - return this->abuffer; - else - return this->bbuffer; + return (buffer_switch) ? abuffer : bbuffer; } std::string Object::get_texture_buffer() const { - if (this->buffer_switch) - return this->bbuffer; - else - return this->abuffer; + return (buffer_switch) ? bbuffer : abuffer; } Object::~Object() { - if (this->image != nullptr) - delete this->image; + if (image != nullptr) + delete image; - if (this->gl_object != nullptr) - delete this->gl_object; + if (gl_object != nullptr) + delete gl_object; - if (this->gl_uv_object != nullptr) - delete this->gl_uv_object; + if (gl_uv_object != nullptr) + delete gl_uv_object; - for (auto &effect : this->effects) + for (auto &effect : effects) { delete effect; } diff --git a/src/objects/pass.cc b/src/objects/pass.cc index 7825602..cb3a3c0 100644 --- a/src/objects/pass.cc +++ b/src/objects/pass.cc @@ -24,69 +24,69 @@ Pass::Pass(Json::Value root, PassStage stage) switch (stage) { case EFFECT0_PASS: { - auto uniforms = root["constantshadervalues"]; + auto shader_values = root["constantshadervalues"]; - for (auto &name : uniforms.getMemberNames()) + for (auto &name : shader_values.getMemberNames()) { auto uniform = Uniform(); uniform.name = name; - json_number(json_user_value(uniforms[name]), + json_number(json_user_value(shader_values[name]), glm::value_ptr(uniform.value)); - this->uniforms.push_back(uniform); + uniforms.push_back(uniform); } break; } case EFFECT1_PASS: { - auto material = root["material"]; + auto pass_material = root["material"]; - if (material.isString()) - this->material = new Material(material.asString()); + if (pass_material.isString()) + material = new Material(pass_material.asString()); - this->target = root.get("target", "previous").asString(); + target = root.get("target", "previous").asString(); for (auto &bind : root["bind"]) { auto index = bind["index"].asInt(); - this->binds[index] = bind["name"].asString(); + binds[index] = bind["name"].asString(); } break; } case MATERIAL_ONLY_PASS: - this->target = "previous"; + target = "previous"; [[fallthrough]]; case MATERIAL_PASS: { - this->shader = root["shader"].asString(); + shader = root["shader"].asString(); - auto blend = root.get("blending", "normal").asString(); + auto blending = root.get("blending", "normal").asString(); - if (blend == "normal") - this->blend = NORMAL; - else if (blend == "translucent") - this->blend = TRANSLUCENT; + if (blending == "normal") + blend = NORMAL; + else if (blending == "translucent") + blend = TRANSLUCENT; break; } } - auto _textures = root["textures"]; + auto pass_textures = root["textures"]; - for (int i = 0; i < textures.size(); i++) + for (int i = 0; i < pass_textures.size(); i++) { - auto texture = _textures[i]; + auto texture = pass_textures[i]; if (texture.isString()) - this->textures[i] = texture.asString(); + textures[i] = texture.asString(); } - auto _combos = root["combos"]; + auto pass_combos = root["combos"]; - for (auto &name : _combos.getMemberNames()) + for (auto &name : pass_combos.getMemberNames()) { - this->combos.emplace_back((Combo){name, _combos[name].asInt()}); + combos.emplace_back((Combo){name, pass_combos[name].asInt()}); } } @@ -94,13 +94,13 @@ void Pass::load(PassStage stage, Pass *pass) { for (int i = 0; i < 8; i++) { - if (this->textures[i].empty()) + if (textures[i].empty()) continue; - pass->textures[i] = this->textures[i]; + pass->textures[i] = textures[i]; } - for (auto &combo : this->combos) + for (auto &combo : combos) { pass->combos.push_back(combo); } @@ -108,13 +108,13 @@ void Pass::load(PassStage stage, Pass *pass) switch (stage) { case EFFECT0_PASS: - for (auto &uniform : this->uniforms) + for (auto &uniform : uniforms) { pass->uniforms.push_back(uniform); } break; case EFFECT1_PASS: - pass->target = this->target; + pass->target = target; if (pass->target == "previous") { @@ -130,20 +130,20 @@ void Pass::load(PassStage stage, Pass *pass) for (int i = 0; i < 8; i++) { - if (this->binds[i].empty()) + if (binds[i].empty()) continue; - if (this->binds[i] == "previous") + if (binds[i] == "previous") pass->textures[i] = pass->object->get_texture_buffer(); else - pass->textures[i] = this->binds[i] + pass->effect->buffer_id; + pass->textures[i] = binds[i] + pass->effect->buffer_id; } - if (this->target == "previous") + if (target == "previous") pass->object->swap_buffer(); - if (this->material != nullptr) - this->material->load(pass->object, MATERIAL_EFFECT, pass, false); + if (material != nullptr) + material->load(pass->object, MATERIAL_EFFECT, pass, false); break; case MATERIAL_ONLY_PASS: @@ -156,36 +156,36 @@ void Pass::load(PassStage stage, Pass *pass) } [[fallthrough]]; case MATERIAL_PASS: - pass->shader = this->shader; + pass->shader = shader; break; } } void Pass::generate_pass(Engine *engine) { - this->rpass = new RenderPass(); + rpass = new RenderPass(); - this->rpass->combine = this->combine; - this->rpass->combine_blend = this->object->color_blend_mode; + rpass->combine = combine; + rpass->combine_blend = object->color_blend_mode; - this->rpass->shader = new Shader(this->shader); + rpass->shader = new Shader(shader); - auto rshader = this->rpass->shader; + auto rshader = rpass->shader; for (int i = 0; i < 8; i++) { - if (this->textures[i].empty() && !rshader->textures[i].empty()) - this->textures[i] = rshader->textures[i]; + if (textures[i].empty() && !rshader->textures[i].empty()) + textures[i] = rshader->textures[i]; - if (this->textures[i].empty()) + if (textures[i].empty()) continue; - auto asset = asset_manager()->get_file(this->textures[i], TEXTURE); + auto asset = asset_manager()->get_file(textures[i], TEXTURE); if (asset->type != ASSET_VOID) - this->rpass->textures[i] = new Texture(asset); + rpass->textures[i] = new Texture(asset); else - this->rpass->textures[i] = engine->get_framebuffer_texture(this->textures[i]); + rpass->textures[i] = engine->get_framebuffer_texture(textures[i]); } for (auto &uniform : rshader->uniforms) @@ -196,12 +196,12 @@ void Pass::generate_pass(Engine *engine) uniform.uname.compare(10, 10, "Resolution") == 0) { auto index = uniform.uname[9] - '0'; - if (this->rpass->textures[index] != nullptr) - uniform.value = this->rpass->textures[index]->texture_resolution; + if (rpass->textures[index] != nullptr) + uniform.value = rpass->textures[index]->texture_resolution; } } - for (auto &pass_uniform : this->uniforms) + for (auto &pass_uniform : uniforms) { for (auto &shader_uniform : rshader->uniforms) { @@ -224,7 +224,7 @@ void Pass::generate_pass(Engine *engine) } } - for (auto &pass_combo : this->combos) + for (auto &pass_combo : combos) { auto add = true; for (auto &shader_combo : rshader->combos) @@ -240,69 +240,69 @@ void Pass::generate_pass(Engine *engine) rshader->combos.push_back(pass_combo); } - this->rpass->shader->compile(); + rpass->shader->compile(); - this->rpass->target = engine->get_framebuffer(this->target); + rpass->target = engine->get_framebuffer(target); - if (this->effect == nullptr) + if (effect == nullptr) { - if (this->object->passthrough || this->combine) - this->rpass->model = &this->object->model; + if (object->passthrough || combine) + rpass->model = &object->model; else - this->rpass->model = &this->object->ortho; + rpass->model = &object->ortho; - if (this->object->passthrough) - this->rpass->robject = this->object->gl_object; + if (object->passthrough) + rpass->robject = object->gl_object; else - this->rpass->robject = this->object->gl_uv_object; + rpass->robject = object->gl_uv_object; } else { - if (this->combine) + if (combine) { - this->rpass->robject = this->object->gl_object; - this->rpass->model = &this->object->model; + rpass->robject = object->gl_object; + rpass->model = &object->model; } else { - this->rpass->robject = engine->default_object; - this->rpass->model = &engine->identity; + rpass->robject = engine->default_object; + rpass->model = &engine->identity; } } } void Pass::draw(Engine *engine) { - if (this->rpass != nullptr) - this->rpass->draw(engine); + if (rpass != nullptr) + rpass->draw(engine); } Pass::~Pass() { - if (this->material != nullptr) - delete this->material; + if (material != nullptr) + delete material; - if (this->rpass != nullptr) - delete this->rpass; + if (rpass != nullptr) + delete rpass; } void RenderPass::draw(Engine *engine) { - this->target->buffer->bind(); - this->shader->bind(engine, this->model); + target->buffer->bind(); + shader->bind(engine, model); - this->robject->bind(); + robject->bind(); - for (int i = 0; i < this->shader->texture_count; i++) + for (int i = 0; i < shader->texture_count; i++) { - if (this->textures[i] != nullptr) - this->textures[i]->bind(i); + if (textures[i] != nullptr) + textures[i]->bind(i); } BlendMode blend; - if (this->combine) - blend = this->combine_blend; + if (combine) + blend = combine_blend; else blend = NORMAL; @@ -318,15 +318,15 @@ void RenderPass::draw(Engine *engine) break; } - if (this->combine) + if (combine) engine->view.center_scale(engine->context->width, engine->context->height); else - engine->view.default_viewport(this->target->buffer->width, this->target->buffer->height); + engine->view.default_viewport(target->buffer->width, target->buffer->height); glDrawArrays(GL_TRIANGLES, 0, 6); #if 0 - engine->combine_buffer->buffer->blit(this->context->width, this->context->height); + engine->combine_buffer->buffer->blit(context->width, context->height); engine->context->swap_buffers(); std::this_thread::sleep_for(std::chrono::seconds(1)); #endif @@ -334,13 +334,13 @@ void RenderPass::draw(Engine *engine) RenderPass::~RenderPass() { - if (this->shader != nullptr) - delete this->shader; + if (shader != nullptr) + delete shader; for (int i = 0; i < 8; i++) { - if (this->textures[i] != nullptr && !this->textures[i]->wrapped) - delete this->textures[i]; + if (textures[i] != nullptr && !textures[i]->wrapped) + delete textures[i]; } } diff --git a/src/objects/scene.cc b/src/objects/scene.cc index 5c00147..2bedb54 100644 --- a/src/objects/scene.cc +++ b/src/objects/scene.cc @@ -26,28 +26,28 @@ Scene::Scene(std::string path) auto camera = root["camera"]; auto general = root["general"]; auto ortho = general["orthogonalprojection"]; + + sscanf_vec3(json_user_value(camera.get("center", "")).asCString(), cam.center); + sscanf_vec3(json_user_value(camera.get("eye", "")).asCString(), cam.eye); + sscanf_vec3(json_user_value(camera.get("up", "")).asCString(), cam.up); - sscanf_vec3(json_user_value(camera.get("center", "")).asCString(), this->camera.center); - sscanf_vec3(json_user_value(camera.get("eye", "")).asCString(), this->camera.eye); - sscanf_vec3(json_user_value(camera.get("up", "")).asCString(), this->camera.up); + clear_enabled = general.get("clearenabled", true).asBool(); - this->clear_enabled = general.get("clearenabled", false).asBool(); + sscanf_vec3(json_user_value(general.get("clearcolor", "")).asCString(), clear_color); + clear_color[3] = 1.f; - sscanf_vec3(json_user_value(general.get("clearcolor", "")).asCString(), this->clear_color); - this->clear_color[3] = 1.f; - - this->width = json_user_value(ortho.get("width", 0.f)).asFloat(); - this->height = json_user_value(ortho.get("height", 0.f)).asFloat(); + width = json_user_value(ortho.get("width", 0.f)).asFloat(); + height = json_user_value(ortho.get("height", 0.f)).asFloat(); for (auto &object : root["objects"]) { - this->objects.emplace_back(new Object(object)); + objects.emplace_back(new Object(object)); } } Object *Scene::get_object_by_id(u32 id) { - for (auto &object : this->objects) + for (auto &object : objects) { if (object->id == id) { @@ -60,14 +60,14 @@ Object *Scene::get_object_by_id(u32 id) void Scene::load(Engine *engine) { - engine->view.width = this->width; - engine->view.height = this->height; + engine->view.width = width; + engine->view.height = height; - for (auto &object : this->objects) + for (auto &object : objects) { for (auto &dep : object->deps) { - auto dep_object = this->get_object_by_id(dep); + auto dep_object = get_object_by_id(dep); if (dep_object) dep_object->load(engine); } @@ -75,7 +75,7 @@ void Scene::load(Engine *engine) object->load(engine); } - for (auto &object : this->objects) + for (auto &object : objects) { for (auto &pass : object->passes) pass->generate_pass(engine); @@ -84,7 +84,7 @@ void Scene::load(Engine *engine) void Scene::draw(Engine *engine) { - for (auto &object : this->objects) + for (auto &object : objects) { object->draw(engine); } @@ -92,29 +92,8 @@ void Scene::draw(Engine *engine) Scene::~Scene() { - for (auto &object : this->objects) + for (auto &object : objects) { delete object; } } - -s32 Scene::estimated_buffer_count() -{ - return 0; -// s32 total = 0; -// -// for (auto &object : this->objects) -// { -// for (auto &effect : object->effects) -// { -// for (auto &pass1 : effect->passes1) -// { -// if (!pass1->target.empty()) -// total++; -// } -// } -// total += 2; -// } -// -// return total; -} diff --git a/src/objects/scene.h b/src/objects/scene.h index 47aa19a..2f6f210 100644 --- a/src/objects/scene.h +++ b/src/objects/scene.h @@ -15,6 +15,16 @@ using namespace glm; namespace Mauri { +struct Camera { + vec3 center; + vec3 eye; + vec3 up; + + float farz; + float nearz; + float fov; +}; + class Scene { public: @@ -37,16 +47,7 @@ class Scene std::vector<Object *> objects; private: - struct - { - vec3 center; - vec3 eye; - vec3 up; - - float farz; - float nearz; - float fov; - } camera; + Camera cam; }; } // namespace Mauri diff --git a/src/texture.cc b/src/texture.cc index c47352b..debbac3 100644 --- a/src/texture.cc +++ b/src/texture.cc @@ -1,11 +1,5 @@ #define STB_IMAGE_IMPLEMENTATION -extern "C" -{ #include <stb_image.h> -} - -#define STB_IMAGE_WRITE_IMPLEMENTATION -#include <stb_image_write.h> #include <s3tc.h> @@ -29,27 +23,27 @@ static byte *load_image_rgba(byte *data, s32 len) Texture::Texture(Asset *asset) { - this->hash = asset->hash; + hash = asset->hash; // auto type = asset->read_str(9); // auto itype = asset->read_str(9); asset->seek(18); - this->format = (TextureFormat)asset->read<u32>(); + format = (TextureFormat)asset->read<u32>(); - this->flags.integer = asset->read<u32>(); + flags.integer = asset->read<u32>(); - this->texture_width = asset->read<u32>(); - this->texture_height = asset->read<u32>(); + texture_width = asset->read<u32>(); + texture_height = asset->read<u32>(); - this->width = asset->read<u32>(); - this->height = asset->read<u32>(); + width = asset->read<u32>(); + height = asset->read<u32>(); - this->texture_resolution[0] = this->texture_width; - this->texture_resolution[1] = this->texture_height; - this->texture_resolution[2] = this->width; - this->texture_resolution[3] = this->height; + texture_resolution[0] = texture_width; + texture_resolution[1] = texture_height; + texture_resolution[2] = width; + texture_resolution[3] = height; asset->seek(4); @@ -59,18 +53,18 @@ Texture::Texture(Asset *asset) if (container.compare(0, 8, "TEXB0003") == 0) { - this->version = TEXB0003; + version = TEXB0003; asset->seek(4); iformat = asset->read<u32>(); } else if (container.compare(0, 8, "TEXB0002") == 0) { - this->version = TEXB0002; + version = TEXB0002; asset->seek(4); } else if (container.compare(0, 8, "TEXB0001") == 0) { - this->version = TEXB0001; + version = TEXB0001; asset->seek(4); } else @@ -80,7 +74,7 @@ Texture::Texture(Asset *asset) auto mm_count = asset->read<u32>(); - this->texture = new RenderTexture(this->flags.map.NO_INTERPOLATION, this->flags.map.CLAMP_UV, mm_count); + texture = new RenderTexture(flags.map.NO_INTERPOLATION, flags.map.CLAMP_UV, mm_count); for (int i = 0; i < mm_count; i++) { @@ -90,7 +84,7 @@ Texture::Texture(Asset *asset) auto lz4_compressed = false; auto decompressed_byte_count = 0; - if (this->version == TEXB0002 || this->version == TEXB0003) + if (version == TEXB0002 || version == TEXB0003) { lz4_compressed = asset->read<u32>() == 1; decompressed_byte_count = asset->read<u32>(); @@ -107,21 +101,21 @@ Texture::Texture(Asset *asset) { auto decompressed = new char[decompressed_byte_count]; LZ4_decompress_safe(reinterpret_cast<char *>(buffer), decompressed, - byte_count, decompressed_byte_count); + byte_count, decompressed_byte_count); buffer = reinterpret_cast<byte *>(decompressed); } if (iformat == -1) { - switch (this->format) + switch (format) { case RGBA8888: - this->texture->upload(buffer, mwidth, mheight, i, GL_RGBA, true); + texture->upload(buffer, mwidth, mheight, i, GL_RGBA, true); break; case DXT5: { auto decompressed = new u32[decompressed_byte_count]; BlockDecompressImageDXT5(mwidth, mheight, buffer, decompressed); - this->texture->upload(reinterpret_cast<byte *>(decompressed), + texture->upload(reinterpret_cast<byte *>(decompressed), mwidth, mheight, i, GL_RGBA, true, true); delete[] decompressed; log_warn("%s", "DXT5 Texture"); @@ -130,7 +124,7 @@ Texture::Texture(Asset *asset) case DXT1: { auto decompressed = new u32[decompressed_byte_count * 2]; BlockDecompressImageDXT1(mwidth, mheight, buffer, decompressed); - this->texture->upload(reinterpret_cast<byte *>(decompressed), + texture->upload(reinterpret_cast<byte *>(decompressed), mwidth, mheight, i, GL_RGBA, true, true); delete[] decompressed; log_warn("%s", "DXT1 Texture"); @@ -140,11 +134,11 @@ Texture::Texture(Asset *asset) log_warn("%s", "DXT3 Texture"); break; case RG88: - this->texture->upload(buffer, mwidth, mheight, i, GL_RG, true); + texture->upload(buffer, mwidth, mheight, i, GL_RG, true); log_warn("%s", "RG88 Texture"); break; case R8: - this->texture->upload(buffer, mwidth, mheight, i, GL_RED, true); + texture->upload(buffer, mwidth, mheight, i, GL_RED, true); log_warn("%s", "RG8 Texture"); break; default: @@ -155,7 +149,7 @@ Texture::Texture(Asset *asset) else { auto data = load_image_rgba(buffer, decompressed_byte_count); - this->texture->upload(data, mwidth, mheight, i, GL_RGBA, true); + texture->upload(data, mwidth, mheight, i, GL_RGBA, true); free(data); } @@ -170,32 +164,34 @@ Texture::Texture(Asset *asset) Texture::~Texture() { - if (!this->wrapped) - delete this->texture; + if (!wrapped) + delete texture; } void Texture::bind(s32 index) { - this->texture->bind(index); + texture->bind(index); } Framebuffer::Framebuffer(f32 width, f32 height, f32 scale) { - this->buffer = new RenderFramebuffer(width, height, scale); + buffer = new RenderFramebuffer(width, height, scale); - this->texture = new Texture(); - this->texture->wrapped = true; + texture = new Texture(); + texture->wrapped = true; - this->texture->texture = this->buffer->texture; + texture->texture = buffer->texture; - this->texture->texture_resolution[0] = this->buffer->width; - this->texture->texture_resolution[1] = this->buffer->height; - this->texture->texture_resolution[2] = this->buffer->width; - this->texture->texture_resolution[3] = this->buffer->height; + texture->texture_resolution[0] = buffer->width; + texture->texture_resolution[1] = buffer->height; + texture->texture_resolution[2] = buffer->width; + texture->texture_resolution[3] = buffer->height; } Framebuffer::~Framebuffer() { - delete this->texture; - delete this->buffer; + if (texture != nullptr) + delete texture; + if (buffer != nullptr) + delete buffer; } |