Class GLRenderer
- All Implemented Interfaces:
Renderer
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applyRenderState
(RenderState state) Applies the givenRenderState
, making the necessary GL calls so that the state is applied.protected void
bindProgram
(Shader shader) void
cleanup()
Deletes all previously usedNative Objects
on this Renderer, and then resets the native objects.void
clearBuffers
(boolean color, boolean depth, boolean stencil) Clears certain channels of the currently bound framebuffer.void
Clears the clipping rectangle set withRenderer.setClipRect(int, int, int, int)
.void
int
convertElementMode
(Mesh.Mode mode) Convert a mesh mode to the corresponding GL value.int
void
copyFrameBuffer
(FrameBuffer src, FrameBuffer dst) Copy the source buffer to the destination buffer, including both color and depth.void
copyFrameBuffer
(FrameBuffer src, FrameBuffer dst, boolean copyDepth) Copies contents from src to dst, scaling if necessary.void
copyFrameBuffer
(FrameBuffer src, FrameBuffer dst, boolean copyColor, boolean copyDepth) Copies contents from src to dst, scaling if necessary.void
Deletes a vertex buffer from the GPU.void
Deletes the buffer object from the GPU.void
Deletes a framebuffer and all attached renderbuffers.void
deleteImage
(Image image) Deletes a texture from the GPU.void
deleteShader
(Shader shader) Deletes a shader.void
Deletes the provided shader source.void
drawTriangleArray
(Mesh.Mode mode, int count, int vertCount) void
drawTriangleList
(VertexBuffer indexBuf, Mesh mesh, int count) static int
extractVersion
(String version) int[]
generateProfilingTasks
(int numTasks) Generates a pool of gpu queries meant to use as profiling tasks.boolean
Gets the alpha to coverage state.getCaps()
Gets the capabilities of the renderer.Returns the current FrameBuffer that is being rendered to.int
Gets the default anisotropic filter level for textures.Vector2f[]
Gets the limits of the renderer.float
Determine the maximum allowed width for lines.long
getProfilingTime
(int taskId) Returns the time in nanoseconds elapsed for the task with the given id.Copies the render statistics.void
Detects available capabilities of the GPU.void
Invalidates the current rendering state.boolean
Test whether images with the sRGB flag will be linearized when read by a shader.boolean
Test whether colors rendered to the main framebuffer undergo linear-to-sRGB conversion.boolean
isTaskResultAvailable
(int taskId) Checks if the profiling results are available.static boolean
void
modifyTexture
(Texture2D dest, Image src, int destX, int destY, int srcX, int srcY, int areaW, int areaH) Copy a part of an image to a texture 2d.void
modifyTexture
(Texture tex, Image pixels, int x, int y) Deprecated.Use modifyTexture(Texture2D dest, Image src, int destX, int destY, int srcX, int srcY, int areaW, int areaH)void
void
Called when a new frame has been rendered.void
pushDebugGroup
(String name) void
readFrameBuffer
(FrameBuffer fb, ByteBuffer byteBuf) Reads the pixels currently stored in the specified framebuffer into the given ByteBuffer object.void
readFrameBufferWithFormat
(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) Reads the pixels currently stored in the specified framebuffer into the given ByteBuffer object.void
renderMesh
(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) Renderscount
meshes, with the geometry data supplied and per-instance data supplied.void
Resets all previously usedNative Objects
on this Renderer.protected void
resetUniformLocations
(Shader shader) void
setAlphaToCoverage
(boolean value) Sets the alpha to coverage state.void
setBackgroundColor
(ColorRGBA color) Sets the background (aka clear) color.void
setClipRect
(int x, int y, int width, int height) Specifies a clipping rectangle.void
setDebugEnabled
(boolean v) void
setDefaultAnisotropicFilter
(int level) Sets the default anisotropic filter level for textures.void
setDepthRange
(float start, float end) \ |* Render State *| \void
Sets the framebuffer that will be drawn to.void
setGenerateMipmapsForFrameBuffer
(boolean v) Enable/Disable default automatic generation of mipmaps for framebuffersvoid
setLinearizeSrgbImages
(boolean linearize) void
Sets the framebuffer that will be set instead of the main framebuffer when a call to setFrameBuffer(null) is made.void
setMainFrameBufferSrgb
(boolean enableSrgb) Specifies whether color values in the main framebuffer are in SRGB format.void
void
Sets the shader to use for rendering.void
setShaderStorageBufferObject
(int bindingPoint, BufferObject bufferObject) void
setTexture
(int unit, Texture tex) Assigns a Texture to the specified texture unit.void
setUniformBufferObject
(int bindingPoint, BufferObject bufferObject) void
void
setVertexAttrib
(VertexBuffer vb, VertexBuffer idb) void
setViewPort
(int x, int y, int w, int h) \ |* Camera and World transforms *| \void
startProfiling
(int taskId) Starts a time profiling task on the GPU.void
Will stop the last profiling task started with startProfiling.void
Uploads a vertex buffer to the GPU.void
void
void
protected void
updateShaderBufferBlock
(Shader shader, ShaderBufferBlock bufferBlock) Updates the buffer block for the shader.protected void
updateShaderBufferBlocks
(Shader shader) Updates all shader's buffer blocks.void
updateShaderData
(Shader shader) void
void
Uploads data of the buffer object on the GPU.protected void
updateShaderUniforms
(Shader shader) void
updateTexImageData
(Image img, Texture.Type type, int unit, boolean scaleToPot) Uploads the given image to the GL driver.protected void
updateUniform
(Shader shader, Uniform uniform) void
Uploads data of the buffer object on the GPU.protected void
updateUniformLocation
(Shader shader, Uniform uniform) Update the location of the specified Uniform in the specified Shader.void
updateVertexArray
(Mesh mesh, VertexBuffer instanceData)
-
Constructor Details
-
GLRenderer
-
-
Method Details
-
setGenerateMipmapsForFrameBuffer
public void setGenerateMipmapsForFrameBuffer(boolean v) Enable/Disable default automatic generation of mipmaps for framebuffers- Parameters:
v
- Default is true
-
setDebugEnabled
public void setDebugEnabled(boolean v) -
popDebugGroup
public void popDebugGroup()- Specified by:
popDebugGroup
in interfaceRenderer
-
pushDebugGroup
- Specified by:
pushDebugGroup
in interfaceRenderer
-
getStatistics
Description copied from interface:Renderer
Copies the render statistics.The statistics allow tracking of how data per frame, such as number of objects rendered, number of triangles, etc. These are updated when the Renderer's methods are used, make sure to call
Statistics.clearFrame()
at the appropriate time to get accurate info per frame.- Specified by:
getStatistics
in interfaceRenderer
- Returns:
- a new instance
-
getCaps
Description copied from interface:Renderer
Gets the capabilities of the renderer. -
getLimits
Description copied from interface:Renderer
Gets the limits of the renderer. -
isWebGL
-
extractVersion
-
initialize
public void initialize()Description copied from interface:Renderer
Detects available capabilities of the GPU. Must be called prior to any other Renderer methods.- Specified by:
initialize
in interfaceRenderer
-
invalidateState
public void invalidateState()Description copied from interface:Renderer
Invalidates the current rendering state. Should be called after the GL state was changed manually or through an external library.- Specified by:
invalidateState
in interfaceRenderer
-
resetGLObjects
public void resetGLObjects()Description copied from interface:Renderer
Resets all previously usedNative Objects
on this Renderer. The state of the native objects is reset in such way, that using them again will cause the renderer to reupload them. Call this method when you know the GL context is going to shut down.- Specified by:
resetGLObjects
in interfaceRenderer
- See Also:
-
cleanup
public void cleanup()Description copied from interface:Renderer
Deletes all previously usedNative Objects
on this Renderer, and then resets the native objects. -
setDepthRange
public void setDepthRange(float start, float end) \ |* Render State *| \- Specified by:
setDepthRange
in interfaceRenderer
- Parameters:
start
- The range startend
- The range end
-
clearBuffers
public void clearBuffers(boolean color, boolean depth, boolean stencil) Description copied from interface:Renderer
Clears certain channels of the currently bound framebuffer.- Specified by:
clearBuffers
in interfaceRenderer
- Parameters:
color
- True if to clear colors (RGBA)depth
- True if to clear depth/zstencil
- True if to clear stencil buffer (if available, otherwise ignored)
-
setBackgroundColor
Description copied from interface:Renderer
Sets the background (aka clear) color.- Specified by:
setBackgroundColor
in interfaceRenderer
- Parameters:
color
- The background color to set
-
setDefaultAnisotropicFilter
public void setDefaultAnisotropicFilter(int level) Description copied from interface:Renderer
Sets the default anisotropic filter level for textures.If the
texture anisotropic filter
is set to 0, then the default level is used. Otherwise, if the texture level is 1 or greater, then the texture's value overrides the default value.- Specified by:
setDefaultAnisotropicFilter
in interfaceRenderer
- Parameters:
level
- The default anisotropic filter level to use. Default: 1.
-
setAlphaToCoverage
public void setAlphaToCoverage(boolean value) Description copied from interface:Renderer
Sets the alpha to coverage state.When alpha coverage and multi-sampling is enabled, each pixel will contain alpha coverage in all of its subsamples, which is then combined when other future alpha-blended objects are rendered.
Alpha-to-coverage is useful for rendering transparent objects without having to worry about sorting them.
- Specified by:
setAlphaToCoverage
in interfaceRenderer
- Parameters:
value
- true to enable alpha coverage, otherwise false
-
applyRenderState
Description copied from interface:Renderer
Applies the givenRenderState
, making the necessary GL calls so that the state is applied.- Specified by:
applyRenderState
in interfaceRenderer
- Parameters:
state
- the RenderState to apply
-
setViewPort
public void setViewPort(int x, int y, int w, int h) \ |* Camera and World transforms *| \- Specified by:
setViewPort
in interfaceRenderer
- Parameters:
x
- The x coordinate of the viewporty
- The y coordinate of the viewportw
- Width of the viewporth
- Height of the viewport
-
setClipRect
public void setClipRect(int x, int y, int width, int height) Description copied from interface:Renderer
Specifies a clipping rectangle. For all future rendering commands, no pixels will be allowed to be rendered outside of the clip rectangle.- Specified by:
setClipRect
in interfaceRenderer
- Parameters:
x
- The x coordinate of the clip recty
- The y coordinate of the clip rectwidth
- Width of the clip rectheight
- Height of the clip rect
-
clearClipRect
public void clearClipRect()Description copied from interface:Renderer
Clears the clipping rectangle set withRenderer.setClipRect(int, int, int, int)
.- Specified by:
clearClipRect
in interfaceRenderer
-
postFrame
public void postFrame()Description copied from interface:Renderer
Called when a new frame has been rendered. Currently, this will simply delete any OpenGL objects from the GPU which have been garbage collected by the GC. -
bindProgram
-
updateUniformLocation
Update the location of the specified Uniform in the specified Shader.- Parameters:
shader
- the Shader containing the Uniform (not null)uniform
- the Uniform to update (not null)
-
updateUniform
-
updateShaderBufferBlock
Updates the buffer block for the shader.- Parameters:
shader
- the shader.bufferBlock
- the storage block.
-
updateShaderUniforms
-
updateShaderBufferBlocks
Updates all shader's buffer blocks.- Parameters:
shader
- the shader.
-
resetUniformLocations
-
convertShaderType
-
updateShaderSourceData
-
updateShaderData
-
setShader
Description copied from interface:Renderer
Sets the shader to use for rendering. If the shader has not been uploaded yet, it is compiled and linked. If it has been uploaded, then the uniform data is updated and the shader is set. -
deleteShaderSource
Description copied from interface:Renderer
Deletes the provided shader source.- Specified by:
deleteShaderSource
in interfaceRenderer
- Parameters:
source
- The ShaderSource to delete.
-
deleteShader
Description copied from interface:Renderer
Deletes a shader. This method also deletes the attached shader sources.- Specified by:
deleteShader
in interfaceRenderer
- Parameters:
shader
- Shader to delete.- See Also:
-
copyFrameBuffer
Copy the source buffer to the destination buffer, including both color and depth.- Parameters:
src
- the source buffer (unaffected)dst
- the destination buffer
-
copyFrameBuffer
Description copied from interface:Renderer
Copies contents from src to dst, scaling if necessary. set copyDepth to false to only copy the color buffers.- Specified by:
copyFrameBuffer
in interfaceRenderer
- Parameters:
src
- the source FrameBuffer (unaffected)dst
- the destination FrameBuffer (modified)copyDepth
- true→copy depth info, false→don't copy it
-
copyFrameBuffer
Description copied from interface:Renderer
Copies contents from src to dst, scaling if necessary.- Specified by:
copyFrameBuffer
in interfaceRenderer
- Parameters:
src
- the source FrameBuffer (unaffected)dst
- the destination FrameBuffer (modified)copyColor
- true→copy color info, false→don't copy itcopyDepth
- true→copy depth info, false→don't copy it
-
updateRenderTexture
-
updateFrameBufferAttachment
-
updateFrameBuffer
-
getFrameBufferSamplePositions
-
setMainFrameBufferOverride
Description copied from interface:Renderer
Sets the framebuffer that will be set instead of the main framebuffer when a call to setFrameBuffer(null) is made.- Specified by:
setMainFrameBufferOverride
in interfaceRenderer
- Parameters:
fb
- The framebuffer to override the main framebuffer.
-
getCurrentFrameBuffer
Description copied from interface:Renderer
Returns the current FrameBuffer that is being rendered to.- Specified by:
getCurrentFrameBuffer
in interfaceRenderer
- Returns:
- the FrameBuffer or null if rendering to the screen.
-
setReadDrawBuffers
-
setFrameBuffer
Description copied from interface:Renderer
Sets the framebuffer that will be drawn to. If the framebuffer has not been initialized yet, it will be created and its render surfaces and attached textures will be allocated.- Specified by:
setFrameBuffer
in interfaceRenderer
- Parameters:
fb
- The framebuffer to set
-
readFrameBuffer
Description copied from interface:Renderer
Reads the pixels currently stored in the specified framebuffer into the given ByteBuffer object. Only color pixels are transferred, the format is RGBA with 8 bits per component. The given byte buffer should have at least fb.getWidth() * fb.getHeight() * 4 bytes remaining.- Specified by:
readFrameBuffer
in interfaceRenderer
- Parameters:
fb
- The framebuffer to read frombyteBuf
- The bytebuffer to transfer color data to
-
readFrameBufferWithFormat
Description copied from interface:Renderer
Reads the pixels currently stored in the specified framebuffer into the given ByteBuffer object. Only color pixels are transferred, with the given format. The given byte buffer should have at least fb.getWidth() * fb.getHeight() * 4 bytes remaining.- Specified by:
readFrameBufferWithFormat
in interfaceRenderer
- Parameters:
fb
- The framebuffer to read frombyteBuf
- The bytebuffer to transfer color data toformat
- the image format to use when reading the frameBuffer.
-
deleteFrameBuffer
Description copied from interface:Renderer
Deletes a framebuffer and all attached renderbuffers.- Specified by:
deleteFrameBuffer
in interfaceRenderer
- Parameters:
fb
- the FrameBuffer to be deleted
-
updateTexImageData
Uploads the given image to the GL driver.- Parameters:
img
- The image to uploadtype
- How the data in the image argument should be interpreted.unit
- The texture slot to be used to upload the image, not importantscaleToPot
- If true, the image will be scaled to power-of-2 dimensions before being uploaded.
-
setTexture
Description copied from interface:Renderer
Assigns a Texture to the specified texture unit.- Specified by:
setTexture
in interfaceRenderer
- Parameters:
unit
- the index of the texture unit (≥0)tex
- the Texture to assign- Throws:
TextureUnitException
- if the texture unit doesn't exist
-
setUniformBufferObject
- Specified by:
setUniformBufferObject
in interfaceRenderer
-
setShaderStorageBufferObject
- Specified by:
setShaderStorageBufferObject
in interfaceRenderer
-
modifyTexture
Deprecated.Use modifyTexture(Texture2D dest, Image src, int destX, int destY, int srcX, int srcY, int areaW, int areaH)Description copied from interface:Renderer
Modifies the given Texture with the given Image. The image will be put at x and y into the texture. NOTE: this is only supported for uncompressed 2D images without mipmaps.- Specified by:
modifyTexture
in interfaceRenderer
- Parameters:
tex
- the Texture that will be modifiedpixels
- the source Image data to copy data fromx
- the x position to put the image into the texturey
- the y position to put the image into the texture
-
modifyTexture
public void modifyTexture(Texture2D dest, Image src, int destX, int destY, int srcX, int srcY, int areaW, int areaH) Copy a part of an image to a texture 2d.- Parameters:
dest
- The destination image, where the source will be copiedsrc
- The source image that contains the data to copydestX
- First pixel of the destination image from where the src image will be drawn (x component)destY
- First pixel of the destination image from where the src image will be drawn (y component)srcX
- First pixel to copy (x component)srcY
- First pixel to copy (y component)areaW
- Width of the area to copyareaH
- Height of the area to copy
-
deleteImage
Description copied from interface:Renderer
Deletes a texture from the GPU.- Specified by:
deleteImage
in interfaceRenderer
- Parameters:
image
- the texture to delete
-
updateBufferData
Description copied from interface:Renderer
Uploads a vertex buffer to the GPU.- Specified by:
updateBufferData
in interfaceRenderer
- Parameters:
vb
- The vertex buffer to upload
-
updateShaderStorageBufferObjectData
Description copied from interface:Renderer
Uploads data of the buffer object on the GPU.- Specified by:
updateShaderStorageBufferObjectData
in interfaceRenderer
- Parameters:
bo
- the buffer object to upload.
-
updateUniformBufferObjectData
Description copied from interface:Renderer
Uploads data of the buffer object on the GPU.- Specified by:
updateUniformBufferObjectData
in interfaceRenderer
- Parameters:
bo
- the buffer object to upload.
-
deleteBuffer
Description copied from interface:Renderer
Deletes a vertex buffer from the GPU.- Specified by:
deleteBuffer
in interfaceRenderer
- Parameters:
vb
- The vertex buffer to delete
-
deleteBuffer
Description copied from interface:Renderer
Deletes the buffer object from the GPU.- Specified by:
deleteBuffer
in interfaceRenderer
- Parameters:
bo
- the buffer object to delete.
-
clearVertexAttribs
public void clearVertexAttribs() -
setVertexAttrib
-
setVertexAttrib
-
drawTriangleArray
-
drawTriangleList
-
convertElementMode
Convert a mesh mode to the corresponding GL value.- Parameters:
mode
- input enum value (not null)- Returns:
- the corresponding GL value
-
updateVertexArray
-
renderMesh
Description copied from interface:Renderer
Renderscount
meshes, with the geometry data supplied and per-instance data supplied. The shader which is currently set withsetShader
is responsible for transforming the input vertices into clip space and shading it based on the given vertex attributes. The integer variable gl_InstanceID can be used to access the current instance of the mesh being rendered inside the vertex shader. If the instance data is non-null, then it is submitted as a per-instance vertex attribute to the shader.- Specified by:
renderMesh
in interfaceRenderer
- Parameters:
mesh
- The mesh to renderlod
- The LOD level to use, seeMesh.setLodLevels(com.jme3.scene.VertexBuffer[])
.count
- Number of mesh instances to renderinstanceData
- When count is greater than 1, these buffers provide the per-instance attributes.
-
setMainFrameBufferSrgb
public void setMainFrameBufferSrgb(boolean enableSrgb) Description copied from interface:Renderer
Specifies whether color values in the main framebuffer are in SRGB format.If enabled, color values rendered to the main framebuffer undergo linear -> sRGB conversion.
This is identical to
FrameBuffer.setSrgb(boolean)
except it is toggled for the main framebuffer instead of an offscreen buffer.This should be set together with
Renderer.setLinearizeSrgbImages(boolean)
As a shorthand, the user can set
AppSettings.setGammaCorrection(boolean)
to true to toggle bothRenderer.setLinearizeSrgbImages(boolean)
andRenderer.setMainFrameBufferSrgb(boolean)
if theCaps.Srgb
is supported by the GPU.- Specified by:
setMainFrameBufferSrgb
in interfaceRenderer
- Parameters:
enableSrgb
- true for sRGB colorspace, false for linear colorspace- See Also:
-
setLinearizeSrgbImages
public void setLinearizeSrgbImages(boolean linearize) Description copied from interface:Renderer
If enabled, allimages
with thesRGB flag
set shall undergo an sRGB to linear RGB color conversion when read by a shader.The conversion is performed for the following formats: -
Image.Format.RGB8
-Image.Format.RGBA8
-Image.Format.Luminance8
-Image.Format.Luminance8Alpha8
-Image.Format.DXT1
-Image.Format.DXT1A
-Image.Format.DXT3
-Image.Format.DXT5
For all other formats, no conversion is performed.
If this option is toggled at runtime, textures must be reloaded for the change to take effect.
- Specified by:
setLinearizeSrgbImages
in interfaceRenderer
- Parameters:
linearize
- If sRGB images undergo sRGB -> linear conversion prior to rendering.- See Also:
-
generateProfilingTasks
public int[] generateProfilingTasks(int numTasks) Description copied from interface:Renderer
Generates a pool of gpu queries meant to use as profiling tasks.- Specified by:
generateProfilingTasks
in interfaceRenderer
- Parameters:
numTasks
- the number of task ids to generate- Returns:
- an array of tasks ids.
-
startProfiling
public void startProfiling(int taskId) Description copied from interface:Renderer
Starts a time profiling task on the GPU. This will profile all operations called between startProfiling and stopProfiling- Specified by:
startProfiling
in interfaceRenderer
- Parameters:
taskId
- the id of the task to start profiling.
-
stopProfiling
public void stopProfiling()Description copied from interface:Renderer
Will stop the last profiling task started with startProfiling.- Specified by:
stopProfiling
in interfaceRenderer
-
getProfilingTime
public long getProfilingTime(int taskId) Description copied from interface:Renderer
Returns the time in nanoseconds elapsed for the task with the given id. Note that the result may not be available right after stopProfiling has been called. You need to check if the result is available with isTaskResultAvailable. Also note that it's guaranteed that the result will be available on next frame. If you use getProfilingTime on the next frame you called stopProfiling, you don't need to check the result availability with isTaskResultAvailable- Specified by:
getProfilingTime
in interfaceRenderer
- Parameters:
taskId
- the id of the task given by startProfiling.- Returns:
- the time in nanosecond of the profiling task with the given id.
-
isTaskResultAvailable
public boolean isTaskResultAvailable(int taskId) Description copied from interface:Renderer
Checks if the profiling results are available.- Specified by:
isTaskResultAvailable
in interfaceRenderer
- Parameters:
taskId
- the id of the task provided by startProfiling- Returns:
- true if the results of the task with the given task id are available.
-
getAlphaToCoverage
public boolean getAlphaToCoverage()Description copied from interface:Renderer
Gets the alpha to coverage state.- Specified by:
getAlphaToCoverage
in interfaceRenderer
- Returns:
- true if alpha coverage is enabled, otherwise false
-
getDefaultAnisotropicFilter
public int getDefaultAnisotropicFilter()Description copied from interface:Renderer
Gets the default anisotropic filter level for textures.- Specified by:
getDefaultAnisotropicFilter
in interfaceRenderer
- Returns:
- the default filter level
-
getMaxLineWidth
public float getMaxLineWidth()Determine the maximum allowed width for lines.- Specified by:
getMaxLineWidth
in interfaceRenderer
- Returns:
- the maximum width (in pixels)
-
isLinearizeSrgbImages
public boolean isLinearizeSrgbImages()Test whether images with the sRGB flag will be linearized when read by a shader.- Specified by:
isLinearizeSrgbImages
in interfaceRenderer
- Returns:
- true for linearization, false for no linearization
-
isMainFrameBufferSrgb
public boolean isMainFrameBufferSrgb()Test whether colors rendered to the main framebuffer undergo linear-to-sRGB conversion.- Specified by:
isMainFrameBufferSrgb
in interfaceRenderer
- Returns:
- true for conversion, false for no conversion
-