2 ms·
What about stuff like this, these weird castings that pop up in Swift that you don't worry about in Objective-C when dealing with C APIs: glBindBuffer(GLenum(G
by hellofunk 11y ago
What about stuff like this, these weird castings that pop up in Swift that you don't worry about in Objective-C when dealing with C APIs:
glBindBuffer(GLenum(GL_ARRAY_BUFFER), bufferIds[1])
glBufferData(GLenum(GL_ARRAY_BUFFER), sizeof(Float) * tcSize, tc, GLenum(GL_STATIC_DRAW))
That just looks silly to me.
- potatolicious 11y agoSwift enums are considerably different from C/Obj-C enums so the cast is unavoidable. Specifically unlike C enums, Swift enums can be backed by non-integer types like Strings. For numeric types that have a clear equivalence in C-land, Swift is seamless.
- comex 11y agoActually, GLenum is not a C enum in the first place; it's just an integer typedef.
- mikeash 11y agoThe lack of implicit integer conversions does dirty up the code a bit when using C APIs built around them, but I don't find it to be a particularly big deal. Regarding the post in your other comment, none of that really has anything to do with C interop. C doesn't even have generics, so the whole thrust of the article (that it's hard to build a generic function that works on all integer types) doesn't apply.
- cballard 11y agoThis appears to be a peculiarity of the OpenGL headers - GL_ARRAY_BUFFER is just a #define: #define GL_ARRAY_BUFFER 0x8892 Instead of a proper constant. Therefore, Swift interprets it as an integer, which is fairly reasonable. GLEnum is: typedef uint32_t GLenum; Which is not compatible with Int in Swift, thus the "cast". If GL_ARRAY_BUFFER was: extern GLenum GL_ARRAY_BUFFER; It would work as expected.