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

Readback stencil buffer for debugger on GLES #16198

Merged
merged 4 commits into from
Oct 11, 2022

Conversation

unknownbrackets
Copy link
Collaborator

@unknownbrackets unknownbrackets commented Oct 11, 2022

This allows reading the stencil buffer via the API (so now depth and stencil both work) under GLES 3.1+. Was very straight-forward given the depth readback.

Just for example, a simple nodejs script to grab stencil (see ppsspp-api-samples):

const PPSSPP = require('./sdk');
const ppsspp = new PPSSPP();
const fs = require('fs');

main();

async function main() {
	try {
		await ppsspp.autoConnect();
		await ppsspp.send({ event: 'version', name: 'stencil-screenshot', version: '1.0.0' });

		// Need to pause emulation to take a screenshot.
		await ppsspp.send({ event: 'cpu.stepping' });
		const result = await ppsspp.send({ event: 'gpu.buffer.renderStencil', type: 'uri', alpha: false });
		await ppsspp.send({ event: 'cpu.resume' });

		const dataPrefix = 'data:image/png;base64,';
		if (!result.uri || result.uri.substr(0, dataPrefix.length) !== dataPrefix) {
			throw 'Unexpected data URI returned';
		}

		const buffer = Buffer.from(result.uri.substr('data:image/png;base64,'.length), 'base64');
		fs.writeFileSync('screenshot.png', buffer);
	} catch (err) {
		console.error('Something went wrong:', err);
	} finally {
		try {
			ppsspp.disconnect();
		} catch (err) {
			console.error('Could not disconnect:', err);
		}
	}
}

-[Unknown]

Copy link
Owner

@hrydgard hrydgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you're sending "alpha: false" in the example code, does that affect things when reading stencil?

@hrydgard hrydgard merged commit 804220a into hrydgard:master Oct 11, 2022
@unknownbrackets
Copy link
Collaborator Author

I see you're sending "alpha: false" in the example code, does that affect things when reading stencil?

Yes, when using the debugger APIs, alpha: true means the red channel is always 100% and the alpha channel represents the amount of stencil (or depth.) And alpha: false means the red channel is the amount of stencil/depth.

-[Unknown]

@unknownbrackets unknownbrackets deleted the gles-stencil branch October 11, 2022 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants