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:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -13,3 +13,6 @@
|
|||||||
[submodule "libs/glew-2.0.0"]
|
[submodule "libs/glew-2.0.0"]
|
||||||
path = libs/glew-2.0.0
|
path = libs/glew-2.0.0
|
||||||
url = https://omigamedev@bitbucket.org/omigamedev/libglew-2.0.0.git
|
url = https://omigamedev@bitbucket.org/omigamedev/libglew-2.0.0.git
|
||||||
|
[submodule "libs/curl-android-ios"]
|
||||||
|
path = libs/curl-android-ios
|
||||||
|
url = https://github.com/gcesarmza/curl-android-ios
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ target_include_directories(native-lib PRIVATE
|
|||||||
../libs/tinyxml2
|
../libs/tinyxml2
|
||||||
../libs/yoga
|
../libs/yoga
|
||||||
../libs/stb
|
../libs/stb
|
||||||
../libs/curl/android/include
|
../libs/curl-android-ios/prebuilt-with-ssl/android/include
|
||||||
)
|
)
|
||||||
|
|
||||||
# add lib dependencies
|
# add lib dependencies
|
||||||
@@ -54,7 +54,7 @@ target_link_libraries(
|
|||||||
native-lib
|
native-lib
|
||||||
android
|
android
|
||||||
app-glue
|
app-glue
|
||||||
${CMAKE_SOURCE_DIR}/../libs/curl/android/armeabi-v7a/libcurl.a
|
${CMAKE_SOURCE_DIR}/../libs/curl-android-ios/prebuilt-with-ssl/android/armeabi-v7a/libcurl.a
|
||||||
EGL
|
EGL
|
||||||
GLESv3
|
GLESv3
|
||||||
log
|
log
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
<activity android:name="android.app.NativeActivity"
|
<activity android:name="android.app.NativeActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:configChanges="orientation|keyboardHidden"
|
android:configChanges="orientation|keyboardHidden"
|
||||||
android:screenOrientation="sensorLandscape">
|
android:screenOrientation="sensorLandscape"
|
||||||
|
android:noHistory="true">
|
||||||
<meta-data android:name="android.app.lib_name"
|
<meta-data android:name="android.app.lib_name"
|
||||||
android:value="native-lib" />
|
android:value="native-lib" />
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
|||||||
case APP_CMD_TERM_WINDOW:
|
case APP_CMD_TERM_WINDOW:
|
||||||
// The window is being hidden or closed, clean it up.
|
// The window is being hidden or closed, clean it up.
|
||||||
engine_term_display(engine);
|
engine_term_display(engine);
|
||||||
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case APP_CMD_GAINED_FOCUS:
|
case APP_CMD_GAINED_FOCUS:
|
||||||
// When our app gains focus, we start monitoring the accelerometer.
|
// When our app gains focus, we start monitoring the accelerometer.
|
||||||
@@ -326,7 +327,7 @@ void android_main(struct android_app* state) {
|
|||||||
app_dummy();
|
app_dummy();
|
||||||
|
|
||||||
LOG("NETWORK TESTING...");
|
LOG("NETWORK TESTING...");
|
||||||
curl_test();
|
//curl_test();
|
||||||
LOG("NETWORK TESTED");
|
LOG("NETWORK TESTED");
|
||||||
|
|
||||||
memset(&engine, 0, sizeof(engine));
|
memset(&engine, 0, sizeof(engine));
|
||||||
|
|||||||
@@ -205,10 +205,6 @@
|
|||||||
<ClInclude Include="engine\texture.h" />
|
<ClInclude Include="engine\texture.h" />
|
||||||
<ClInclude Include="engine\util.h" />
|
<ClInclude Include="engine\util.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<None Include="engine\bezier" />
|
|
||||||
<None Include="engine\canvas" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|||||||
@@ -114,8 +114,4 @@
|
|||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<None Include="engine\bezier" />
|
|
||||||
<None Include="engine\canvas" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -487,6 +487,10 @@ void App::init()
|
|||||||
|
|
||||||
void App::update(float dt)
|
void App::update(float dt)
|
||||||
{
|
{
|
||||||
|
// update offscreen stuff
|
||||||
|
if (canvas && canvas->m_canvas)
|
||||||
|
canvas->m_canvas->stroke_draw();
|
||||||
|
|
||||||
glClearColor(.1f, .1f, .1f, 1.f);
|
glClearColor(.1f, .1f, .1f, 1.f);
|
||||||
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
glViewport(0, 0, (GLsizei)width, (GLsizei)height);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class BrushMesh
|
|||||||
public:
|
public:
|
||||||
ui::Shader shader;
|
ui::Shader shader;
|
||||||
GLuint buffers[3]{ 0 };
|
GLuint buffers[3]{ 0 };
|
||||||
|
GLuint vao{ 0 };
|
||||||
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
struct vertex_t { glm::vec4 pos; glm::vec2 uvs; };
|
||||||
struct instance_t { glm::mat4 mvp; float flow; };
|
struct instance_t { glm::mat4 mvp; float flow; };
|
||||||
int loc_flow;
|
int loc_flow;
|
||||||
@@ -95,21 +96,60 @@ public:
|
|||||||
|
|
||||||
loc_flow = shader.GetAttribLocation("a_flow");
|
loc_flow = shader.GetAttribLocation("a_flow");
|
||||||
loc_mvp = shader.GetAttribLocation("a_mvp");
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
void draw(const std::vector<StrokeSample>& samples, const glm::mat4& proj)
|
void draw(const std::vector<StrokeSample>& samples, const glm::mat4& proj)
|
||||||
{
|
{
|
||||||
std::vector<instance_t> attributes;
|
std::vector<instance_t> attributes;
|
||||||
attributes.reserve(samples.size());
|
attributes.reserve(samples.size());
|
||||||
for (const auto& s : samples)
|
for (const auto& s : samples)
|
||||||
{
|
{
|
||||||
auto mvp = proj *
|
auto mvp = proj *
|
||||||
glm::translate(glm::vec3(s.pos, 0)) *
|
glm::translate(glm::vec3(s.pos, 0)) *
|
||||||
glm::scale(glm::vec3(s.size, s.size, 1)) *
|
glm::scale(glm::vec3(s.size, s.size, 1)) *
|
||||||
glm::eulerAngleZ(s.angle);
|
glm::eulerAngleZ(s.angle);
|
||||||
attributes.emplace_back(instance_t{ mvp, s.flow });
|
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(0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
|
||||||
@@ -124,16 +164,16 @@ public:
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[2]);
|
glBindBuffer(GL_ARRAY_BUFFER, buffers[2]);
|
||||||
glBufferData(GL_ARRAY_BUFFER, (int)(sizeof(instance_t) * attributes.size()), attributes.data(), GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, (int)(sizeof(instance_t) * attributes.size()), attributes.data(), GL_STATIC_DRAW);
|
||||||
// Loop over each column of the matrix...
|
// Loop over each column of the matrix...
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
// Set up the vertex attribute
|
// Set up the vertex attribute
|
||||||
glVertexAttribPointer(loc_mvp + i, 4, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
glVertexAttribPointer(loc_mvp + i, 4, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
||||||
(GLvoid*)(offsetof(instance_t, mvp) + sizeof(glm::vec4) * i));
|
(GLvoid*)(offsetof(instance_t, mvp) + sizeof(glm::vec4) * i));
|
||||||
// Enable it
|
// Enable it
|
||||||
glEnableVertexAttribArray(loc_mvp + i);
|
glEnableVertexAttribArray(loc_mvp + i);
|
||||||
// Make it instanced
|
// Make it instanced
|
||||||
glVertexAttribDivisor(loc_mvp + i, 1);
|
glVertexAttribDivisor(loc_mvp + i, 1);
|
||||||
}
|
}
|
||||||
glEnableVertexAttribArray(loc_flow);
|
glEnableVertexAttribArray(loc_flow);
|
||||||
glVertexAttribPointer(loc_flow, 1, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
glVertexAttribPointer(loc_flow, 1, GL_FLOAT, GL_FALSE, sizeof(instance_t),
|
||||||
(GLvoid*)offsetof(instance_t, flow));
|
(GLvoid*)offsetof(instance_t, flow));
|
||||||
@@ -150,6 +190,7 @@ public:
|
|||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ELEMENT_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)
|
void stroke_update(glm::vec2 point, float pressure)
|
||||||
{
|
{
|
||||||
m_current_stroke->add_point(point, pressure);
|
m_current_stroke->add_point(point, pressure);
|
||||||
|
}
|
||||||
|
void stroke_draw()
|
||||||
|
{
|
||||||
|
if (!(m_current_stroke && m_current_stroke->has_sample()))
|
||||||
|
return;
|
||||||
|
|
||||||
m_fb.bindFramebuffer();
|
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);
|
auto bitmap = std::make_unique<uint8_t[]>(w*h);
|
||||||
chars.resize(num_chars);
|
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());
|
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());
|
font_tex.create(w, h, GL_RED, bitmap.get());
|
||||||
|
#else
|
||||||
|
font_tex.create(w, h, GL_LUMINANCE, bitmap.get());
|
||||||
|
#endif // __APPLE__
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
1
libs/curl-android-ios
Submodule
1
libs/curl-android-ios
Submodule
Submodule libs/curl-android-ios added at d4b60d3fe0
Reference in New Issue
Block a user