Constructor and Description |
---|
GLRenderer(GL gl,
GLExt glext,
GLFbo glfbo) |
Modifier and Type | Method and Description |
---|---|
void |
applyRenderState(RenderState state)
Applies the given
RenderState , making the necessary
GL calls so that the state is applied. |
protected void |
bindProgram(Shader shader) |
void |
cleanup()
Deletes all previously used
Native 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 |
clearClipRect()
Clears the clipping rectangle set with
Renderer.setClipRect(int, int, int, int) . |
void |
clearVertexAttribs() |
int |
convertElementMode(Mesh.Mode mode)
Convert a mesh mode to the corresponding GL value.
|
int |
convertShaderType(Shader.ShaderType type) |
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 |
deleteBuffer(BufferObject bo)
Deletes the buffer object from the GPU.
|
void |
deleteBuffer(VertexBuffer vb)
Deletes a vertex buffer from the GPU.
|
void |
deleteFrameBuffer(FrameBuffer fb)
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 |
deleteShaderSource(Shader.ShaderSource source)
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(java.lang.String version) |
int[] |
generateProfilingTasks(int numTasks)
Generates a pool of gpu queries meant to use as profiling tasks.
|
boolean |
getAlphaToCoverage()
Gets the alpha to coverage state.
|
java.util.EnumSet<Caps> |
getCaps()
Gets the capabilities of the renderer.
|
int |
getDefaultAnisotropicFilter()
Gets the default anisotropic filter level for textures.
|
Vector2f[] |
getFrameBufferSamplePositions(FrameBuffer fb) |
java.util.EnumMap<Limits,java.lang.Integer> |
getLimits()
Gets the limits of the renderer.
|
float |
getMaxLineWidth()
Determine the maximum allowed width for lines.
|
long |
getProfilingTime(int taskId)
Returns the time in nanoseconds elapsed for the task with the given id.
|
Statistics |
getStatistics()
Copies the render statistics.
|
void |
initialize()
Detects available capabilities of the GPU.
|
void |
invalidateState()
Invalidates the current rendering state.
|
boolean |
isLinearizeSrgbImages()
Test whether images with the sRGB flag will be linearized when read by a
shader.
|
boolean |
isMainFrameBufferSrgb()
Test whether colors rendered to the main framebuffer undergo
linear-to-sRGB conversion.
|
boolean |
isTaskResultAvailable(int taskId)
Checks if the profiling results are available.
|
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 |
popDebugGroup() |
void |
postFrame()
Called when a new frame has been rendered.
|
void |
pushDebugGroup(java.lang.String name) |
void |
readFrameBuffer(FrameBuffer fb,
java.nio.ByteBuffer byteBuf)
Reads the pixels currently stored in the specified framebuffer
into the given ByteBuffer object.
|
void |
readFrameBufferWithFormat(FrameBuffer fb,
java.nio.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)
Renders
count meshes, with the geometry data supplied and
per-instance data supplied. |
void |
resetGLObjects()
Resets all previously used
Native 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 |
setFrameBuffer(FrameBuffer fb)
Sets the framebuffer that will be drawn to.
|
void |
setGenerateMipmapsForFrameBuffer(boolean v)
Enable/Disable default automatic generation of mipmaps for framebuffers
|
void |
setLinearizeSrgbImages(boolean linearize)
|
void |
setMainFrameBufferOverride(FrameBuffer fb)
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 |
setReadDrawBuffers(FrameBuffer fb) |
void |
setShader(Shader shader)
Sets the shader to use for rendering.
|
void |
setTexture(int unit,
Texture tex)
Assigns a Texture to the specified texture unit.
|
void |
setVertexAttrib(VertexBuffer vb) |
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 |
stopProfiling()
Will stop the last profiling task started with startProfiling.
|
void |
updateBufferData(BufferObject bo)
Uploads data of the buffer object on the GPU.
|
void |
updateBufferData(VertexBuffer vb)
Uploads a vertex buffer to the GPU.
|
void |
updateFrameBuffer(FrameBuffer fb) |
void |
updateFrameBufferAttachment(FrameBuffer fb,
FrameBuffer.RenderBuffer rb) |
void |
updateRenderTexture(FrameBuffer fb,
FrameBuffer.RenderBuffer rb) |
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 |
updateShaderSourceData(Shader.ShaderSource source) |
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) |
protected void |
updateUniformLocation(Shader shader,
Uniform uniform)
Update the location of the specified Uniform in the specified Shader.
|
void |
updateVertexArray(Mesh mesh,
VertexBuffer instanceData) |
public void setGenerateMipmapsForFrameBuffer(boolean v)
v
- Default is truepublic void setDebugEnabled(boolean v)
public void popDebugGroup()
popDebugGroup
in interface Renderer
public void pushDebugGroup(java.lang.String name)
pushDebugGroup
in interface Renderer
public Statistics getStatistics()
Renderer
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.
getStatistics
in interface Renderer
public java.util.EnumSet<Caps> getCaps()
Renderer
public java.util.EnumMap<Limits,java.lang.Integer> getLimits()
Renderer
public static int extractVersion(java.lang.String version)
public void initialize()
Renderer
initialize
in interface Renderer
public void invalidateState()
Renderer
invalidateState
in interface Renderer
public void resetGLObjects()
Renderer
Native 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.resetGLObjects
in interface Renderer
NativeObject.resetObject()
public void cleanup()
Renderer
Native Objects
on this Renderer, and
then resets the native objects.cleanup
in interface Renderer
Renderer.resetGLObjects()
,
NativeObject.deleteObject(java.lang.Object)
public void setDepthRange(float start, float end)
setDepthRange
in interface Renderer
start
- The range startend
- The range endpublic void clearBuffers(boolean color, boolean depth, boolean stencil)
Renderer
clearBuffers
in interface Renderer
color
- True if to clear colors (RGBA)depth
- True if to clear depth/zstencil
- True if to clear stencil buffer (if available, otherwise
ignored)public void setBackgroundColor(ColorRGBA color)
Renderer
setBackgroundColor
in interface Renderer
color
- The background color to setpublic void setDefaultAnisotropicFilter(int level)
Renderer
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.
setDefaultAnisotropicFilter
in interface Renderer
level
- The default anisotropic filter level to use. Default: 1.public void setAlphaToCoverage(boolean value)
Renderer
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.
setAlphaToCoverage
in interface Renderer
value
- true to enable alpha coverage, otherwise falsepublic void applyRenderState(RenderState state)
Renderer
RenderState
, making the necessary
GL calls so that the state is applied.applyRenderState
in interface Renderer
state
- the RenderState to applypublic void setViewPort(int x, int y, int w, int h)
setViewPort
in interface Renderer
x
- The x coordinate of the viewporty
- The y coordinate of the viewportw
- Width of the viewporth
- Height of the viewportpublic void setClipRect(int x, int y, int width, int height)
Renderer
setClipRect
in interface Renderer
x
- The x coordinate of the clip recty
- The y coordinate of the clip rectwidth
- Width of the clip rectheight
- Height of the clip rectpublic void clearClipRect()
Renderer
Renderer.setClipRect(int, int, int, int)
.clearClipRect
in interface Renderer
public void postFrame()
Renderer
protected void bindProgram(Shader shader)
protected void updateUniformLocation(Shader shader, Uniform uniform)
shader
- the Shader containing the Uniform (not null)uniform
- the Uniform to update (not null)protected void updateShaderBufferBlock(Shader shader, ShaderBufferBlock bufferBlock)
shader
- the shader.bufferBlock
- the storage block.protected void updateShaderUniforms(Shader shader)
protected void updateShaderBufferBlocks(Shader shader)
shader
- the shader.protected void resetUniformLocations(Shader shader)
public int convertShaderType(Shader.ShaderType type)
public void updateShaderSourceData(Shader.ShaderSource source)
public void updateShaderData(Shader shader)
public void setShader(Shader shader)
Renderer
public void deleteShaderSource(Shader.ShaderSource source)
Renderer
deleteShaderSource
in interface Renderer
source
- The ShaderSource to delete.public void deleteShader(Shader shader)
Renderer
deleteShader
in interface Renderer
shader
- Shader to delete.Renderer.deleteShaderSource(com.jme3.shader.Shader.ShaderSource)
public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst)
src
- the source buffer (unaffected)dst
- the destination bufferpublic void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth)
Renderer
copyFrameBuffer
in interface Renderer
src
- the source FrameBuffer (unaffected)dst
- the destination FrameBuffer (modified)copyDepth
- true→copy depth info, false→don't copy itpublic void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyColor, boolean copyDepth)
Renderer
copyFrameBuffer
in interface Renderer
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 itpublic void updateRenderTexture(FrameBuffer fb, FrameBuffer.RenderBuffer rb)
public void updateFrameBufferAttachment(FrameBuffer fb, FrameBuffer.RenderBuffer rb)
public void updateFrameBuffer(FrameBuffer fb)
public Vector2f[] getFrameBufferSamplePositions(FrameBuffer fb)
public void setMainFrameBufferOverride(FrameBuffer fb)
Renderer
setMainFrameBufferOverride
in interface Renderer
fb
- The framebuffer to override the main framebuffer.public void setReadDrawBuffers(FrameBuffer fb)
public void setFrameBuffer(FrameBuffer fb)
Renderer
setFrameBuffer
in interface Renderer
fb
- The framebuffer to setpublic void readFrameBuffer(FrameBuffer fb, java.nio.ByteBuffer byteBuf)
Renderer
readFrameBuffer
in interface Renderer
fb
- The framebuffer to read frombyteBuf
- The bytebuffer to transfer color data topublic void readFrameBufferWithFormat(FrameBuffer fb, java.nio.ByteBuffer byteBuf, Image.Format format)
Renderer
readFrameBufferWithFormat
in interface Renderer
fb
- The framebuffer to read frombyteBuf
- The bytebuffer to transfer color data toformat
- the image format to use when reading the frameBuffer.public void deleteFrameBuffer(FrameBuffer fb)
Renderer
deleteFrameBuffer
in interface Renderer
fb
- the FrameBuffer to be deletedpublic void updateTexImageData(Image img, Texture.Type type, int unit, boolean scaleToPot)
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.public void setTexture(int unit, Texture tex) throws TextureUnitException
Renderer
setTexture
in interface Renderer
unit
- the index of the texture unit (≥0)tex
- the Texture to assignTextureUnitException
- if the texture unit doesn't exist@Deprecated public void modifyTexture(Texture tex, Image pixels, int x, int y)
Renderer
modifyTexture
in interface Renderer
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 texturepublic void modifyTexture(Texture2D dest, Image src, int destX, int destY, int srcX, int srcY, int areaW, int areaH)
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 copypublic void deleteImage(Image image)
Renderer
deleteImage
in interface Renderer
image
- the texture to deletepublic void updateBufferData(VertexBuffer vb)
Renderer
updateBufferData
in interface Renderer
vb
- The vertex buffer to uploadpublic void updateBufferData(BufferObject bo)
Renderer
updateBufferData
in interface Renderer
bo
- the buffer object to upload.public void deleteBuffer(VertexBuffer vb)
Renderer
deleteBuffer
in interface Renderer
vb
- The vertex buffer to deletepublic void deleteBuffer(BufferObject bo)
Renderer
deleteBuffer
in interface Renderer
bo
- the buffer object to delete.public void clearVertexAttribs()
public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb)
public void setVertexAttrib(VertexBuffer vb)
public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount)
public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count)
public int convertElementMode(Mesh.Mode mode)
mode
- input enum value (not null)public void updateVertexArray(Mesh mesh, VertexBuffer instanceData)
public void renderMesh(Mesh mesh, int lod, int count, VertexBuffer[] instanceData)
Renderer
count
meshes, with the geometry data supplied and
per-instance data supplied.
The shader which is currently set with setShader
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.renderMesh
in interface Renderer
mesh
- The mesh to renderlod
- The LOD level to use, see Mesh.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.public void setMainFrameBufferSrgb(boolean enableSrgb)
Renderer
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 both Renderer.setLinearizeSrgbImages(boolean)
and
Renderer.setMainFrameBufferSrgb(boolean)
if the
Caps.Srgb
is supported by the GPU.
setMainFrameBufferSrgb
in interface Renderer
enableSrgb
- true for sRGB colorspace, false for linear colorspaceFrameBuffer.setSrgb(boolean)
,
Caps.Srgb
public void setLinearizeSrgbImages(boolean linearize)
Renderer
images
with the
sRGB 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.
setLinearizeSrgbImages
in interface Renderer
linearize
- If sRGB images undergo sRGB -> linear conversion prior to rendering.Caps.Srgb
public int[] generateProfilingTasks(int numTasks)
Renderer
generateProfilingTasks
in interface Renderer
numTasks
- the number of task ids to generatepublic void startProfiling(int taskId)
Renderer
startProfiling
in interface Renderer
taskId
- the id of the task to start profiling.public void stopProfiling()
Renderer
stopProfiling
in interface Renderer
public long getProfilingTime(int taskId)
Renderer
getProfilingTime
in interface Renderer
taskId
- the id of the task given by startProfiling.public boolean isTaskResultAvailable(int taskId)
Renderer
isTaskResultAvailable
in interface Renderer
taskId
- the id of the task provided by startProfilingpublic boolean getAlphaToCoverage()
Renderer
getAlphaToCoverage
in interface Renderer
public int getDefaultAnisotropicFilter()
Renderer
getDefaultAnisotropicFilter
in interface Renderer
public float getMaxLineWidth()
getMaxLineWidth
in interface Renderer
public boolean isLinearizeSrgbImages()
isLinearizeSrgbImages
in interface Renderer
public boolean isMainFrameBufferSrgb()
isMainFrameBufferSrgb
in interface Renderer