Skip to content

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.

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.

ReturnsSignatureSummary
RenderStatecreate() factoryCreates a state with the defaults: opaque white, no blending, no texture, no shader, the window as target, and depth and color writes on.

PropertyTypeDefaultSummary
cullbooleanfalseIf true, the backend skips the triangles that face away from the viewer.
lightingbooleanfalseIf true, the default shader shades each vertex by its normal, with a light that faces the viewer, as for 3D models.
lineWidthfloat1FWidth of the lines that the Tessellator draws, in design pixels like every other thickness: 2F covers 4 screen pixels at a scale of 2.
depthTestbooleanfalseIf true, a fragment farther than the depth already stored is discarded.
depthWritebooleantrueIf true, the draws write their depth into the depth buffer.
lineSmoothbooleanfalseIf true, the lines get antialiased edges.
alphaCutofffloat0FAlpha, on 1, at or below which the shaders discard a fragment; 0F keeps every fragment.
blendBlendStateBlendState.DISABLEDHow the next draws combine with the pixels already on the target, a BlendState.
stencilStencilStateStencilState.DISABLEDStencil test and operations of the next draws, a StencilState.
shaderIShadernullShader of the next draws; null draws with the default shader of the backend, which draws the vertex colors and the texture.
textureITexturenullTexture that the next draws sample; null draws plain colors.
frameBufferIFrameBuffernullTarget of the next draws; null is the window.
textureMipmapbooleantrueIf false, the next draws sample the texture without its mip levels, even when it has some.
textureWrapTextureWrapTextureWrap.REPEATWhat the texture shows outside the coordinates 0 to 1, a TextureWrap.
textureFilterTextureFilterTextureFilter.NEARESTHow the texture is sampled between its pixels, a TextureFilter.
colorWritebooleantrueIf false, the draws write nothing into the color channels, only depth or stencil, as the masks do.

ReturnsSignatureSummary
thiscolor(float red, float green, float blue, float alpha) fluentSets the current color, channels on 1: the color of the vertices that carry none, so it tints a textured draw without vertex colors.
thisviewport(int x, int y, int width, int height) fluentSets the rectangle of the target that the projection maps to, in pixels: x, y from the bottom-left corner, width, height.
RenderStatecopy()Returns an independent copy of the whole state.
thisload(RenderState state) fluentCopies every setting of another state into this one.
floatgetRed()Returns the red channel of the current color, on 1.
floatgetBlue()Returns the blue channel of the current color, on 1.
floatgetGreen()Returns the green channel of the current color, on 1.
floatgetAlpha()Returns the alpha channel of the current color, on 1.
intgetViewportX()Returns the left edge of the viewport, in pixels of the target.
intgetViewportY()Returns the bottom edge of the viewport, in pixels of the target counted from its bottom row.
intgetViewportWidth()Returns the width of the viewport, in pixels.
intgetViewportHeight()Returns the height of the viewport, in pixels.

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.

  • this cull(boolean cull) fluent
  • boolean isCull()

Default: false

If true, the backend skips the triangles that face away from the viewer.

  • this lighting(boolean lighting) fluent
  • boolean 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.

  • this lineWidth(float lineWidth) fluent
  • float 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.

  • this depthTest(boolean depthTest) fluent
  • boolean isDepthTest()

Default: false

If true, a fragment farther than the depth already stored is discarded.

  • this depthWrite(boolean depthWrite) fluent
  • boolean isDepthWrite()

Default: true

If true, the draws write their depth into the depth buffer.

  • this lineSmooth(boolean lineSmooth) fluent
  • boolean isLineSmooth()

Default: false

If true, the lines get antialiased edges.

  • this alphaCutoff(float alphaCutoff) fluent
  • float 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) fluent
  • BlendState getBlend()

Default: BlendState.DISABLED

How the next draws combine with the pixels already on the target, a BlendState.

  • this stencil(StencilState stencil) fluent
  • StencilState 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.

  • this shader(IShader shader) fluent
  • IShader 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.

  • this texture(ITexture texture) fluent
  • ITexture getTexture()

Default: null

Texture that the next draws sample; null draws plain colors. Setting a texture turns textureMipmap back on.

  • this frameBuffer(IFrameBuffer frameBuffer) fluent
  • IFrameBuffer getFrameBuffer()

Default: null

Target of the next draws; null is the window.

  • this textureMipmap(boolean textureMipmap) fluent
  • boolean isTextureMipmap()

Default: true

If false, the next draws sample the texture without its mip levels, even when it has some.

  • this textureWrap(TextureWrap textureWrap) fluent
  • TextureWrap getTextureWrap()

Default: TextureWrap.REPEAT

What the texture shows outside the coordinates 0 to 1, a TextureWrap.

  • this textureFilter(TextureFilter textureFilter) fluent
  • TextureFilter getTextureFilter()

Default: TextureFilter.NEAREST

How the texture is sampled between its pixels, a TextureFilter.

  • this colorWrite(boolean colorWrite) fluent
  • boolean isColorWrite()

Default: true

If false, the draws write nothing into the color channels, only depth or stencil, as the masks do.

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. 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.

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.


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

Report a problem with this page