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

offSetX and offSetY how is this working? #75

Open
fjtrujy opened this issue Jan 28, 2024 · 1 comment
Open

offSetX and offSetY how is this working? #75

fjtrujy opened this issue Jan 28, 2024 · 1 comment
Assignees

Comments

@fjtrujy
Copy link
Member

fjtrujy commented Jan 28, 2024

I have some questions about how these values are working.

Why those values are set by default as:

gsGlobal->OffsetX = (int)(2048.0f * 16.0f);
gsGlobal->OffsetY = (int)(2048.0f * 16.0f);

Then later on we are doing:

*p_data++ = GS_SETREG_XYOFFSET_1( gsGlobal->OffsetX, gsGlobal->OffsetY);
*p_data++ = GS_XYOFFSET_1;

And finally, everytime we perform any primitive we are doing things like:

static inline int gsKit_float_to_int_x(const GSGLOBAL *gsGlobal, float fx)
{
	return __gsKit_float_to_int_xy(fx, gsGlobal->OffsetX);
}

static inline int gsKit_float_to_int_y(const GSGLOBAL *gsGlobal, float fy)
{
	return __gsKit_float_to_int_xy(fy, gsGlobal->OffsetY);
}

static inline gs_xyz2 vertex_to_XYZ2(const GSGLOBAL *gsGlobal, float fx, float fy, int iz)
{
	gs_xyz2 res;

	res.xyz.x = gsKit_float_to_int_x(gsGlobal, fx);
	res.xyz.y = gsKit_float_to_int_y(gsGlobal, fy);
	res.xyz.z = iz;
	res.tag = GS_XYZ2;

	return res;
}

Shouldn't be these values set originally as 0,0 and then never use those values when calculating the final vertex position?

@rickgaiser
Copy link
Member

These offsets are very important when drawing to the GS, especially when drawing outside of the draw area.

The GS coordinate system uses 12.4 bits fixed point resolution. So we can draw from 0 to 4095 (12 bit), with subpixel accuracy of 1/16th pixel (4bit).

The render buffer can be placed into this 4k x 4k area using the offset registers. Good practice is to put the renderbuffer in the center of this area (as OPL does).

What you need is an offset into the renderbuffer. Such offset does not exist in the gs hardware, and also not in gsKit as far as I'm aware. You'll have to manage the offset in your application (SDL in this specific case).
You probably also want to set the scissor to make sure you don't draw outside of your viewport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants