diff --git a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/GraphicsRenderer.groovy b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/GraphicsRenderer.groovy index 13bb2581..fde42cbc 100644 --- a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/GraphicsRenderer.groovy +++ b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/GraphicsRenderer.groovy @@ -24,8 +24,6 @@ import org.joml.Matrix4f import org.joml.Vector2f import org.joml.primitives.Rectanglef -import groovy.transform.stc.ClosureParams -import groovy.transform.stc.SimpleType import java.nio.ByteBuffer /** @@ -129,19 +127,4 @@ interface GraphicsRenderer extends Closeable, EventTarget { * {@code null} to set the render target as the screen. */ void setRenderTarget(Framebuffer framebuffer) - - /** - * Use a batching material builder within the context of the given closure - * that will return a single renderable material that is the sum of all the - * materials initialized within the closure. - * - * @param closure - * @return - * A material that represents all of the materials created within the - * closure. This material can then be rendered as normal to render all of - * the created materials at once. - */ - Tuple2 withMaterialBundler( - @ClosureParams(value = SimpleType, options = 'nz.net.ultraq.redhorizon.engine.graphics.MaterialBundler') - Closure closure) } diff --git a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/MaterialBundler.groovy b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/MaterialBundler.groovy deleted file mode 100644 index cd21ca24..00000000 --- a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/MaterialBundler.groovy +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021, Emanuel Rabina (http://www.ultraq.net.nz/) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package nz.net.ultraq.redhorizon.engine.graphics - -/** - * A builder for batching together several similar meshes and materials into a - * single mesh & material, which can then be used for rendering them all out - * with a single draw call. - * - * @author Emanuel Rabina - */ -interface MaterialBundler extends GraphicsRenderer { - - /** - * Build a batched mesh and material that represents all of the meshes and - * materials created with calls to {@link #createMesh} and {@link #createMaterial}. - * - * @return - */ - Tuple2 bundle() -} diff --git a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/opengl/OpenGLMaterialBundler.groovy b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/opengl/OpenGLMaterialBundler.groovy deleted file mode 100644 index daca84f4..00000000 --- a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/opengl/OpenGLMaterialBundler.groovy +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2021, Emanuel Rabina (http://www.ultraq.net.nz/) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package nz.net.ultraq.redhorizon.engine.graphics.opengl - -import nz.net.ultraq.redhorizon.engine.graphics.Attribute -import nz.net.ultraq.redhorizon.engine.graphics.Material -import nz.net.ultraq.redhorizon.engine.graphics.MaterialBundler -import nz.net.ultraq.redhorizon.engine.graphics.Mesh -import nz.net.ultraq.redhorizon.engine.graphics.VertexBufferLayout -import nz.net.ultraq.redhorizon.events.EventTarget - -import org.joml.Matrix4f -import org.joml.Vector2f -import org.joml.Vector3f - -import groovy.transform.TupleConstructor - -/** - * A material builder for OpenGL. - * - * @author Emanuel Rabina - */ -@TupleConstructor(defaults = false) -class OpenGLMaterialBundler implements MaterialBundler, EventTarget { - - // TODO: Derive the layout from the materials being bundled, not hard-coded in this class - private static final VertexBufferLayout VERTEX_BUFFER_LAYOUT = new VertexBufferLayout( - Attribute.POSITION, - Attribute.COLOUR, - Attribute.TEXTURE_UVS - ) - - @Delegate - final OpenGLRenderer renderer - - // This currently works because meshes and materials are created in pairs, so - // this bundler works on that assumption - private final List meshes = [] - private final List materials = [] - - @Override - Tuple2 bundle() { - - var allVertices = [] - var allTextureUVs = [] - var allIndices = [] - var indexOffset = 0 - for (var i = 0; i < meshes.size(); i++) { - var mesh = meshes[i] - var material = materials[i] - allVertices.addAll(mesh.vertices.collect { vertex -> - var position = material.transform.transformPosition(new Vector3f(vertex, 0)) - return new Vector2f(position.x, position.y) - }) - allTextureUVs.addAll(mesh.textureUVs) - allIndices.addAll(mesh.indices.collect { index -> index + indexOffset }) - indexOffset += mesh.vertices.size() - } - - // Return a new mesh and material based off the first ones in the lists - // which is assumed to be representative of the entire batch - - var templateMesh = meshes.first() - var mesh = new OpenGLMesh(templateMesh.vertexType, VERTEX_BUFFER_LAYOUT, templateMesh.colour, - allVertices as Vector2f[], allTextureUVs as Vector2f[], allIndices as int[]) - - var templateMaterial = materials.first() - var material = new Material( - texture: templateMaterial.texture, - transform: new Matrix4f() - ) - - return new Tuple2<>(mesh, material) - } - -// @Override -// @NamedVariant -// Material createMaterial(Texture texture = null, Matrix4f transform = null) { -// -// var material = new Material(texture, transform) -// materials << material -// return material -// } -// -} diff --git a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/opengl/OpenGLRenderer.groovy b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/opengl/OpenGLRenderer.groovy index 8c5fe4ee..a0be7802 100644 --- a/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/opengl/OpenGLRenderer.groovy +++ b/redhorizon-engine/source/nz/net/ultraq/redhorizon/engine/graphics/opengl/OpenGLRenderer.groovy @@ -26,7 +26,6 @@ import nz.net.ultraq.redhorizon.engine.graphics.FramebufferDeletedEvent import nz.net.ultraq.redhorizon.engine.graphics.FramebufferSizeEvent import nz.net.ultraq.redhorizon.engine.graphics.GraphicsConfiguration import nz.net.ultraq.redhorizon.engine.graphics.GraphicsRenderer -import nz.net.ultraq.redhorizon.engine.graphics.GraphicsRendererEvent import nz.net.ultraq.redhorizon.engine.graphics.GraphicsResource import nz.net.ultraq.redhorizon.engine.graphics.Material import nz.net.ultraq.redhorizon.engine.graphics.Mesh @@ -58,8 +57,6 @@ import static org.lwjgl.opengl.GL30C.glBindFramebuffer import static org.lwjgl.opengl.KHRDebug.* import groovy.transform.NamedVariant -import groovy.transform.stc.ClosureParams -import groovy.transform.stc.SimpleType import java.lang.reflect.Modifier import java.nio.ByteBuffer @@ -320,15 +317,4 @@ class OpenGLRenderer implements GraphicsRenderer { - OpenGL version: ${glGetString(GL_VERSION)} """.stripIndent() } - - @Override - Tuple2 withMaterialBundler( - @ClosureParams(value = SimpleType, options = 'nz.net.ultraq.redhorizon.engine.graphics.MaterialBundler') - Closure closure) { - - def materialBuilder = new OpenGLMaterialBundler(this) - materialBuilder.relay(GraphicsRendererEvent, this) - closure(materialBuilder) - return materialBuilder.bundle() - } }