From 87a3134fd8f084416825a2a38a050f6aca6931c6 Mon Sep 17 00:00:00 2001 From: ienaga Date: Tue, 3 Sep 2024 11:46:50 +0900 Subject: [PATCH] =?UTF-8?q?#154=20webgl=E3=83=91=E3=83=83=E3=82=B1?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=82=92v2=E3=81=B8=E7=A7=BB=E8=A1=8C(WIP)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/webgl/src/Context.ts | 2 +- .../ContextBeginNodeRenderingService.test.ts | 10 ++++++++-- ...meBufferManagerTransferMainCanvasService.ts | 5 +++-- packages/webgl/src/VertexArrayObject.ts | 18 ++++++++++-------- .../usecase/VertexArrayObjectBootUseCase.ts | 6 ------ .../ShaderManagerSetTextureUniformService.ts | 18 ++++-------------- .../usecase/ShaderManagerDrawTextureUseCase.ts | 4 ++-- 7 files changed, 28 insertions(+), 35 deletions(-) diff --git a/packages/webgl/src/Context.ts b/packages/webgl/src/Context.ts index 0967c3e9..065176d0 100644 --- a/packages/webgl/src/Context.ts +++ b/packages/webgl/src/Context.ts @@ -301,7 +301,7 @@ export class Context this.$clearColorR, this.$clearColorG, this.$clearColorB, - this.$clearColorA + this.$clearColorA, ); } diff --git a/packages/webgl/src/Context/service/ContextBeginNodeRenderingService.test.ts b/packages/webgl/src/Context/service/ContextBeginNodeRenderingService.test.ts index 7627e73d..6d7152f0 100644 --- a/packages/webgl/src/Context/service/ContextBeginNodeRenderingService.test.ts +++ b/packages/webgl/src/Context/service/ContextBeginNodeRenderingService.test.ts @@ -18,8 +18,14 @@ describe("ContextBeginNodeRenderingService.js method test", () => "scissor": vi.fn((x, y, w, h) => { expect(x).toBe(1); expect(y).toBe(2); - expect(w).toBe(3); - expect(h).toBe(4); + if (w === 3) { + expect(w).toBe(3); + expect(h).toBe(4); + } else { + expect(w).toBe(4); + expect(h).toBe(5); + } + }), "clear": vi.fn((v) => { return "clear"; }), "viewport": vi.fn((x, y, w, h) => { diff --git a/packages/webgl/src/FrameBufferManager/service/FrameBufferManagerTransferMainCanvasService.ts b/packages/webgl/src/FrameBufferManager/service/FrameBufferManagerTransferMainCanvasService.ts index 5c9081ad..0b6713a9 100644 --- a/packages/webgl/src/FrameBufferManager/service/FrameBufferManagerTransferMainCanvasService.ts +++ b/packages/webgl/src/FrameBufferManager/service/FrameBufferManagerTransferMainCanvasService.ts @@ -1,5 +1,5 @@ import type { IAttachmentObject } from "../../interface/IAttachmentObject"; -import { $setFramebufferBound } from "../../FrameBufferManager"; +import { $readFrameBuffer } from "../../FrameBufferManager"; import { $gl, $context @@ -23,7 +23,6 @@ export const execute = (): void => $gl.DRAW_FRAMEBUFFER, null ); - $setFramebufferBound(false); const width = mainAttachmentObject.width; const height = mainAttachmentObject.height; @@ -35,4 +34,6 @@ export const execute = (): void => $gl.COLOR_BUFFER_BIT, $gl.NEAREST ); + + $gl.bindFramebuffer($gl.FRAMEBUFFER, $readFrameBuffer); }; \ No newline at end of file diff --git a/packages/webgl/src/VertexArrayObject.ts b/packages/webgl/src/VertexArrayObject.ts index c77a7ccf..63e41be6 100644 --- a/packages/webgl/src/VertexArrayObject.ts +++ b/packages/webgl/src/VertexArrayObject.ts @@ -1,5 +1,5 @@ import type { IVertexArrayObject } from "./interface/IVertexArrayObject"; - +import { execute as vertexArrayObjectCreateRectVertexArrayObjectUseCase } from "./VertexArrayObject/usecase/VertexArrayObjectCreateRectVertexArrayObjectUseCase"; /** * @description VertexArrayObjectの再利用のための配列のオブジェクトプール、 * Object pool of array for reusing VertexArrayObject @@ -107,18 +107,20 @@ export const $setInstancedVertexArrayObject = (vertex_array_object: IVertexArray * @type {IVertexArrayObject} * @protected */ -export let $rectVertexArrayObject: IVertexArrayObject; +let $rectVertexArrayObject: IVertexArrayObject; /** - * @description 矩形描画用のVertexArrayObjectをセット - * Set the VertexArrayObject for rectangle drawing + * @description 矩形描画用のVertexArrayObjectを返却 + * Returns the VertexArrayObject for rectangle drawing * - * @param {IVertexArrayObject} vertex_array_object - * @return {void} + * @return {IVertexArrayObject} * @method * @protected */ -export const $setRectVertexArrayObject = (vertex_array_object: IVertexArrayObject): void => +export const $getRectVertexArrayObject = (): IVertexArrayObject => { - $rectVertexArrayObject = vertex_array_object; + if (!$rectVertexArrayObject) { + $rectVertexArrayObject = vertexArrayObjectCreateRectVertexArrayObjectUseCase() + } + return $rectVertexArrayObject as NonNullable; }; diff --git a/packages/webgl/src/VertexArrayObject/usecase/VertexArrayObjectBootUseCase.ts b/packages/webgl/src/VertexArrayObject/usecase/VertexArrayObjectBootUseCase.ts index 23674e92..257ee46f 100644 --- a/packages/webgl/src/VertexArrayObject/usecase/VertexArrayObjectBootUseCase.ts +++ b/packages/webgl/src/VertexArrayObject/usecase/VertexArrayObjectBootUseCase.ts @@ -3,7 +3,6 @@ import { execute as vertexArrayObjectCreateRectVertexArrayObjectUseCase } from " import { $setInstancedVertexArrayObject, $setAttributeWebGLBuffer, - $setRectVertexArrayObject } from "../../VertexArrayObject"; /** @@ -25,9 +24,4 @@ export const execute = (gl: WebGL2RenderingContext): void => $setInstancedVertexArrayObject( vertexArrayObjectCreateInstancedVertexArrayObjectUseCase() ); - - // 矩形描画用のVertexArrayObjectをセット - $setRectVertexArrayObject( - vertexArrayObjectCreateRectVertexArrayObjectUseCase() - ); }; \ No newline at end of file diff --git a/packages/webgl/src/shader/ShaderManager/service/ShaderManagerSetTextureUniformService.ts b/packages/webgl/src/shader/ShaderManager/service/ShaderManagerSetTextureUniformService.ts index 61451a20..b6bb4db4 100644 --- a/packages/webgl/src/shader/ShaderManager/service/ShaderManagerSetTextureUniformService.ts +++ b/packages/webgl/src/shader/ShaderManager/service/ShaderManagerSetTextureUniformService.ts @@ -1,6 +1,5 @@ import type { ShaderManager } from "../../ShaderManager"; import { - $context, $getViewportWidth, $getViewportHeight } from "../../../WebGLUtil"; @@ -19,7 +18,6 @@ import { export const execute = (shader_manager: ShaderManager, width: number, height: number): void => { const highp = shader_manager.highp; - const matrix = $context.$matrix; // vertex: u_offset highp[0] = 0; @@ -30,19 +28,11 @@ export const execute = (shader_manager: ShaderManager, width: number, height: nu highp[3] = height; // vertex: u_matrix - highp[4] = matrix[0]; - highp[5] = matrix[1]; - highp[6] = matrix[2]; - - highp[8] = matrix[3]; - highp[9] = matrix[4]; - highp[10] = matrix[5]; - - highp[12] = matrix[6]; - highp[13] = matrix[7]; - highp[14] = matrix[8]; + highp[4] = 1; + highp[9] = 1; + highp[14] = 1; // vertex: u_viewport - highp[7] = $getViewportWidth(); + highp[7] = $getViewportWidth(); highp[11] = $getViewportHeight(); }; \ No newline at end of file diff --git a/packages/webgl/src/shader/ShaderManager/usecase/ShaderManagerDrawTextureUseCase.ts b/packages/webgl/src/shader/ShaderManager/usecase/ShaderManagerDrawTextureUseCase.ts index e1153b31..3b16a837 100644 --- a/packages/webgl/src/shader/ShaderManager/usecase/ShaderManagerDrawTextureUseCase.ts +++ b/packages/webgl/src/shader/ShaderManager/usecase/ShaderManagerDrawTextureUseCase.ts @@ -2,7 +2,7 @@ import type { ShaderManager } from "../../ShaderManager"; import { execute as vertexArrayObjectBindService } from "../../../VertexArrayObject/service/VertexArrayObjectBindService"; import { $gl } from "../../../WebGLUtil"; import { execute as blendResetService } from "../../../Blend/service/BlendResetService"; -import { $rectVertexArrayObject } from "../../../VertexArrayObject"; +import { $getRectVertexArrayObject } from "../../../VertexArrayObject"; /** * @description Textureの描画を行います。 @@ -22,7 +22,7 @@ export const execute = (shader_manager: ShaderManager): void => blendResetService(); // bind vertex array - vertexArrayObjectBindService($rectVertexArrayObject); + vertexArrayObjectBindService($getRectVertexArrayObject()); // draw fill $gl.drawArrays($gl.TRIANGLE_STRIP, 0, 4);