RenderState
final class RenderState
Package: dev.joid.lib.bridge.render.state · Module: core · Source: RenderState.java
The settings that every draw reads, color, blending, texture, shader, lines, depth, stencil, viewport and target.
Description
Section titled “Description”getState() of the render bridge, BridgeHandler.RENDER.get(), holds the current state.
Change it inside withState(...) of the render bridge, which restores it afterwards, even when your code throws; the setters return the state, so they chain.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
RenderState | create() factory | Creates a state with the defaults: opaque white, no blending, no texture, no shader, the window as target, and depth and color writes on. |
Properties
Section titled “Properties”Other properties
Section titled “Other properties”| Property | Type | Default | Summary |
|---|---|---|---|
| cull | boolean | false | If true, the backend skips the triangles that face away from the viewer. |
| lighting | boolean | false | If true, the default shader shades each vertex by its normal, with a light that faces the viewer, as for 3D models. |
| lineWidth | float | 1F | Width of the lines that the Tessellator draws, in design pixels like every other thickness: 2F covers 4 screen pixels at a scale of 2. |
| depthTest | boolean | false | If true, a fragment farther than the depth already stored is discarded. |
| depthWrite | boolean | true | If true, the draws write their depth into the depth buffer. |
| lineSmooth | boolean | false | If true, the lines get antialiased edges. |
| alphaCutoff | float | 0F | Alpha, on 1, at or below which the shaders discard a fragment; 0F keeps every fragment. |
| blend | BlendState | BlendState.DISABLED | How the next draws combine with the pixels already on the target, a BlendState. |
| stencil | StencilState | StencilState.DISABLED | Stencil test and operations of the next draws, a StencilState. |
| shader | IShader | null | Shader of the next draws; null draws with the default shader of the backend, which draws the vertex colors and the texture. |
| texture | ITexture | null | Texture that the next draws sample; null draws plain colors. |
| frameBuffer | IFrameBuffer | null | Target of the next draws; null is the window. |
| textureMipmap | boolean | true | If false, the next draws sample the texture without its mip levels, even when it has some. |
| textureWrap | TextureWrap | TextureWrap.REPEAT | What the texture shows outside the coordinates 0 to 1, a TextureWrap. |
| textureFilter | TextureFilter | TextureFilter.NEAREST | How the texture is sampled between its pixels, a TextureFilter. |
| colorWrite | boolean | true | If false, the draws write nothing into the color channels, only depth or stencil, as the masks do. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
this | color(float red, float green, float blue, float alpha) fluent | Sets the current color, channels on 1: the color of the vertices that carry none, so it tints a textured draw without vertex colors. |
this | viewport(int x, int y, int width, int height) fluent | Sets the rectangle of the target that the projection maps to, in pixels: x, y from the bottom-left corner, width, height. |
RenderState | copy() | Returns an independent copy of the whole state. |
this | load(RenderState state) fluent | Copies every setting of another state into this one. |
float | getRed() | Returns the red channel of the current color, on 1. |
float | getBlue() | Returns the blue channel of the current color, on 1. |
float | getGreen() | Returns the green channel of the current color, on 1. |
float | getAlpha() | Returns the alpha channel of the current color, on 1. |
int | getViewportX() | Returns the left edge of the viewport, in pixels of the target. |
int | getViewportY() | Returns the bottom edge of the viewport, in pixels of the target counted from its bottom row. |
int | getViewportWidth() | Returns the width of the viewport, in pixels. |
int | getViewportHeight() | Returns the height of the viewport, in pixels. |
Creation details
Section titled “Creation details”create
Section titled “create”RenderState create() factory
Creates a state with the defaults: opaque white, no blending, no texture, no shader, the window as target, and depth and color writes on.
Property details
Section titled “Property details”this cull(boolean cull)fluentboolean isCull()
Default: false
If true, the backend skips the triangles that face away from the viewer.
lighting
Section titled “lighting”this lighting(boolean lighting)fluentboolean isLighting()
Default: false
If true, the default shader shades each vertex by its normal, with a light that faces the viewer, as for 3D models.
lineWidth
Section titled “lineWidth”this lineWidth(float lineWidth)fluentfloat getLineWidth()
Default: 1F
Width of the lines that the Tessellator draws, in design pixels like every other thickness: 2F covers 4 screen pixels at a scale of 2.
A width other than 1F, or a smooth line, draws each segment as a quad; a line of 1F without lineSmooth stays the line of one screen pixel of the GPU.
depthTest
Section titled “depthTest”this depthTest(boolean depthTest)fluentboolean isDepthTest()
Default: false
If true, a fragment farther than the depth already stored is discarded.
depthWrite
Section titled “depthWrite”this depthWrite(boolean depthWrite)fluentboolean isDepthWrite()
Default: true
If true, the draws write their depth into the depth buffer.
lineSmooth
Section titled “lineSmooth”this lineSmooth(boolean lineSmooth)fluentboolean isLineSmooth()
Default: false
If true, the lines get antialiased edges.
alphaCutoff
Section titled “alphaCutoff”this alphaCutoff(float alphaCutoff)fluentfloat getAlphaCutoff()
Default: 0F
Alpha, on 1, at or below which the shaders discard a fragment; 0F keeps every fragment.
UI.mask sets 0.5F to keep only the opaque part of an image.
this blend(BlendState blend)fluentBlendState getBlend()
Default: BlendState.DISABLED
How the next draws combine with the pixels already on the target, a BlendState.
stencil
Section titled “stencil”this stencil(StencilState stencil)fluentStencilState getStencil()
Default: StencilState.DISABLED
Stencil test and operations of the next draws, a StencilState.
It works on the window only: a framebuffer has no stencil.
shader
Section titled “shader”this shader(IShader shader)fluentIShader getShader()
Default: null
Shader of the next draws; null draws with the default shader of the backend, which draws the vertex colors and the texture.
A ShaderProgram sets it while it is bound.
texture
Section titled “texture”this texture(ITexture texture)fluentITexture getTexture()
Default: null
Texture that the next draws sample; null draws plain colors.
Setting a texture turns textureMipmap back on.
frameBuffer
Section titled “frameBuffer”this frameBuffer(IFrameBuffer frameBuffer)fluentIFrameBuffer getFrameBuffer()
Default: null
Target of the next draws; null is the window.
textureMipmap
Section titled “textureMipmap”this textureMipmap(boolean textureMipmap)fluentboolean isTextureMipmap()
Default: true
If false, the next draws sample the texture without its mip levels, even when it has some.
textureWrap
Section titled “textureWrap”this textureWrap(TextureWrap textureWrap)fluentTextureWrap getTextureWrap()
Default: TextureWrap.REPEAT
What the texture shows outside the coordinates 0 to 1, a TextureWrap.
textureFilter
Section titled “textureFilter”this textureFilter(TextureFilter textureFilter)fluentTextureFilter getTextureFilter()
Default: TextureFilter.NEAREST
How the texture is sampled between its pixels, a TextureFilter.
colorWrite
Section titled “colorWrite”this colorWrite(boolean colorWrite)fluentboolean isColorWrite()
Default: true
If false, the draws write nothing into the color channels, only depth or stencil, as the masks do.
Method details
Section titled “Method details”this color(float red, float green, float blue, float alpha) fluent
Sets the current color, channels on 1: the color of the vertices that carry none, so it tints a textured draw without vertex colors.
viewport
Section titled “viewport”this viewport(int x, int y, int width, int height) fluent
Sets the rectangle of the target that the projection maps to, in pixels: x, y from the bottom-left corner, width, height.
A draw with an empty viewport draws nothing.
RenderState copy()
Returns an independent copy of the whole state.
this load(RenderState state) fluent
Copies every setting of another state into this one.
getRed
Section titled “getRed”float getRed()
Returns the red channel of the current color, on 1.
getBlue
Section titled “getBlue”float getBlue()
Returns the blue channel of the current color, on 1.
getGreen
Section titled “getGreen”float getGreen()
Returns the green channel of the current color, on 1.
getAlpha
Section titled “getAlpha”float getAlpha()
Returns the alpha channel of the current color, on 1.
getViewportX
Section titled “getViewportX”int getViewportX()
Returns the left edge of the viewport, in pixels of the target.
getViewportY
Section titled “getViewportY”int getViewportY()
Returns the bottom edge of the viewport, in pixels of the target counted from its bottom row.
getViewportWidth
Section titled “getViewportWidth”int getViewportWidth()
Returns the width of the viewport, in pixels.
getViewportHeight
Section titled “getViewportHeight”int getViewportHeight()
Returns the height of the viewport, in pixels.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
