Skip to content

Commit

Permalink
fixed issues caused by further migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
codex128 committed Aug 22, 2024
1 parent 4b1e4e6 commit c0597be
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 102 deletions.
18 changes: 11 additions & 7 deletions RenthylCore/main/java/codex/renthyl/FGPipelineContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@

import codex.renthyl.resources.RenderObjectMap;
import codex.renthyl.debug.GraphEventCapture;
import com.jme3.app.Application;
import com.jme3.app.state.AppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.renderer.pipeline.AbstractPipelineContext;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.pipeline.PipelineContext;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -44,27 +43,31 @@
*
* @author codex
*/
public class FGPipelineContext extends AbstractPipelineContext {
public class FGPipelineContext implements PipelineContext {

private static final Logger LOG = Logger.getLogger(FGPipelineContext.class.getName());

private final RenderObjectMap renderObjects;
private final ExecutionThreadManager threadManager = new ExecutionThreadManager();
private final AtomicBoolean rendered = new AtomicBoolean(false);
private GraphEventCapture eventCapture;

public FGPipelineContext(RenderManager rm) {
renderObjects = new RenderObjectMap(this, true);
}

@Override
public void startRenderFrame(RenderManager rm) {
public boolean startViewPortRender(RenderManager rm, ViewPort vp) {
if (eventCapture != null) {
eventCapture.beginRenderFrame();
}
renderObjects.newFrame();
return rendered.getAndSet(true);
}
@Override
public void endRenderFrame(RenderManager rm) {
public void endViewPortRender(RenderManager rm, ViewPort vp) {}
@Override
public void endContextRenderFrame(RenderManager rm) {
if (eventCapture != null) {
eventCapture.endRenderFrame();
}
Expand All @@ -78,6 +81,7 @@ public void endRenderFrame(RenderManager rm) {
}
eventCapture = null;
}
rendered.set(false);
}

public void setEventCapture(GraphEventCapture eventCapture) {
Expand Down
3 changes: 2 additions & 1 deletion RenthylCore/main/java/codex/renthyl/FGRenderContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ public void renderTextures(Texture2D color, Texture2D depth) {
*/
public void resizeCamera(int w, int h, boolean fixAspect, boolean ortho, boolean force) {
Camera cam = viewPort.getCamera();
if (cam.resize(w, h, fixAspect, force)) {
if (force || w != cam.getWidth() || h != cam.getHeight()) {
cam.resize(w, h, fixAspect);
renderManager.setCamera(cam, ortho);
}
}
Expand Down
1 change: 1 addition & 0 deletions RenthylCore/main/java/codex/renthyl/FrameGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public boolean hasRenderedThisFrame() {
@Override
public void endRenderFrame(RenderManager rm) {
root.renderingComplete();
resources.endRenderFrame();
rendered = false;
}
@Override
Expand Down
29 changes: 25 additions & 4 deletions RenthylCore/main/java/codex/renthyl/GeometryQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
*/
package codex.renthyl;

import com.jme3.renderer.DepthRange;
import codex.boost.export.SavableObject;
import codex.boost.render.DepthRange;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import com.jme3.renderer.Camera;
import com.jme3.renderer.GeometryRenderHandler;
import com.jme3.renderer.RenderManager;
Expand All @@ -37,6 +43,7 @@
import com.jme3.renderer.queue.NullComparator;
import com.jme3.scene.Geometry;
import com.jme3.util.ListSort;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.function.Function;
Expand All @@ -50,7 +57,7 @@
*
* @author codex
*/
public class GeometryQueue implements Iterable<Geometry> {
public class GeometryQueue implements Iterable<Geometry>, Savable {

private static final int DEFAULT_SIZE = 32;

Expand Down Expand Up @@ -115,7 +122,7 @@ public void render(RenderManager renderManager, GeometryRenderHandler handler) {
if (handler == null) {
handler = GeometryRenderHandler.DEFAULT;
}
renderManager.getRenderer().setDepthRange(depth);
depth.apply(renderManager.getRenderer());
if (!perspective) {
renderManager.setCamera(cam, true);
}
Expand All @@ -127,7 +134,7 @@ public void render(RenderManager renderManager, GeometryRenderHandler handler) {
if (!perspective) {
renderManager.setCamera(cam, false);
}
renderManager.getRenderer().setDepthRange(DepthRange.IDENTITY);
DepthRange.NORMAL.apply(renderManager.getRenderer());
for (GeometryQueue q : internalQueues) {
q.render(renderManager, handler);
}
Expand Down Expand Up @@ -423,6 +430,20 @@ public int getAllocatedSpace() {
public Iterator<Geometry> iterator() {
return new GeometryIterator();
}
@Override
public void write(JmeExporter ex) throws IOException {
OutputCapsule out = ex.getCapsule(this);
out.write(new SavableObject(comparator), "comparator", SavableObject.NULL);
out.write(depth, "depth", DepthRange.NORMAL);
out.write(perspective, "perspective", true);
}
@Override
public void read(JmeImporter im) throws IOException {
InputCapsule in = im.getCapsule(this);
comparator = SavableObject.read(in, "comparator", GeometryComparator.class);
depth.set(SavableObject.readSavable(in, "depth", DepthRange.class, DepthRange.NORMAL));
perspective = in.readBoolean("perspective", true);
}

private class GeometryIterator implements Iterator<Geometry> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public abstract class AbstractResourceDef <T> implements ResourceDef<T> {
private Consumer<T> disposalMethod;
private int staticTimeout = -1;
private boolean useExisting = true;
private boolean allowCasualAllocation = true;
private boolean allowReservations = true;
private boolean disposeOnRelease = false;
private boolean readConcurrent = true;

Expand All @@ -59,6 +61,16 @@ public boolean isUseExisting() {
return useExisting;
}

@Override
public boolean isAllowCasualAllocation() {
return allowCasualAllocation;
}

@Override
public boolean isAllowReservations() {
return allowReservations;
}

@Override
public boolean isDisposeOnRelease() {
return disposeOnRelease;
Expand Down Expand Up @@ -104,6 +116,29 @@ public void setStaticTimeout(int staticTimout) {
public void setUseExisting(boolean useExisting) {
this.useExisting = useExisting;
}

/**
* Allows this definitions resource to be reallocated casually
* without a specific object id.
* <p>
* default=true
*
* @param allowCasualAllocation
*/
public void setAllowCasualAllocation(boolean allowCasualAllocation) {
this.allowCasualAllocation = allowCasualAllocation;
}

/**
* Sets this definition's resource to allow itself to be reserved.
* <p>
* default=true
*
* @param allowReservations
*/
public void setAllowReservations(boolean allowReservations) {
this.allowReservations = allowReservations;
}

/**
* Sets the resource to be disposed when it is first unused.
Expand Down
19 changes: 19 additions & 0 deletions RenthylCore/main/java/codex/renthyl/definitions/ResourceDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ public default boolean isUseExisting() {
return true;
}

/**
* Returns true if reallocation of this definition's resource is allowed
* casually without a specific object id.
*
* @return
*/
public default boolean isAllowCasualAllocation() {
return true;
}

/**
* Returns true if reserving this definition's resource is allowed.
*
* @return
*/
public default boolean isAllowReservations() {
return true;
}

/**
* Returns true if the resource should be disposed after being
* released and having no users.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,14 @@ public int packLights(LightList lights, ColorRGBA ambient, List<LightProbe> prob
packedLight = true;
int id = l.getType().getId();
if (lightShadowIndexMap != null) {
System.out.println("has light shadow index map");
// allow 2 bits for light type
if (id > 3) {
throw new IllegalStateException("Light type id is larger than two bits: cannot pack shadow indices.");
}
Integer shadowIndex = lightShadowIndexMap.get(l);
System.out.println(" shadow index = "+shadowIndex);
if (shadowIndex != null) {
// let zero represent no shadow data available for this light
id += (shadowIndex + 1) << 2;
//id += (shadowIndex << 2) + 1;
}
}
tempColor.set(l.getColor()).setAlpha(id);
Expand Down
8 changes: 2 additions & 6 deletions RenthylCore/main/java/codex/renthyl/modules/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,8 @@ public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule out = ex.getCapsule(this);
SavableObject.writeFromCollection(out, targets, "targets");
if (source != null && source instanceof Savable) {
out.write((Savable)source, "source", NullSavable.INSTANCE);
}
if (defaultValue != null && defaultValue instanceof Savable) {
out.write((Savable)defaultValue, "default", NullSavable.INSTANCE);
}
out.write(new SavableObject(source), "source", SavableObject.NULL);
out.write(new SavableObject(defaultValue), "default", SavableObject.NULL);
}
@Override
public void read(JmeImporter im) throws IOException {
Expand Down
79 changes: 79 additions & 0 deletions RenthylCore/main/java/codex/renthyl/modules/cache/CacheRead.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package codex.renthyl.modules.cache;

import codex.boost.export.SavableObject;
import codex.renthyl.FGRenderContext;
import codex.renthyl.FrameGraph;
import codex.renthyl.client.GraphSource;
import codex.renthyl.modules.RenderPass;
import codex.renthyl.resources.ResourceTicket;
import com.jme3.export.InputCapsule;
import com.jme3.export.OutputCapsule;
import java.io.IOException;

/**
*
* @author codex
*/
public class CacheRead extends RenderPass {

public static final String OUTPUT = "Output";

private GraphSource<String> keySource;
private ResourceTicket output;

public CacheRead() {}
public CacheRead(GraphSource<String> keySource) {
this.keySource = keySource;
}

@Override
protected void initialize(FrameGraph frameGraph) {
output = addOutput(OUTPUT);
}
@Override
protected void prepare(FGRenderContext context) {
declare(null, output);
}
@Override
protected void execute(FGRenderContext context) {
String key = keySource.getGraphValue(frameGraph, context.getViewPort());
if (key != null) {
resources.acquireCached(output, key);
}
}
@Override
protected void reset(FGRenderContext context) {}
@Override
protected void cleanup(FrameGraph frameGraph) {}
@Override
protected void write(OutputCapsule out) throws IOException {
out.write(new SavableObject(keySource), "keySource", SavableObject.NULL);
}
@Override
protected void read(InputCapsule in) throws IOException {
keySource = SavableObject.read(in, "keySource", GraphSource.class);
}

/**
* Sets the source of the cache key to use.
*
* @param keySource
*/
public void setKeySource(GraphSource<String> keySource) {
this.keySource = keySource;
}

/**
* Gets the source of the cache key to use.
*
* @return
*/
public GraphSource<String> getKeySource() {
return keySource;
}

}
Loading

0 comments on commit c0597be

Please sign in to comment.