Swift OpenGL es enums - ios

When using Swift to create an OpenGL app I get this error whenever I use OpenGL commands, for example:
glBindRenderbuffer(GL_RENDERBUFFER, self.colorRenderBuffer)
I get an error 'Int32' is not convertible to 'Glenum'
Any ideas how to fix this?

Constants like the ones OpenGL uses are imported in Swift as top-level variable declarations instead of enum declarations. Because OpenGL doesn't actually use an enum, you'll have to explicitly construct a GLenum with GL_RENDERBUFFER as its primitive value:
glBindRenderbuffer(GLenum(GL_RENDERBUFFER), 0)

Related

sampler2DArray on IOS OpenGLES3.0

We're upgrading (!) our code on IOS from OpenGLES2.0 to OpenGLES3.0 so we can use texture arrays.
We build against OpenGLES3.0 defines and open a GL3.0 context, and I can initialise a texture array fine, but the shader code gives an error on this line when I compile it at runtime.
uniform sampler2DArray mySamplerName;
It complains about a "syntax error" on mySamplerName as if it doesn't understand sampler2DArray as a keyword
If I use
uniform sampler3D mySamplerName;
it compiles ok, but that's not what I want.
Yes, I know OpenGL is deprecated, but does anyone know if this should work on IOS ?
Thanks
Shaun

CGImageRef not found when binding a static library to Xamarin.iOS

I am trying to bind some *.framework library which (among others) uses CoreGraphics.
So, the code generated by Sharpie is as follows:
// +(CGImageRef)rotateCGImage:(CGImageRef)image byRadians:(double)radians;
[Static]
[Export ("rotateCGImage:byRadians:")]
unsafe CGImageRef* RotateCGImage (CGImageRef* image, double radians);
However, when trying to build it, I receive error message like "CGImageRef could not be found".
Also, I can't find corresponding class in the list of members of CoreGraphics in Assembly Explorer.
(Same way as using CoreGraphics; doesn't help.)
It looks like this class (or struct) is just not supported by Mono: I just can't find it in regular iOS project libraries neither.
And actually, there is a number of similar "ref-like" classes which are missed: CMSampleBufferRef from Core Media, CVImageBufferRef from Core Video etc.
So, how can I handle this situation?
Please try the solution in this thread:
CGImageRef doesn't exist in Xamarin. In Obj-C, CGImageRef is just a pointer to CGImage, so I would think you could just change all of those CGImageRef to CGImage.
I think it should be something like this:
[Static]
[Export("rotateCGImage:byRadians:")]
unsafe CGImage RotateCGImage(CGImage image, double radians);
The same to other "...Ref" in your project.
From what I've found out (and one of the approaches Xamarin team uses inside of their framework), the solution is as follows:
static extern CGImagePixelFormatInfo CGImageGetPixelFormatInfo (/* __nullable CGImageRef */ IntPtr handle);
static extern IntPtr /* CFStringRef */ CGImageGetUTType (/* __nullable CGImageRef* */ IntPtr image);
So, because of C# managed architecture, there are no explicit pointers to implement, that's why they just didn't create any *Ref-like classes across Mono.
The only thing to point here is that they pass IntPtr for both cases: CGImageRef and CGImageRef*, which has sense of course. However, the trick is in passing the CGImage pointer correctly inside of calling method, because in first case it must be this:
image == null ? IntPtr.Zero : image.Handle
so, passing a pointer of the CGImage. But in second case it must be a pointer to Handle, I assume.

Accelerate framework - vDSP_zvmags - Swift 4.2

In Swift 4.0 Xcode 9.4.1 using the vDSP_zvmags function and passing an inout float array variable works however in Swift 4.2 Xcode 10.1 complains that one cannot pass an array parameter when a expecting a float type.
//Class variable
private var magnitudes: [Float]!
self.magnitudes = [Float](repeating: 0.0, count: self.halfSize)
vDSP_zvmags(&(self.complexBuffer!), 1, &self.magnitudes!, 1, UInt(self.halfSize))
Error message:
Cannot convert value of type '[Float]' to expected argument type 'Float'
&self.magnitudes! is underlined in red.
Can someone shed some light as to why it is acceptable in Swift 4.0 and not acceptable in Swift 4.2? The function does not appear to have changed between the 2 functions, I have checked in Apple's documentation and looked at the vDSP library doc.
If the class variable is initialized on declaration to empty float array the error disappears.

Cannot invoke initializer for type 'SCNMatrix4'

I'm working on ARKit and trying to initialize SCNMatrix but its throwing following error:
Code snippet:
if let frame = self.sceneView.session.currentFrame {
let mat = SCNMatrix4(frame.camera.transform)
return (dir, pos)
}
Error:
Cannot invoke initializer for type ‘SCNMatrix4’ with an argument list
of type ‘(matrix_float4x4)’ Overloads for ‘SCNMatrix4’ exist with
these partially matching parameter lists: (float4x4), (double4x4)
Does anyone face something similar kind of issue?
You're using an old Xcode beta. Swift bridging for SIMD matrix types changed in Xcode 9.0 beta 2. (As of this writing, beta 3 is current.)
With said changes, matrix_float_4x4 and float4x4 are the same type, so your code should work fine.

iOS Metal requires constant in fragment function

I'm trying to understand Apple's Metal and converting some old opengl shaders. I'm stuck in an error that appears only in one project and not the others. I wanted to ask if there is a compiler option or something like that, that I do not know and can cause this error.
So... I've got an audio visualizer for a music player that I wrote sometime ago using opengl on ndk for Android. I converted the shader to metal on an empty project. The fragment method signature is like this:
fragment float4 spectrum_fragment_func(
Vertex vert [[stage_in]],
device Fragment *uniforms [[buffer(0)]],
device float *left [[buffer(1)]],
device float *right [[buffer(2)]]
)
I'm updating the Fragment object in code. It has a "time" value and needs to be updated for the effects to take place, meaning I cannot use constant values.
Shader compiles and works without any problems on the test application, that simply has a ViewController and my MTKView class.
When I copy the classes and shaders as-is to another project, I start getting this error:
/Volumes/Additional/Projects/.../Visuals/Shaders.metal:31:189:
Pointer argument to fragment function must be const
If I convert the Fragment variable to constant, this time error appears for the next value in the signature. It seems that in this project, something is changed and does not accept any other types of variables but only consts...
If anyone had a similar problem, or know how to solve this I'm stuck and need some help.

Resources