Skip to content
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

ex.Canvas forces dimensions to next size power of 2 #2403

Closed
eonarheim opened this issue Jul 7, 2022 · 1 comment · Fixed by #2404
Closed

ex.Canvas forces dimensions to next size power of 2 #2403

eonarheim opened this issue Jul 7, 2022 · 1 comment · Fixed by #2404
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior

Comments

@eonarheim
Copy link
Member

Steps to Reproduce

Setting the dimension of a ex.Canvas to 200x200 forces it to 256x256, this is unexpected to users. If we need power of two images it should be handled internally not leaked to the user.

There does seem to be a bug in the current ex.Canvas which forces the dimensions to be the next greatest power of 2 size. We should be able to fix ex.Canvas to allow arbitrary width/height before we release the next version of excalibur this week 👍

Here is a workaround to center the ex.Canvas in that snippet:

const canvas = new ex.Canvas({
    width: 256,
    height: 256,
    cache: true,  // If true draw once until flagged dirty again, otherwise draw to Canvas every frame
    draw: (ctx) => {
        console.log('With cache=true I draw once');
        ctx.fillStyle = 'red';
        ctx.fillRect(56/2, 56/2, 200, 200);
    }
})

image

Expected Result

ex.Canvas dimension should have been 200x200

Actual Result

ex.Canvas was unexpectedly 256x256

Environment

  • browsers and versions: NA
  • operating system: NA
  • Excalibur versions: v0.26.0

Current Workaround

Compensate by setting the ex.Canvas to a power of two, then offset to center.

@eonarheim eonarheim added the bug This issue describes undesirable, incorrect, or unexpected behavior label Jul 7, 2022
@eonarheim
Copy link
Member Author

With the switch to webgl2 I think we can drop the power of two manipulation as well 🎉

https://webgl2fundamentals.org/webgl/lessons/webgl2-whats-new.html

eonarheim added a commit that referenced this issue Jul 7, 2022
…2404)

Closes #2403

## Changes:

- Removes unnecessary POT enforcement in the `ex.Raster` base class
- Removes all power of two code, webgl2 doesn't need this anymore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes undesirable, incorrect, or unexpected behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant