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

[Renderers] Add ability to negotiate capabilities with the renderer #90

Open
EmmanuelMess opened this issue Dec 23, 2024 · 8 comments
Open

Comments

@EmmanuelMess
Copy link

If the renderer is incapable of showing 3D textures, or drawing specific elements, like some colors (for example monocrome interfaces), clay should be able to take that into account, and inform the final user. This would probably become more important if new rendering commands are added to simplify the rendering.

@EmmanuelMess
Copy link
Author

Also, hover might not be available on devices with no cursors (touchscreens, SoC connected to a screen).

@nicbarker
Copy link
Owner

This is a really interesting idea, do you have a particular approach in mind that you're envisioning?

@nicbarker nicbarker changed the title Add ability to negotiate capabilities with the renderer [Renderers] Add ability to negotiate capabilities with the renderer Dec 24, 2024
@EmmanuelMess
Copy link
Author

EmmanuelMess commented Dec 25, 2024

This is a really interesting idea, do you have a particular approach in mind that you're envisioning?

Linux allows programs to negotiate capabilities with drivers (I could only find this implemented for cameras, but I think its implemented for other drivers too), so the idea comes from there. If I were to do it, I would make the user pass renderer generated (probably gigantic) configuration struct to clay on initialization (in linux its done with bitsetting via ioctl).

typedef struct Capabilities {
    bool hasCursor;
    bool hasMeshImplementation;
	bool hasScissor;
} Capabilities;

// In renderer
void RendererName_GetCapabilities() {
	return (Capabilities) {
		.hasCursor = false,
		.hasMeshImplementation = false,
		.hasScissor = true,
		//etc
	};	
}

void main() {
	//...

	Capabilities cap = RendererName_GetCapabilities();
	Clay_Initialize(..., cap);
	//...
}

@VisenDev
Copy link

Why not use bitflags for this?

#define RENDERER_CAPABILITY_CURSOR  1<<0
#define RENDERER_CAPABILITY_SCISSOR 1<<1
#define RENDERER_CAPABILITY_MESH    1<<2
#define RENDERER_CAPABILITY_COLOR   1<<3
//etc

#define STANDARD_RENDERER_CAPABILITIES \
    RENDERER_CAPABILITY_CURSOR  | \
    RENDERER_CAPABILITY_SCISSOR | \
    RENDERER_CAPABILITY_MESH    | \
    RENDERER_CAPABILITY_COLOR    

int main() {
    int renderer_capability_flags = STANDARD_RENDERER_CAPABILITIES;

    printf("%d\n", renderer_capability_flags);
    return 0;
}

@EmmanuelMess
Copy link
Author

Why not use bitflags for this?

It is easier to "miss" stuff when doing bitflags as compared to structs IMO. Leaving a bit turned off is easier than leaving a field blank in a struct when filling it.

@FintasticMan
Copy link
Contributor

At least use bitfields in the struct then for packing. (And then the end result will—in theory—be identical to setting bits like suggested anyway)

@EmmanuelMess
Copy link
Author

At least use bitfields in the struct then for packing. (And then the end result will—in theory—be identical to setting bits like suggested anyway)

There could be a way to allow the compiler to pack the entire struct into a set of unsigned ints, if your concern is for optimization.

@FintasticMan
Copy link
Contributor

Exactly, my suggestion is to define the struct like this:

typedef struct Capabilities {
    unsigned hasCursor : 1;
    unsigned hasMeshImplementation : 1;
    unsigned hasScissor : 1;
} Capabilities;

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

4 participants