mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-15 23:55:53 +01:00
More steps towards actually using the new loader
This commit is contained in:
parent
9e699b7715
commit
a35c7150c2
8 changed files with 139 additions and 25 deletions
|
@ -3,15 +3,17 @@ package com.jozufozu.flywheel.backend.gl.shader;
|
||||||
import org.lwjgl.opengl.GL20;
|
import org.lwjgl.opengl.GL20;
|
||||||
|
|
||||||
public enum ShaderType {
|
public enum ShaderType {
|
||||||
VERTEX("vertex", GL20.GL_VERTEX_SHADER),
|
VERTEX("vertex", "VERTEX_SHADER", GL20.GL_VERTEX_SHADER),
|
||||||
FRAGMENT("fragment", GL20.GL_FRAGMENT_SHADER),
|
FRAGMENT("fragment", "FRAGMENT_SHADER", GL20.GL_FRAGMENT_SHADER),
|
||||||
;
|
;
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
|
public final String define;
|
||||||
public final int glEnum;
|
public final int glEnum;
|
||||||
|
|
||||||
ShaderType(String name, int glEnum) {
|
ShaderType(String name, String define, int glEnum) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.define = define;
|
||||||
this.glEnum = glEnum;
|
this.glEnum = glEnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.jozufozu.flywheel.backend.pipeline;
|
||||||
|
|
||||||
|
public enum GLSLVersion {
|
||||||
|
V110(110),
|
||||||
|
V120(120),
|
||||||
|
;
|
||||||
|
|
||||||
|
public final int version;
|
||||||
|
|
||||||
|
GLSLVersion(int version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Integer.toString(version);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.jozufozu.flywheel.backend.pipeline;
|
||||||
|
|
||||||
|
import org.lwjgl.opengl.GL20;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.backend.Backend;
|
||||||
|
import com.jozufozu.flywheel.backend.gl.GlObject;
|
||||||
|
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
|
||||||
|
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
|
||||||
|
|
||||||
|
public class GlShader extends GlObject {
|
||||||
|
|
||||||
|
public GlShader(ShaderType type, CharSequence source) {
|
||||||
|
int handle = GL20.glCreateShader(type.glEnum);
|
||||||
|
|
||||||
|
GlCompat.safeShaderSource(handle, source);
|
||||||
|
|
||||||
|
GL20.glCompileShader(handle);
|
||||||
|
|
||||||
|
String log = GL20.glGetShaderInfoLog(handle);
|
||||||
|
|
||||||
|
if (!log.isEmpty()) {
|
||||||
|
Backend.log.error("Shader compilation log for " + "DUBUG"+ ": " + log);
|
||||||
|
Backend.log.error(source);
|
||||||
|
}
|
||||||
|
//Backend.log.debug(shader.printSource());
|
||||||
|
|
||||||
|
if (GL20.glGetShaderi(handle, GL20.GL_COMPILE_STATUS) != GL20.GL_TRUE) {
|
||||||
|
throw new RuntimeException("Could not compile " + "DEBUG" + ". See log for details.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setHandle(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void deleteInternal(int handle) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.jozufozu.flywheel.backend.pipeline;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.backend.gl.shader.ShaderType;
|
||||||
|
|
||||||
|
public class Shader {
|
||||||
|
|
||||||
|
private final GLSLVersion version;
|
||||||
|
private final CharSequence source;
|
||||||
|
|
||||||
|
public Shader(GLSLVersion version, CharSequence source) {
|
||||||
|
this.version = version;
|
||||||
|
this.source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlShader create(ShaderType type) {
|
||||||
|
|
||||||
|
StringBuilder source = new StringBuilder();
|
||||||
|
|
||||||
|
source.append("#version ")
|
||||||
|
.append(version.version)
|
||||||
|
.append('\n');
|
||||||
|
|
||||||
|
source.append("#define ")
|
||||||
|
.append(type.define)
|
||||||
|
.append('\n');
|
||||||
|
|
||||||
|
source.append(this.source);
|
||||||
|
|
||||||
|
return new GlShader(type, source);
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,7 @@ public class SourceFile {
|
||||||
|
|
||||||
private final ShaderSources parent;
|
private final ShaderSources parent;
|
||||||
private final String source;
|
private final String source;
|
||||||
|
private final CharSequence elided;
|
||||||
private final ImmutableList<String> lines;
|
private final ImmutableList<String> lines;
|
||||||
|
|
||||||
private final IntList lineStarts;
|
private final IntList lineStarts;
|
||||||
|
@ -62,12 +63,18 @@ public class SourceFile {
|
||||||
this.includes = parseIncludes();
|
this.includes = parseIncludes();
|
||||||
this.functions = parseFunctions();
|
this.functions = parseFunctions();
|
||||||
this.structs = parseStructs();
|
this.structs = parseStructs();
|
||||||
|
|
||||||
|
this.elided = createElidedSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSource() {
|
public String getSource() {
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CharSequence getElidedSource() {
|
||||||
|
return elided;
|
||||||
|
}
|
||||||
|
|
||||||
public ShaderSources getParent() {
|
public ShaderSources getParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
@ -119,10 +126,7 @@ public class SourceFile {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence elided = null;
|
private CharSequence createElidedSource() {
|
||||||
|
|
||||||
public CharSequence getElidedSource() {
|
|
||||||
if (elided == null) {
|
|
||||||
StringBuilder out = new StringBuilder();
|
StringBuilder out = new StringBuilder();
|
||||||
|
|
||||||
int lastEnd = 0;
|
int lastEnd = 0;
|
||||||
|
@ -135,10 +139,7 @@ public class SourceFile {
|
||||||
|
|
||||||
out.append(source, lastEnd, source.length());
|
out.append(source, lastEnd, source.length());
|
||||||
|
|
||||||
elided = out.toString();
|
return out;
|
||||||
}
|
|
||||||
|
|
||||||
return elided;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,8 @@ import java.util.List;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.jozufozu.flywheel.backend.ShaderSources;
|
import com.jozufozu.flywheel.backend.ShaderSources;
|
||||||
|
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
|
||||||
|
import com.jozufozu.flywheel.backend.loading.Program;
|
||||||
import com.jozufozu.flywheel.core.shader.IMultiProgram;
|
import com.jozufozu.flywheel.core.shader.IMultiProgram;
|
||||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||||
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
import com.jozufozu.flywheel.core.shader.spec.ProgramSpec;
|
||||||
|
@ -34,7 +36,9 @@ public class WorldShaderPipeline<P extends WorldProgram> {
|
||||||
|
|
||||||
builder.include(file);
|
builder.include(file);
|
||||||
|
|
||||||
builder.build();
|
CharSequence output = builder.build();
|
||||||
|
|
||||||
|
//Program program = new Program()
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.jozufozu.flywheel.core.shader;
|
package com.jozufozu.flywheel.core.shader;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL20.glUniform1f;
|
import static org.lwjgl.opengl.GL20.glUniform1f;
|
||||||
|
import static org.lwjgl.opengl.GL20.glUniform2f;
|
||||||
import static org.lwjgl.opengl.GL20.glUniform3f;
|
import static org.lwjgl.opengl.GL20.glUniform3f;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -9,21 +10,21 @@ import com.jozufozu.flywheel.backend.loading.Program;
|
||||||
import com.jozufozu.flywheel.core.shader.extension.IProgramExtension;
|
import com.jozufozu.flywheel.core.shader.extension.IProgramExtension;
|
||||||
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
import com.jozufozu.flywheel.util.AnimationTickHolder;
|
||||||
|
|
||||||
|
import net.minecraft.client.MainWindow;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.math.vector.Matrix4f;
|
import net.minecraft.util.math.vector.Matrix4f;
|
||||||
|
|
||||||
public class WorldProgram extends ExtensibleGlProgram {
|
public class WorldProgram extends ExtensibleGlProgram {
|
||||||
protected final int uTime;
|
protected final int uTime = getUniformLocation("uTime");
|
||||||
protected final int uViewProjection;
|
protected final int uViewProjection = getUniformLocation("uViewProjection");
|
||||||
protected final int uCameraPos;
|
protected final int uCameraPos = getUniformLocation("uCameraPos");
|
||||||
|
protected final int uWindowSize = getUniformLocation("uWindowSize");
|
||||||
|
|
||||||
protected int uBlockAtlas;
|
protected int uBlockAtlas;
|
||||||
protected int uLightMap;
|
protected int uLightMap;
|
||||||
|
|
||||||
public WorldProgram(Program program, List<IProgramExtension> extensions) {
|
public WorldProgram(Program program, List<IProgramExtension> extensions) {
|
||||||
super(program, extensions);
|
super(program, extensions);
|
||||||
uTime = getUniformLocation("uTime");
|
|
||||||
uViewProjection = getUniformLocation("uViewProjection");
|
|
||||||
uCameraPos = getUniformLocation("uCameraPos");
|
|
||||||
|
|
||||||
super.bind();
|
super.bind();
|
||||||
registerSamplers();
|
registerSamplers();
|
||||||
|
@ -36,14 +37,30 @@ public class WorldProgram extends ExtensibleGlProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadViewProjection(Matrix4f viewProjection) {
|
public void uploadViewProjection(Matrix4f viewProjection) {
|
||||||
|
if (uViewProjection < 0) return;
|
||||||
|
|
||||||
uploadMatrixUniform(uViewProjection, viewProjection);
|
uploadMatrixUniform(uViewProjection, viewProjection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void uploadWindowSize() {
|
||||||
|
if (uWindowSize < 0) return;
|
||||||
|
|
||||||
|
MainWindow window = Minecraft.getInstance().getWindow();
|
||||||
|
|
||||||
|
int height = window.getScreenHeight();
|
||||||
|
int width = window.getScreenWidth();
|
||||||
|
glUniform2f(uWindowSize, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
public void uploadCameraPos(double camX, double camY, double camZ) {
|
public void uploadCameraPos(double camX, double camY, double camZ) {
|
||||||
|
if (uCameraPos < 0) return;
|
||||||
|
|
||||||
glUniform3f(uCameraPos, (float) camX, (float) camY, (float) camZ);
|
glUniform3f(uCameraPos, (float) camX, (float) camY, (float) camZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void uploadTime(float renderTime) {
|
public void uploadTime(float renderTime) {
|
||||||
|
if (uTime < 0) return;
|
||||||
|
|
||||||
glUniform1f(uTime, renderTime);
|
glUniform1f(uTime, renderTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +68,7 @@ public class WorldProgram extends ExtensibleGlProgram {
|
||||||
public void bind() {
|
public void bind() {
|
||||||
super.bind();
|
super.bind();
|
||||||
|
|
||||||
|
uploadWindowSize();
|
||||||
uploadTime(AnimationTickHolder.getRenderTime());
|
uploadTime(AnimationTickHolder.getRenderTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
uniform sampler2D uBlockAtlas;
|
uniform sampler2D uBlockAtlas;
|
||||||
uniform sampler2D uLightMap;
|
uniform sampler2D uLightMap;
|
||||||
|
uniform vec2 uWindowSize;
|
||||||
|
|
||||||
vec4 FLWBlockTexture(vec2 texCoords) {
|
vec4 FLWBlockTexture(vec2 texCoords) {
|
||||||
return texture2D(uBlockAtlas, texCoords);
|
return texture2D(uBlockAtlas, texCoords);
|
||||||
|
|
Loading…
Reference in a new issue