I have ported the contents of OpenGL (webGL) to Metal and have a question

Viewed 196

I have ported the contents of OpenGL (webGL) to Metal and have a question. When doing the following in OpenGL (webGL),

-I want to bind and render the framebuffer in OpenGL (webGL).

gl.bindFramebuffer(gl.FLAMEBUFFER, buffer[0].framebuffer)
gl.useProgram(…)
gl.enableAttribute(VBO, Location, attStride)
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, IBO)
gl.uniform2fv....

gi.drawElement(gl.TRAIANGLES,..., gl.UNSIGNED_SHORT, 0)

What if you want to do the same with Metal? It's a rudimentary question, but I'd be happy if you could tell me.

1 Answers

There's not really a frame buffer concept in Metal. You can render to any texture that has renderTarget usage. You can get a texture from a CAMetalDrawable (which you can get from a CAMetalLayer), or you can create one yourself, using MTLDevice.makeTexture method and passing the appropriate MTLTextureDescriptor.

Then, when you want to render into it, you need to create a render command encoder, which you can make from an MTLCommandBuffer. You will need to pass an MTLRenderPassDescriptor. In that descriptor, you can set the texture along with it's load and store actions in the appropriate render target slot (there are 8 of them).

There's actually a WWDC talk that goes in depth on how to port GL apps to Metal: Bringing OpenGL Apps to Metal

Related