integrate and link lib curl for android, add VAO support for brush draw, sync canvas with screen redraw instead of input events
This commit is contained in:
@@ -487,6 +487,10 @@ void App::init()
|
||||
|
||||
void App::update(float dt)
|
||||
{
|
||||
// update offscreen stuff
|
||||
if (canvas && canvas->m_canvas)
|
||||
canvas->m_canvas->stroke_draw();
|
||||
|
||||
glClearColor(.1f, .1f, .1f, 1.f);
|
||||
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
@@ -34,6 +34,7 @@ class BrushMesh
|
||||
public:
|
||||
ui::Shader shader;
|
||||
GLuint buffers[3]{ 0 };
|
||||
GLuint vao{ 0 };
|
||||
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
||||
struct instance_t { glm::mat4 mvp; float flow; };
|
||||
int loc_flow;
|
||||
@@ -95,21 +96,60 @@ public:
|
||||
|
||||
loc_flow = shader.GetAttribLocation("a_flow");
|
||||
loc_mvp = shader.GetAttribLocation("a_mvp");
|
||||
|
||||
|
||||
#if USE_VBO
|
||||
glGenVertexArrays(1, &vao);
|
||||
if (!vao)
|
||||
return false;
|
||||
glBindVertexArray(vao);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, pos));
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vertex_t), (GLvoid*)offsetof(vertex_t, uvs));
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[2]);
|
||||
// Loop over each column of the matrix...
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// Set up the vertex attribute
|
||||
glVertexAttribPointer(loc_mvp + i, 4, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
||||
(GLvoid*)(offsetof(instance_t, mvp) + sizeof(glm::vec4) * i));
|
||||
// Enable it
|
||||
glEnableVertexAttribArray(loc_mvp + i);
|
||||
// Make it instanced
|
||||
glVertexAttribDivisor(loc_mvp + i, 1);
|
||||
}
|
||||
glEnableVertexAttribArray(loc_flow);
|
||||
glVertexAttribPointer(loc_flow, 1, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
||||
(GLvoid*)offsetof(instance_t, flow));
|
||||
glVertexAttribDivisor(loc_flow, 1);
|
||||
glBindVertexArray(0);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
void draw(const std::vector<StrokeSample>& samples, const glm::mat4& proj)
|
||||
{
|
||||
std::vector<instance_t> attributes;
|
||||
attributes.reserve(samples.size());
|
||||
for (const auto& s : samples)
|
||||
{
|
||||
auto mvp = proj *
|
||||
glm::translate(glm::vec3(s.pos, 0)) *
|
||||
glm::scale(glm::vec3(s.size, s.size, 1)) *
|
||||
glm::eulerAngleZ(s.angle);
|
||||
attributes.emplace_back(instance_t{ mvp, s.flow });
|
||||
}
|
||||
std::vector<instance_t> attributes;
|
||||
attributes.reserve(samples.size());
|
||||
for (const auto& s : samples)
|
||||
{
|
||||
auto mvp = proj *
|
||||
glm::translate(glm::vec3(s.pos, 0)) *
|
||||
glm::scale(glm::vec3(s.size, s.size, 1)) *
|
||||
glm::eulerAngleZ(s.angle);
|
||||
attributes.emplace_back(instance_t{ mvp, s.flow });
|
||||
}
|
||||
#ifdef USE_VBO
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, (int)(sizeof(instance_t) * attributes.size()), attributes.data(), GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glBindVertexArray(vao);
|
||||
glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0, (int)samples.size());
|
||||
glBindVertexArray(0);
|
||||
#else
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
|
||||
@@ -124,16 +164,16 @@ public:
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, (int)(sizeof(instance_t) * attributes.size()), attributes.data(), GL_STATIC_DRAW);
|
||||
// Loop over each column of the matrix...
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// Set up the vertex attribute
|
||||
glVertexAttribPointer(loc_mvp + i, 4, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
||||
(GLvoid*)(offsetof(instance_t, mvp) + sizeof(glm::vec4) * i));
|
||||
// Enable it
|
||||
glEnableVertexAttribArray(loc_mvp + i);
|
||||
// Make it instanced
|
||||
glVertexAttribDivisor(loc_mvp + i, 1);
|
||||
}
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// Set up the vertex attribute
|
||||
glVertexAttribPointer(loc_mvp + i, 4, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
||||
(GLvoid*)(offsetof(instance_t, mvp) + sizeof(glm::vec4) * i));
|
||||
// Enable it
|
||||
glEnableVertexAttribArray(loc_mvp + i);
|
||||
// Make it instanced
|
||||
glVertexAttribDivisor(loc_mvp + i, 1);
|
||||
}
|
||||
glEnableVertexAttribArray(loc_flow);
|
||||
glVertexAttribPointer(loc_flow, 1, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
||||
(GLvoid*)offsetof(instance_t, flow));
|
||||
@@ -150,6 +190,7 @@ public:
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||
#endif // USE_VBO
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -57,6 +57,11 @@ public:
|
||||
void stroke_update(glm::vec2 point, float pressure)
|
||||
{
|
||||
m_current_stroke->add_point(point, pressure);
|
||||
}
|
||||
void stroke_draw()
|
||||
{
|
||||
if (!(m_current_stroke && m_current_stroke->has_sample()))
|
||||
return;
|
||||
|
||||
m_fb.bindFramebuffer();
|
||||
|
||||
|
||||
@@ -16,7 +16,11 @@ bool Font::load(const char* ttf, int font_size)
|
||||
auto bitmap = std::make_unique<uint8_t[]>(w*h);
|
||||
chars.resize(num_chars);
|
||||
int ret = stbtt_BakeFontBitmap(file.m_data, 0, (float)font_size, bitmap.get(), w, h, start_char, num_chars, chars.data());
|
||||
#ifdef __APPLE__
|
||||
font_tex.create(w, h, GL_RED, bitmap.get());
|
||||
#else
|
||||
font_tex.create(w, h, GL_LUMINANCE, bitmap.get());
|
||||
#endif // __APPLE__
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user