Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postprocessing+ Emissive texture rework + Optimize rendering performance #179

Merged
merged 24 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/gregtech/api/GTValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ public static boolean isModLoaded(String modid) {
return isModLoadedCache.get(modid);
}
boolean isLoaded = Loader.instance().getIndexedModList().containsKey(modid);
if (!isLoaded) {
try {
Class.forName(modid);
isLoaded = true;
} catch (ClassNotFoundException ignored) {
}
}
isModLoadedCache.put(modid, isLoaded);
return isLoaded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ public boolean isActive() {
return isActive;
}

public boolean isWorking() {
return isActive && !hasNotEnoughEnergy && workingEnabled;
}

public boolean isAllowOverclocking() {
return allowOverclocking;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gregtech/api/cover/CoverBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gregtech.api.gui.IUIHolder;
import gregtech.api.render.SimpleSidedCubeRenderer.RenderSide;
import gregtech.api.render.Textures;
import gregtech.common.asm.hooks.BloomRenderLayerHooks;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -177,7 +178,7 @@ public <T> T getCapability(Capability<T> capability, T defaultValue) {

@SideOnly(Side.CLIENT)
public boolean canRenderInLayer(BlockRenderLayer renderLayer) {
return renderLayer == BlockRenderLayer.CUTOUT;
return renderLayer == BlockRenderLayer.CUTOUT || renderLayer == BloomRenderLayerHooks.BLOOM;
}

@SideOnly(Side.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void renderGlParticlesInLayer(Tessellator tessellator, Entity entityIn,
ArrayDeque<GTParticle> particles = renderQueue.get(handler)[layer];
if (particles.isEmpty()) continue;
BufferBuilder buffer = tessellator.getBuffer();
handler.preDraw(layer, buffer, entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
handler.preDraw(buffer);
for (final Particle particle : particles) {
try {
particle.renderParticle(buffer, entityIn, partialTicks, rotationX, rotationXZ, rotationZ, rotationYZ, rotationXY);
Expand All @@ -171,7 +171,7 @@ public String call() {
throw new ReportedException(crashreport);
}
}
handler.postDraw(layer, buffer, tessellator);
handler.postDraw(buffer);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public TexturedParticleHandler(boolean depth, ResourceLocation texture) {
}

@Override
public void preDraw(int layer, BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
public void preDraw(BufferBuilder buffer) {
if (depth) {
GlStateManager.depthMask(true);
} else {
Expand All @@ -78,8 +78,8 @@ public void preDraw(int layer, BufferBuilder buffer, Entity entityIn, float part
}

@Override
public void postDraw(int layer, BufferBuilder buffer, Tessellator tessellator) {
tessellator.draw();
public void postDraw(BufferBuilder buffer) {
Tessellator.getInstance().draw();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.shader.Framebuffer;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import org.lwjgl.opengl.EXTFramebufferObject;

Expand Down Expand Up @@ -39,12 +38,12 @@ public FBOShaderHandler(ShaderProgram program) {
fbo = new Framebuffer(1000, 1000, false);
}

public void hookPreDraw(Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
public void hookPreDraw() {
program.useShader();
}

@Override
public final void preDraw(int layer, BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
public final void preDraw(BufferBuilder buffer) {
if (program != null) {
int lastID = glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
fbo.setFramebufferColor(0.0F, 0.0F, 0.0F, 0.0F);
Expand All @@ -55,7 +54,7 @@ public final void preDraw(int layer, BufferBuilder buffer, Entity entityIn, floa
GlStateManager.viewport(0, 0, 1000, 1000);
Tessellator tessellator = Tessellator.getInstance();

hookPreDraw(entityIn, partialTicks, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
hookPreDraw();

buffer.begin(7, DefaultVertexFormats.POSITION_TEX);
buffer.pos(-1, 1, 0).tex(0, 0).endVertex();
Expand All @@ -81,8 +80,8 @@ public final void preDraw(int layer, BufferBuilder buffer, Entity entityIn, floa
}

@Override
public final void postDraw(int layer, BufferBuilder buffer, Tessellator tessellator) {
tessellator.draw();
public final void postDraw(BufferBuilder buffer) {
Tessellator.getInstance().draw();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package gregtech.api.entities.particle;

import gregtech.api.render.ICustomRenderFast;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;

/**
* Created with IntelliJ IDEA.
Expand All @@ -12,28 +11,15 @@
* @Description: copyright Created by brandon3055 on 30/11/2016.
*/

public interface IGTParticleHandler {

/**
* Run any pre render gl code here.
* You can also start drawing quads.
*/
void preDraw(int layer, BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ);

/**
* Run any post render gl code here.
* This is where you would draw if you started drawing in preDraw
*/
void postDraw(int layer, BufferBuilder buffer, Tessellator tessellator);

public interface IGTParticleHandler extends ICustomRenderFast {
IGTParticleHandler DEFAULT_FX_HANDLER = new IGTParticleHandler() {
@Override
public void preDraw(int layer, BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
public void preDraw(BufferBuilder buffer) {

}

@Override
public void postDraw(int layer, BufferBuilder buffer, Tessellator tessellator) {
public void postDraw(BufferBuilder buffer) {
}
};
}
2 changes: 2 additions & 0 deletions src/main/java/gregtech/api/gui/impl/FakeModularGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public void drawScreen(double x, double y, float partialTicks) {

GlStateManager.translate(-scale * halfW, -scale * halfH, 0.01);
GlStateManager.scale(scale, scale, 1);
modularUI.backgroundPath.draw(0, 0, modularUI.getWidth(), modularUI.getHeight());
GlStateManager.translate(0, 0, -0.01);
GlStateManager.depthMask(false);

drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/gregtech/api/gui/resources/ResourceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void bindTexture(String rs) {

public static boolean isResourceExist(String rs) {
if (!cachedResources.containsKey(rs)) {
InputStream inputstream = ResourceHelper.class.getResourceAsStream("/assets/" + GTValues.MODID + "/" + rs);
InputStream inputstream = ResourceHelper.class.getResourceAsStream(String.format("/assets/%s/%s", GTValues.MODID, rs));
if(inputstream == null) {
return false;
}
Expand All @@ -55,4 +55,13 @@ public static boolean isResourceExist(String rs) {
return true;
}

public static boolean isTextureExist(ResourceLocation textureResource) {
InputStream inputstream = ResourceHelper.class.getResourceAsStream(String.format("/assets/%s/textures/%s.png", GTValues.MODID, textureResource.getPath()));
if(inputstream == null) {
return false;
}
IOUtils.closeQuietly(inputstream);
return true;
}

}
4 changes: 2 additions & 2 deletions src/main/java/gregtech/api/gui/resources/ShaderTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private ShaderTexture(ShaderProgram program, ShaderObject object) {
}

public static ShaderTexture createShader(String location) {
if (FMLCommonHandler.instance().getSide().isClient()) {
if (FMLCommonHandler.instance().getSide().isClient() && Shaders.allowedShader()) {
if (!PROGRAMS.containsKey(location)) {
ShaderObject object = Shaders.loadShader(ShaderObject.ShaderType.FRAGMENT, location);
if (object != null) {
Expand All @@ -70,7 +70,7 @@ public static ShaderTexture createShader(String location) {
}

public static ShaderTexture createRawShader(String rawShader) {
if (FMLCommonHandler.instance().getSide().isClient()) {
if (FMLCommonHandler.instance().getSide().isClient() && Shaders.allowedShader()) {
ShaderProgram program = new ShaderProgram();
ShaderObject object = new ShaderObject(ShaderObject.ShaderType.FRAGMENT, rawShader).compileShader();
program.attachShader(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ public interface IFastRenderMetaTileEntity {
int RENDER_PASS_TRANSLUCENT = 1;

@SideOnly(Side.CLIENT)
void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks);
default void renderMetaTileEntityFast(CCRenderState renderState, Matrix4 translation, float partialTicks) {};

@SideOnly(Side.CLIENT)
default void renderMetaTileEntity(double x, double y, double z, float partialTicks) {

}

AxisAlignedBB getRenderBoundingBox();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import gregtech.api.util.GTUtility;
import gregtech.common.ConfigHolder;
import gregtech.common.advancement.GTTriggers;
import gregtech.common.asm.hooks.BloomRenderLayerHooks;
import net.minecraft.block.Block;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
Expand Down Expand Up @@ -198,7 +199,7 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,

@SideOnly(Side.CLIENT)
public boolean canRenderInLayer(BlockRenderLayer renderLayer) {
return renderLayer == BlockRenderLayer.CUTOUT_MIPPED;
return renderLayer == BlockRenderLayer.CUTOUT_MIPPED || renderLayer == BloomRenderLayerHooks.BLOOM;
}

@SideOnly(Side.CLIENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,9 @@ public boolean shouldRenderInPass(int pass) {
CoverBehavior cover = metaTileEntity.getCoverAtSide(side);
if (cover instanceof IFastRenderMetaTileEntity && ((IFastRenderMetaTileEntity) cover).shouldRenderInPass(pass)) {
return true;
} else if (cover instanceof IRenderMetaTileEntity && ((IRenderMetaTileEntity) cover).shouldRenderInPass(pass)) {
return true;
}
}
if (metaTileEntity instanceof IRenderMetaTileEntity) {
return ((IRenderMetaTileEntity) metaTileEntity).shouldRenderInPass(pass);
} else if (metaTileEntity instanceof IFastRenderMetaTileEntity) {
if (metaTileEntity instanceof IFastRenderMetaTileEntity) {
return ((IFastRenderMetaTileEntity) metaTileEntity).shouldRenderInPass(pass);
}
return false;
Expand All @@ -243,9 +239,7 @@ public boolean shouldRenderInPass(int pass) {
@Nonnull
@Override
public AxisAlignedBB getRenderBoundingBox() {
if (metaTileEntity instanceof IRenderMetaTileEntity) {
return ((IRenderMetaTileEntity) metaTileEntity).getRenderBoundingBox();
} else if (metaTileEntity instanceof IFastRenderMetaTileEntity) {
if (metaTileEntity instanceof IFastRenderMetaTileEntity) {
return ((IFastRenderMetaTileEntity) metaTileEntity).getRenderBoundingBox();
}
return new AxisAlignedBB(getPos());
Expand All @@ -255,4 +249,9 @@ public AxisAlignedBB getRenderBoundingBox() {
public boolean canRenderBreaking() {
return false;
}

@Override
public boolean hasFastRenderer() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import gregtech.api.render.OrientedOverlayRenderer;
import gregtech.api.render.Textures;
import gregtech.api.util.GTUtility;
import gregtech.common.blocks.BlockFireboxCasing;
import gregtech.common.blocks.VariantActiveBlock;
import gregtech.common.metatileentities.electric.multiblockpart.MetaTileEntityRotorHolder;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -146,7 +148,13 @@ public static Predicate<BlockWorldState> partPredicate(Class<? extends IMultiblo
}

public static Predicate<BlockWorldState> statePredicate(IBlockState... allowedStates) {
return blockWorldState -> ArrayUtils.contains(allowedStates, blockWorldState.getBlockState());
for (IBlockState allowedState : allowedStates) {
if (allowedState.getBlock() instanceof VariantActiveBlock) {
allowedStates = ArrayUtils.add(allowedStates, allowedState.withProperty(VariantActiveBlock.ACTIVE, true));
}
}
IBlockState[] finalAllowedStates = allowedStates;
return blockWorldState -> ArrayUtils.contains(finalAllowedStates, blockWorldState.getBlockState());
}

public static Predicate<BlockWorldState> blockPredicate(Block... block) {
Expand Down
Loading