littlektframework / littlekt

A multiplatform WebGPU 2D game framework written in Kotlin. Build your own game engine on top.
https://littlekt.com
Apache License 2.0
313 stars 12 forks source link

Update `FrameBuffer` to handle multiple color attachments #227

Closed LeHaine closed 7 months ago

LeHaine commented 7 months ago

FrameBuffer

The previous FrameBuffer implementation allowed only a single color attachment and assumed you were using it directly. The new implementation will allow a list of a new object ColorAttachment which takes the original parameters.

Old

val fbo = FrameBuffer(250, 250, hasDepth = false, hasStencil = false, hasPackedDepthStencil = false, format = Pixmap.Format.RGBA8888, minFilter = TexMinFilter.LINEAR, magFilter = TexMagFilter.LINEAR)

batch.draw(fbo.colorBufferTexture, 0f, 0f)

This way can still be used. No breaking changes regarding usage.

New

val fbo = FrameBuffer(250, 250, hasDepth = false, hasStencil = false, hasPackedDepthStencil = false, colorAttachments = listOf(ColorAttachment(format = Pixmap.Format.RGBA8888, minFilter = TexMinFilter.LINEAR, magFilter = TexMagFilter.LINEAR, wrap = TexWrap.CLAMP_TO_EDGE)))

batch.draw(fbo.textures[0], 0f, 0f)

colorAttachments will default to a single color attachment listOf(ColorAttachment()). FrameBuffer.textures is a list that will contain the textures for each color attachment on the FBO.

GL

Added the GL.drawBuffers(size: Int, buffers: IntBuffer) function Added the GL.clearBuffer[fuiv]() functions

Shaders

Updated GlslGenerator to support the use of gl_FragData[n] inside fragment shaders. This will generate the correct out variables if using GLSL 3.0+ if the gl_FragColor or gl_FragData[n] is referenced anyway in the shader code. Added support for GL_EXT_DrawBuffers for version GLES 2.0