Skip to content

Updated renderer to allow viewport to be set manually #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 22 additions & 13 deletions src/core/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export class Renderer {

// Attach renderer to gl so that all classes have access to internal state functions
this.gl.renderer = this;

// initialise size values
this.setSize(width, height);


// gl state stores to avoid redundant calls on methods used internally
this.state = {};
this.state.blendFunc = { src: this.gl.ONE, dst: this.gl.ZERO };
Expand All @@ -69,7 +66,10 @@ export class Renderer {
this.state.boundBuffer = null;
this.state.uniformLocations = new Map();
this.state.currentProgram = null;


// initialise size values
this.setSize(width, height);

// store requested extensions
this.extensions = {};

Expand Down Expand Up @@ -119,6 +119,8 @@ export class Renderer {
this.gl.canvas.width = width * this.dpr;
this.gl.canvas.height = height * this.dpr;

this.setViewport(1,1);

if (!this.gl.canvas.style) return;
Object.assign(this.gl.canvas.style, {
width: width + 'px',
Expand All @@ -127,12 +129,18 @@ export class Renderer {
}

setViewport(width, height, x = 0, y = 0) {
if (this.state.viewport.width === width && this.state.viewport.height === height) return;
this.state.viewport.width = width;
this.state.viewport.height = height;
this.state.viewport.x = x;
this.state.viewport.y = y;
this.gl.viewport(x, y, width, height);
this.state.viewport.width = this.width * this.dpr * width;
this.state.viewport.height = this.height * this.dpr * height;
this.state.viewport.x = this.width * this.dpr * x;
this.state.viewport.y = this.height * this.dpr * y;
}

updateViewport() {
this.gl.viewport(
this.state.viewport.x,
this.state.viewport.y,
this.state.viewport.width,
this.state.viewport.height);
}

setScissor(width, height, x = 0, y = 0) {
Expand Down Expand Up @@ -353,7 +361,8 @@ export class Renderer {
if (target === null) {
// make sure no render target bound so draws to canvas
this.bindFramebuffer();
this.setViewport(this.width * this.dpr, this.height * this.dpr);
this.updateViewport();
//this.setViewport(this.width * this.dpr, this.height * this.dpr);
} else {
// bind supplied render target and update viewport
this.bindFramebuffer(target);
Expand Down Expand Up @@ -393,4 +402,4 @@ export class Renderer {
node.draw({ camera });
});
}
}
}