forked from Asek3/Oculus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: IMS <[email protected]>
- Loading branch information
Showing
20 changed files
with
437 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.coderbot.iris.colorspace; | ||
|
||
public enum ColorSpace { | ||
SRGB, | ||
DCI_P3, | ||
DISPLAY_P3, | ||
REC2020, | ||
ADOBE_RGB | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/net/coderbot/iris/colorspace/ColorSpaceComputeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package net.coderbot.iris.colorspace; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import net.coderbot.iris.gl.IrisRenderSystem; | ||
import net.coderbot.iris.gl.program.ComputeProgram; | ||
import net.coderbot.iris.gl.program.ProgramBuilder; | ||
import net.coderbot.iris.gl.texture.InternalTextureFormat; | ||
import net.coderbot.iris.shaderpack.StringPair; | ||
import net.coderbot.iris.shaderpack.preprocessor.JcppProcessor; | ||
import org.apache.commons.io.IOUtils; | ||
import org.lwjgl.opengl.GL43C; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class ColorSpaceComputeConverter implements ColorSpaceConverter { | ||
private int width; | ||
private int height; | ||
private ColorSpace colorSpace; | ||
private ComputeProgram program; | ||
|
||
private int target; | ||
public ColorSpaceComputeConverter(int width, int height, ColorSpace colorSpace) { | ||
rebuildProgram(width, height, colorSpace); | ||
} | ||
|
||
public void rebuildProgram(int width, int height, ColorSpace colorSpace) { | ||
if (program != null) { | ||
program.destroy(); | ||
program = null; | ||
} | ||
|
||
this.width = width; | ||
this.height = height; | ||
this.colorSpace = colorSpace; | ||
|
||
String source; | ||
try { | ||
source = new String(IOUtils.toByteArray(Objects.requireNonNull(getClass().getResourceAsStream("/colorSpace.csh"))), StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
List<StringPair> defineList = new ArrayList<>(); | ||
defineList.add(new StringPair("COMPUTE", "")); | ||
defineList.add(new StringPair("CURRENT_COLOR_SPACE", String.valueOf(colorSpace.ordinal()))); | ||
|
||
for (ColorSpace space : ColorSpace.values()) { | ||
defineList.add(new StringPair(space.name(), String.valueOf(space.ordinal()))); | ||
} | ||
source = JcppProcessor.glslPreprocessSource(source, defineList); | ||
ProgramBuilder builder = ProgramBuilder.beginCompute("colorSpaceCompute", source, ImmutableSet.of()); | ||
builder.addTextureImage(() -> target, InternalTextureFormat.RGBA8, "readImage"); | ||
this.program = builder.buildCompute(); | ||
} | ||
|
||
public void process(int targetImage) { | ||
if (colorSpace == ColorSpace.SRGB) return; | ||
|
||
this.target = targetImage; | ||
program.use(); | ||
IrisRenderSystem.dispatchCompute(width / 8, height / 8, 1); | ||
IrisRenderSystem.memoryBarrier(GL43C.GL_SHADER_IMAGE_ACCESS_BARRIER_BIT | GL43C.GL_TEXTURE_FETCH_BARRIER_BIT); | ||
ComputeProgram.unbind(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/net/coderbot/iris/colorspace/ColorSpaceConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.coderbot.iris.colorspace; | ||
|
||
public interface ColorSpaceConverter { | ||
void rebuildProgram(int width, int height, ColorSpace colorSpace); | ||
void process(int target); | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/net/coderbot/iris/colorspace/ColorSpaceFragmentConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package net.coderbot.iris.colorspace; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.mojang.blaze3d.platform.GlStateManager; | ||
import net.coderbot.iris.gl.IrisRenderSystem; | ||
import net.coderbot.iris.gl.framebuffer.GlFramebuffer; | ||
import net.coderbot.iris.gl.program.Program; | ||
import net.coderbot.iris.gl.program.ProgramBuilder; | ||
import net.coderbot.iris.gl.uniform.UniformUpdateFrequency; | ||
import net.coderbot.iris.postprocess.FullScreenQuadRenderer; | ||
import net.coderbot.iris.shaderpack.StringPair; | ||
import net.coderbot.iris.shaderpack.preprocessor.JcppProcessor; | ||
import net.coderbot.iris.vendored.joml.Matrix4f; | ||
import org.apache.commons.io.IOUtils; | ||
import org.lwjgl.opengl.GL11C; | ||
import org.lwjgl.opengl.GL30C; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.*; | ||
|
||
public class ColorSpaceFragmentConverter implements ColorSpaceConverter { | ||
private int width; | ||
private int height; | ||
private ColorSpace colorSpace; | ||
private Program program; | ||
private GlFramebuffer framebuffer; | ||
private int swapTexture; | ||
|
||
private int target; | ||
public ColorSpaceFragmentConverter(int width, int height, ColorSpace colorSpace) { | ||
rebuildProgram(width, height, colorSpace); | ||
} | ||
|
||
public void rebuildProgram(int width, int height, ColorSpace colorSpace) { | ||
if (program != null) { | ||
program.destroy(); | ||
program = null; | ||
framebuffer.destroy(); | ||
framebuffer = null; | ||
GlStateManager._deleteTexture(swapTexture); | ||
swapTexture = 0; | ||
} | ||
|
||
this.width = width; | ||
this.height = height; | ||
this.colorSpace = colorSpace; | ||
|
||
String vertexSource; | ||
String source; | ||
try { | ||
vertexSource = new String(IOUtils.toByteArray(Objects.requireNonNull(getClass().getResourceAsStream("/colorSpace.vsh"))), StandardCharsets.UTF_8); | ||
source = new String(IOUtils.toByteArray(Objects.requireNonNull(getClass().getResourceAsStream("/colorSpace.csh"))), StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
List<StringPair> defineList = new ArrayList<>(); | ||
defineList.add(new StringPair("CURRENT_COLOR_SPACE", String.valueOf(colorSpace.ordinal()))); | ||
|
||
for (ColorSpace space : ColorSpace.values()) { | ||
defineList.add(new StringPair(space.name(), String.valueOf(space.ordinal()))); | ||
} | ||
source = JcppProcessor.glslPreprocessSource(source, defineList); | ||
|
||
ProgramBuilder builder = ProgramBuilder.begin("colorSpaceFragment", vertexSource, null, source, ImmutableSet.of()); | ||
|
||
builder.uniformJomlMatrix(UniformUpdateFrequency.ONCE, "projection", () -> new Matrix4f(2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, -1, -1, 0, 1)); | ||
builder.addDynamicSampler(() -> target, "readImage"); | ||
|
||
swapTexture = GlStateManager._genTexture(); | ||
IrisRenderSystem.texImage2D(swapTexture, GL30C.GL_TEXTURE_2D, 0, GL30C.GL_RGBA8, width, height, 0, GL30C.GL_RGBA, GL30C.GL_UNSIGNED_BYTE, null); | ||
|
||
this.framebuffer = new GlFramebuffer(); | ||
framebuffer.addColorAttachment(0, swapTexture); | ||
this.program = builder.build(); | ||
} | ||
|
||
public void process(int targetImage) { | ||
if (colorSpace == ColorSpace.SRGB) return; | ||
|
||
this.target = targetImage; | ||
program.use(); | ||
framebuffer.bind(); | ||
FullScreenQuadRenderer.INSTANCE.render(); | ||
Program.unbind(); | ||
framebuffer.bindAsReadBuffer(); | ||
IrisRenderSystem.copyTexSubImage2D(targetImage, GL11C.GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.