### Manually Configure SceneEnqueuePass Queues (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md This example demonstrates the explicit configuration of a SceneEnqueuePass with five distinct queues (Opaque, Transparent, Translucent, Sky, Gui), each with its own comparator and specific rendering settings. This provides fine-grained control over geometry sorting and rendering behavior. ```java SceneEnqueuePass p = new SceneEnqueuePass(); p.addQueue(RenderQueue.Bucket.Opaque.name(), new BasicGeometryQueue(new OpaqueComparator())); p.addQueue(RenderQueue.Bucket.Transparent.name(), new BasicGeometryQueue(new TransparentComparator())); p.addQueue(RenderQueue.Bucket.Translucent.name(), new BasicGeometryQueue(new TransparentComparator())); p.addQueue(RenderQueue.Bucket.Sky.name(), new BasicGeometryQueue(new NullComparator()) { @Override public void applySettings(FrameGraphContext context) { context.getDepthRange().pushValue(DepthRange.REAR); } @Override public void restoreSettings(FrameGraphContext context) { context.getDepthRange().pop(); } }); p.addQueue(RenderQueue.Bucket.Gui.name(), new BasicGeometryQueue(new GuiComparator()) { @Override public void applySettings(FrameGraphContext context) { context.getDepthRange().pushValue(DepthRange.FRONT); context.getCamera().pushValue(true); } @Override public void restoreSettings(FrameGraphContext context) { context.getDepthRange().pop(); context.getCamera().pop(); } }); ``` -------------------------------- ### JmeFrameGraph Setup for JMonkeyEngine in Java Source: https://context7.com/codex128/renthyl/llms.txt Integrates the Renthyl rendering system with JMonkeyEngine. A `JmeFrameGraph` is instantiated using JMonkeyEngine's `AssetManager`. This `JmeFrameGraph` is then registered as the viewport's rendering pipeline, allowing Renthyl tasks to seamlessly integrate with JMonkeyEngine's rendering capabilities. ```java import codex.renthyljme.JmeFrameGraph; import com.jme3.app.SimpleApplication; import com.jme3.asset.AssetManager; import com.jme3.renderer.ViewPort; public class MyApp extends SimpleApplication { @Override public void simpleInitApp() { // Create JME-specific framegraph JmeFrameGraph frameGraph = new JmeFrameGraph(assetManager); // Register as viewport pipeline viewPort.setPipeline(frameGraph); // Add JME rendering tasks // Tasks will automatically integrate with JME's rendering system } } ``` -------------------------------- ### Create SceneEnqueuePass with Legacy Queues (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Creates a SceneEnqueuePass using the 'withLegacyQueues' factory method. This pass extracts geometries from the scene into optimized GeometryQueues, mimicking JME's default queue setup. ```java SceneEnqueuePass enqueue = SceneEnqueuePass.withLegacyQueues(); ``` -------------------------------- ### Task Communication with Sockets for Resource Sharing in Java Source: https://context7.com/codex128/renthyl/llms.txt Illustrates how tasks can exchange data using sockets. It shows a producer task (TextureGeneratorTask) emitting data via an ArgumentSocket and a consumer task (TextureProcessorTask) receiving it via a ValueSocket. The example also covers connecting these sockets within a FrameGraph. ```java import codex.renthyl.tasks.AbstractTask; import codex.renthyl.sockets.ArgumentSocket; import codex.renthyl.sockets.ValueSocket; // Producer task public class TextureGeneratorTask extends AbstractTask { public final ArgumentSocket outputTexture = new ArgumentSocket<>(this); public TextureGeneratorTask() { addSocket(outputTexture); } @Override protected void renderTask() { Texture texture = createTexture(); outputTexture.setValue(texture); } private Texture createTexture() { // Create and return texture return new Texture(); } } // Consumer task public class TextureProcessorTask extends AbstractTask { public final ValueSocket inputTexture = new ValueSocket<>(this); public TextureProcessorTask() { addSocket(inputTexture); } @Override protected void renderTask() { Texture texture = inputTexture.acquire(); if (texture != null) { processTexture(texture); } } private void processTexture(Texture texture) { // Process texture } } // Connect tasks FrameGraph fg = new FrameGraph(); TextureGeneratorTask generator = fg.addTask(new TextureGeneratorTask()); TextureProcessorTask processor = fg.addTask(new TextureProcessorTask()); // Link sockets to enable resource flow processor.inputTexture.setUpstream(generator.outputTexture); fg.render(new BasicGlobalAttributes(), 0.016f); ``` -------------------------------- ### Allocate Integer Array Resource Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md This snippet illustrates how to allocate an integer array using the ResourceAllocator and the defined IntArrayDef. It uses getPosition() for start and end arguments, ensuring safe allocation practices. ```java @Override protected void renderTask() { ResourceWrapper wrapper = allocator.allocate(arrayDef, getPosition(), getPosition()); ... } ``` -------------------------------- ### Create Custom JME Rendering Pass with RasterTask Source: https://context7.com/codex128/renthyl/llms.txt This example demonstrates how to extend the RasterTask class to create a custom rendering pass within JMonkeyEngine. It shows how to access the JME rendering context, set the target framebuffer, clear buffers, and render scene geometry. The task also includes restoring the previous framebuffer after rendering. ```java import codex.renthyljme.RasterTask; import codex.renthyljme.FrameGraphContext; import com.jme3.renderer.Renderer; import com.jme3.texture.FrameBuffer; public class CustomRenderPass extends RasterTask { private FrameBuffer frameBuffer; public CustomRenderPass(FrameBuffer frameBuffer) { this.frameBuffer = frameBuffer; } @Override protected void renderTask() { // Access JME context FrameGraphContext ctx = context; Renderer renderer = ctx.getRenderer(); // Set render target renderer.setFrameBuffer(frameBuffer); // Clear buffers renderer.clearBuffers(true, true, true); // Render scene geometry // Implementation here // Restore previous framebuffer renderer.setFrameBuffer(null); } } // Usage // JmeFrameGraph fg = new JmeFrameGraph(assetManager); // FrameBuffer fb = new FrameBuffer(1920, 1080, 1); // fg.addTask(new CustomRenderPass(fb)); ``` -------------------------------- ### Illegal Task Design: Mutating Input Resources Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Presents an example of an illegal task design where an input resource (an integer array) is mutated. This is illegal because it can lead to synchronization issues and concurrent modification errors if other tasks depend on the original state of the resource. ```java public class IllegalTask extends AbstractTask { public final TransitiveSocket input = new TransitiveSocket(this); public IllegalTask() { addSocket(input); } @Override protected void renderTask() { int[] inArray = input.acquire(); inArray[0] = 56; } } ``` -------------------------------- ### Create and Render a Basic FrameGraph in Java Source: https://context7.com/codex128/renthyl/llms.txt Demonstrates the fundamental steps to set up a FrameGraph, add a custom rendering task, and execute the rendering pipeline. This involves creating a FrameGraph instance, defining a task that extends AbstractTask, and calling the render method with global attributes and time. ```java import codex.renthyl.FrameGraph; import codex.renthyl.BasicGlobalAttributes; import codex.renthyl.tasks.AbstractTask; // Create custom task public class MyRenderTask extends AbstractTask { @Override protected void renderTask() { // Rendering logic here System.out.println("Rendering frame"); } } // Setup and render FrameGraph frameGraph = new FrameGraph(); frameGraph.addTask(new MyRenderTask()); BasicGlobalAttributes globals = new BasicGlobalAttributes(); float timePerFrame = 0.016f; // 60 FPS frameGraph.render(globals, timePerFrame); ``` -------------------------------- ### Setting Default Value for ArgumentSocket Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Provides an example of setting a default string value for the textSocket of a PrintToConsole task when using an ArgumentSocket. This value is used if the socket has no upstream connection. ```java print.textSocket.setValue("default value"); ``` -------------------------------- ### Connecting ConcatText and PrintToConsole Sockets in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Demonstrates setting up a FrameGraph with ConcatText and PrintToConsole tasks, and then explicitly connecting the output socket of ConcatText ('resultSocket') to the input socket of PrintToConsole ('textSocket') using setUpstream. Dependencies: FrameGraph, ConcatText, PrintToConsole. ```java FrameGraph fg = new FrameGraph(); ConcatText concat = fg.add(new ConcatText("Hello", "World")); PrintToConsole print = fg.add(new PrintToConsole()); print.textSocket.setUpstream(concat.resultSocket); fg.render(); ``` -------------------------------- ### Initialize and Add a Filter to FilterChain in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Demonstrates the initialization of a FilterChain and the addition of a specific filter (CrossHatchPass) to it. This is the first step in applying post-processing effects. ```java FilterChain filters = new FilterChain(); filters.add(new CrossHatchPass(assetManager, allocator)); ``` -------------------------------- ### SimpleForwardTest Application Structure in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Provides the main application structure for a simple forward renderer. It initializes a scene with a blue cube, sets up the JmeFrameGraph pipeline, and configures render passes and tasks, including queue ordering. ```java public class SimpleForwardTest extends SimpleApplication { public static void main(String[] args) { SimpleForwardTest app = new SimpleForwardTest(); app.start(); } @Override public void simpleInitApp() { Geometry geometry = new Geometry("cube", new Box(1, 1, 1)); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); geometry.setMaterial(mat); rootNode.attachChild(geometry); JmeFrameGraph fg = new JmeFrameGraph(assetManager); viewPort.setPipeline(fg); ResourceAllocationState allocator = new ResourceAllocationState(); stateManager.attach(allocator); fg.add(new ControlRenderPass()); SceneEnqueuePass enqueue = SceneEnqueuePass.withLegacyQueues(); MapToList orderQueues = new MapToList<>(new String[] { RenderQueue.Bucket.Opaque.name(), RenderQueue.Bucket.Sky.name(), RenderQueue.Bucket.Transparent.name(), RenderQueue.Bucket.Gui.name(), RenderQueue.Bucket.Translucent.name() }); GeometryPass render = new GeometryPass(allocator); OutputPass out = fg.addTask(new OutputPass()); orderQueues.getMap().setUpstream(enqueue.getQueues()); render.getGeometry().addCollectionSource(orderQueues.getList()); out.getColor().setUpstream(render.getOutColor()); out.getDepth().setUpstream(render.getOutDepth()); } } ``` -------------------------------- ### Configure Render Output with FilterChain in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Shows how to redirect the rendering output through a FilterChain before it reaches the final output. This involves setting up the upstream connections for color and depth buffers. ```java //out.getColor().setUpstream(render.getOutColor()); filters.getSceneColor().setUpstream(render.getOutColor()); filters.getSceneDepth().setUpstream(render.getOutDepth()); out.getColor().setUpstream(filters.getFilterResult()); ``` -------------------------------- ### Using PrintToConsole with FrameGraph in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Demonstrates how to create a FrameGraph, add a PrintToConsole task to it, and then render the FrameGraph. Shows basic usage for outputting text. Dependencies: FrameGraph, PrintToConsole. ```java FrameGraph fg = new FrameGraph(); fg.add(new PrintToConsole("Hello World!")); fg.render(); ``` -------------------------------- ### Create and Attach a Basic Geometry (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md This Java code creates an unshaded blue cube geometry and attaches it to the root node of the scene. This is a prerequisite for rendering. ```java Geometry geometry = new Geometry("cube", new Box(1, 1, 1)); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); geometry.setMaterial(mat); rootNode.attachChild(geometry); ``` -------------------------------- ### Initialize and Manage ShortTermAllocator Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Demonstrates how to initialize, use, flush, and clear the ShortTermAllocator for managing resources. ShortTermAllocator is preferred for most use cases. Flush should be called before or after each render frame, and clear should be called when the application ends. ```java ShortTermAllocator allocator = new ShortTermAllocator(); GenerateIntegerArray gen = new GenerateIntegerArray(allocator); allocator.flush(); allocator.clear(); ``` -------------------------------- ### Declare and Initialize AllocationSocket Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md This code demonstrates the declaration and initialization of an AllocationSocket for integer arrays. It requires both the task and a ResourceAllocator, simplifying resource acquisition and management. ```java public final AllocationSocket arraySocket; public GenerateIntegerArray(ResourceAllocator allocator) { arraySocket = addSocket(new AllocationSocket<>(this, allocator, arrayDef)); ... } ``` -------------------------------- ### Connect Render Passes using makeInput Source: https://github.com/codex128/renthyl/wiki/2.-FrameGraphs-from-Scratch Demonstrates how to establish connections between render passes using the `makeInput` method. This method links the output of a source pass to the input of a target pass by selecting specific ResourceTickets based on their names. ```java targetPass.getMainInputGroup().makeInput( sourcePass.getMainOutputGroup(), TicketSelector.name("SourceTicketName"), TicketSelector.name("TargetTicketName")); ``` -------------------------------- ### Resource Allocation with ResourceAllocator in Java Source: https://context7.com/codex128/renthyl/llms.txt Demonstrates efficient resource management using ResourceAllocator and ShortTermAllocator for graphics resources like textures. It defines custom resource requirements with TextureDef, handling creation, evaluation, conformity, and disposal. Tasks can acquire and use these resources via AllocationSocket. ```java import codex.renthyl.resources.ResourceAllocator; import codex.renthyl.resources.ShortTermAllocator; import codex.renthyl.definitions.ResourceDef; import codex.renthyl.sockets.allocation.AllocationSocket; // Define resource requirements public class TextureDef implements ResourceDef { private final int width, height; public TextureDef(int width, int height) { this.width = width; this.height = height; } @Override public Texture createResource() { return new Texture(width, height); } @Override public Float evaluateResource(Object resource) { if (!(resource instanceof Texture)) return null; Texture tex = (Texture) resource; if (tex.getWidth() == width && tex.getHeight() == height) { return 0f; // Perfect match } return 1f; // Can be resized } @Override public Texture conformResource(Object resource) { Texture tex = (Texture) resource; tex.resize(width, height); return tex; } @Override public void dispose(Texture resource) { resource.delete(); } } // Use allocation socket in task public class AllocatingTask extends AbstractTask { private final AllocationSocket textureSocket; public AllocatingTask(ResourceAllocator allocator) { TextureDef def = new TextureDef(1024, 1024); this.textureSocket = new AllocationSocket<>(this, allocator, def); addSocket(textureSocket); } @Override protected void renderTask() { Texture texture = textureSocket.acquire(); // Use allocated texture renderToTexture(texture); } private void renderToTexture(Texture texture) { // Rendering implementation } } // Setup with allocator ResourceAllocator allocator = new ShortTermAllocator(); FrameGraph fg = new FrameGraph(); fg.addTask(new AllocatingTask(allocator)); ``` -------------------------------- ### Push Render Technique Setting in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Demonstrates how to set a forced rendering technique within a RasterTask using the FrameGraphContext. It pushes a specific technique name onto the context's forced technique stack. ```java context.getForcedTechnique().pushValue("Technique_To_Force"); ``` -------------------------------- ### Direct RenderingQueue Usage in Java Source: https://context7.com/codex128/renthyl/llms.txt Provides low-level control over rendering by directly interacting with the BasicRenderingQueue. This involves creating a queue, defining renderable tasks, and manually executing the rendering pipeline stages: stage, update, prepare, render, and reset. A simplified pipeline method is also available for executing tasks in sequence. ```java import codex.renthyl.render.queue.BasicRenderingQueue; import codex.renthyl.render.queue.RenderingQueue; import codex.renthyl.render.Renderable; import codex.renthyl.GlobalAttributes; import codex.renthyl.BasicGlobalAttributes; import java.util.Arrays; // Create queue and tasks RenderingQueue queue = new BasicRenderingQueue(); GlobalAttributes globals = new BasicGlobalAttributes(); Renderable task1 = new MyRenderTask(); Renderable task2 = new MyRenderTask(); // Manual pipeline execution for (Renderable task : Arrays.asList(task1, task2)) { task.stage(globals, queue); } queue.update(0.016f); queue.prepare(); queue.render(); queue.reset(); // Or use simplified pipeline method queue.pipeline(globals, Arrays.asList(task1, task2), 0.016f); ``` -------------------------------- ### Using ArgumentSocket for Default Values Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Demonstrates how to use an ArgumentSocket in PrintToConsole to provide a default value when no upstream task is connected. This allows a task to operate independently with a pre-defined value. ```java //public final TransitiveSocket textSocket = new TransitiveSocket<>(this); public final ArgumentSocket textSocket = new ArgumentSocket<>(this); ``` -------------------------------- ### Conform IntBuffer Resource for Allocation (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Implements the conformResource method to prepare a selected IntBuffer for allocation by setting its limit. This method is called only on resources that have passed evaluation and ensures the buffer's limit is set to the minimum required size. ```java @Override public IntBuffer conformResource(Object resource) { IntBuffer buffer = (IntBuffer)resource; buffer.limit(minimumSize); return buffer; } ``` -------------------------------- ### Initialize JmeFrameGraph (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Initializes a JmeFrameGraph, which is an extension of FrameGraph designed to interface with JME's rendering system. It requires an AssetManager. ```java JmeFrameGraph fg = new JmeFrameGraph(assetManager); ``` -------------------------------- ### Apply Socket Values to Material in Custom Java Filter Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Shows the implementation of the configureMaterial method in a custom filter. It demonstrates how to acquire values from the registered argument sockets and apply them to the filter's material properties. ```java @Override protected void configureMaterial(Material material) { material.setColor("Color", color.acquire()); material.setFloat("Factor", factor.acquire()); } ``` -------------------------------- ### Create a Custom Post-Process Filter in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Provides a basic structure for creating a custom post-processing filter by extending RenthylJme's AbstractFilterTask. It includes constructor implementation and placeholder for material configuration. ```java public class MyCustomFilter extends AbstractFilterTask { public MyCustomFilter(AssetManager assetManager, ResourceAllocator allocator) { super(allocator, new Material(assetManager, "My/Custom/Filter.j3md"), false); } @Override protected void configureMaterial(Material material) { // todo: implement } } ``` -------------------------------- ### Basic Renthyl FrameGraph Usage (Java) Source: https://github.com/codex128/renthyl/blob/master/README.md Demonstrates the fundamental usage of Renthyl's FrameGraph in Java. It involves creating a FrameGraph object, adding custom tasks, and then rendering the graph. ```java FrameGraph fg = new FrameGraph(); fg.addTask(new MyCustomTask()); fg.addTask(new SomeOtherTask()); fg.render(); ``` -------------------------------- ### Adding Multiple PrintToConsole Tasks in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Illustrates adding multiple PrintToConsole tasks to a single FrameGraph and rendering them. Also shows the usage of addTask which returns the added task. Dependencies: FrameGraph, PrintToConsole. ```java FrameGraph fg = new FrameGraph(); fg.add(new PrintToConsole("Hello World!")); fg.add(new PrintToConsole("First Renthyl program.")); PrintToConsole home = fg.addTask(new PrintToConsole("Home sweet home")); fg.render(); ``` -------------------------------- ### Integrate FrameGraph with JMonkeyEngine (Java) Source: https://github.com/codex128/renthyl/blob/master/README.md Shows how to set up a basic forward-style FrameGraph within a JMonkeyEngine 3.8+ application. This involves creating the graph, registering it with the viewport, setting up resource allocation, and defining rendering passes. ```java // create and attach framegraph JmeFrameGraph fg = new JmeFrameGraph(assetManager); viewPort.setPipeline(fg); // create resource allocator ResourceAllocatorState allocator = new ResourceAllocatorState(); stateManager.attach(allocator); // create tasks SceneEnqueuePass enqueue = SceneEnqueuePass.withSingleQueue(); GeometryPass geometry = new GeometryTask(allocator); OutputPass out = fg.addTask(new OutputPass()); // share task resources geometry.getGeometry().addMapSource(enqueue.getQueues()); out.getColor().setUpstream(geometry.getOutColor()); out.getDepth().setUpstream(geometry.getOutDepth()); ``` -------------------------------- ### Integrate ResourceAllocatorState with JMonkeyEngine Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Shows how to use ResourceAllocatorState, an extension of ShortTermAllocator, within JMonkeyEngine applications. It automatically handles flush and clear operations by hooking into the application's lifecycle. Attach the state to the state manager. ```java ResourceAllocatorState allocator = new ResourceAllocatorState(); stateManager.attach(allocator); ``` -------------------------------- ### Initialize FrameGraph Source: https://github.com/codex128/renthyl/wiki/2.-FrameGraphs-from-Scratch Creates a new FrameGraph instance, which serves as the central container for managing render passes and their execution order. It requires an AssetManager for resource handling. ```java FrameGraph fg = new FrameGraph(assetManager); ``` -------------------------------- ### Create IntBuffer Resource (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Implements the createResource method to allocate a new IntBuffer using LWJGL3's MemoryUtil. The buffer is created with a specified minimum size for its capacity. ```java @Override public IntBuffer createResource() { // using Lwjgl MemoryUtil for allocation return MemoryUtil.memAllocInt(minimumSize); } ``` -------------------------------- ### Initialize Renthyl for JMonkeyEngine Source: https://github.com/codex128/renthyl/wiki/1.-Hello-Renthyl Initializes the Renthyl rendering engine. This is a prerequisite before creating or using any FrameGraphs. It typically requires the application context. ```java Renthyl.initialize(application); ``` -------------------------------- ### Add RenthylJme Dependency (Gradle) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md This snippet shows how to add the RenthylJme library as a dependency in a Gradle build file. Ensure you are using a compatible version of RenthylJme. ```groovy dependencies { ... implementation "com.github.codex128.Renthyl:RenthylJme:2.0.1-alpha" } ``` -------------------------------- ### Full GenerateIntegerArray Task Implementation Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md This is the complete code for the GenerateIntegerArray task, integrating the AllocationSocket for streamlined resource allocation, population, and automatic wrapper management. ```java public class GenerateIntegerArray extends AbstractTask { public final AllocationSocket arraySocket; private final IntArrayDef arrayDef = new IntArrayDef(); public GenerateIntegerArray(ResourceAllocator allocator) { arraySocket = addSocket(new AllocationSocket<>(this, allocator, arrayDef)); arrayDef.setSize(10); } @Override protected void renderTask() { int[] array = arraySocket.acquire(); for (int i = 0; i < array.length; i++) { array[i] = i; } } } ``` -------------------------------- ### Initialize GenerateIntegerArray Task Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md This snippet shows the basic structure of a GenerateIntegerArray task, extending AbstractTask. It initializes the task and includes a placeholder for the renderTask logic. ```java public class GenerateIntegerArray extends AbstractTask { public GenerateIntegerArray() { } @Override protected void renderTask() { int[] array = ... for (int i = 0; i < array.length; i++) { array[i] = i; } } } ``` -------------------------------- ### Declare and Reference Resources in RenderPass Preparation (Java) Source: https://github.com/codex128/renthyl/wiki/3.-Hello-RenderPass This Java code snippet demonstrates how a RenderPass declares its output resources using `declare` and references its input resources using `reference` within the FrameGraph's preparation phase. It's crucial for the resource manager to correctly allocate and manage textures. ```java import com.example.FGRenderContext; import com.example.TextureDefinition; import com.example.ResourceTicket; public abstract class RenderPass { protected TextureDefinition texDef; protected ResourceTicket out; protected ResourceTicket in; protected void prepare(FGRenderContext context) { declare(texDef, out); reference(in); } protected abstract void declare(TextureDefinition definition, ResourceTicket ticket); protected abstract void reference(ResourceTicket ticket); // ... other methods } ``` -------------------------------- ### Order Geometry Queues with MapToList in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Creates a MapToList object to order geometry queues by specific bucket names. This ensures render order: Opaque, Sky, Transparent, Gui, Translucent. It uses a String array for keys and GeometryQueue objects for values. ```java MapToList orderQueues = new MapToList<>(new String[] { RenderQueue.Bucket.Opaque.name(), RenderQueue.Bucket.Sky.name(), RenderQueue.Bucket.Transparent.name(), RenderQueue.Bucket.Gui.name(), RenderQueue.Bucket.Translucent.name() }); ``` -------------------------------- ### Connect Renderer Tasks in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Connects the geometry, color, and depth output tasks to the renderer. It takes the geometry from the render module and outputs color and depth information. ```java render.getGeometry().addMapSource(enqueue.getQueues()); out.getColor().setUpstream(render.getOutColor()); out.getDepth().setUpstream(render.getOutDepth()); ``` -------------------------------- ### Manage JME Resources with AllocationSocket for Deferred Rendering Source: https://context7.com/codex128/renthyl/llms.txt This snippet illustrates the use of AllocationSocket for automatic allocation and reuse of JME rendering resources, specifically for a deferred rendering pass. It shows how to define and allocate textures for color and normal buffers, as well as a framebuffer, using ResourceAllocator. The acquired resources are then attached to the framebuffer for rendering. ```java import codex.renthyljme.definitions.TextureDef; import codex.renthyljme.definitions.FrameBufferDef; import codex.renthyl.sockets.allocation.AllocationSocket; import codex.renthyl.resources.ResourceAllocator; import com.jme3.texture.Image.Format; import com.jme3.texture.Texture2D; import com.jme3.texture.FrameBuffer; public class DeferredRenderingTask extends RasterTask { public final AllocationSocket colorBuffer; public final AllocationSocket normalBuffer; public final AllocationSocket gBuffer; public DeferredRenderingTask(ResourceAllocator allocator, int width, int height) { // Allocate color texture TextureDef colorDef = new TextureDef(width, height, Format.RGBA8); this.colorBuffer = new AllocationSocket<>(this, allocator, colorDef); addSocket(colorBuffer); // Allocate normal texture TextureDef normalDef = new TextureDef(width, height, Format.RGB16F); this.normalBuffer = new AllocationSocket<>(this, allocator, normalDef); addSocket(normalBuffer); // Allocate framebuffer FrameBufferDef fbDef = new FrameBufferDef(width, height, 1); this.gBuffer = new AllocationSocket<>(this, allocator, fbDef); addSocket(gBuffer); } @Override protected void renderTask() { Texture2D color = colorBuffer.acquire(); Texture2D normal = normalBuffer.acquire(); FrameBuffer fb = gBuffer.acquire(); // Attach textures to framebuffer fb.setColorTexture(color); fb.setColorTexture(normal, 1); // Render to G-Buffer context.getRenderer().setFrameBuffer(fb); renderGeometryPass(); } private void renderGeometryPass() { // Geometry rendering implementation } } // Usage with resource allocator // ResourceAllocator allocator = new ShortTermAllocator(); // JmeFrameGraph fg = new JmeFrameGraph(assetManager); // DeferredRenderingTask deferredPass = fg.addTask( // new DeferredRenderingTask(allocator, 1920, 1080) // ); ``` -------------------------------- ### Evaluate IntBuffer Resource Suitability (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Implements the evaluateResource method to determine the suitability of an IntBuffer for allocation. It checks if the resource is an IntBuffer and if its capacity meets the minimum requirement, returning 0f for acceptance or null for rejection. ```java @Override public Float evaluateResource(Object resource) { if (!(resource instanceof IntBuffer)) { return null; // not an IntBuffer, cannot be used at all } IntBuffer buffer = (IntBuffer)resource; if (buffer.capacity() >= minimumSize) { return 0f; } else { return null; // not the correct size } } ``` -------------------------------- ### Set Viewport Pipeline (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Registers the initialized JmeFrameGraph as the rendering pipeline for the main viewport. This directs JME to use the framegraph for rendering. ```java viewPort.setPipeline(fg); ``` -------------------------------- ### Provide Values Using Attribute Socket Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Demonstrates how to use the Attribute task, which functions as both a Renderable and a Socket, to provide a static value to a task's input socket. This is a straightforward way to inject data into the render graph. ```java FrameGraph fg = new FrameGraph(); PrintToConsole print = fg.addTask(new PrintToConsole("nothing to see")); Attribute inText = new Attribute<>("Text from an Attribute"); print.textSocket.setUpstream(inText); fg.render(); ``` -------------------------------- ### PrintToConsole Renderable Implementation in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md A simple Renderable implementation using AbstractTask that prints a given text to the console when rendered. It takes a String in its constructor and overrides the renderTask method to perform the printing. Dependencies: AbstractTask, System.out.println. ```java public class PrintToConsole extends AbstractTask { private final String text; public PrintToConsole(String text) { this.text = text; } @Override protected void renderTask() { System.out.println("Rendering text: " + text); } } ``` -------------------------------- ### Acquire Array using AllocationSocket Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md This snippet shows the simplified rendering logic when using an AllocationSocket. The array is acquired directly using arraySocket.acquire(), and the loop populates the array. ```java @Override protected void renderTask() { int[] array = arraySocket.acquire(); for (int i = 0; i < array.length; i++) { array[i] = i; } } ``` -------------------------------- ### Slow Method for Acquiring and Attaching Output Texture (Java) Source: https://github.com/codex128/renthyl/wiki/3.-Hello-RenderPass Demonstrates the less efficient, manual way to acquire an output texture and attach it to a FrameBuffer. This involves clearing color targets, acquiring the texture, and setting it as a target. ```java // the slow way to get and attach the output texture b.clearColorTargets(); Texture2D outTex = resources.acquire(output); fb.addColorTarget(FrameBuffer.target(outTex)); fb.setUpdateNeeded(); ``` -------------------------------- ### Multithreaded Rendering with Executor in Java Source: https://context7.com/codex128/renthyl/llms.txt Enables parallel execution of rendering tasks by leveraging Java's `Executor` framework. A `FixedThreadPool` is created to manage threads, and a `FrameGraph` is initialized with this executor. Tasks added to the `FrameGraph` can then be executed concurrently, optimizing performance based on task dependencies. ```java import java.util.concurrent.Executor; import java.util.concurrent.Executors; import codex.renthyl.FrameGraph; // Create executor for multithreading Executor executor = Executors.newFixedThreadPool(4); // FrameGraph with multithreading support FrameGraph frameGraph = new FrameGraph(executor); // Add tasks that can execute in parallel frameGraph.addTask(new IndependentTask1()); frameGraph.addTask(new IndependentTask2()); frameGraph.addTask(new IndependentTask3()); // Tasks will be executed in parallel where dependencies allow frameGraph.render(new BasicGlobalAttributes(), 0.016f); ``` -------------------------------- ### Configure Array Size Requirement Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md This code shows how to configure the IntArrayDef to specify a minimum size requirement for the integer array. In this case, it's set to 10 elements. ```java public GenerateIntegerArray(ResourceAllocator allocator) { ... arrayDef.setSize(10); } ``` -------------------------------- ### Create a Forward FrameGraph Source: https://github.com/codex128/renthyl/wiki/1.-Hello-Renthyl Creates a new FrameGraph using a factory method, specifically a forward rendering pipeline. This FrameGraph will be used to control the rendering process for a specific viewport. It requires an AssetManager to load necessary resources. ```java FrameGraph fg = Renthyl.forward(assetManager); ``` -------------------------------- ### Java ResourceDef Interface for Resource Definition and Creation Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md The ResourceDef interface extends Disposer and defines methods for creating, evaluating, and conforming resources. It's used by ResourceAllocator to select the best existing resource or create a new one if none are suitable. The evaluateResource method scores existing resources, and conformResource casts them to the target type. ```java public interface ResourceDef extends Disposer { T createResource(); Float evaluateResource(Object resource); T conformResource(Object resource); } ``` -------------------------------- ### Ensuring Task Execution via Upstream Connection Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Shows how re-establishing the upstream connection between PrintToConsole and ConcatText ensures that ConcatText is rendered by the FrameGraph. This highlights the dependency-driven rendering mechanism. ```java print.textSocket.setUpstream(concat.resultSocket); ``` -------------------------------- ### Initialize Input and Output Tickets Source: https://github.com/codex128/renthyl/wiki/3.-Hello-RenderPass This Java code demonstrates how to initialize the input and output ResourceTickets within the initialize() method of a RenderPass. It uses 'addInput' and 'addOutput' methods to register named tickets with the FrameGraph. ```java protected void initialize(FrameGraph frameGraph) { input = addInput("Input"); output = addOutput("Output"); } ``` -------------------------------- ### Acquire Input Texture (Java) Source: https://github.com/codex128/renthyl/wiki/3.-Hello-RenderPass Fetches the input texture using a ResourceTicket. If the resource does not exist, an exception is thrown. This is suitable for mandatory inputs. ```java Texture2D inTex = resources.acquire(input); ``` -------------------------------- ### Define and Register Argument Sockets in Custom Java Filter Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Illustrates how to define custom argument sockets (e.g., ColorRGBA, Float) within a custom filter class and register them using the addSockets method. These sockets will be used to pass parameters to the filter's material. ```java private final ArgumentSocket color = new ArgumentSocket<>(ColorRGBA.Blue); private final ArgumentSocket factor = new ArgumentSocket<>(1f); public MyCustomFilter(AssetManager assetManager, ResourceAllocator allocator) { ... // Other constructor logic addSockets(color, factor); } ``` -------------------------------- ### Implement Conditional Rendering with Multiplexor Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Explains how to use the Multiplexor task to select one of multiple inputs based on an index for conditional rendering. Inputs not selected are not processed, making it efficient for enabling/disabling parts of the render graph. An out-of-bounds index results in null output. ```java FrameGraph fg = new FrameGraph(); PrintToConsole print = fg.addTask(new PrintToConsole("nothing to see")); ConcatText helloWorld = new ConcatText("Hello", "World")); ConcatText fireIce = new ConcatText("Fire", "Ice")); Multiplexor mux = new Multiplexor(); mux.addUpstream(helloWorld.resultSocket); mux.addUpstream(fireIce.resultSocket); print.textSocket.setUpstream(mux); fg.render(); mux.getIndex().setValue(1); fg.render(); mux.getIndex().setValue(2); fg.render(); ``` -------------------------------- ### Attach Resource Allocation State (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Attaches a ResourceAllocationState to the state manager. This is crucial for managing the lifecycle of rendering resources like textures, framebuffers, and render targets. ```java ResourceAllocationState allocator = new ResourceAllocationState(); stateManager.attach(allocator); ``` -------------------------------- ### Transform String with Java Derivative Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Demonstrates how to use the Derivative abstract class in Java to transform an input string by appending an exclamation mark. It sets up a FrameGraph, an Attribute for the initial string, a PrintToConsole task, and a Derivative to modify the string before it's printed. ```java FrameGraph fg = new FrameGraph(); Attribute startText = new Attribute<>("I am happy"); PrintToConsole print = fg.addTask(new PrintToConsole("nothing to see")); Derivative exclaim = new Derivative() { @Override public String apply(String input) { return input + '!'; } }; exclaim.setUpstream(startText); print.textSocket.setUpstream(exclaim); fg.render(); ``` -------------------------------- ### Pop Render Technique Setting in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/RenthylWithJme.md Shows how to remove the currently set forced rendering technique from the FrameGraphContext's stack. This reverts the rendering settings to their previous state after a specific technique is no longer needed. ```java context.getForcedTechnique().pop(); ``` -------------------------------- ### Connect Geometry and Output Passes (Java) Source: https://github.com/codex128/renthyl/wiki/2.-FrameGraphs-from-Scratch Connects the 'Color' ticket from the geometry pass's main output group to the 'Color' ticket in the output pass's main input group. This utilizes the makeInput method and TicketSelector.name for specific ticket matching. ```java out.getMainInputGroup().makeInput( geometry.getMainOutputGroup(), TicketSelector.name("Color"), TicketSelector.name("Color")); ``` -------------------------------- ### Define Output Texture Definition Source: https://github.com/codex128/renthyl/wiki/3.-Hello-RenderPass This Java code snippet shows how to define the properties for the output texture using TextureDef. It demonstrates two ways to initialize TextureDef: using a static helper method and using a constructor with a class and an image mapping function. ```java private final TextureDef texDef = TextureDef.texture2D(); ``` ```java private final TextureDef texDef = new TextureDef<>(Texture2D.class, img -> new Texture2D(img)); ``` -------------------------------- ### Concatenate Two Strings with FrameGraph Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Demonstrates concatenating two strings using ConcatText and printing the result via PrintToConsole within a FrameGraph. It shows how tasks are added and connected, and how the FrameGraph manages rendering based on dependencies. ```java ConcatText concat = fg.add(new ConcatText("Hello", "World")); PrintToConsole print = fg.add(new PrintToConsole()); print.textSocket.setUpstream(concat.resultSocket); fg.render(); } } public class ConcatText extends AbstractTask { private final String text1, text2; public final ArgumentSocket resultSocket = new ArithmeticException<>(this); public ConcatText(String text1, String text2) { this.text1 = text1; this.text2 = text2; addSocket(resultSocket); } @Override protected void renderTask() { String result = text1 + '/' + text2; resultSocket.setValue(result); } } public class PrintToConsole extends AbstractTask { private final TransitiveSocket textSocket = new TransitiveSocket<>(this); public PrintToConsole(String text) { this.text = text; addSocket(textSocket); } @Override protected void renderTask() { System.out.println("Rendering text: " + textSocket.acquire()); } } ``` -------------------------------- ### Connect Enqueue and Merge Passes (Java) Source: https://github.com/codex128/renthyl/wiki/2.-FrameGraphs-from-Scratch Connects multiple tickets ('Opaque', 'Sky', 'Transparent', 'Gui', 'Translucent') from the enqueue pass's main output group to the merge pass's main input group, which uses a DynamicTicketList. This allows for arbitrary connections to DynamicTicketLists. ```java merge.getMainInputGroup().makeInput( enqueue.getMainOutputGroup(), TicketSelector.names("Opaque", "Sky", "Transparent", "Gui", "Translucent"), TicketSelector.All); ``` -------------------------------- ### Configuring PrintToConsole to Receive Data via TransitiveSocket in Java Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Modifies the PrintToConsole class to accept input via a TransitiveSocket named 'textSocket' instead of a direct String field. The socket is registered, and its value is acquired during renderTask. Dependencies: AbstractTask, TransitiveSocket. ```java //private final String text; public final TransitiveSocket textSocket = new TransitiveSocket<>(this); public PrintToConsole(/*String text*/) { //this.text = text; addSocket(textSocket); } @Override protected void renderTask() { //System.out.println("Rendering text: " + text); String result = textSocket.acquire(); System.out.println("Rendering text: " + result); } ``` -------------------------------- ### IntBufferDef Class Implementation (Java) Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md Defines an IntBufferDef that implements the ResourceDef interface for IntBuffer types. It includes methods for creating, evaluating, conforming, and disposing of IntBuffer resources, with a focus on managing buffer size. ```java public class IntBufferDef implements ResourceDef { private int minimumSize; public IntBufferDef(int minimumSize) { this.minimumSize = minimumSize; } @Override public IntBuffer createResource() {} @Override public Float evaluateResource(Object resource) {} @Override public IntBuffer conformResource(Object resource) {} @Override public void dispose(IntBuffer resource) {} } ``` -------------------------------- ### Extract Resource from Wrapper Source: https://github.com/codex128/renthyl/blob/master/Wiki/2_0_0/HowToUseRenthyl.md This code explains how to extract the underlying integer array from a ResourceWrapper using the IntArrayDef. This step is necessary because ResourceWrappers are type-agnostic. ```java int[] array = arrayDef.conformResource(wrapper.get()); ``` -------------------------------- ### Reserve Output Resource for Performance (Java) Source: https://github.com/codex128/renthyl/wiki/3.-Hello-RenderPass This Java code snippet shows how to use the `reserve` method to hint to the FrameGraph's resource manager that a specific output resource should be preserved. Reserving resources, particularly textures, can significantly improve performance by minimizing FrameBuffer re-binding across frames. ```java import com.example.ResourceTicket; // Assume 'out' is a defined ResourceTicket for an output resource // Assume this call is within the prepare method after declare(texDef, out); reserve(out); // Method definition (example): protected abstract void reserve(ResourceTicket ticket); ```