Skip to content

Commit

Permalink
Merge branch '1.18.2' into 1.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 18, 2023
2 parents c40d668 + 5db622e commit fc1ea6c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static ImmutableList<ClearPass> createClearPasses(RenderTargets renderTar
}

RenderTarget target = renderTargets.get(buffer);
if (target == null) return;
Vector4f clearColor = settings.getClearColor().orElse(defaultClearColor);
clearByColor.computeIfAbsent(new Vector2i(target.getWidth(), target.getHeight()), size -> new HashMap<>()).computeIfAbsent(new ClearPassInformation(clearColor, target.getWidth(), target.getHeight()), color -> new IntArrayList()).add(buffer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,6 @@ public NewWorldRenderingPipeline(ProgramSet programSet) throws IOException {
BlockRenderingSettings.INSTANCE.setSeparateEntityDraws(programSet.getPackDirectives().shouldUseSeparateEntityDraws());
BlockRenderingSettings.INSTANCE.setUseExtendedVertexFormat(true);

this.clearPassesFull = ClearPassCreator.createClearPasses(renderTargets, true,
programSet.getPackDirectives().getRenderTargetDirectives());
this.clearPasses = ClearPassCreator.createClearPasses(renderTargets, false,
programSet.getPackDirectives().getRenderTargetDirectives());

if (shadowRenderTargets == null && shadowDirectives.isShadowEnabled() == OptionalBoolean.TRUE) {
shadowRenderTargets = new ShadowRenderTargets(this, shadowMapResolution, shadowDirectives);
}
Expand Down Expand Up @@ -498,6 +493,11 @@ public NewWorldRenderingPipeline(ProgramSet programSet) throws IOException {
this.customUniforms.optimise();
boolean hasRun = false;

this.clearPassesFull = ClearPassCreator.createClearPasses(renderTargets, true,
programSet.getPackDirectives().getRenderTargetDirectives());
this.clearPasses = ClearPassCreator.createClearPasses(renderTargets, false,
programSet.getPackDirectives().getRenderTargetDirectives());

for (ComputeProgram program : setup) {
if (program != null) {
if (!hasRun) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public CompositeRenderer(WorldRenderingPipeline pipeline, PackDirectives packDir
// Flip the buffers that this shader wrote to, and set pass width and height
ImmutableMap<Integer, Boolean> explicitFlips = directives.getExplicitFlips();

GlFramebuffer framebuffer = renderTargets.createColorFramebuffer(flipped, drawBuffers);

for (int buffer : drawBuffers) {
RenderTarget target = renderTargets.get(buffer);
if ((passWidth > 0 && passWidth != target.getWidth()) || (passHeight > 0 && passHeight != target.getHeight())) {
Expand All @@ -147,8 +149,6 @@ public CompositeRenderer(WorldRenderingPipeline pipeline, PackDirectives packDir
flippedAtLeastOnce.add(buffer);
}

GlFramebuffer framebuffer = renderTargets.createColorFramebuffer(flipped, drawBuffers);

explicitFlips.forEach((buffer, shouldFlip) -> {
if (shouldFlip) {
bufferFlipper.flip(buffer);
Expand Down Expand Up @@ -308,6 +308,8 @@ public void renderAll() {
}

private static void setupMipmapping(net.coderbot.iris.rendertarget.RenderTarget target, boolean readFromAlt) {
if (target == null) return;

int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();

// TODO: Only generate the mipmap if a valid mipmap hasn't been generated or if we've written to the buffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public FinalPassRenderer(WorldRenderingPipeline pipeline, ProgramSet pack, Rende
}

SwapPass swap = new SwapPass();
RenderTarget target1 = renderTargets.get(target);
RenderTarget target1 = renderTargets.getOrCreate(target);
swap.target = target;
swap.width = target1.getWidth();
swap.height = target1.getHeight();
Expand Down Expand Up @@ -293,6 +293,8 @@ public void recalculateSwapPassSize() {
}

private static void setupMipmapping(RenderTarget target, boolean readFromAlt) {
if (target == null) return;

int texture = readFromAlt ? target.getAltTexture() : target.getMainTexture();

// TODO: Only generate the mipmap if a valid mipmap hasn't been generated or if we've written to the buffer
Expand All @@ -317,6 +319,7 @@ private static void setupMipmapping(RenderTarget target, boolean readFromAlt) {
}

private static void resetRenderTarget(RenderTarget target) {
if (target == null) return;
// Resets the sampling mode of the given render target and then unbinds it to prevent accidental sampling of it
// elsewhere.
int filter = GL20C.GL_LINEAR;
Expand Down
47 changes: 36 additions & 11 deletions src/main/java/net/coderbot/iris/rendertarget/RenderTargets.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class RenderTargets {
private DepthCopyStrategy copyStrategy;

private final List<GlFramebuffer> ownedFramebuffers;
private final Map<Integer, PackRenderTargetDirectives.RenderTargetSettings> targetSettingsMap;
private final PackDirectives packDirectives;

private int cachedWidth;
private int cachedHeight;
Expand All @@ -43,13 +45,8 @@ public class RenderTargets {
public RenderTargets(int width, int height, int depthTexture, int depthBufferVersion, DepthBufferFormat depthFormat, Map<Integer, PackRenderTargetDirectives.RenderTargetSettings> renderTargets, PackDirectives packDirectives) {
targets = new RenderTarget[renderTargets.size()];

renderTargets.forEach((index, settings) -> {
// TODO: Handle mipmapping?
Vector2i dimensions = packDirectives.getTextureScaleOverride(index, width, height);
targets[index] = RenderTarget.builder().setDimensions(dimensions.x, dimensions.y)
.setInternalFormat(settings.getInternalFormat())
.setPixelFormat(settings.getInternalFormat().getPixelFormat()).build();
});
targetSettingsMap = renderTargets;
this.packDirectives = packDirectives;

this.currentDepthTexture = depthTexture;
this.currentDepthFormat = depthFormat;
Expand Down Expand Up @@ -88,7 +85,9 @@ public void destroy() {
}

for (RenderTarget target : targets) {
target.destroy();
if (target != null) {
target.destroy();
}
}

noTranslucents.destroy();
Expand All @@ -104,9 +103,33 @@ public RenderTarget get(int index) {
throw new IllegalStateException("Tried to use destroyed RenderTargets");
}

if (targets[index] == null) {
return null;
}

return targets[index];
}

public RenderTarget getOrCreate(int index) {
if (destroyed) {
throw new IllegalStateException("Tried to use destroyed RenderTargets");
}

if (targets[index] != null) return targets[index];

create(index);

return targets[index];
}

private void create(int index) {
PackRenderTargetDirectives.RenderTargetSettings settings = targetSettingsMap.get(index);
Vector2i dimensions = packDirectives.getTextureScaleOverride(index, cachedWidth, cachedHeight);
targets[index] = RenderTarget.builder().setDimensions(dimensions.x, dimensions.y)
.setInternalFormat(settings.getInternalFormat())
.setPixelFormat(settings.getInternalFormat().getPixelFormat()).build();
}

public int getDepthTexture() {
return currentDepthTexture;
}
Expand Down Expand Up @@ -174,7 +197,9 @@ public boolean resizeIfNeeded(int newDepthBufferVersion, int newDepthTextureId,
cachedHeight = newHeight;

for (int i = 0; i < targets.length; i++) {
targets[i].resize(packDirectives.getTextureScaleOverride(i, newWidth, newHeight));
if (targets[i] != null) {
targets[i].resize(packDirectives.getTextureScaleOverride(i, newWidth, newHeight));
}
}

fullClearRequired = true;
Expand Down Expand Up @@ -253,7 +278,7 @@ private GlFramebuffer createEmptyFramebuffer() {

// NB: Before OpenGL 3.0, all framebuffers are required to have a color
// attachment no matter what.
framebuffer.addColorAttachment(0, get(0).getMainTexture());
framebuffer.addColorAttachment(0, getOrCreate(0).getMainTexture());
framebuffer.noDrawBuffers();

return framebuffer;
Expand Down Expand Up @@ -316,7 +341,7 @@ public GlFramebuffer createColorFramebuffer(ImmutableSet<Integer> stageWritesToM
+ getRenderTargetCount() + " render targets are supported.");
}

RenderTarget target = this.get(drawBuffers[i]);
RenderTarget target = this.getOrCreate(drawBuffers[i]);

int textureId = stageWritesToMain.contains(drawBuffers[i]) ? target.getMainTexture() : target.getAltTexture();

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/net/coderbot/iris/samplers/IrisImages.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ public static void addRenderTargetImages(ImageHolder images, Supplier<ImmutableS
for (int i = 0; i < renderTargets.getRenderTargetCount(); i++) {
final int index = i;

final String name = "colorimg" + i;

if (!images.hasImage(name)) continue;

// Note: image bindings *are* impacted by buffer flips.
IntSupplier textureID = () -> {
ImmutableSet<Integer> flippedBuffers = flipped.get();
RenderTarget target = renderTargets.get(index);
RenderTarget target = renderTargets.getOrCreate(index);

if (flippedBuffers.contains(index)) {
return target.getAltTexture();
Expand All @@ -31,8 +35,7 @@ public static void addRenderTargetImages(ImageHolder images, Supplier<ImmutableS
}
};

final InternalTextureFormat internalFormat = renderTargets.get(i).getInternalFormat();
final String name = "colorimg" + i;
final InternalTextureFormat internalFormat = renderTargets.getOrCreate(i).getInternalFormat();

images.addTextureImage(textureID, internalFormat, name);
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/coderbot/iris/samplers/IrisSamplers.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void addRenderTargetSamplers(SamplerHolder samplers, Supplier<Immu

IntSupplier texture = () -> {
ImmutableSet<Integer> flippedBuffers = flipped.get();
RenderTarget target = renderTargets.get(index);
RenderTarget target = renderTargets.getOrCreate(index);

if (flippedBuffers.contains(index)) {
return target.getAltTexture();
Expand All @@ -71,8 +71,6 @@ public static void addRenderTargetSamplers(SamplerHolder samplers, Supplier<Immu
}
};

RenderTarget target = renderTargets.get(index);

final String name = "colortex" + i;

// TODO: How do custom textures interact with aliases?
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "iris",
"version": "1.6.6-development-environment",
"version": "1.6.9-development-environment",

"name": "Iris",
"description": "A modern shaders mod for Minecraft intended to be compatible with existing OptiFine shader packs",
Expand Down

0 comments on commit fc1ea6c

Please sign in to comment.