Skip to content

Commit

Permalink
#154 webglパッケージをv2へ移行(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Sep 3, 2024
1 parent 59fd340 commit 87a3134
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/webgl/src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export class Context
this.$clearColorR,
this.$clearColorG,
this.$clearColorB,
this.$clearColorA
this.$clearColorA,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IAttachmentObject } from "../../interface/IAttachmentObject";
import { $setFramebufferBound } from "../../FrameBufferManager";
import { $readFrameBuffer } from "../../FrameBufferManager";
import {
$gl,
$context
Expand All @@ -23,7 +23,6 @@ export const execute = (): void =>
$gl.DRAW_FRAMEBUFFER,
null
);
$setFramebufferBound(false);

const width = mainAttachmentObject.width;
const height = mainAttachmentObject.height;
Expand All @@ -35,4 +34,6 @@ export const execute = (): void =>
$gl.COLOR_BUFFER_BIT,
$gl.NEAREST
);

$gl.bindFramebuffer($gl.FRAMEBUFFER, $readFrameBuffer);
};
18 changes: 10 additions & 8 deletions packages/webgl/src/VertexArrayObject.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<IVertexArrayObject>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { execute as vertexArrayObjectCreateRectVertexArrayObjectUseCase } from "
import {
$setInstancedVertexArrayObject,
$setAttributeWebGLBuffer,
$setRectVertexArrayObject
} from "../../VertexArrayObject";

/**
Expand All @@ -25,9 +24,4 @@ export const execute = (gl: WebGL2RenderingContext): void =>
$setInstancedVertexArrayObject(
vertexArrayObjectCreateInstancedVertexArrayObjectUseCase()
);

// 矩形描画用のVertexArrayObjectをセット
$setRectVertexArrayObject(
vertexArrayObjectCreateRectVertexArrayObjectUseCase()
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ShaderManager } from "../../ShaderManager";
import {
$context,
$getViewportWidth,
$getViewportHeight
} from "../../../WebGLUtil";
Expand All @@ -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;
Expand All @@ -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();
};
Original file line number Diff line number Diff line change
Expand Up @@ -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の描画を行います。
Expand All @@ -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);
Expand Down

0 comments on commit 87a3134

Please sign in to comment.