iosobjective-cswiftglkit

GLKit: Format Objective-C GLKit parameters for Swift


Scenario

I am building an application that manipulates the chroma values of video frames. I am using Objective-C code from another project and translating it into Swift. But I have come across an odd piece of code that I would like to translate to Swift, if I could even figure out what it means. Method is below:

- (void)updateUniformValues
{
   // Precalculate the mvpMatrix
   GLKMatrix4 modelViewProjectionMatrix = GLKMatrix4Multiply(
      self.transform.projectionMatrix, 
      self.transform.modelviewMatrix);
   glUniformMatrix4fv(uniforms[GMVPMatrix], 1, 0, 
      modelViewProjectionMatrix.m);

   // Texture samplers
   const GLint samplerIDs[1] = {self.texture2d0.name};
   glUniform1iv(uniforms[GSamplers2D], 1, 
      samplerIDs); 
}

note: self.texture2d0 is of type GLKEffectPropertyTexture

The line in question is const GLint samplerIDs[1] = {self.texture2d0.name};. I have coded in Objective-C for years before programming in Swift, but I have never seen something like this before. So it's a constant of type Glint, but is assigned a value from a self.texture2d0 block with no return statement? And the [1] makes me feel like it should be an Array. So confused.

Question

What is this line doing? And how can I translate this into Swift?


Solution

  • It's an samplerIDs is a const array of GLint, with a single non-const member, self.texture2d0.name.

    It would be analogous to:

    let samplerIDs = [self.texture2d0.name]