Further refactor | Update resources.qrc, cursor_frag.glsl, and 68 more files...

This commit is contained in:
Skarn
2022-01-16 21:23:56 +03:00
parent 4d39f1a4cc
commit 929b2afd06
44 changed files with 675 additions and 688 deletions

View File

@@ -24,27 +24,35 @@
<file alias="icon-shadow">../media/project-icon-shadow.png</file> <file alias="icon-shadow">../media/project-icon-shadow.png</file>
</qresource> </qresource>
<qresource prefix="/shader"> <qresource prefix="/shader">
<file alias="m2_vs">../src/glsl/m2_vert.glsl</file> <file alias="m2_vs">../src/noggit/rendering/glsl/m2_vert.glsl</file>
<file alias="m2_fs">../src/glsl/m2_frag.glsl</file> <file alias="m2_fs">../src/noggit/rendering/glsl/m2_frag.glsl</file>
<file alias="m2_box_vs">../src/glsl/m2_box_vert.glsl</file> <file alias="m2_box_vs">../src/noggit/rendering/glsl/m2_box_vert.glsl</file>
<file alias="m2_box_fs">../src/glsl/m2_box_frag.glsl</file> <file alias="m2_box_fs">../src/noggit/rendering/glsl/m2_box_frag.glsl</file>
<file alias="particle_vs">../src/glsl/particle_vert.glsl</file> <file alias="particle_vs">../src/noggit/rendering/glsl/particle_vert.glsl</file>
<file alias="particle_fs">../src/glsl/particle_frag.glsl</file> <file alias="particle_fs">../src/noggit/rendering/glsl/particle_frag.glsl</file>
<file alias="ribbon_vs">../src/glsl/ribbon_vert.glsl</file> <file alias="ribbon_vs">../src/noggit/rendering/glsl/ribbon_vert.glsl</file>
<file alias="ribbon_fs">../src/glsl/ribbon_frag.glsl</file> <file alias="ribbon_fs">../src/noggit/rendering/glsl/ribbon_frag.glsl</file>
<file alias="terrain_vs">../src/glsl/terrain_vert.glsl</file> <file alias="terrain_vs">../src/noggit/rendering/glsl/terrain_vert.glsl</file>
<file alias="terrain_fs">../src/glsl/terrain_frag.glsl</file> <file alias="terrain_fs">../src/noggit/rendering/glsl/terrain_frag.glsl</file>
<file alias="wmo_vs">../src/glsl/wmo_vert.glsl</file> <file alias="wmo_vs">../src/noggit/rendering/glsl/wmo_vert.glsl</file>
<file alias="wmo_fs">../src/glsl/wmo_frag.glsl</file> <file alias="wmo_fs">../src/noggit/rendering/glsl/wmo_frag.glsl</file>
<file alias="liquid_vs">../src/glsl/liquid_vert.glsl</file> <file alias="liquid_vs">../src/noggit/rendering/glsl/liquid_vert.glsl</file>
<file alias="liquid_fs">../src/glsl/liquid_frag.glsl</file> <file alias="liquid_fs">../src/noggit/rendering/glsl/liquid_frag.glsl</file>
<file alias="mfbo_vs">../src/glsl/mfbo_vert.glsl</file> <file alias="mfbo_vs">../src/noggit/rendering/glsl/mfbo_vert.glsl</file>
<file alias="mfbo_fs">../src/glsl/mfbo_frag.glsl</file> <file alias="mfbo_fs">../src/noggit/rendering/glsl/mfbo_frag.glsl</file>
<file alias="cursor_vs">../src/glsl/cursor_vert.glsl</file> <file alias="cursor_vs">../src/noggit/rendering/glsl/cursor_vert.glsl</file>
<file alias="cursor_fs">../src/glsl/cursor_frag.glsl</file> <file alias="cursor_fs">../src/noggit/rendering/glsl/cursor_frag.glsl</file>
<file alias="horizon_vs">../src/glsl/horizon_vert.glsl</file> <file alias="horizon_vs">../src/noggit/rendering/glsl/horizon_vert.glsl</file>
<file alias="horizon_fs">../src/glsl/horizon_frag.glsl</file> <file alias="horizon_fs">../src/noggit/rendering/glsl/horizon_frag.glsl</file>
<file alias="occluder_vs">../src/glsl/occluder_vert.glsl</file> <file alias="occluder_vs">../src/noggit/rendering/glsl/occluder_vert.glsl</file>
<file alias="occluder_fs">../src/glsl/occluder_frag.glsl</file> <file alias="occluder_fs">../src/noggit/rendering/glsl/occluder_frag.glsl</file>
<file alias="wire_box_vs">../src/noggit/rendering/glsl/wire_box_vert.glsl</file>
<file alias="wire_box_fs">../src/noggit/rendering/glsl/wire_box_frag.glsl</file>
<file alias="grid_vs">../src/noggit/rendering/glsl/grid_vert.glsl</file>
<file alias="grid_fs">../src/noggit/rendering/glsl/grid_frag.glsl</file>
<file alias="sphere_vs">../src/noggit/rendering/glsl/sphere_vert.glsl</file>
<file alias="sphere_fs">../src/noggit/rendering/glsl/sphere_frag.glsl</file>
<file alias="square_vs">../src/noggit/rendering/glsl/square_vert.glsl</file>
<file alias="square_fs">../src/noggit/rendering/glsl/square_frag.glsl</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@@ -7,7 +7,7 @@
#include <noggit/TileWater.hpp> #include <noggit/TileWater.hpp>
#include <noggit/liquid_layer.hpp> #include <noggit/liquid_layer.hpp>
#include <noggit/World.h> #include <noggit/World.h>
#include <noggit/LiquidTextureManager.hpp> #include <noggit/rendering/LiquidTextureManager.hpp>
#include <ClientFile.hpp> #include <ClientFile.hpp>
#include <stdexcept> #include <stdexcept>

View File

@@ -5,7 +5,7 @@
#include <noggit/tool_enums.hpp> #include <noggit/tool_enums.hpp>
#include <opengl/context.hpp> #include <opengl/context.hpp>
#include <opengl/types.hpp> #include <opengl/types.hpp>
#include <noggit/LiquidTextureManager.hpp> #include <noggit/rendering/LiquidTextureManager.hpp>
#include <noggit/rendering/LiquidRender.hpp> #include <noggit/rendering/LiquidRender.hpp>
#include <memory> #include <memory>

View File

@@ -4,7 +4,7 @@
#include <math/frustum.hpp> #include <math/frustum.hpp>
#include <math/trig.hpp> #include <math/trig.hpp>
#include <noggit/CursorRender.hpp> #include <noggit/rendering/CursorRender.hpp>
#include <noggit/Misc.h> #include <noggit/Misc.h>
#include <noggit/Model.h> // ModelManager #include <noggit/Model.h> // ModelManager
#include <noggit/Selection.h> #include <noggit/Selection.h>
@@ -18,10 +18,10 @@
#include <noggit/world_model_instances_storage.hpp> #include <noggit/world_model_instances_storage.hpp>
#include <noggit/ui/MinimapCreator.hpp> #include <noggit/ui/MinimapCreator.hpp>
#include <noggit/ContextObject.hpp> #include <noggit/ContextObject.hpp>
#include <opengl/primitives.hpp> #include <noggit/rendering/Primitives.hpp>
#include <opengl/shader.fwd.hpp> #include <opengl/shader.fwd.hpp>
#include <opengl/types.hpp> #include <opengl/types.hpp>
#include <noggit/LiquidTextureManager.hpp> #include <noggit/rendering/LiquidTextureManager.hpp>
#include <optional> #include <optional>
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <map> #include <map>

View File

@@ -1,8 +1,8 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3). // This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/CursorRender.hpp> #include "CursorRender.hpp"
#include "math/trig.hpp" #include "math/trig.hpp"
#include <opengl/shader.hpp> #include "opengl/shader.hpp"
namespace Noggit namespace Noggit
{ {

View File

@@ -1,8 +1,8 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3). // This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once #pragma once
#include <opengl/scoped.hpp> #include "opengl/scoped.hpp"
#include <opengl/shader.fwd.hpp> #include "opengl/shader.fwd.hpp"
#include <memory> #include <memory>

View File

@@ -1,9 +1,9 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3). // This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include "LiquidTextureManager.hpp" #include "LiquidTextureManager.hpp"
#include <opengl/context.inl> #include "opengl/context.inl"
#include <noggit/DBC.h> #include "noggit/DBC.h"
#include <noggit/application/NoggitApplication.hpp> #include "noggit/application/NoggitApplication.hpp"
LiquidTextureManager::LiquidTextureManager(Noggit::NoggitRenderContext context) LiquidTextureManager::LiquidTextureManager(Noggit::NoggitRenderContext context)
: _context(context) : _context(context)

View File

@@ -3,12 +3,12 @@
#ifndef NOGGIT_LIQUIDTEXTUREMANAGER_HPP #ifndef NOGGIT_LIQUIDTEXTUREMANAGER_HPP
#define NOGGIT_LIQUIDTEXTUREMANAGER_HPP #define NOGGIT_LIQUIDTEXTUREMANAGER_HPP
#include <noggit/TextureManager.h> #include "noggit/TextureManager.h"
#include <noggit/ContextObject.hpp> #include "noggit/ContextObject.hpp"
#include <external/tsl/robin_map.h> #include "external/tsl/robin_map.h"
#include <tuple> #include <tuple>
#include <glm/vec2.hpp> #include "external/glm/vec2.hpp"
template<typename ... Args> template<typename ... Args>
std::string string_format(const std::string& format, Args ... args) std::string string_format(const std::string& format, Args ... args)

View File

@@ -0,0 +1,381 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <noggit/rendering/Primitives.hpp>
#include <math/bounding_box.hpp>
#include <noggit/Misc.h>
#include <opengl/scoped.hpp>
#include <opengl/context.hpp>
#include <opengl/types.hpp>
#include <array>
#include <vector>
#include <glm/gtx/quaternion.hpp>
using namespace Noggit::Rendering::Primitives;
void WireBox::draw ( glm::mat4x4 const& model_view
, glm::mat4x4 const& projection
, glm::mat4x4 const& transform
, glm::vec4 const& color
, glm::vec3 const& min_point
, glm::vec3 const& max_point
)
{
if (!_buffers_are_setup)
{
setup_buffers();
}
OpenGL::Scoped::use_program wire_box_shader {*_program.get()};
auto points = math::box_points(min_point, max_point);
auto glmPoints = std::vector<glm::vec3>();
for(auto const point : points)
{
glmPoints.push_back(glm::vec3(point.x, point.y, point.z));
}
wire_box_shader.uniform("model_view", model_view);
wire_box_shader.uniform("projection", projection);
wire_box_shader.uniform("transform", transform);
wire_box_shader.uniform("color", color);
wire_box_shader.uniform("pointPositions", glmPoints);
OpenGL::Scoped::bool_setter<GL_LINE_SMOOTH, GL_TRUE> const line_smooth;
gl.hint(GL_LINE_SMOOTH_HINT, GL_NICEST);
OpenGL::Scoped::vao_binder const _(_vao[0]);
gl.drawElements (GL_LINE_STRIP, _indices, 16, GL_UNSIGNED_BYTE, nullptr);
}
void WireBox::setup_buffers()
{
_program.reset(new OpenGL::program( {{ GL_VERTEX_SHADER, OpenGL::shader::src_from_qrc("wire_box_vs") }
, { GL_FRAGMENT_SHADER, OpenGL::shader::src_from_qrc("wire_box_fs")}}));
_vao.upload();
_buffers.upload();
//std::vector<glm::vec3> positions (math::box_points (min_point, max_point));
static std::array<std::uint8_t, 16> const indices
{{5, 7, 3, 2, 0, 1, 3, 1, 5, 4, 0, 4, 6, 2, 6, 7}};
OpenGL::Scoped::buffer_binder<GL_ELEMENT_ARRAY_BUFFER> const index_buffer (_indices);
gl.bufferData ( GL_ELEMENT_ARRAY_BUFFER
, indices.size() * sizeof (*indices.data())
, indices.data()
, GL_STATIC_DRAW
);
OpenGL::Scoped::use_program shader (*_program.get());
OpenGL::Scoped::vao_binder const _ (_vao[0]);
_buffers_are_setup = true;
}
void WireBox::unload()
{
_vao.unload();
_buffers.unload();
_program.reset();
_buffers_are_setup = false;
}
void Grid::draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, glm::vec4 const& color
, float radius
)
{
if (!_buffers_are_setup)
{
setup_buffers();
}
OpenGL::Scoped::use_program sphere_shader {*_program.get()};
sphere_shader.uniform("model_view_projection", mvp);
sphere_shader.uniform("origin", glm::vec3(pos.x,pos.y,pos.z));
sphere_shader.uniform("color", color);
sphere_shader.uniform("radius", radius);
OpenGL::Scoped::vao_binder const _(_vao[0]);
gl.drawElements(GL_LINES, _indices_vbo, _indice_count, GL_UNSIGNED_SHORT, nullptr);
}
void Grid::setup_buffers()
{
_vao.upload();
_buffers.upload();
_program.reset(new OpenGL::program({{ GL_VERTEX_SHADER
, OpenGL::shader::src_from_qrc("grid_vs")
}
, { GL_FRAGMENT_SHADER
, OpenGL::shader::src_from_qrc("grid_fs")
}
}));
std::vector<glm::vec3> vertices;
std::vector<std::uint16_t> indices;
int slices = 20;
for(int j = 0; j <= slices; ++j)
{
for(int i = 0; i <= slices; ++i)
{
float x = static_cast<float>(i) / static_cast<float>(slices);
float y = 0;
float z = static_cast<float>(j) / static_cast<float>(slices);
vertices.push_back(glm::vec3(x, y, z));
}
}
for(int j = 0; j < slices; ++j)
{
for(int i = 0; i < slices; ++i)
{
int row1 = j * (slices + 1);
int row2 = (j + 1) * (slices + 1);
indices.push_back(row1 + i);
indices.push_back(row1 + i + 1);
indices.push_back(row1 + i + 1);
indices.push_back(row2 + i + 1);
indices.push_back(row2 + i + 1);
indices.push_back(row2 + i);
indices.push_back(row2 + i);
indices.push_back(row1 + i);
}
}
_indice_count = indices.size();
gl.bufferData<GL_ARRAY_BUFFER, glm::vec3>
(_vertices_vbo, vertices, GL_STATIC_DRAW);
gl.bufferData<GL_ELEMENT_ARRAY_BUFFER, std::uint16_t>
(_indices_vbo, indices, GL_STATIC_DRAW);
OpenGL::Scoped::index_buffer_manual_binder indices_binder(_indices_vbo);
OpenGL::Scoped::use_program shader (*_program.get());
{
OpenGL::Scoped::vao_binder const _ (_vao[0]);
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> const vertices_binder (_vertices_vbo);
shader.attrib("position", 3, GL_FLOAT, GL_FALSE, 0, 0);
indices_binder.bind();
}
_buffers_are_setup = true;
}
void Grid::unload()
{
_vao.unload();
_buffers.unload();
_program.reset();
_buffers_are_setup = false;
}
void Sphere::draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, glm::vec4 const& color
, float radius
)
{
if (!_buffers_are_setup)
{
setup_buffers();
}
OpenGL::Scoped::use_program sphere_shader {*_program.get()};
sphere_shader.uniform("model_view_projection", mvp);
sphere_shader.uniform("origin", glm::vec3(pos.x,pos.y,pos.z));
sphere_shader.uniform("radius", radius);
sphere_shader.uniform("color", color);
OpenGL::Scoped::vao_binder const _(_vao[0]);
gl.drawElements(GL_TRIANGLES, _indices_vbo, _indice_count, GL_UNSIGNED_SHORT, nullptr);
}
void Sphere::setup_buffers()
{
_vao.upload();
_buffers.upload();
std::vector<glm::vec3> vertices;
std::vector<std::uint16_t> indices;
_program.reset(new OpenGL::program({{ GL_VERTEX_SHADER
, OpenGL::shader::src_from_qrc("sphere_vs")}
, { GL_FRAGMENT_SHADER
, OpenGL::shader::src_from_qrc("sphere_fs")
}}));
int segment = 27;
// add overlapping vertices at the end for an easier vertices generations
for (int rotation_step = 0; rotation_step <= segment; ++rotation_step)
{
math::degrees rotation(360.f*rotation_step / static_cast<float>(segment));
auto rotationQuat = glm::angleAxis(rotation._, glm::vec3(0, 0, 1));
for (int i = 0; i < segment; ++i)
{
float x = glm::cos(math::radians(math::degrees(i * 360 / segment))._);
float z = glm::sin(math::radians(math::degrees(i * 360 / segment))._);
glm::vec4 v(x, 0.f, z,0.0f);
vertices.emplace_back(glm::toMat4(rotationQuat) * v);
if (rotation_step < segment)
{
indices.emplace_back(i + rotation_step*segment);
indices.emplace_back(((i + 1) % segment) + rotation_step * segment);
indices.emplace_back(i + (rotation_step+1) * segment);
indices.emplace_back(i + (rotation_step+1) * segment);
indices.emplace_back(((i + 1) % segment) + rotation_step * segment);
indices.emplace_back(((i + 1) % segment) + (rotation_step+1) * segment);
}
}
}
_indice_count = indices.size();
gl.bufferData<GL_ARRAY_BUFFER, glm::vec3>
(_vertices_vbo, vertices, GL_STATIC_DRAW);
gl.bufferData<GL_ELEMENT_ARRAY_BUFFER, std::uint16_t>
(_indices_vbo, indices, GL_STATIC_DRAW);
OpenGL::Scoped::index_buffer_manual_binder indices_binder(_indices_vbo);
OpenGL::Scoped::use_program shader (*_program.get());
{
OpenGL::Scoped::vao_binder const _ (_vao[0]);
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> const vertices_binder (_vertices_vbo);
shader.attrib("position", 3, GL_FLOAT, GL_FALSE, 0, 0);
indices_binder.bind();
}
_buffers_are_setup = true;
}
void Sphere::unload()
{
_vao.unload();
_buffers.unload();
_program.reset();
_buffers_are_setup = false;
}
void Square::draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, float radius
, math::radians inclination
, math::radians orientation
, glm::vec4 const& color
)
{
if (!_buffers_are_setup)
{
setup_buffers();
}
OpenGL::Scoped::use_program sphere_shader {*_program.get()};
sphere_shader.uniform("model_view_projection", mvp);
sphere_shader.uniform("origin", glm::vec3(pos.x,pos.y,pos.z));
sphere_shader.uniform("radius", radius);
sphere_shader.uniform("inclination", inclination._);
sphere_shader.uniform("orientation", orientation._);
sphere_shader.uniform("color", color);
OpenGL::Scoped::vao_binder const _ (_vao[0]);
gl.drawElements(GL_TRIANGLES, _indices_vbo, 6, GL_UNSIGNED_SHORT, nullptr);
}
void Square::setup_buffers()
{
_vao.upload();
_buffers.upload();
std::vector<glm::vec3> vertices =
{
{-1.f, 0.f, -1.f}
,{-1.f, 0.f, 1.f}
,{ 1.f, 0.f, 1.f}
,{ 1.f, 0.f, -1.f}
};
std::vector<std::uint16_t> indices = {0,1,2, 2,3,0};
_program.reset(new OpenGL::program({{ GL_VERTEX_SHADER
, OpenGL::shader::src_from_qrc("square_vs")
}, { GL_FRAGMENT_SHADER
, OpenGL::shader::src_from_qrc("square_fs")
}}));
gl.bufferData<GL_ARRAY_BUFFER, glm::vec3>
(_vertices_vbo, vertices, GL_STATIC_DRAW);
gl.bufferData<GL_ELEMENT_ARRAY_BUFFER, std::uint16_t>
(_indices_vbo, indices, GL_STATIC_DRAW);
OpenGL::Scoped::index_buffer_manual_binder indices_binder (_indices_vbo);
OpenGL::Scoped::use_program shader(*_program.get());
{
OpenGL::Scoped::vao_binder const _ (_vao[0]);
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> const vertices_binder (_vertices_vbo);
shader.attrib("position", 3, GL_FLOAT, GL_FALSE, 0, 0);
indices_binder.bind();
}
_buffers_are_setup = true;
}
void Square::unload()
{
_vao.unload();
_buffers.unload();
_program.reset();
_buffers_are_setup = false;
}

View File

@@ -0,0 +1,133 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#include <opengl/scoped.hpp>
#include <opengl/shader.hpp>
#include <math/trig.hpp>
#include <noggit/ContextObject.hpp>
#include <memory>
#include <unordered_map>
namespace math
{
struct vector_3d;
struct vector_4d;
}
namespace Noggit::Rendering::Primitives
{
class WireBox
{
public:
WireBox() {}
WireBox(const WireBox&);
WireBox& operator=(WireBox& box ) { return *this; };
public:
static WireBox& getInstance(Noggit::NoggitRenderContext context)
{
static std::unordered_map<Noggit::NoggitRenderContext, WireBox> instances;
if (instances.find(context) == instances.end())
{
WireBox instance;
instances[context] = instance;
}
return instances.at(context);
}
void draw ( glm::mat4x4 const& model_view
, glm::mat4x4 const& projection
, glm::mat4x4 const& transform
, glm::vec4 const& color
, glm::vec3 const& min_point
, glm::vec3 const& max_point
);
void unload();
private:
bool _buffers_are_setup = false;
void setup_buffers();
OpenGL::Scoped::deferred_upload_vertex_arrays<1> _vao;
OpenGL::Scoped::deferred_upload_buffers<1> _buffers;
GLuint const& _indices = _buffers[0];
std::unique_ptr<OpenGL::program> _program;
};
class Grid
{
public:
void draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, glm::vec4 const& color
, float radius
);
void unload();
private:
bool _buffers_are_setup = false;
void setup_buffers();
int _indice_count = 0;
OpenGL::Scoped::deferred_upload_vertex_arrays<1> _vao;
OpenGL::Scoped::deferred_upload_buffers<2> _buffers;
GLuint const& _vertices_vbo = _buffers[0];
GLuint const& _indices_vbo = _buffers[1];
std::unique_ptr<OpenGL::program> _program;
};
class Sphere
{
public:
void draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, glm::vec4 const& color
, float radius
);
void unload();
private:
bool _buffers_are_setup = false;
void setup_buffers();
int _indice_count = 0;
OpenGL::Scoped::deferred_upload_vertex_arrays<1> _vao;
OpenGL::Scoped::deferred_upload_buffers<2> _buffers;
GLuint const& _vertices_vbo = _buffers[0];
GLuint const& _indices_vbo = _buffers[1];
std::unique_ptr<OpenGL::program> _program;
};
class Square
{
public:
void draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, float radius // radius of the biggest circle fitting inside the square drawn
, math::radians inclination
, math::radians orientation
, glm::vec4 const& color
);
void unload();
private:
bool _buffers_are_setup = false;
void setup_buffers();
OpenGL::Scoped::deferred_upload_vertex_arrays<1> _vao;
OpenGL::Scoped::deferred_upload_buffers<2> _buffers;
GLuint const& _vertices_vbo = _buffers[0];
GLuint const& _indices_vbo = _buffers[1];
std::unique_ptr<OpenGL::program> _program;
};
}

View File

@@ -9,13 +9,13 @@
#include <math/trig.hpp> #include <math/trig.hpp>
#include <noggit/tool_enums.hpp> #include <noggit/tool_enums.hpp>
#include <noggit/CursorRender.hpp> #include <noggit/rendering/CursorRender.hpp>
#include <noggit/LiquidTextureManager.hpp> #include <noggit/rendering/LiquidTextureManager.hpp>
#include <noggit/map_horizon.h> #include <noggit/map_horizon.h>
#include <noggit/Sky.h> #include <noggit/Sky.h>
#include <opengl/shader.hpp> #include <opengl/shader.hpp>
#include <opengl/primitives.hpp> #include <noggit/rendering/Primitives.hpp>
#include <memory> #include <memory>
@@ -123,8 +123,8 @@ namespace Noggit::Rendering
// cursor // cursor
Noggit::CursorRender _cursor_render; Noggit::CursorRender _cursor_render;
OpenGL::primitives::sphere _sphere_render; Noggit::Rendering::Primitives::Sphere _sphere_render;
OpenGL::primitives::square _square_render; Noggit::Rendering::Primitives::Square _square_render;
// buffers // buffers
OpenGL::Scoped::deferred_upload_buffers<8> _buffers; OpenGL::Scoped::deferred_upload_buffers<8> _buffers;

View File

@@ -0,0 +1,10 @@
#version 330 core
uniform vec4 color;
out vec4 out_color;
void main()
{
out_color = color;
}

View File

@@ -0,0 +1,17 @@
#version 330 core
in vec4 position;
uniform mat4 model_view_projection;
uniform vec3 origin;
uniform float radius;
void main()
{
vec4 pos = position;
pos.xyz *= radius;
vec3 origin_fixed = vec3(origin.x - radius / 2.0f, origin.y, origin.z - radius / 2.0f);
pos.xyz += origin_fixed;
gl_Position = model_view_projection * pos;
}

View File

@@ -0,0 +1,10 @@
#version 330 core
uniform vec4 color;
out vec4 out_color;
void main()
{
out_color = color;
}

View File

@@ -0,0 +1,15 @@
#version 330 core
in vec4 position;
uniform mat4 model_view_projection;
uniform vec3 origin;
uniform float radius;
void main()
{
vec4 pos = position;
pos.xyz *= radius;
pos.xyz += origin;
gl_Position = model_view_projection * pos;
}

View File

@@ -0,0 +1,10 @@
#version 330 core
uniform vec4 color;
out vec4 out_color;
void main()
{
out_color = color;
}

View File

@@ -0,0 +1,24 @@
#version 330 core
in vec4 position;
uniform mat4 model_view_projection;
uniform vec3 origin;
uniform float radius;
uniform float inclination;
uniform float orientation;
void main()
{
vec4 pos = position;
float cos_o = cos(orientation);
float sin_o = sin(orientation);
pos.y += pos.x * tan(inclination) * radius;
pos.x = (position.x*cos_o - position.z * sin_o) * radius;
pos.z = (position.z*cos_o + position.x * sin_o) * radius;
pos.xyz += origin;
gl_Position = model_view_projection * pos;
}

View File

@@ -0,0 +1,10 @@
#version 330 core
uniform vec4 color;
out vec4 out_color;
void main()
{
out_color = color;
}

View File

@@ -0,0 +1,11 @@
#version 330 core
uniform vec3 pointPositions[8];
uniform mat4 model_view;
uniform mat4 projection;
uniform mat4 transform;
void main()
{
gl_Position = projection * model_view * transform * vec4(pointPositions[gl_VertexID], 1.0);
}

View File

@@ -9,8 +9,8 @@
#include <noggit/ContextObject.hpp> #include <noggit/ContextObject.hpp>
#include <noggit/BoolToggleProperty.hpp> #include <noggit/BoolToggleProperty.hpp>
#include <noggit/ui/tools/ViewportManager/ViewportManager.hpp> #include <noggit/ui/tools/ViewportManager/ViewportManager.hpp>
#include <opengl/primitives.hpp> #include <noggit/rendering/Primitives.hpp>
#include <noggit/LiquidTextureManager.hpp> #include "noggit/rendering/LiquidTextureManager.hpp"
#include <QOpenGLWidget> #include <QOpenGLWidget>
#include <QSettings> #include <QSettings>
@@ -68,7 +68,7 @@ class PreviewRenderer : public Noggit::Ui::Tools::ViewportManager::Viewport
std::vector<ModelInstance> _model_instances; std::vector<ModelInstance> _model_instances;
std::vector<WMOInstance> _wmo_instances; std::vector<WMOInstance> _wmo_instances;
OpenGL::primitives::grid _grid; Noggit::Rendering::Primitives::Grid _grid;
float _animtime = 0.f; float _animtime = 0.f;

View File

@@ -1,508 +0,0 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#include <math/bounding_box.hpp>
#include <noggit/Misc.h>
#include <opengl/scoped.hpp>
#include <opengl/context.hpp>
#include <opengl/context.inl>
#include <opengl/primitives.hpp>
#include <opengl/types.hpp>
#include <array>
#include <vector>
#include <glm/gtx/quaternion.hpp>
namespace OpenGL
{
namespace primitives
{
void wire_box::draw ( glm::mat4x4 const& model_view
, glm::mat4x4 const& projection
, glm::mat4x4 const& transform
, glm::vec4 const& color
, glm::vec3 const& min_point
, glm::vec3 const& max_point
)
{
if (!_buffers_are_setup)
{
setup_buffers();
}
OpenGL::Scoped::use_program wire_box_shader {*_program.get()};
auto points = math::box_points(min_point, max_point);
auto glmPoints = std::vector<glm::vec3>();
for(auto const point : points)
{
glmPoints.push_back(glm::vec3(point.x, point.y, point.z));
}
wire_box_shader.uniform("model_view", model_view);
wire_box_shader.uniform("projection", projection);
wire_box_shader.uniform("transform", transform);
wire_box_shader.uniform("color", color);
wire_box_shader.uniform("pointPositions", glmPoints);
OpenGL::Scoped::bool_setter<GL_LINE_SMOOTH, GL_TRUE> const line_smooth;
gl.hint(GL_LINE_SMOOTH_HINT, GL_NICEST);
OpenGL::Scoped::vao_binder const _(_vao[0]);
gl.drawElements (GL_LINE_STRIP, _indices, 16, GL_UNSIGNED_BYTE, nullptr);
}
void wire_box::setup_buffers()
{
_program.reset(new OpenGL::program( {{ GL_VERTEX_SHADER
, R"code(
#version 330 core
uniform vec3 pointPositions[8];
uniform mat4 model_view;
uniform mat4 projection;
uniform mat4 transform;
void main()
{
gl_Position = projection * model_view * transform * vec4(pointPositions[gl_VertexID], 1.0);
}
)code"}
, { GL_FRAGMENT_SHADER
, R"code(
#version 330 core
uniform vec4 color;
out vec4 out_color;
void main()
{
out_color = color;
}
)code"
}
}));
_vao.upload();
_buffers.upload();
//std::vector<glm::vec3> positions (math::box_points (min_point, max_point));
static std::array<std::uint8_t, 16> const indices
{{5, 7, 3, 2, 0, 1, 3, 1, 5, 4, 0, 4, 6, 2, 6, 7}};
Scoped::buffer_binder<GL_ELEMENT_ARRAY_BUFFER> const index_buffer (_indices);
gl.bufferData ( GL_ELEMENT_ARRAY_BUFFER
, indices.size() * sizeof (*indices.data())
, indices.data()
, GL_STATIC_DRAW
);
OpenGL::Scoped::use_program shader (*_program.get());
OpenGL::Scoped::vao_binder const _ (_vao[0]);
_buffers_are_setup = true;
}
void wire_box::unload()
{
_vao.unload();
_buffers.unload();
_program.reset();
_buffers_are_setup = false;
}
void grid::draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, glm::vec4 const& color
, float radius
)
{
if (!_buffers_are_setup)
{
setup_buffers();
}
OpenGL::Scoped::use_program sphere_shader {*_program.get()};
sphere_shader.uniform("model_view_projection", mvp);
sphere_shader.uniform("origin", glm::vec3(pos.x,pos.y,pos.z));
sphere_shader.uniform("color", color);
sphere_shader.uniform("radius", radius);
OpenGL::Scoped::vao_binder const _(_vao[0]);
gl.drawElements(GL_LINES, _indices_vbo, _indice_count, GL_UNSIGNED_SHORT, nullptr);
}
void grid::setup_buffers()
{
_vao.upload();
_buffers.upload();
_program.reset(new OpenGL::program({{ GL_VERTEX_SHADER
, R"code(
#version 330 core
in vec4 position;
uniform mat4 model_view_projection;
uniform vec3 origin;
uniform float radius;
void main()
{
vec4 pos = position;
pos.xyz *= radius;
vec3 origin_fixed = vec3(origin.x - radius / 2.0f, origin.y, origin.z - radius / 2.0f);
pos.xyz += origin_fixed;
gl_Position = model_view_projection * pos;
}
)code"
}
, { GL_FRAGMENT_SHADER
, R"code(
#version 330 core
uniform vec4 color;
out vec4 out_color;
void main()
{
out_color = color;
}
)code"
}
}));
std::vector<glm::vec3> vertices;
std::vector<std::uint16_t> indices;
int slices = 20;
for(int j = 0; j <= slices; ++j)
{
for(int i = 0; i <= slices; ++i)
{
float x = static_cast<float>(i) / static_cast<float>(slices);
float y = 0;
float z = static_cast<float>(j) / static_cast<float>(slices);
vertices.push_back(glm::vec3(x, y, z));
}
}
for(int j = 0; j < slices; ++j)
{
for(int i = 0; i < slices; ++i)
{
int row1 = j * (slices + 1);
int row2 = (j + 1) * (slices + 1);
indices.push_back(row1 + i);
indices.push_back(row1 + i + 1);
indices.push_back(row1 + i + 1);
indices.push_back(row2 + i + 1);
indices.push_back(row2 + i + 1);
indices.push_back(row2 + i);
indices.push_back(row2 + i);
indices.push_back(row1 + i);
}
}
_indice_count = indices.size();
gl.bufferData<GL_ARRAY_BUFFER, glm::vec3>
(_vertices_vbo, vertices, GL_STATIC_DRAW);
gl.bufferData<GL_ELEMENT_ARRAY_BUFFER, std::uint16_t>
(_indices_vbo, indices, GL_STATIC_DRAW);
Scoped::index_buffer_manual_binder indices_binder(_indices_vbo);
OpenGL::Scoped::use_program shader (*_program.get());
{
OpenGL::Scoped::vao_binder const _ (_vao[0]);
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> const vertices_binder (_vertices_vbo);
shader.attrib("position", 3, GL_FLOAT, GL_FALSE, 0, 0);
indices_binder.bind();
}
_buffers_are_setup = true;
}
void grid::unload()
{
_vao.unload();
_buffers.unload();
_program.reset();
_buffers_are_setup = false;
}
void sphere::draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, glm::vec4 const& color
, float radius
)
{
if (!_buffers_are_setup)
{
setup_buffers();
}
OpenGL::Scoped::use_program sphere_shader {*_program.get()};
sphere_shader.uniform("model_view_projection", mvp);
sphere_shader.uniform("origin", glm::vec3(pos.x,pos.y,pos.z));
sphere_shader.uniform("radius", radius);
sphere_shader.uniform("color", color);
OpenGL::Scoped::vao_binder const _(_vao[0]);
gl.drawElements(GL_TRIANGLES, _indices_vbo, _indice_count, GL_UNSIGNED_SHORT, nullptr);
}
void sphere::setup_buffers()
{
_vao.upload();
_buffers.upload();
std::vector<glm::vec3> vertices;
std::vector<std::uint16_t> indices;
_program.reset(new OpenGL::program({{ GL_VERTEX_SHADER
, R"code(
#version 330 core
in vec4 position;
uniform mat4 model_view_projection;
uniform vec3 origin;
uniform float radius;
void main()
{
vec4 pos = position;
pos.xyz *= radius;
pos.xyz += origin;
gl_Position = model_view_projection * pos;
}
)code"
}
, { GL_FRAGMENT_SHADER
, R"code(
#version 330 core
uniform vec4 color;
out vec4 out_color;
void main()
{
out_color = color;
}
)code"
}
}));
int segment = 27;
// add overlapping vertices at the end for an easier vertices generations
for (int rotation_step = 0; rotation_step <= segment; ++rotation_step)
{
math::degrees rotation(360.f*rotation_step / static_cast<float>(segment));
auto rotationQuat = glm::angleAxis(rotation._, glm::vec3(0, 0, 1));
for (int i = 0; i < segment; ++i)
{
float x = glm::cos(math::radians(math::degrees(i * 360 / segment))._);
float z = glm::sin(math::radians(math::degrees(i * 360 / segment))._);
glm::vec4 v(x, 0.f, z,0.0f);
vertices.emplace_back(glm::toMat4(rotationQuat) * v);
if (rotation_step < segment)
{
indices.emplace_back(i + rotation_step*segment);
indices.emplace_back(((i + 1) % segment) + rotation_step * segment);
indices.emplace_back(i + (rotation_step+1) * segment);
indices.emplace_back(i + (rotation_step+1) * segment);
indices.emplace_back(((i + 1) % segment) + rotation_step * segment);
indices.emplace_back(((i + 1) % segment) + (rotation_step+1) * segment);
}
}
}
_indice_count = indices.size();
gl.bufferData<GL_ARRAY_BUFFER, glm::vec3>
(_vertices_vbo, vertices, GL_STATIC_DRAW);
gl.bufferData<GL_ELEMENT_ARRAY_BUFFER, std::uint16_t>
(_indices_vbo, indices, GL_STATIC_DRAW);
Scoped::index_buffer_manual_binder indices_binder(_indices_vbo);
OpenGL::Scoped::use_program shader (*_program.get());
{
OpenGL::Scoped::vao_binder const _ (_vao[0]);
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> const vertices_binder (_vertices_vbo);
shader.attrib("position", 3, GL_FLOAT, GL_FALSE, 0, 0);
indices_binder.bind();
}
_buffers_are_setup = true;
}
void sphere::unload()
{
_vao.unload();
_buffers.unload();
_program.reset();
_buffers_are_setup = false;
}
void square::draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, float radius
, math::radians inclination
, math::radians orientation
, glm::vec4 const& color
)
{
if (!_buffers_are_setup)
{
setup_buffers();
}
OpenGL::Scoped::use_program sphere_shader {*_program.get()};
sphere_shader.uniform("model_view_projection", mvp);
sphere_shader.uniform("origin", glm::vec3(pos.x,pos.y,pos.z));
sphere_shader.uniform("radius", radius);
sphere_shader.uniform("inclination", inclination._);
sphere_shader.uniform("orientation", orientation._);
sphere_shader.uniform("color", color);
OpenGL::Scoped::vao_binder const _ (_vao[0]);
gl.drawElements(GL_TRIANGLES, _indices_vbo, 6, GL_UNSIGNED_SHORT, nullptr);
}
void square::setup_buffers()
{
_vao.upload();
_buffers.upload();
std::vector<glm::vec3> vertices =
{
{-1.f, 0.f, -1.f}
,{-1.f, 0.f, 1.f}
,{ 1.f, 0.f, 1.f}
,{ 1.f, 0.f, -1.f}
};
std::vector<std::uint16_t> indices = {0,1,2, 2,3,0};
_program.reset(new OpenGL::program({{ GL_VERTEX_SHADER
, R"code(
#version 330 core
in vec4 position;
uniform mat4 model_view_projection;
uniform vec3 origin;
uniform float radius;
uniform float inclination;
uniform float orientation;
void main()
{
vec4 pos = position;
float cos_o = cos(orientation);
float sin_o = sin(orientation);
pos.y += pos.x * tan(inclination) * radius;
pos.x = (position.x*cos_o - position.z * sin_o) * radius;
pos.z = (position.z*cos_o + position.x * sin_o) * radius;
pos.xyz += origin;
gl_Position = model_view_projection * pos;
}
)code"
}
, { GL_FRAGMENT_SHADER
, R"code(
#version 330 core
uniform vec4 color;
out vec4 out_color;
void main()
{
out_color = color;
}
)code"
}
}));
gl.bufferData<GL_ARRAY_BUFFER, glm::vec3>
(_vertices_vbo, vertices, GL_STATIC_DRAW);
gl.bufferData<GL_ELEMENT_ARRAY_BUFFER, std::uint16_t>
(_indices_vbo, indices, GL_STATIC_DRAW);
Scoped::index_buffer_manual_binder indices_binder (_indices_vbo);
OpenGL::Scoped::use_program shader(*_program.get());
{
OpenGL::Scoped::vao_binder const _ (_vao[0]);
OpenGL::Scoped::buffer_binder<GL_ARRAY_BUFFER> const vertices_binder (_vertices_vbo);
shader.attrib("position", 3, GL_FLOAT, GL_FALSE, 0, 0);
indices_binder.bind();
}
_buffers_are_setup = true;
}
void square::unload()
{
_vao.unload();
_buffers.unload();
_program.reset();
_buffers_are_setup = false;
}
}
}

View File

@@ -1,134 +0,0 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#include <opengl/scoped.hpp>
#include <opengl/shader.hpp>
#include <noggit/ContextObject.hpp>
#include <memory>
#include <unordered_map>
namespace math
{
struct vector_3d;
struct vector_4d;
}
namespace OpenGL
{
namespace primitives
{
class wire_box
{
public:
wire_box() {}
wire_box( const wire_box&);
wire_box& operator=( wire_box& box ) { return *this; };
public:
static wire_box& getInstance(Noggit::NoggitRenderContext context)
{
static std::unordered_map<Noggit::NoggitRenderContext, wire_box> instances;
if (instances.find(context) == instances.end())
{
wire_box instance;
instances[context] = instance;
}
return instances.at(context);
}
void draw ( glm::mat4x4 const& model_view
, glm::mat4x4 const& projection
, glm::mat4x4 const& transform
, glm::vec4 const& color
, glm::vec3 const& min_point
, glm::vec3 const& max_point
);
void unload();
private:
bool _buffers_are_setup = false;
void setup_buffers();
Scoped::deferred_upload_vertex_arrays<1> _vao;
Scoped::deferred_upload_buffers<1> _buffers;
GLuint const& _indices = _buffers[0];
std::unique_ptr<OpenGL::program> _program;
};
class grid
{
public:
void draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, glm::vec4 const& color
, float radius
);
void unload();
private:
bool _buffers_are_setup = false;
void setup_buffers();
int _indice_count = 0;
Scoped::deferred_upload_vertex_arrays<1> _vao;
Scoped::deferred_upload_buffers<2> _buffers;
GLuint const& _vertices_vbo = _buffers[0];
GLuint const& _indices_vbo = _buffers[1];
std::unique_ptr<OpenGL::program> _program;
};
class sphere
{
public:
void draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, glm::vec4 const& color
, float radius
);
void unload();
private:
bool _buffers_are_setup = false;
void setup_buffers();
int _indice_count = 0;
Scoped::deferred_upload_vertex_arrays<1> _vao;
Scoped::deferred_upload_buffers<2> _buffers;
GLuint const& _vertices_vbo = _buffers[0];
GLuint const& _indices_vbo = _buffers[1];
std::unique_ptr<OpenGL::program> _program;
};
class square
{
public:
void draw(glm::mat4x4 const& mvp
, glm::vec3 const& pos
, float radius // radius of the biggest circle fitting inside the square drawn
, math::radians inclination
, math::radians orientation
, glm::vec4 const& color
);
void unload();
private:
bool _buffers_are_setup = false;
void setup_buffers();
Scoped::deferred_upload_vertex_arrays<1> _vao;
Scoped::deferred_upload_buffers<2> _buffers;
GLuint const& _vertices_vbo = _buffers[0];
GLuint const& _indices_vbo = _buffers[1];
std::unique_ptr<OpenGL::program> _program;
};
}
}