mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-29 08:26:37 +01:00
Miscellaneous gl changes while debugging
- Only unbind at the end of MaterialManagerImpl#render - Add GlBufferType#bind and #unbind - Make GlVertexArray#unbind static
This commit is contained in:
parent
e08633af3c
commit
7813eedf61
8 changed files with 37 additions and 23 deletions
|
@ -11,7 +11,7 @@ public class GlVertexArray extends GlObject {
|
||||||
Backend.getInstance().compat.vao.bindVertexArray(handle());
|
Backend.getInstance().compat.vao.bindVertexArray(handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbind() {
|
public static void unbind() {
|
||||||
Backend.getInstance().compat.vao.bindVertexArray(0);
|
Backend.getInstance().compat.vao.bindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,11 @@ public abstract class GlBuffer extends GlObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind() {
|
public void bind() {
|
||||||
GL20.glBindBuffer(type.glEnum, handle());
|
type.bind(handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unbind() {
|
public void unbind() {
|
||||||
GL20.glBindBuffer(type.glEnum, 0);
|
type.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doneForThisFrame() {
|
public void doneForThisFrame() {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import org.lwjgl.opengl.GL40;
|
||||||
import org.lwjgl.opengl.GL42;
|
import org.lwjgl.opengl.GL42;
|
||||||
import org.lwjgl.opengl.GL43;
|
import org.lwjgl.opengl.GL43;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
|
||||||
public enum GlBufferType {
|
public enum GlBufferType {
|
||||||
ARRAY_BUFFER(GL15C.GL_ARRAY_BUFFER),
|
ARRAY_BUFFER(GL15C.GL_ARRAY_BUFFER),
|
||||||
ELEMENT_ARRAY_BUFFER(GL15C.GL_ELEMENT_ARRAY_BUFFER),
|
ELEMENT_ARRAY_BUFFER(GL15C.GL_ELEMENT_ARRAY_BUFFER),
|
||||||
|
@ -29,4 +31,12 @@ public enum GlBufferType {
|
||||||
GlBufferType(int glEnum) {
|
GlBufferType(int glEnum) {
|
||||||
this.glEnum = glEnum;
|
this.glEnum = glEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void bind(int buffer) {
|
||||||
|
GlStateManager._glBindBuffer(glEnum, buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unbind() {
|
||||||
|
GlStateManager._glBindBuffer(glEnum, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
||||||
// persistent mapping sync point
|
// persistent mapping sync point
|
||||||
instanceVBO.doneForThisFrame();
|
instanceVBO.doneForThisFrame();
|
||||||
|
|
||||||
vao.unbind();
|
GlVertexArray.unbind();
|
||||||
|
|
||||||
GlError.pollAndThrow(() -> modelData.name() + "_unbind");
|
GlError.pollAndThrow(() -> modelData.name() + "_unbind");
|
||||||
}
|
}
|
||||||
|
@ -72,16 +72,12 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
||||||
vao.bind();
|
vao.bind();
|
||||||
|
|
||||||
model.setupState();
|
model.setupState();
|
||||||
|
|
||||||
vao.unbind();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
vao.bind();
|
vao.bind();
|
||||||
|
|
||||||
instanceVBO = GlBuffer.requestPersistent(GlBufferType.ARRAY_BUFFER);
|
instanceVBO = GlBuffer.requestPersistent(GlBufferType.ARRAY_BUFFER);
|
||||||
AttribUtil.enableArrays(model.getAttributeCount() + instanceFormat.getAttributeCount());
|
AttribUtil.enableArrays(model.getAttributeCount() + instanceFormat.getAttributeCount());
|
||||||
|
|
||||||
vao.unbind();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInitialized() {
|
public boolean isInitialized() {
|
||||||
|
|
|
@ -5,6 +5,8 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.jozufozu.flywheel.backend.gl.GlVertexArray;
|
||||||
|
import com.jozufozu.flywheel.backend.gl.buffer.GlBufferType;
|
||||||
import com.jozufozu.flywheel.backend.state.RenderLayer;
|
import com.jozufozu.flywheel.backend.state.RenderLayer;
|
||||||
import com.jozufozu.flywheel.core.WorldContext;
|
import com.jozufozu.flywheel.core.WorldContext;
|
||||||
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
import com.jozufozu.flywheel.core.shader.WorldProgram;
|
||||||
|
@ -89,6 +91,10 @@ public class MaterialManagerImpl<P extends WorldProgram> implements MaterialMana
|
||||||
|
|
||||||
group.render(state, viewProjection, camX, camY, camZ);
|
group.render(state, viewProjection, camX, camY, camZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlBufferType.ELEMENT_ARRAY_BUFFER.unbind();
|
||||||
|
GlBufferType.ARRAY_BUFFER.unbind();
|
||||||
|
GlVertexArray.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
|
|
@ -22,8 +22,6 @@ public class ArrayModelRenderer extends ModelRenderer {
|
||||||
vao.bind();
|
vao.bind();
|
||||||
|
|
||||||
model.drawCall();
|
model.drawCall();
|
||||||
|
|
||||||
vao.unbind();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -44,7 +42,7 @@ public class ArrayModelRenderer extends ModelRenderer {
|
||||||
|
|
||||||
AttribUtil.enableArrays(this.model.getAttributeCount());
|
AttribUtil.enableArrays(this.model.getAttributeCount());
|
||||||
|
|
||||||
vao.unbind();
|
GlVertexArray.unbind();
|
||||||
|
|
||||||
this.model.clearState();
|
this.model.clearState();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,14 +39,14 @@ public class FullscreenQuad {
|
||||||
|
|
||||||
GL20.glVertexAttribPointer(0, 4, GlNumericType.FLOAT.getGlEnum(), false, 4 * 4, 0);
|
GL20.glVertexAttribPointer(0, 4, GlNumericType.FLOAT.getGlEnum(), false, 4 * 4, 0);
|
||||||
|
|
||||||
vao.unbind();
|
GlVertexArray.unbind();
|
||||||
vbo.unbind();
|
vbo.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw() {
|
public void draw() {
|
||||||
vao.bind();
|
vao.bind();
|
||||||
GL20.glDrawArrays(GL20.GL_TRIANGLES, 0, 6);
|
GL20.glDrawArrays(GL20.GL_TRIANGLES, 0, 6);
|
||||||
vao.unbind();
|
GlVertexArray.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public void delete() {
|
||||||
|
|
|
@ -28,16 +28,7 @@ public class CrumblingGroup<P extends CrumblingProgram> extends MaterialGroupImp
|
||||||
|
|
||||||
int renderTex = RenderSystem.getShaderTexture(0);
|
int renderTex = RenderSystem.getShaderTexture(0);
|
||||||
|
|
||||||
ResourceLocation texture = RenderTextures.getShaderTexture(0);
|
updateAtlasSize();
|
||||||
|
|
||||||
if (texture != null) {
|
|
||||||
SheetData atlasData = AtlasInfo.getAtlasData(texture);
|
|
||||||
|
|
||||||
width = atlasData.width;
|
|
||||||
height = atlasData.height;
|
|
||||||
} else {
|
|
||||||
width = height = 256;
|
|
||||||
}
|
|
||||||
|
|
||||||
type.clearRenderState();
|
type.clearRenderState();
|
||||||
|
|
||||||
|
@ -56,6 +47,19 @@ public class CrumblingGroup<P extends CrumblingProgram> extends MaterialGroupImp
|
||||||
CrumblingRenderer._currentLayer.clearRenderState();
|
CrumblingRenderer._currentLayer.clearRenderState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateAtlasSize() {
|
||||||
|
ResourceLocation texture = RenderTextures.getShaderTexture(0);
|
||||||
|
|
||||||
|
if (texture != null) {
|
||||||
|
SheetData atlasData = AtlasInfo.getAtlasData(texture);
|
||||||
|
|
||||||
|
width = atlasData.width;
|
||||||
|
height = atlasData.height;
|
||||||
|
} else {
|
||||||
|
width = height = 256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup(P p) {
|
public void setup(P p) {
|
||||||
p.setAtlasSize(width, height);
|
p.setAtlasSize(width, height);
|
||||||
|
|
Loading…
Reference in a new issue