mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 23:47:09 +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());
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
public static void unbind() {
|
||||
Backend.getInstance().compat.vao.bindVertexArray(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@ public abstract class GlBuffer extends GlObject {
|
|||
}
|
||||
|
||||
public void bind() {
|
||||
GL20.glBindBuffer(type.glEnum, handle());
|
||||
type.bind(handle());
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
GL20.glBindBuffer(type.glEnum, 0);
|
||||
type.unbind();
|
||||
}
|
||||
|
||||
public void doneForThisFrame() {
|
||||
|
|
|
@ -8,6 +8,8 @@ import org.lwjgl.opengl.GL40;
|
|||
import org.lwjgl.opengl.GL42;
|
||||
import org.lwjgl.opengl.GL43;
|
||||
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
|
||||
public enum GlBufferType {
|
||||
ARRAY_BUFFER(GL15C.GL_ARRAY_BUFFER),
|
||||
ELEMENT_ARRAY_BUFFER(GL15C.GL_ELEMENT_ARRAY_BUFFER),
|
||||
|
@ -29,4 +31,12 @@ public enum GlBufferType {
|
|||
GlBufferType(int 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
|
||||
instanceVBO.doneForThisFrame();
|
||||
|
||||
vao.unbind();
|
||||
GlVertexArray.unbind();
|
||||
|
||||
GlError.pollAndThrow(() -> modelData.name() + "_unbind");
|
||||
}
|
||||
|
@ -72,16 +72,12 @@ public class GPUInstancer<D extends InstanceData> extends AbstractInstancer<D> {
|
|||
vao.bind();
|
||||
|
||||
model.setupState();
|
||||
|
||||
vao.unbind();
|
||||
});
|
||||
|
||||
vao.bind();
|
||||
|
||||
instanceVBO = GlBuffer.requestPersistent(GlBufferType.ARRAY_BUFFER);
|
||||
AttribUtil.enableArrays(model.getAttributeCount() + instanceFormat.getAttributeCount());
|
||||
|
||||
vao.unbind();
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
|
|
|
@ -5,6 +5,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
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.core.WorldContext;
|
||||
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);
|
||||
}
|
||||
|
||||
GlBufferType.ELEMENT_ARRAY_BUFFER.unbind();
|
||||
GlBufferType.ARRAY_BUFFER.unbind();
|
||||
GlVertexArray.unbind();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -22,8 +22,6 @@ public class ArrayModelRenderer extends ModelRenderer {
|
|||
vao.bind();
|
||||
|
||||
model.drawCall();
|
||||
|
||||
vao.unbind();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,7 +42,7 @@ public class ArrayModelRenderer extends ModelRenderer {
|
|||
|
||||
AttribUtil.enableArrays(this.model.getAttributeCount());
|
||||
|
||||
vao.unbind();
|
||||
GlVertexArray.unbind();
|
||||
|
||||
this.model.clearState();
|
||||
}
|
||||
|
|
|
@ -39,14 +39,14 @@ public class FullscreenQuad {
|
|||
|
||||
GL20.glVertexAttribPointer(0, 4, GlNumericType.FLOAT.getGlEnum(), false, 4 * 4, 0);
|
||||
|
||||
vao.unbind();
|
||||
GlVertexArray.unbind();
|
||||
vbo.unbind();
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
vao.bind();
|
||||
GL20.glDrawArrays(GL20.GL_TRIANGLES, 0, 6);
|
||||
vao.unbind();
|
||||
GlVertexArray.unbind();
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
|
|
@ -28,16 +28,7 @@ public class CrumblingGroup<P extends CrumblingProgram> extends MaterialGroupImp
|
|||
|
||||
int renderTex = RenderSystem.getShaderTexture(0);
|
||||
|
||||
ResourceLocation texture = RenderTextures.getShaderTexture(0);
|
||||
|
||||
if (texture != null) {
|
||||
SheetData atlasData = AtlasInfo.getAtlasData(texture);
|
||||
|
||||
width = atlasData.width;
|
||||
height = atlasData.height;
|
||||
} else {
|
||||
width = height = 256;
|
||||
}
|
||||
updateAtlasSize();
|
||||
|
||||
type.clearRenderState();
|
||||
|
||||
|
@ -56,6 +47,19 @@ public class CrumblingGroup<P extends CrumblingProgram> extends MaterialGroupImp
|
|||
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
|
||||
public void setup(P p) {
|
||||
p.setAtlasSize(width, height);
|
||||
|
|
Loading…
Reference in a new issue