Class MeshRenderer
java.lang.Object
lol.trq.helios.mesh.MeshRenderer
- All Implemented Interfaces:
AutoCloseable
Draws 3D meshes written through the sinks:
quads(), lines() and textured(). Vertices are
in the current model-view space; inside Minecraft's world render (such as RenderWorldLastEvent) that is
world coordinates relative to the camera, the space MinecraftWorld returns.
Each sink streams into its own buffer and flushes when it is full, when another sink is written to (so draws keep
the order they were written in), when the texture or lighting changes, and at flush(). Call
flush() when done drawing, and endFrame() once per frame (Helios.tick()
does). Each flush saves and restores every piece of GL state it touches.
Meshes that do not change can be recorded once with a MeshRecorder and drawn from a StaticMesh
with draw(StaticMesh, float[]), which uploads nothing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatAmbient light.static final floatDiffuse strength of each light.static final float[]First light direction of Minecraft 1.8.9's entity lighting, in world space, normalized.static final float[]Second light direction of Minecraft 1.8.9's entity lighting, in world space, normalized.static final floatDefault alpha cutoff of textured meshes, as Minecraft's alpha test for entities. -
Constructor Summary
ConstructorsConstructorDescriptionMeshRenderer(GlBackend gl, GlStateCache cache, ShaderLoader shaders, int capacity) Creates a renderer. -
Method Summary
Modifier and TypeMethodDescriptionalphaCutoff(float cutoff) Sets the alpha at or below which textured fragments are discarded, so transparent texels write no depth.voidclose()Deletes the programs, vertex arrays and buffers.cull(boolean on) Sets back-face culling for what follows.depth(boolean test, boolean write) Sets depth testing and writing for what follows.voiddraw(StaticMesh mesh, float[] model) Draws a recorded mesh, after flushing what was written so far.intReturns how many draw calls this renderer has issued, for tests and profiling.voidendFrame()Marks the end of a frame for the streamed vertex buffers.voidflush()Draws everything written so far.lighting(boolean on) Turns Minecraft 1.8.9 entity lighting on or off for the textured quads that follow: each fragment's colour is multiplied bymin(1, AMBIENT + DIFFUSE * (max(0, n·LIGHT0) + max(0, n·LIGHT1))).lines()Returns the sink for anti-aliased lines.quads()Returns the sink for flat-coloured quads.texture(int textureId) Sets the texture of the textured quads that follow, flushing those already written with another.textured()Returns the sink for textured, optionally lit quads; they use the texture set bytexture(int).
-
Field Details
-
LIGHT0
public static final float[] LIGHT0First light direction of Minecraft 1.8.9's entity lighting, in world space, normalized. -
LIGHT1
public static final float[] LIGHT1Second light direction of Minecraft 1.8.9's entity lighting, in world space, normalized. -
DIFFUSE
public static final float DIFFUSEDiffuse strength of each light.- See Also:
-
AMBIENT
public static final float AMBIENTAmbient light.- See Also:
-
TEXTURED_ALPHA_CUTOFF
public static final float TEXTURED_ALPHA_CUTOFFDefault alpha cutoff of textured meshes, as Minecraft's alpha test for entities.- See Also:
-
-
Constructor Details
-
MeshRenderer
Creates a renderer.- Parameters:
gl- the backendcache- the host's state cacheshaders- the loader that resolves the built-in shaderscapacity- quads per draw call, per sink
-
-
Method Details
-
quads
-
lines
-
textured
Returns the sink for textured, optionally lit quads; they use the texture set bytexture(int).- Returns:
- the sink
-
texture
Sets the texture of the textured quads that follow, flushing those already written with another.- Parameters:
textureId- the GL texture, or 0 for none- Returns:
- this renderer
-
lighting
Turns Minecraft 1.8.9 entity lighting on or off for the textured quads that follow: each fragment's colour is multiplied bymin(1, AMBIENT + DIFFUSE * (max(0, n·LIGHT0) + max(0, n·LIGHT1))). On by default. The light directions are in world space, so normals must be too, as they are inside Minecraft's world render.- Parameters:
on- whether lighting is on- Returns:
- this renderer
-
alphaCutoff
Sets the alpha at or below which textured fragments are discarded, so transparent texels write no depth. Defaults to 0.10000000149011612f. Coloured quads and lines discard only fully transparent fragments.- Parameters:
cutoff- the cutoff in[0, 1)- Returns:
- this renderer
-
depth
Sets depth testing and writing for what follows. Both are on by default; turn writing off for translucent meshes, and testing off to draw through walls.- Parameters:
test- whether fragments are depth testedwrite- whether fragments write depth- Returns:
- this renderer
-
cull
Sets back-face culling for what follows. Off by default, so quads show from both sides. With culling on, quads wound counter-clockwise on screen face the viewer.- Parameters:
on- whether back faces are culled- Returns:
- this renderer
-
flush
public void flush()Draws everything written so far. -
draw
Draws a recorded mesh, after flushing what was written so far. Uses the current texture, lighting, depth and cull settings, as the streamed sinks do.- Parameters:
mesh- the meshmodel- a transform applied on the GPU, ornullfor none
-
drawCalls
public int drawCalls()Returns how many draw calls this renderer has issued, for tests and profiling.- Returns:
- the draw call count
-
endFrame
public void endFrame()Marks the end of a frame for the streamed vertex buffers.Helios.tick()calls it. -
close
public void close()Deletes the programs, vertex arrays and buffers. Recorded meshes are closed separately.- Specified by:
closein interfaceAutoCloseable
-