APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.prism.es2

public Class ES2Shader

extends BaseGraphicsResource
implements Shader
Class Inheritance
All Implemented Interfaces
com.sun.prism.ps.Shader, com.sun.prism.GraphicsResource
Imports
com.sun.prism.impl.BaseGraphicsResource, .Disposer, com.sun.prism.ps.Shader, java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, java.nio.FloatBuffer, .IntBuffer, java.util.Arrays, .HashMap, .Map

Represents an OpenGL shader program object, which can be constructed from the source code for a vertex shader, a fragment shader, or both. Contains convenience methods for enabling/disabling shader state.

Usage example:

    String source =
        "uniform sampler2D myTex;" +
        "void main(void)" +
        "{" +
        "    vec4 src = texture2D(myTex, gl_TexCoord[0].st);" +
        "    gl_FragColor = src.bgra;" + // swizzle!
        "}";
    ES2Shader shader = new ES2Shader(source);
    shader.setConstant("myTex", 0); // myTex will be on texture unit 0
    ...
    shader.enable();
    texture.enable();
    texture.bind();
    ...
    texture.disable();
    shader.disable();
};

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final ES2Context
private float[]
private final boolean
private final int
private int
programID

The handle to the OpenGL shader program object.

private final Map<String, ES2Shader.Uniform>
private boolean
Inherited from com.sun.prism.impl.BaseGraphicsResource:
disposerRecord

Constructor Summary

AccessConstructor and Description
private
ES2Shader(ES2Context context, int programID, int vertexShaderID, int[] fragmentShaderID, Map<String, Integer> samplers, int maxTexCoordIndex, boolean isPixcoordUsed)

Method Summary

Modifier and TypeMethod and Description
pack-priv static ES2Shader
createFromSource(ES2Context context, String vert, String[] frag, Map<String, Integer> samplers, Map<String, Integer> attributes, int maxTexCoordIndex, boolean isPixcoordUsed)

pack-priv static ES2Shader
createFromSource(ES2Context context, String vert, InputStream frag, Map<String, Integer> samplers, Map<String, Integer> attributes, int maxTexCoordIndex, boolean isPixcoordUsed)

public void
disable()

Implements com.sun.prism.ps.Shader.disable.

Disables this shader program in the current GL context's state.

public void
dispose()

Implements abstract com.sun.prism.impl.BaseGraphicsResource.dispose.

Implements com.sun.prism.GraphicsResource.dispose.

Disposes the native resources used by this program object.

public void
enable()

Implements com.sun.prism.ps.Shader.enable.

Enables this shader program in the current GL context's state.

public int

Returns:

the maximum texcoord index referenced by this shader program
getMaxTexCoordIndex
()

Returns the maximum texcoord index referenced by this shader program.

public int

Returns:

the OpenGL program object handle for this fragment shader
getProgramObject
()

Returns the underlying OpenGL program object handle for this fragment shader.

private ES2Shader.Uniform
public boolean

Returns:

true if this shader uses the special pixcoord variable
isPixcoordUsed
()

Returns true if this shader uses the special pixcoord variable, otherwise returns false

public boolean
isValid()

Implements com.sun.prism.ps.Shader.isValid.

Returns whether this shader is valid and can be used for rendering.

pack-priv static String
public void
setConstant(String
the name of the uniform variable to be set
name
,
int
the first uniform parameter
i0
)

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided integer value.

public void
setConstant(String
the name of the uniform variable to be set
name
,
int
the first uniform parameter
i0
,
int
the second uniform parameter
i1
)

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided integer values.

public void
setConstant(String
the name of the uniform variable to be set
name
,
int
the first uniform parameter
i0
,
int
the second uniform parameter
i1
,
int
the third uniform parameter
i2
)

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided integer values.

public void
setConstant(String
the name of the uniform variable to be set
name
,
int
the first uniform parameter
i0
,
int
the second uniform parameter
i1
,
int
the third uniform parameter
i2
,
int
the fourth uniform parameter
i3
)

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided integer values.

public void
setConstant(String
the name of the uniform variable to be set
name
,
float
the first uniform parameter
f0
)

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided float value.

public void
setConstant(String
the name of the uniform variable to be set
name
,
float
the first uniform parameter
f0
,
float
the second uniform parameter
f1
)

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided float values.

public void
setConstant(String
the name of the uniform variable to be set
name
,
float
the first uniform parameter
f0
,
float
the second uniform parameter
f1
,
float
the third uniform parameter
f2
)

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided float values.

public void
setConstant(String
the name of the uniform variable to be set
name
,
float
the first uniform parameter
f0
,
float
the second uniform parameter
f1
,
float
the third uniform parameter
f2
,
float
the fourth uniform parameter
f3
)

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided float values.

public void
setConstants(String
the name of the uniform variable to be set
name
,
IntBuffer
the array values to be set
buf
,
int
the offset into the vals array
off
,
int
the number of ivec4 elements in the array
count
)

Implements com.sun.prism.ps.Shader.setConstants.

Sets the uniform array variable of the given name with the provided int array values.

public void
setConstants(String
the name of the uniform variable to be set
name
,
FloatBuffer
the array values to be set
buf
,
int
the offset into the vals array
off
,
int
the number of vec4 elements in the array
count
)

Implements com.sun.prism.ps.Shader.setConstants.

Sets the uniform array variable of the given name with the provided float array values.

public void
setMatrix(String
the name of the uniform variable to be set
name
,
float[]
the matrix values to be set
buf
)

Sets the uniform matrix variable of the given name with the provided float array values.

Field Detail

contextback to summary
private final ES2Context context
currentMatrixback to summary
private float[] currentMatrix
isPixcoordUsedback to summary
private final boolean isPixcoordUsed
maxTexCoordIndexback to summary
private final int maxTexCoordIndex
programIDback to summary
private int programID

The handle to the OpenGL shader program object.

uniformsback to summary
private final Map<String, ES2Shader.Uniform> uniforms
validback to summary
private boolean valid

Constructor Detail

ES2Shaderback to summary
private ES2Shader(ES2Context context, int programID, int vertexShaderID, int[] fragmentShaderID, Map<String, Integer> samplers, int maxTexCoordIndex, boolean isPixcoordUsed) throws RuntimeException

Method Detail

createFromSourceback to summary
pack-priv static ES2Shader createFromSource(ES2Context context, String vert, String[] frag, Map<String, Integer> samplers, Map<String, Integer> attributes, int maxTexCoordIndex, boolean isPixcoordUsed)
createFromSourceback to summary
pack-priv static ES2Shader createFromSource(ES2Context context, String vert, InputStream frag, Map<String, Integer> samplers, Map<String, Integer> attributes, int maxTexCoordIndex, boolean isPixcoordUsed)
disableback to summary
public void disable() throws RuntimeException

Implements com.sun.prism.ps.Shader.disable.

Disables this shader program in the current GL context's state.

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
disposeback to summary
public void dispose() throws RuntimeException

Implements abstract com.sun.prism.impl.BaseGraphicsResource.dispose.

Implements com.sun.prism.GraphicsResource.dispose.

Disposes the native resources used by this program object.

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
enableback to summary
public void enable() throws RuntimeException

Implements com.sun.prism.ps.Shader.enable.

Enables this shader program in the current GL context's state.

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
getMaxTexCoordIndexback to summary
public int getMaxTexCoordIndex()

Returns the maximum texcoord index referenced by this shader program.

Returns:int

the maximum texcoord index referenced by this shader program

getProgramObjectback to summary
public int getProgramObject()

Returns the underlying OpenGL program object handle for this fragment shader. Most applications will not need to access this, since it is handled automatically by the enable() and dispose() methods.

Returns:int

the OpenGL program object handle for this fragment shader

getUniformback to summary
private ES2Shader.Uniform getUniform(String name)
isPixcoordUsedback to summary
public boolean isPixcoordUsed()

Returns true if this shader uses the special pixcoord variable, otherwise returns false

Returns:boolean

true if this shader uses the special pixcoord variable

isValidback to summary
public boolean isValid()

Implements com.sun.prism.ps.Shader.isValid.

Doc from com.sun.prism.ps.Shader.isValid.

Returns whether this shader is valid and can be used for rendering. Called on the rendering thread.

Annotations
@Override
readStreamIntoStringback to summary
pack-priv static String readStreamIntoString(InputStream in)
setConstantback to summary
public void setConstant(String name, int i0) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided integer value.

Parameters
name:String

the name of the uniform variable to be set

i0:int

the first uniform parameter

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantback to summary
public void setConstant(String name, int i0, int i1) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided integer values.

Parameters
name:String

the name of the uniform variable to be set

i0:int

the first uniform parameter

i1:int

the second uniform parameter

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantback to summary
public void setConstant(String name, int i0, int i1, int i2) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided integer values.

Parameters
name:String

the name of the uniform variable to be set

i0:int

the first uniform parameter

i1:int

the second uniform parameter

i2:int

the third uniform parameter

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantback to summary
public void setConstant(String name, int i0, int i1, int i2, int i3) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided integer values.

Parameters
name:String

the name of the uniform variable to be set

i0:int

the first uniform parameter

i1:int

the second uniform parameter

i2:int

the third uniform parameter

i3:int

the fourth uniform parameter

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantback to summary
public void setConstant(String name, float f0) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided float value.

Parameters
name:String

the name of the uniform variable to be set

f0:float

the first uniform parameter

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantback to summary
public void setConstant(String name, float f0, float f1) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided float values.

Parameters
name:String

the name of the uniform variable to be set

f0:float

the first uniform parameter

f1:float

the second uniform parameter

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantback to summary
public void setConstant(String name, float f0, float f1, float f2) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided float values.

Parameters
name:String

the name of the uniform variable to be set

f0:float

the first uniform parameter

f1:float

the second uniform parameter

f2:float

the third uniform parameter

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantback to summary
public void setConstant(String name, float f0, float f1, float f2, float f3) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstant.

Sets the uniform variable of the given name with the provided float values.

Parameters
name:String

the name of the uniform variable to be set

f0:float

the first uniform parameter

f1:float

the second uniform parameter

f2:float

the third uniform parameter

f3:float

the fourth uniform parameter

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantsback to summary
public void setConstants(String name, IntBuffer buf, int off, int count) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstants.

Sets the uniform array variable of the given name with the provided int array values.

Parameters
name:String

the name of the uniform variable to be set

buf:IntBuffer

the array values to be set

off:int

the offset into the vals array

count:int

the number of ivec4 elements in the array

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setConstantsback to summary
public void setConstants(String name, FloatBuffer buf, int off, int count) throws RuntimeException

Implements com.sun.prism.ps.Shader.setConstants.

Sets the uniform array variable of the given name with the provided float array values.

Parameters
name:String

the name of the uniform variable to be set

buf:FloatBuffer

the array values to be set

off:int

the offset into the vals array

count:int

the number of vec4 elements in the array

Annotations
@Override
Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
setMatrixback to summary
public void setMatrix(String name, float[] buf) throws RuntimeException

Sets the uniform matrix variable of the given name with the provided float array values.

Parameters
name:String

the name of the uniform variable to be set

buf:float[]

the matrix values to be set

Exceptions
RuntimeException:
if no OpenGL context was current or if any OpenGL-related errors occurred
com.sun.prism.es2 back to summary

private Class ES2Shader.ES2ShaderDisposerRecord

extends Object
implements Record
Class Inheritance
All Implemented Interfaces
com.sun.prism.impl.Disposer.Record

Field Summary

Modifier and TypeField and Description
private final ES2Context
private int[]
private int
private int

Constructor Summary

AccessConstructor and Description
private
ES2ShaderDisposerRecord(ES2Context context, int vertexShaderID, int[] fragmentShaderID, int programID)

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private final ES2Context context
fragmentShaderIDback to summary
private int[] fragmentShaderID
programIDback to summary
private int programID
vertexShaderIDback to summary
private int vertexShaderID

Constructor Detail

ES2ShaderDisposerRecordback to summary
private ES2ShaderDisposerRecord(ES2Context context, int vertexShaderID, int[] fragmentShaderID, int programID)

Method Detail

disposeback to summary
public void dispose()

Implements com.sun.prism.impl.Disposer.Record.dispose.

Annotations
@Override
com.sun.prism.es2 back to summary

private Class ES2Shader.Uniform

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private Object

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

locationback to summary
private int location
valuesback to summary
private Object values

Constructor Detail

Uniformback to summary
private Uniform()