Skip to content

Commit

Permalink
refactor(rendering): working on renderer endFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
ruggero-visintin committed Dec 3, 2023
1 parent 9bee95e commit a333a65
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/renderer/Renderer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { RenderCommand } from './RenderCommand';

export class Renderer {
public readonly commandBuffer: RenderCommand[] = [];
private _commandBuffer: RenderCommand[] = [];

public get commandBuffer(): RenderCommand[] {
return this._commandBuffer;
}

public pushRenderCommand(command: RenderCommand): void {
this.commandBuffer.push(command);
this._commandBuffer.push(command);
}

public endFrame(): void {
this._commandBuffer = [];
}
}
29 changes: 29 additions & 0 deletions test/renderer/Renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,33 @@ describe('renderer/Renderer', () => {
expect(renderer.commandBuffer).toContain(renderCommand);
});
});

describe('.endFrame()', () => {
it.skip('Should execute queued rendering commands', () => {
const renderCommand = {
renderCommandID: RenderCommandID.RC_DrawPrimitive,
primitiveType: PrimitiveType.Rectangle,
position: [0, 0],
size: [0, 0]
};

renderer.pushRenderCommand(renderCommand);
renderer.endFrame();
})

it('Should clear the command buffer', () => {
const renderCommand = {
renderCommandID: RenderCommandID.RC_DrawPrimitive,
primitiveType: PrimitiveType.Rectangle,
position: [0, 0],
size: [0, 0]
};

renderer.pushRenderCommand(renderCommand);
renderer.endFrame();

expect(renderer.commandBuffer).toEqual([]);

});
});
});

0 comments on commit a333a65

Please sign in to comment.