Move color wheel state mapping to renderer gl
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "node_colorwheel.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "shader.h"
|
||||
#include "log.h"
|
||||
#include "app.h"
|
||||
@@ -29,43 +30,67 @@ void NodeColorWheel::init_controls()
|
||||
|
||||
void NodeColorWheel::loaded()
|
||||
{
|
||||
m_circle.create<64>(.5, .4, Circle::kUVMapping::Tube);
|
||||
m_cur_hue.create<16>(.05, 0.04);
|
||||
m_cur_quad.create<16>(.04, 0.03, Circle::kUVMapping::Tube);
|
||||
m_circle.create<64>(.5f, .4f, Circle::kUVMapping::Tube);
|
||||
m_cur_hue.create<16>(.05f, 0.04f);
|
||||
m_cur_quad.create<16>(.04f, 0.03f, Circle::kUVMapping::Tube);
|
||||
|
||||
float quad_scale = glm::sin(glm::radians(45.f)) * 0.8f;
|
||||
m_quad.create<1>(quad_scale, quad_scale);
|
||||
|
||||
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; glm::vec4 col; };
|
||||
std::vector<vertex_t> vertices;
|
||||
float l = 0.4;
|
||||
float l = 0.4f;
|
||||
vertices.push_back({{glm::cos(4.f/3.f*glm::pi<float>())*l,glm::sin(4.f/3.f*glm::pi<float>())*l,0,1},{1,-1},{1,1,1,1}});
|
||||
vertices.push_back({{glm::cos(2.f/3.f*glm::pi<float>())*l,glm::sin(2.f/3.f*glm::pi<float>())*l,0,1},{0,0},{0,0,0,1}});
|
||||
vertices.push_back({{l,0,0,1},{1,1},{1,0,0,1}});
|
||||
|
||||
App::I->render_task([&]
|
||||
{
|
||||
const auto buffer_target = pp::renderer::gl::array_buffer_target();
|
||||
const auto upload_usage = pp::renderer::gl::static_draw_buffer_usage();
|
||||
const auto attribute_type = pp::renderer::gl::vertex_attribute_float_component_type();
|
||||
const auto attribute_normalized =
|
||||
static_cast<GLboolean>(pp::renderer::gl::vertex_attribute_not_normalized());
|
||||
|
||||
glGenBuffers(1, &buffers);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(vertex_t), vertices.data(), GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(buffer_target, buffers);
|
||||
glBufferData(buffer_target, vertices.size() * sizeof(vertex_t), vertices.data(), upload_usage);
|
||||
glBindBuffer(buffer_target, 0);
|
||||
|
||||
glGenVertexArrays(1, &arrays);
|
||||
glBindVertexArray(arrays);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)0);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, uvs));
|
||||
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, col));
|
||||
glBindBuffer(buffer_target, buffers);
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
4,
|
||||
attribute_type,
|
||||
attribute_normalized,
|
||||
sizeof(vertex_t),
|
||||
(GLvoid*)0);
|
||||
glVertexAttribPointer(
|
||||
1,
|
||||
2,
|
||||
attribute_type,
|
||||
attribute_normalized,
|
||||
sizeof(vertex_t),
|
||||
(GLvoid*)offsetof(vertex_t, uvs));
|
||||
glVertexAttribPointer(
|
||||
2,
|
||||
4,
|
||||
attribute_type,
|
||||
attribute_normalized,
|
||||
sizeof(vertex_t),
|
||||
(GLvoid*)offsetof(vertex_t, col));
|
||||
glBindVertexArray(0);
|
||||
});
|
||||
}
|
||||
|
||||
void NodeColorWheel::draw()
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
ShaderManager::use(kShader::ColorHue);
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp * glm::eulerAngleZ(glm::radians(-90.f)));
|
||||
ShaderManager::u_int(kShaderUniform::Direction, 0); // set horizontal
|
||||
@@ -74,9 +99,8 @@ void NodeColorWheel::draw()
|
||||
// ShaderManager::use(kShader::ColorTri);
|
||||
// ShaderManager::u_mat4(kShaderUniform::MVP, m_mvp);
|
||||
// ShaderManager::u_vec4(kShaderUniform::Col, glm::vec4(m_hsv, 0.f));
|
||||
// GLenum type = GL_TRIANGLES;
|
||||
// glBindVertexArray(arrays);
|
||||
// glDrawArrays(type, 0, 3);
|
||||
// glDrawArrays(pp::renderer::gl::primitive_mode_for_fill_count(3U), 0, 3);
|
||||
// glBindVertexArray(0);
|
||||
|
||||
ShaderManager::use(kShader::Color);
|
||||
@@ -144,8 +168,8 @@ kEventResult NodeColorWheel::handle_event(Event* e)
|
||||
else if (l >= 0.4f && l <= 0.5f)
|
||||
{
|
||||
mode = 1;
|
||||
auto pos = glm::normalize(me->m_pos - m_pos - GetSize() * 0.5f);
|
||||
m_hsv.x = (glm::atan(pos.y, -pos.x) + glm::pi<float>()) / glm::two_pi<float>();
|
||||
auto normalized_pos = glm::normalize(me->m_pos - m_pos - GetSize() * 0.5f);
|
||||
m_hsv.x = (glm::atan(normalized_pos.y, -normalized_pos.x) + glm::pi<float>()) / glm::two_pi<float>();
|
||||
handle_color_change();
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user