diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-17 23:10:55 -0400 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-03-17 23:10:55 -0400 |
commit | c29a911cd1a3f23f66478f205cace14487aadc56 (patch) | |
tree | 43308a2b186314c74e04441f5470a652cf607540 /frontend/_wasm | |
parent | 1a08dd2bd6839f0be4b12dc5317ab0b00ca23ae1 (diff) |
Beginning to build out the orthographic renderer, and updated styles
Diffstat (limited to 'frontend/_wasm')
-rw-r--r-- | frontend/_wasm/output.js | 30 | ||||
-rwxr-xr-x | frontend/_wasm/output.wasm | bin | 29351 -> 30239 bytes | |||
-rw-r--r-- | frontend/_wasm/wasm.cpp | 22 |
3 files changed, 44 insertions, 8 deletions
diff --git a/frontend/_wasm/output.js b/frontend/_wasm/output.js index ee8462a..6043271 100644 --- a/frontend/_wasm/output.js +++ b/frontend/_wasm/output.js @@ -2509,6 +2509,26 @@ var ASM_CONSTS = { return id; } + function _glDeleteBuffers(n, buffers) { + for (var i = 0; i < n; i++) { + var id = HEAP32[(((buffers)+(i*4))>>2)]; + var buffer = GL.buffers[id]; + + // From spec: "glDeleteBuffers silently ignores 0's and names that do not + // correspond to existing buffer objects." + if (!buffer) continue; + + GLctx.deleteBuffer(buffer); + buffer.name = 0; + GL.buffers[id] = null; + + if (id == GLctx.currentArrayBufferBinding) GLctx.currentArrayBufferBinding = 0; + if (id == GLctx.currentElementArrayBufferBinding) GLctx.currentElementArrayBufferBinding = 0; + if (id == GLctx.currentPixelPackBufferBinding) GLctx.currentPixelPackBufferBinding = 0; + if (id == GLctx.currentPixelUnpackBufferBinding) GLctx.currentPixelUnpackBufferBinding = 0; + } + } + function _glDeleteProgram(id) { if (!id) return; var program = GL.programs[id]; @@ -2533,6 +2553,14 @@ var ASM_CONSTS = { GL.shaders[id] = null; } + function _glDeleteVertexArrays(n, vaos) { + for (var i = 0; i < n; i++) { + var id = HEAP32[(((vaos)+(i*4))>>2)]; + GLctx['deleteVertexArray'](GL.vaos[id]); + GL.vaos[id] = null; + } + } + function _glDepthFunc(x0) { GLctx['depthFunc'](x0) } function _glDepthMask(flag) { @@ -2832,8 +2860,10 @@ var asmLibraryArg = { "glCompileShader": _glCompileShader, "glCreateProgram": _glCreateProgram, "glCreateShader": _glCreateShader, + "glDeleteBuffers": _glDeleteBuffers, "glDeleteProgram": _glDeleteProgram, "glDeleteShader": _glDeleteShader, + "glDeleteVertexArrays": _glDeleteVertexArrays, "glDepthFunc": _glDepthFunc, "glDepthMask": _glDepthMask, "glDrawArrays": _glDrawArrays, diff --git a/frontend/_wasm/output.wasm b/frontend/_wasm/output.wasm Binary files differindex 2ec3de9..8f520dc 100755 --- a/frontend/_wasm/output.wasm +++ b/frontend/_wasm/output.wasm diff --git a/frontend/_wasm/wasm.cpp b/frontend/_wasm/wasm.cpp index 8673c80..254a5e2 100644 --- a/frontend/_wasm/wasm.cpp +++ b/frontend/_wasm/wasm.cpp @@ -29,6 +29,7 @@ const char* orthographicFragment = " gl_FragColor = VertexColor; \n" "}"; + struct OrthographicProgramData { GLuint shader; @@ -52,6 +53,7 @@ struct OrthographicVertex { struct TriangleObject { OrthographicVertex vertices[3]; Vector2 velocity; + Vector2 position; GLuint mVao; GLuint mVbo; Mat4x4 model; @@ -66,10 +68,6 @@ struct TriangleObject { glBindBuffer(GL_ARRAY_BUFFER, mVbo); glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(OrthographicVertex), &vertices[0], GL_STATIC_DRAW); - for (int idx = 0; idx < 3; idx++) { - printf("%f, %f\n", vertices[idx].position.x, vertices[idx].position.y); - } - glEnableVertexAttribArray(programData->attributes.position); glVertexAttribPointer(programData->attributes.position, 2, GL_FLOAT, GL_FALSE, sizeof(OrthographicVertex), (GLvoid *)0); @@ -144,6 +142,7 @@ int main() { Scene scene; EM_BOOL runScene(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData) { + scene.programData = OrthographicProgramData(); printf("Compiling shaders...\n"); scene.programData.shader = loadShader(orthographicVertex, orthographicFragment); printf("Shaders compiled.\n"); @@ -151,14 +150,17 @@ EM_BOOL runScene(int eventType, const EmscriptenMouseEvent* mouseEvent, void* us printf("Initializing scene...\n"); useShader(scene.programData.shader); + scene.programData.attributes.position = getShaderAttribute(scene.programData.shader, "position"); scene.programData.attributes.color = getShaderAttribute(scene.programData.shader, "color"); scene.programData.uniformVariables.projection = getShaderUniform(scene.programData.shader, "projection"); scene.programData.uniformVariables.model = getShaderUniform(scene.programData.shader, "model"); - scene.triangleObject.vertices[0] = { Vector2 { 220, 365 }, Vector4 { 1.f, 0.f, 0.f, 1.f }}; - scene.triangleObject.vertices[1] = { Vector2 { 320, 480 }, Vector4 { 0.f, 1.f, 0.f, 1.f }}; - scene.triangleObject.vertices[2] = { Vector2 { 420, 365 }, Vector4 { 0.f, 0.f, 1.f, 1.f }}; + scene.triangleObject = TriangleObject(); + scene.triangleObject.vertices[0] = { Vector2 { -100, -50 }, Vector4 { 1.f, 0.f, 0.f, 1.f }}; + scene.triangleObject.vertices[1] = { Vector2 { 0, 50 }, Vector4 { 0.f, 1.f, 0.f, 1.f }}; + scene.triangleObject.vertices[2] = { Vector2 { 100, -50 }, Vector4 { 0.f, 0.f, 1.f, 1.f }}; + scene.triangleObject.position = { 320.f, 480.f - 100.f }; scene.triangleObject.initialize(&scene.programData); scene.projection = Mat4x4().getOrthographicMatrix(0, 640, 0, 480); @@ -195,7 +197,8 @@ EM_BOOL update(double time, void* userData) { // Update scene->triangleObject.velocity = scene->triangleObject.velocity + Vector2 { 0, static_cast<float>(-9.8 * deltaTimeSeconds) }; - scene->triangleObject.model = scene->triangleObject.model.translateByVec2(scene->triangleObject.velocity * deltaTimeSeconds); + scene->triangleObject.position = scene->triangleObject.position + scene->triangleObject.velocity * deltaTimeSeconds; + scene->triangleObject.model = Mat4x4().translateByVec2(scene->triangleObject.position); // Render glEnable(GL_DEPTH_TEST); @@ -213,5 +216,8 @@ EM_BOOL update(double time, void* userData) { EM_BOOL terminateScene(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData) { scene.isTerminated = true; + glDeleteVertexArrays(1, &scene.triangleObject.mVao); + glDeleteBuffers(1, &scene.triangleObject.mVbo); + glDeleteProgram(scene.programData.shader); return true; } |