Search in sources :

Example 1 with VertexBufferConsumer

use of net.minecraftforge.client.model.pipeline.VertexBufferConsumer in project ImmersiveEngineering by BluSunrize.

the class ItemRendererIEOBJ method renderQuadsForGroups.

private void renderQuadsForGroups(String[] groups, IOBJModelCallback<ItemStack> callback, IESmartObjModel model, List<Pair<BakedQuad, ShaderLayer>> quadsForGroup, ItemStack stack, ShaderCase sCase, ItemStack shader, BufferBuilder bb, Tessellator tes, Map<String, Boolean> visible, float partialTicks) {
    quadsForGroup.clear();
    for (String g : groups) {
        if (visible.getOrDefault(g, Boolean.FALSE) && callback.shouldRenderGroup(stack, g))
            quadsForGroup.addAll(model.addQuadsForGroup(callback, stack, g, sCase, shader).stream().filter(Objects::nonNull).collect(Collectors.toList()));
        visible.remove(g);
    }
    if (!callback.areGroupsFullbright(stack, groups))
        bb.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
    else
        bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
    VertexBufferConsumer vbc = new VertexBufferConsumer(bb);
    ShaderLayer lastShaderLayer = null;
    for (Pair<BakedQuad, ShaderLayer> pair : quadsForGroup) {
        BakedQuad bq = pair.getKey();
        ShaderLayer layer = pair.getValue();
        // Switch to or between dynamic layers
        boolean switchDynamic = layer != lastShaderLayer;
        if (switchDynamic) {
            // interrupt batch
            tes.draw();
            if (// finish dynamic call on last layer
            lastShaderLayer != null)
                lastShaderLayer.modifyRender(false, partialTicks);
            // set new layer
            lastShaderLayer = layer;
            if (// start dynamic call on layer
            lastShaderLayer != null)
                lastShaderLayer.modifyRender(true, partialTicks);
            // start new batch
            if (!callback.areGroupsFullbright(stack, groups))
                bb.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
            else
                bb.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
        }
        bq.pipe(vbc);
    }
    tes.draw();
    if (// finish dynamic call on final layer
    lastShaderLayer != null)
        lastShaderLayer.modifyRender(false, partialTicks);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) VertexBufferConsumer(net.minecraftforge.client.model.pipeline.VertexBufferConsumer) ShaderLayer(blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)

Example 2 with VertexBufferConsumer

use of net.minecraftforge.client.model.pipeline.VertexBufferConsumer in project MinecraftForge by MinecraftForge.

the class AnimationModelBase method render.

@SuppressWarnings("unchecked")
@Override
public void render(Entity entity, float limbSwing, float limbSwingSpeed, float timeAlive, float yawHead, float rotationPitch, float scale) {
    IAnimationStateMachine capability = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
    if (capability == null) {
        return;
    }
    Pair<IModelState, Iterable<Event>> pair = capability.apply(timeAlive / 20);
    handleEvents((T) entity, timeAlive / 20, pair.getRight());
    IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
    IBakedModel bakedModel = model.bake(pair.getLeft(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
    BlockPos pos = new BlockPos(entity.posX, entity.posY + entity.height, entity.posZ);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.pushMatrix();
    GlStateManager.rotate(180, 0, 0, 1);
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer VertexBuffer = tessellator.getBuffer();
    VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    VertexBuffer.setTranslation(-0.5, -1.5, -0.5);
    lighter.setParent(new VertexBufferConsumer(VertexBuffer));
    lighter.setWorld(entity.world);
    lighter.setState(Blocks.AIR.getDefaultState());
    lighter.setBlockPos(pos);
    boolean empty = true;
    List<BakedQuad> quads = bakedModel.getQuads(null, null, 0);
    if (!quads.isEmpty()) {
        lighter.updateBlockInfo();
        empty = false;
        for (BakedQuad quad : quads) {
            quad.pipe(lighter);
        }
    }
    for (EnumFacing side : EnumFacing.values()) {
        quads = bakedModel.getQuads(null, side, 0);
        if (!quads.isEmpty()) {
            if (empty)
                lighter.updateBlockInfo();
            empty = false;
            for (BakedQuad quad : quads) {
                quad.pipe(lighter);
            }
        }
    }
    // debug quad
    /*VertexBuffer.pos(0, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 0).lightmap(240, 0).endVertex();
        VertexBuffer.pos(0, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 1).lightmap(240, 0).endVertex();
        VertexBuffer.pos(1, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 1).lightmap(240, 0).endVertex();
        VertexBuffer.pos(1, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 0).lightmap(240, 0).endVertex();*/
    VertexBuffer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBufferConsumer(net.minecraftforge.client.model.pipeline.VertexBufferConsumer) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) IAnimationStateMachine(net.minecraftforge.common.model.animation.IAnimationStateMachine) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Aggregations

BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)2 VertexBufferConsumer (net.minecraftforge.client.model.pipeline.VertexBufferConsumer)2 ShaderLayer (blusunrize.immersiveengineering.api.shader.ShaderCase.ShaderLayer)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 IModel (net.minecraftforge.client.model.IModel)1 IModelState (net.minecraftforge.common.model.IModelState)1 IAnimationStateMachine (net.minecraftforge.common.model.animation.IAnimationStateMachine)1