//	GGVR_GPU_Definitions.h
//
//	© 2026 by Jeff Weeks
//	See TermsOfUse.txt

#ifndef GGVR_GPU_Definitions_h
#define GGVR_GPU_Definitions_h

#include <simd/simd.h>

typedef struct
{
	//	In Curved-Space Pool Hall,
	//		the "game space" is the table space.
	//
	//	In Curved Spaces VR,
	//		the "game space" is the space of the central fundamental cell,
	//		which is centered at the point where the player's head
	//		was when they opened the manifold.
	//
	//	Note: The bridge-of-nose space is still in the (typically curved)
	//	virtual space, before the azimuthal projection.
	//
	simd_float4x4	gameSpaceToBridgeOfNoseSpace;		//	the "view matrix"

	//	As explained in the article
	//
#warning("Add citation upon publication")
	//		State-of-the-art rendering in curved-space virtual reality
	//
	//	central projection works fine in practice even
	//	without these correction factors. They're needed
	//	only for full mathematical correctness.
	float			xFactor,
					yzFactor;
	
	//	Note: The tangent space is a Euclidean space,
	//	after the azimuthal or central projection.
	//
	//	tangentSpaceToClipSpace[] maps the tangent space
	//	at the bridge of the player's nose to each eye space
	//	and then applies the appropriate projection matrix.
	simd_float4x4	tangentSpaceToClipSpace[2];

} GGVRViewProjection;


// MARK: -
// MARK: Euclidean headset-based messages

enum
{
	MessageVertexAttributeTexCoords	= 0
};

//	For the GPU vertex function
enum
{
	MessageBufferIndexVertexAttributes	= 0,
	MessageBufferIndexUniforms			= 1
};

//	For the GPU fragment function
enum
{
	BufferIndexOpacity = 0
};

//	A GPU fragment function typically uses
//	only one texture and one texture sampler at a time.
//	Additional TextureIndexes would be needed
//	only if the fragment function wanted
//	to combine two or more textures at render time.
enum
{
	MessageTextureIndex	= 0
};
enum
{
	MessageSamplerIndex	= 0
};

typedef struct
{
	//	Maps from message coordinates to eye coordinates
	//	and then projects into clip space.
	simd_float4x4	modelViewProjection[2];
	
	float	width,	//	in meters
			height;	//	in meters
	
	//	Curved-Space Pool Hall always uses verticalOffset = 0.0
	//		so that the panel's lower edge sits at the player's eye level.
	//
	//	Curved-Space Catch uses verticalOffset = -0.5
	//		so that the panel's center sits at the player's eye level.
	//
	float	verticalOffset;	//	as a fraction of the panel's height (dimensionless)

} MessageUniforms;

#endif /* GGVR_GPU_Definitions_h */
