Jump to content

Converting a 2d rendering JS application to use WebGL rendering via Pixi


OSRS
 Share

Recommended Posts

Hello,

 

I recently converted a legacy Java game that renders a 2d pixel array on the CPU to run in the browser (using TeaVM transpiler) and am now looking into options for improving performance. Converting the actual game rendering to use WebGL would be a massive undertaking, so I wanted to see if there was a quick and easy way to get a slight improvement by taking the 2d pixel array and having it rendered with Pixi using WebGL, rather than having the 2d canvas draw it.

 

At the moment, my code looks like so:

	for (int i = 0; i < width * height * 4; i += 4) {
		int pixel = this.pixels[i / 4];
		this.rgbPixels.set(i, (pixel >> 16) & 255);
		this.rgbPixels.set(i + 1, (pixel >> 8) & 255);
		this.rgbPixels.set(i + 2, pixel & 255);
		this.rgbPixels.set(i + 3, 255);
	}

	graphics.putImageData(imageData, x, y); //Where graphics = CanvasRenderingContext2D

 

Would appreciate any insight as I am a novice to JS!

 

Thank you!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...