Type RenderTarget

Render Target

Methods

addMaterialFlags( materialFlags ) Adds the given material flags to the render target.
draw( x, y, w, h ) Draws the texture itself at the given position and with given width/height.
drawToTexture( func ) Runs the given function asynchronously in a separate drawing context.
freeRT() Frees the given RT for use by another entity, allowing you to allocate a new one.
getMemoryUsageMiB() Returns the amount of graphics memory being consumed by this render target, in MiB.
getShader() Returns the name of the shader being used to render this render target (one of the rendertarget.SHADER_* enums).
hasMaterialFlags( materialFlags ) Returns true if the render target has all the given material flags enabled.
height() Returns the height of the render target in pixels.
isMaterialLinearWrite() Returns whether the render target's material is set to use linear writes.
isValid() Returns true if the render target is still valid for drawing.
removeMaterialFlags( materialFlags ) Removes the given material flags from the render target.
setMaterialLinearWrite( linearWrite ) Sets whether the render target's material should be drawn using linear pixel writes (i.e. without gamma correction).
setShader( shaderType ) Sets the shader to use to render this render target in future rendering operations.
width() Returns the width of the render target in pixels.


Methods

RenderTarget:addMaterialFlags( materialFlags )
Adds the given material flags to the render target.

Environment:

Client

Parameters:

  • (number) materialFlags: The flags to add (see rendertarget.MATERIAL_FLAG_*).

Return value:

    (number) The material flags set on the render target after adding the given flags.
RenderTarget:draw( x, y, w, h )
Draws the texture itself at the given position and with given width/height. Note that width/height values different from the texture size will stretch the texture, not resize it. Also, note that if the shader is not rendertarget.SHADER_UNLIT_GENERIC, nothing will be drawn.

Environment:

Client

Parameters:

  • x: X position to draw.
  • y: Y position to draw.
  • w: Width.
  • h: Height.
RenderTarget:drawToTexture( func )
Runs the given function asynchronously in a separate drawing context. Anything drawn in the function is rendered to the RT texture.

Environment:

Client

Parameters:

  • (function) func: A function to be executed to draw to the texture.
RenderTarget:freeRT()
Frees the given RT for use by another entity, allowing you to allocate a new one. Do not attempt to draw/update it after freeing or your chip will error.

Environment:

Client
RenderTarget:getMemoryUsageMiB()
Returns the amount of graphics memory being consumed by this render target, in MiB.

Environment:

Client
RenderTarget:getShader()
Returns the name of the shader being used to render this render target (one of the rendertarget.SHADER_* enums).

Environment:

Client
RenderTarget:hasMaterialFlags( materialFlags )
Returns true if the render target has all the given material flags enabled. Multiple flags can be tested at once using bit.bor().

Environment:

Client

Parameters:

  • (number) materialFlags: The material flag(s) to check for.
RenderTarget:height()
Returns the height of the render target in pixels.

Environment:

Client
RenderTarget:isMaterialLinearWrite()
Returns whether the render target's material is set to use linear writes.

Environment:

Client
RenderTarget:isValid()
Returns true if the render target is still valid for drawing. Note that render targets may be forcibly freed if the graphics memory quota is reduced.

Environment:

Client
RenderTarget:removeMaterialFlags( materialFlags )
Removes the given material flags from the render target.

Environment:

Client

Parameters:

  • (number) materialFlags: The flags to remove (see rendertarget.MATERIAL_FLAG_*).

Return value:

    (number) The material flags set on the render target after removing the given flags.
RenderTarget:setMaterialLinearWrite( linearWrite )
Sets whether the render target's material should be drawn using linear pixel writes (i.e. without gamma correction). This applies to drawing the render target as a material and applying a colour modulation in a 2D surface context, such as on a screen or within another render target. This does **not** affect render operations applied within the render target itself. The render target must be using the rendertarget.SHADER_UNLIT_GENERIC shader to apply this setting.

Environment:

Client

Parameters:

  • (boolean) linearWrite: Whether the render target's material should use linear writes.

Usage:

    -- Create a render target and draw a basic white square. 
    local RT = rendertarget.createWithSize( 512, 512 ) 
    -- Set the render target's material to use linear writes, disabling gamma correction. 
    RT:setMaterialLinearWrite( true ) 
    RT:drawToTexture( function() 
    	-- Note: inside the render target, the linear write flag on the RT has **no effect**. 
    	-- Use render.getLinearWriteMaterial() to draw shapes without gamma correction here. 
    	-- Clearing is not affected by gamma correction, as it directly writes the pixel values. 
    	render.clear( 255, 255, 255, 255 ) 
    end ) 
     
    hook( "render", "test", function() 
    	render.clear( 0, 0, 0, 255 ) 
    	-- As the material disables gamma correction, this will draw an exactly 16, 16, 16 colour square. 
    	-- If linear writes were disabled, this would instead draw an 8, 8, 8 colour square. 
    	render.setColor( 16, 16, 16, 255 ) 
    	render.setMaterial( RT ) 
    	render.drawTexturedRect( 0, 0, 128, 128 ) 
    end )
RenderTarget:setShader( shaderType )
Sets the shader to use to render this render target in future rendering operations. Note that 2D rendering can only use rendertarget.SHADER_UNLIT_GENERIC. Attempting to render in 2D with a different shader will fail. Also, note that material flags are separate between shaders, so they should be configured after calling this method.

Environment:

Client

Parameters:

  • (string) shaderType: The shader to use (see rendertarget.SHADER_*).
RenderTarget:width()
Returns the width of the render target in pixels.

Environment:

Client

Valid XHTML 1.0!