-
-
Notifications
You must be signed in to change notification settings - Fork 641
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
[Idea] Pre-fill sType()
for Vulkan structs
#537
Comments
I'm working on this issue and could use some feedback. Currently trying to find an alternative to the
It would be better to simply overload the /** Sets the specified value to the {@link #sType} field. */
public VkBufferMemoryBarrier sType(@NativeType("VkStructureType") int value) { nsType(address(), value); return this; }
/** Sets the default value to the {@link #sType} field. */
public VkBufferMemoryBarrier sType$Default() { return sType(VK10.VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER); } and the call site: VkBufferMemoryBarrier.malloc(stack)
.sType$Default()
.pNext(NULL)
// more members here
; Some ideas for the suffix:
Other than aesthetics, the problem with an arbitrary suffix is that the new name may end up matching exactly another struct member. It won't happen in the case of Vulkan structs, but this is going to be a generic feature of the LWJGL code generator and a naming scheme that minimizes that risk would be welcome. |
I should also mention that there's another, source-incompatible option. The VkBufferMemoryBarrier.malloc(stack)
.sType() // sets default and returns the VkBufferMemoryBarrier instance, not the value of sType
.pNext(NULL)
// more members here
; This would be the cleanest option and the static unsafe accessors ( Note that the next LWJGL 3 release is a major one (3.3.0) and breaking source compatibility is an option we do have. |
I'm not sure if this fits with the generic nature of the feature, but I think I don't think removing the getter is a good idea, it will be very weird. I also thought of an esoteric suggestion: // Singleton instance
public enum Default { DEFAULT }
public class VkBufferMemoryBarrier [...] {
// [...]
/** Sets the default value to the {@link #sType} field. */
public VkBufferMemoryBarrier sType(Default setDefault) { return sType(VK10.VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER); }
// [...]
}
// Usage
VkBufferMemoryBarrier.malloc(stack)
.sType(DEFAULT) // sets default and returns the VkBufferMemoryBarrier instance
.pNext(NULL)
// more members here
; This is source compatible, nice to read, and easy to use. It does require another import [which I mentioned as a downside in the original issue], but that import is shared for all structs, so it is still much reduced. |
I do kinda like the special and typesafe enum overload. Would allow us to also add more enum literals (other than DEFAULT) in the future, should the need arise. And it indeed does read nicer than any suffix of the method name. |
I envisioned the idea being to fill the structure type on allocation (ie during |
I also like the SWinxy appoach (if possible). |
Automatically filling in I initially liked the So, an extra suffixed method may be the least bad solution. It's explicit and easily discoverable, has dedicated javadoc, does not affect performance and no extra import is required. It currently looks like this: I'm still open to naming suggestions or other clever ideas though. |
|
I guess I am jumping into this conversation a bit late. I too was not aware that a dollar sign could be in a method name (old dogs new tricks). As for |
The default |
Environment
3.2.3
13
13
Linux
vulkan
Description
It would be nice if the Vulkan struct classes could have some option to pre-fill or set
sType
automatically, as it's literally based on the type of the struct, rather than needing to type it out. Even just being able to do something likeVkPipelineShaderStageCreateInfo.callocStack().sType(VkPipelineShaderStageCreateInfo.S_TYPE)
would be nicer than having to import the class and a constant.I do understand that this takes it away from looking like the C code, but arguably omitting the setters for the length properties already does that, and this would be a similar convenience feature.
The text was updated successfully, but these errors were encountered: