minor changes and added namespace to avoid conflicts when integrating with PanoPainter

This commit is contained in:
2017-03-15 08:17:22 +00:00
parent ee6d352fc6
commit c34d1a1f44
16 changed files with 112 additions and 39 deletions

View File

@@ -4,6 +4,8 @@
#include "shader.h"
#include "font.h"
#include "asset.h"
#include <tinyxml2.h>
#include <yoga/Yoga.h>
enum class kAttribute : uint16_t
{
@@ -106,7 +108,11 @@ public:
std::function<void()> on_loaded;
bool load(const char* path);
bool reload();
class Node* operator[](uint16_t id) { return m_layouts[id].get(); }
class Node* operator[](uint16_t id)
{
auto i = m_layouts.find(id);
return i == m_layouts.end() ? nullptr : i->second.get();
}
//Node& operator[](const char* ids) { return m_layouts[const_hash(ids)]; }
};
@@ -128,6 +134,7 @@ public:
bool m_destroyed = false;
float m_zoom = 1.f;
glm::vec2 m_scale{ 1.f };
glm::vec2 m_pos;
glm::vec2 m_size;
glm::vec4 m_clip;
@@ -195,6 +202,7 @@ public:
void SetJustify(YGJustify value) { YGNodeStyleSetJustifyContent(y_node, value); }
void SetAlign(YGAlign value) { YGNodeStyleSetAlignItems(y_node, value); }
void SetPositioning(YGPositionType value) { YGNodeStyleSetPositionType(y_node, value); }
void SetAspectRatio(float ar) { YGNodeStyleSetAspectRatio(y_node, ar); }
glm::vec4 rect_intersection(glm::vec4 a, glm::vec4 b)
{
@@ -287,7 +295,7 @@ public:
class NodeBorder : public Node
{
public:
static Plane m_plane;
static ui::Plane m_plane;
glm::vec4 m_color{ 0, 0, 0, 1 };
glm::vec4 m_border_color{ 1, 1, 1, 1 };
float m_thinkness{ 0 };
@@ -338,19 +346,20 @@ public:
}
virtual void draw() override
{
ShaderManager::use(kShader::Color);
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
using namespace ui;
ui::ShaderManager::use(kShader::Color);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
if (m_color.a != 1.f)
glEnable(GL_BLEND);
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
ui::ShaderManager::u_vec4(kShaderUniform::Col, m_color);
m_plane.draw_fill();
if (m_thinkness > 0)
{
glLineWidth(m_thinkness);
ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
ui::ShaderManager::u_vec4(kShaderUniform::Col, m_border_color);
m_plane.draw_stroke();
}
@@ -417,12 +426,13 @@ public:
}
virtual void draw() override
{
using namespace ui;
glm::mat4 pos = glm::translate(glm::vec3(glm::floor(m_pos), 0));
m_mvp = m_proj * pos;
ShaderManager::use(kShader::Font);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
ShaderManager::u_vec4(kShaderUniform::Col, m_color);
ui::ShaderManager::use(kShader::Font);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
ui::ShaderManager::u_vec4(kShaderUniform::Col, m_color);
glEnable(GL_BLEND);
m_text_mesh.draw();
glDisable(GL_BLEND);
@@ -432,9 +442,9 @@ public:
class NodeImage : public Node
{
public:
static Plane m_plane;
static ui::Plane m_plane;
static Sampler m_sampler;
bool m_use_atlas;
bool m_use_atlas = false;
glm::vec4 m_region;
glm::vec2 m_off;
glm::vec2 m_sz;
@@ -459,7 +469,7 @@ public:
}
virtual void create() override
{
if (TextureManager::load(m_path.c_str()))
if (!m_path.empty() && TextureManager::load(m_path.c_str()))
{
auto tex_sz = TextureManager::get(m_tex_id).size();
m_off = m_region.xy / tex_sz;
@@ -492,21 +502,22 @@ public:
}
virtual void draw() override
{
using namespace ui;
TextureManager::get(m_tex_id).bind();
m_sampler.bind(0);
glEnable(GL_BLEND);
if (m_use_atlas)
{
ShaderManager::use(kShader::Atlas);
ShaderManager::u_vec2(kShaderUniform::Tof, m_off);
ShaderManager::u_vec2(kShaderUniform::Tsz, m_sz);
ui::ShaderManager::use(kShader::Atlas);
ui::ShaderManager::u_vec2(kShaderUniform::Tof, m_off);
ui::ShaderManager::u_vec2(kShaderUniform::Tsz, m_sz);
}
else
{
ShaderManager::use(kShader::Texture);
ui::ShaderManager::use(kShader::Texture);
}
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
m_plane.draw_fill();
m_sampler.unbind();
TextureManager::get(m_tex_id).unbind();
@@ -787,7 +798,7 @@ public:
class NodeViewport : public Node
{
public:
std::unique_ptr<Plane> m_faces;
std::unique_ptr<ui::Plane> m_faces;
std::unique_ptr<Sampler> m_sampler;
uint16_t m_tex_id;
glm::vec2 drag_start;
@@ -798,7 +809,8 @@ public:
virtual void draw() override
{
glm::mat4 cam = glm::lookAt(glm::vec3(sinf(angle)*10, 0, -10), glm::vec3(0, 0, 0), glm::vec3(0, -1, 0));
using namespace ui;
glm::mat4 cam = glm::lookAt(glm::vec3(sinf(angle) * 10, 0, -10), glm::vec3(0, 0, 0), glm::vec3(0, -1, 0));
glm::mat4 proj = glm::perspective<float>(glm::radians(45.f), m_clip.z / m_clip.w, .1f, 100);
GLint vp[4];
@@ -814,9 +826,9 @@ public:
TextureManager::get(m_tex_id).bind();
m_sampler->bind(0);
glEnable(GL_BLEND);
ShaderManager::use(kShader::Texture);
ShaderManager::u_int(kShaderUniform::Tex, 0);
ShaderManager::u_mat4(kShaderUniform::MVP, proj * cam);
ui::ShaderManager::use(kShader::Texture);
ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
ui::ShaderManager::u_mat4(kShaderUniform::MVP, proj * cam);
m_faces->draw_fill();
m_sampler->unbind();
TextureManager::get(m_tex_id).unbind();
@@ -831,7 +843,7 @@ public:
}
virtual void create() override
{
m_faces = std::make_unique<Plane>();
m_faces = std::make_unique<ui::Plane>();
m_faces->create<1>(10, 10);
m_sampler = std::make_unique<Sampler>();
m_sampler->create();