Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ jobs:

- name: Build
run: |
cmake -G Ninja -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DBUILD_JVM=OFF -DBUILD_STANDALONE=OFF -B build-debug
cmake --build build-debug -- tests
cmake -DCMAKE_CXX_COMPILER_LAUNCHER=ccache --preset sanitize -DBUILD_JVM=OFF -DBUILD_STANDALONE=OFF
cmake --build --preset sanitize -- tests
- name: Test
run: |
mkdir test-results
# Run tests.
# We dont care about benchmark results, but still run the benchmark
# tests as quickly as possible to catch when something breaks.
build-debug/shared/test/tests \
UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 \
build-sanitize/shared/test/tests \
--benchmark-warmup-time 0 \
--benchmark-samples 1 \
--benchmark-no-analysis \
Expand Down
55 changes: 55 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Base build preset",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_EXPORT_COMPILE_COMMANDS": "on"
}
},
{
"name": "debug",
"inherits": "default",
"displayName": "Debug build",
"binaryDir": "${sourceDir}/build-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"inherits": "default",
"displayName": "Release build",
"binaryDir": "${sourceDir}/build-release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "sanitize",
"inherits": "default",
"displayName": "ASan/UBSan build",
"binaryDir": "${sourceDir}/build-sanitize",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_LINKER": "clang++",
"CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer"
}
}
],
"buildPresets": [
{
"name": "sanitize",
"displayName": "Default Build Preset",
"configurePreset": "sanitize"
}
]
}
21 changes: 8 additions & 13 deletions android/src/main/cpp/graphics/objects/LineGroup2dOpenGl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include "LineGroup2dOpenGl.h"
#include "OwnedBytesHelper.h"
#include <cmath>
#include <cstring>
#include <string>
Expand All @@ -21,23 +22,17 @@ std::shared_ptr<GraphicsObjectInterface> LineGroup2dOpenGl::asGraphicsObject() {
bool LineGroup2dOpenGl::isReady() { return ready; }


void LineGroup2dOpenGl::setLines(const ::SharedBytes & lines, const ::SharedBytes & indices, const Vec3D &origin, bool is3d) {
void LineGroup2dOpenGl::setLines(const ::OwnedBytes & lines, const ::OwnedBytes & indices, const Vec3D &origin, bool is3d) {
std::lock_guard<std::recursive_mutex> lock(dataMutex);
ready = false;
dataReady = false;

lineIndices.resize(indices.elementCount);
lineAttributes.resize(lines.elementCount);
std::tie(lineAttributes, lineAttributesSize) = OwnedBytesHelper::toUniquePtr<GLfloat>(lines);
std::tie(lineIndices, lineIndicesSize) = OwnedBytesHelper::toUniquePtr<GLuint>(indices);

lineOrigin = origin;
this->is3d = is3d;

if (indices.elementCount > 0) {
std::memcpy(lineIndices.data(), (void *) indices.address, indices.elementCount * indices.bytesPerElement);
}
if (lines.elementCount > 0) {
std::memcpy(lineAttributes.data(), (void *) lines.address, lines.elementCount * lines.bytesPerElement);
}

dataReady = true;
}

Expand Down Expand Up @@ -73,7 +68,7 @@ void LineGroup2dOpenGl::setup(const std::shared_ptr<::RenderingContextInterface>
glGenBuffers(1, &vertexAttribBuffer);
}
glBindBuffer(GL_ARRAY_BUFFER, vertexAttribBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * lineAttributes.size(), &lineAttributes[0], GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * lineAttributesSize, lineAttributes.get(), GL_STATIC_DRAW);

size_t floatSize = sizeof(GLfloat);
size_t dimensionality = is3d ? 3 : 2;
Expand Down Expand Up @@ -110,7 +105,7 @@ void LineGroup2dOpenGl::setup(const std::shared_ptr<::RenderingContextInterface>
glGenBuffers(1, &indexBuffer);
}
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * lineIndices.size(), &lineIndices[0], GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * lineIndicesSize, lineIndices.get(), GL_STATIC_DRAW);

glBindVertexArray(0);

Expand Down Expand Up @@ -188,7 +183,7 @@ void LineGroup2dOpenGl::render(const std::shared_ptr<::RenderingContextInterface
shaderProgram->preRender(openGlContext, isScreenSpaceCoords);

// Draw the triangle
glDrawElements(GL_TRIANGLES, lineIndices.size(), GL_UNSIGNED_INT, nullptr);
glDrawElements(GL_TRIANGLES, lineIndicesSize, GL_UNSIGNED_INT, nullptr);

glBindVertexArray(0);

Expand Down
8 changes: 5 additions & 3 deletions android/src/main/cpp/graphics/objects/LineGroup2dOpenGl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LineGroup2dOpenGl : public GraphicsObjectInterface,

// LineGroup2dInterface

virtual void setLines(const ::SharedBytes & lines, const ::SharedBytes & indices, const Vec3D &origin, bool is3d) override;
virtual void setLines(const ::OwnedBytes & lines, const ::OwnedBytes & indices, const Vec3D &origin, bool is3d) override;

virtual std::shared_ptr<GraphicsObjectInterface> asGraphicsObject() override;

Expand Down Expand Up @@ -72,9 +72,11 @@ class LineGroup2dOpenGl : public GraphicsObjectInterface,

GLuint vao;
GLuint vertexAttribBuffer = -1;
std::vector<GLfloat> lineAttributes;
size_t lineAttributesSize;
std::unique_ptr<GLfloat> lineAttributes;
GLuint indexBuffer = -1;
std::vector<GLuint> lineIndices;
size_t lineIndicesSize;
std::unique_ptr<GLuint> lineIndices;
bool glDataBuffersGenerated = false;
Vec3D lineOrigin = Vec3D(0.0, 0.0, 0.0);

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions bridging/android/jni/graphics/common/NativeOwnedBytes.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions bridging/android/jni/graphics/common/NativeOwnedBytes.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions bridging/android/jni/graphics/common/NativeOwnedBytesDestructor.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading