PlutoLib cleanup, module-info.java and array uniforms for PlutoShader

This commit is contained in:
Natty 2022-04-13 02:28:26 +02:00
parent f04df2a6f8
commit 6772912f66
No known key found for this signature in database
GPG Key ID: 40AB22FA416C7019
17 changed files with 238 additions and 34 deletions

View File

@ -1,9 +1,17 @@
## 22.1.0.0-alpha.0
* `[PlutoMesher]` **Partial rewrite**
* *Removed* `VecArray`
* Reduced pointless abstraction
* Creation and destruction no longer logged
* `[PlutoGUI]` **Complete rewrite of the GUI library**
* `[Pluto*]` **Unified the cleanup methods of all OpenGL object classes to `close`**
* `[PlutoLib]` New dependency: `joml-primitives`
* `[PlutoLib]` Now has a `module-info.java`
* `[PlutoLib]` Now uses JetBrains annotations instead of JSR 305
* `[PlutoDisplay]` Removed the `flipped` word from all buffer functions
* `[PlutoRuntime]` Fixed opening .zip filesystems
* `[PlutoShader]` Added `UniformArrayFloat`, `UniformArrayRGBA`,
`UniformArrayVec2`, `UniformArrayVec3`, `UniformArrayVec4`
## 22.0.0.0-alpha.7
* `[PlutoRuntime]` Fixed several resource filesystem bugs

View File

@ -1,5 +1,7 @@
import org.plutoengine.Versions
project.ext["isPlutoBuild"] = true;
tasks.withType<Wrapper> {
distributionType = Wrapper.DistributionType.ALL
gradleVersion = "7.4.2"

View File

@ -15,13 +15,9 @@ dependencies {
api("com.fasterxml.jackson.core", "jackson-core", "2.13.2")
api("com.fasterxml.jackson.core", "jackson-databind", "2.13.2")
api("com.google.guava", "guava", "28.0-jre")
api("org.joml", "joml", Versions.jomlVersion)
api("org.joml", "joml-primitives", Versions.jomlPrimitivesVersion)
api("commons-io", "commons-io", "2.6")
api("org.apache.commons", "commons-lang3", "3.12.0")
}

View File

@ -0,0 +1,25 @@
module org.plutoengine.plutolib {
requires java.base;
requires java.desktop;
requires transitive org.joml;
requires transitive org.joml.primitives;
requires transitive com.fasterxml.jackson.core;
requires transitive com.fasterxml.jackson.databind;
requires transitive com.fasterxml.jackson.annotation;
requires transitive org.jetbrains.annotations;
requires org.yaml.snakeyaml;
requires org.apache.commons.lang3;
opens org.plutoengine.address;
exports org.plutoengine.address;
exports org.plutoengine.util.color;
exports org.plutoengine.io.property;
exports org.plutoengine.math;
exports org.plutoengine.event.lambda;
exports org.plutoengine.chrono;
}

View File

@ -1,6 +1,7 @@
package org.plutoengine.util.color;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;
/**
* A simple 8-bit RGBA color container.
@ -126,7 +127,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public static Color from(@Nonnull IRGBA colorComponents)
public static Color from(@NotNull IRGBA colorComponents)
{
return new Color(Math.round(colorComponents.red() * 255),
Math.round(colorComponents.green() * 255),
@ -140,7 +141,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public static Color from(@Nonnull IRGB colorComponents)
public static Color from(@NotNull IRGB colorComponents)
{
return new Color(Math.round(colorComponents.red() * 255),
Math.round(colorComponents.green() * 255),
@ -153,7 +154,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public static Color from(int color, @Nonnull EnumColorFormat colorFormat)
public static Color from(int color, @NotNull EnumColorFormat colorFormat)
{
return switch (colorFormat)
{
@ -173,7 +174,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public static Color fromAWT(@Nonnull java.awt.Color color)
public static Color fromAWT(@NotNull java.awt.Color color)
{
return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
@ -184,7 +185,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public static Color from(@Nonnull byte[] color, @Nonnull EnumColorFormat colorFormat)
public static Color from(byte @NotNull [] color, @NotNull EnumColorFormat colorFormat)
{
return from(color, 0, colorFormat);
}
@ -195,7 +196,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public static Color from(@Nonnull byte[] color, int offset, @Nonnull EnumColorFormat colorFormat)
public static Color from(byte @NotNull [] color, int offset, @NotNull EnumColorFormat colorFormat)
{
return switch (colorFormat)
{
@ -237,7 +238,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public int get(@Nonnull EnumColorFormat colorFormat)
public int get(@NotNull EnumColorFormat colorFormat)
{
return switch (colorFormat)
{
@ -257,7 +258,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public void get(@Nonnull EnumColorFormat colorFormat, @Nonnull byte[] dataOut)
public void get(@NotNull EnumColorFormat colorFormat, byte @NotNull [] dataOut)
{
get(colorFormat, dataOut, 0);
}
@ -268,7 +269,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public void get(@Nonnull EnumColorFormat colorFormat, @Nonnull byte[] dataOut, int offset)
public void get(@NotNull EnumColorFormat colorFormat, byte @NotNull [] dataOut, int offset)
{
switch (colorFormat)
{
@ -404,7 +405,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public void storeFloatComponentsRGBA(@Nonnull RGBA target)
public void storeFloatComponentsRGBA(@NotNull RGBA target)
{
storeFloatComponentsRGB(target);
target.a = this.alpha / 255.0f;
@ -416,7 +417,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public void storeFloatComponentsRGB(@Nonnull RGB target)
public void storeFloatComponentsRGB(@NotNull RGB target)
{
target.r = this.red / 255.0f;
target.g = this.green / 255.0f;
@ -429,7 +430,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public void storeFloatComponentsHSBA(@Nonnull HSBA target)
public void storeFloatComponentsHSBA(@NotNull HSBA target)
{
var hsb = this.getFloatComponentsHSBA();
@ -445,7 +446,7 @@ public final class Color
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public void storeFloatComponentsHSB(@Nonnull HSB target)
public void storeFloatComponentsHSB(@NotNull HSB target)
{
var hsb = this.getFloatComponentsHSB();

View File

@ -31,8 +31,6 @@ public class VertexArray implements AutoCloseable
this.vertexAttributes.setSize(maxAttributes);
this.glID = GL33.glGenVertexArrays();
Logger.logf(SmartSeverity.ADDED, "Vertex array ID %d created...%n", this.glID);
}
public void createArrayAttribute(AttributeInfo info, ArrayBuffer<?> buffer)

View File

@ -0,0 +1,16 @@
package org.plutoengine.shader.uniform;
import org.lwjgl.opengl.GL33;
public class UniformArrayFloat extends UniformBase
{
public UniformArrayFloat(int location)
{
super(location);
}
public void load(float[] data)
{
GL33.glUniform1fv(this.location, data);
}
}

View File

@ -0,0 +1,58 @@
package org.plutoengine.shader.uniform;
import org.lwjgl.opengl.GL33;
import org.lwjgl.system.MemoryStack;
import org.plutoengine.util.color.IRGBA;
/**
* A uniform allowing loading RGBA color arrays into shader uniforms.
*
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public class UniformArrayRGBA extends UniformVec4
{
/**
* Creates a new instance of the {@link UniformArrayRGBA} uniform
* with the specified shader location.
*
* @param location The location within the shader
*
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public UniformArrayRGBA(int location)
{
super(location);
}
/**
* Loads the {@link IRGBA} color components into the shader uniform.
*
* @param values The {@link IRGBA} color object array
*
* @since 20.2.0.0-alpha.3
* @author 493msi
*/
public void load(IRGBA[] values)
{
final int dimensions = 4;
try (MemoryStack stack = MemoryStack.stackPush())
{
var buf = stack.mallocFloat(dimensions * values.length);
for (var value : values)
{
buf.put(value.red())
.put(value.green())
.put(value.blue())
.put(value.alpha());
}
buf.flip();
GL33.glUniform4fv(this.location, buf);
}
}
}

View File

@ -0,0 +1,34 @@
package org.plutoengine.shader.uniform;
import org.joml.Vector2fc;
import org.joml.Vector4fc;
import org.lwjgl.opengl.GL33;
import org.lwjgl.system.MemoryStack;
public class UniformArrayVec2 extends UniformBase
{
public UniformArrayVec2(int location)
{
super(location);
}
public void load(Vector2fc... values)
{
final int dimensions = 2;
try (MemoryStack stack = MemoryStack.stackPush())
{
var buf = stack.mallocFloat(dimensions * values.length);
int i;
for (i = 0; i < values.length; i++)
values[i].get(i * dimensions, buf);
buf.position(i * dimensions);
buf.flip();
GL33.glUniform2fv(this.location, buf);
}
}
}

View File

@ -0,0 +1,33 @@
package org.plutoengine.shader.uniform;
import org.joml.Vector2fc;
import org.lwjgl.opengl.GL33;
import org.lwjgl.system.MemoryStack;
public class UniformArrayVec3 extends UniformBase
{
public UniformArrayVec3(int location)
{
super(location);
}
public void load(Vector2fc... values)
{
final int dimensions = 3;
try (MemoryStack stack = MemoryStack.stackPush())
{
var buf = stack.mallocFloat(dimensions * values.length);
int i;
for (i = 0; i < values.length; i++)
values[i].get(i * dimensions, buf);
buf.position(i * dimensions);
buf.flip();
GL33.glUniform3fv(this.location, buf);
}
}
}

View File

@ -0,0 +1,32 @@
package org.plutoengine.shader.uniform;
import org.joml.Vector4fc;
import org.lwjgl.opengl.GL33;
import org.lwjgl.system.MemoryStack;
import java.nio.FloatBuffer;
public class UniformArrayVec4 extends UniformBase
{
public UniformArrayVec4(int location)
{
super(location);
}
public void load(Vector4fc... values)
{
final int dimensions = 4;
try (MemoryStack stack = MemoryStack.stackPush())
{
var buf = stack.mallocFloat(dimensions * values.length);
for (int i = 0; i < values.length; i++)
values[i].get(i * dimensions, buf);
buf.flip();
GL33.glUniform4fv(this.location, buf);
}
}
}

View File

@ -10,7 +10,7 @@ public class DisposableTextureSprite extends PartialTextureSprite implements Spr
}
@Override
public void delete()
public void close()
{
this.spriteTexture.close();
this.spriteTexture = null;

View File

@ -1,6 +1,7 @@
package org.plutoengine.graphics.sprite;
public interface SpriteDisposable<T> extends Sprite<T>
public interface SpriteDisposable<T> extends Sprite<T>, AutoCloseable
{
void delete();
@Override
void close();
}

View File

@ -78,12 +78,12 @@ public class BufferedImageTiledSpriteSheet extends TiledSpriteSheet<BufferedImag
}
@Override
public void delete()
public void close()
{
this.drawGraphics.dispose();
this.drawGraphics = null;
super.delete();
super.close();
}
@Override

View File

@ -79,7 +79,7 @@ public class FramebufferTiledSpriteSheet extends TiledSpriteSheet<RectangleTextu
}
@Override
public void delete()
public void close()
{
this.spriteFBO.unbind();
this.spriteFBO.delete();
@ -90,10 +90,7 @@ public class FramebufferTiledSpriteSheet extends TiledSpriteSheet<RectangleTextu
this.spriteSheet.close();
// this.spriteSheet = null;
// Done by parent
super.delete();
super.close();
}
public Sampler2D getSampler()

View File

@ -1,6 +1,6 @@
package org.plutoengine.graphics.spritesheet;
public abstract class SpriteSheet<T>
public abstract class SpriteSheet<T> implements AutoCloseable
{
protected T spriteSheet;
@ -28,5 +28,6 @@ public abstract class SpriteSheet<T>
public abstract int getHeightInPixels();
public abstract void delete();
@Override
public abstract void close();
}

View File

@ -1,5 +1,6 @@
package org.plutoengine.graphics.spritesheet;
import org.jetbrains.annotations.MustBeInvokedByOverriders;
import org.plutoengine.graphics.sprite.Sprite;
import org.plutoengine.graphics.sprite.SpriteDisposable;
import org.plutoengine.graphics.sprite.TileSprite;
@ -89,7 +90,8 @@ public abstract class TiledSpriteSheet<T> extends SpriteSheet<T>
}
@Override
public void delete()
@MustBeInvokedByOverriders
public void close()
{
this.sprites.clear();
this.sprites = null;
@ -132,7 +134,7 @@ public abstract class TiledSpriteSheet<T> extends SpriteSheet<T>
this.drawSprite(sprite, newX, newY, newWidth, newHeight);
if (sprite instanceof SpriteDisposable<?> disposableSprite)
disposableSprite.delete();
disposableSprite.close();
var copySprite = new TileSprite<TiledSpriteSheet<T>>(newX, newY, newWidth, newHeight);
copySprite.setSpriteSheet(this);