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"]
|
||||
path = libs/glew-2.0.0
|
||||
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/yoga
|
||||
../libs/stb
|
||||
../libs/curl/android/include
|
||||
../libs/curl-android-ios/prebuilt-with-ssl/android/include
|
||||
)
|
||||
|
||||
# add lib dependencies
|
||||
@@ -54,7 +54,7 @@ target_link_libraries(
|
||||
native-lib
|
||||
android
|
||||
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
|
||||
GLESv3
|
||||
log
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
<activity android:name="android.app.NativeActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:screenOrientation="sensorLandscape">
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:noHistory="true">
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="native-lib" />
|
||||
<intent-filter>
|
||||
|
||||
@@ -257,6 +257,7 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
|
||||
case APP_CMD_TERM_WINDOW:
|
||||
// The window is being hidden or closed, clean it up.
|
||||
engine_term_display(engine);
|
||||
exit(0);
|
||||
break;
|
||||
case APP_CMD_GAINED_FOCUS:
|
||||
// When our app gains focus, we start monitoring the accelerometer.
|
||||
@@ -326,7 +327,7 @@ void android_main(struct android_app* state) {
|
||||
app_dummy();
|
||||
|
||||
LOG("NETWORK TESTING...");
|
||||
curl_test();
|
||||
//curl_test();
|
||||
LOG("NETWORK TESTED");
|
||||
|
||||
memset(&engine, 0, sizeof(engine));
|
||||
|
||||
@@ -205,10 +205,6 @@
|
||||
<ClInclude Include="engine\texture.h" />
|
||||
<ClInclude Include="engine\util.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="engine\bezier" />
|
||||
<None Include="engine\canvas" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
||||
@@ -114,8 +114,4 @@
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="engine\bezier" />
|
||||
<None Include="engine\canvas" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -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;
|
||||
@@ -96,6 +97,36 @@ 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)
|
||||
@@ -110,6 +141,15 @@ public:
|
||||
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]);
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
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