28package com.jogamp.opengl.util.texture;
30import java.io.IOException;
31import java.net.URLConnection;
32import java.util.ArrayList;
35import com.jogamp.opengl.GL;
36import com.jogamp.opengl.GLException;
37import com.jogamp.opengl.GLProfile;
39import com.jogamp.common.util.IOUtil;
40import com.jogamp.math.Vec4f;
49 private final int textureUnit;
50 private final boolean useBuildInTexLookup;
52 private final int[] texMinMagFilter = {
GL.
GL_NEAREST, GL.GL_NEAREST };
54 private volatile int frameIdx = 0;
55 private volatile boolean manualStepping =
false;
56 private int textureFragmentShaderHashCode = 0;
57 private boolean aRatioAdjustment =
true;
58 private boolean aRatioLbox =
false;
59 private final Vec4f aRatioLboxBackColor =
new Vec4f();
61 public ImageSequence(
final int textureUnit,
final boolean useBuildInTexLookup) {
62 this.textureUnit = textureUnit;
63 this.useBuildInTexLookup = useBuildInTexLookup;
66 public void setParams(
final int magFilter,
final int minFilter,
final int wrapS,
final int wrapT) {
67 texMinMagFilter[0] = minFilter;
68 texMinMagFilter[1] = magFilter;
78 frame.texture.bind(gl);
86 return frames.remove(tex);
92 public final void addFrame(
final GL gl,
final Class<?> context,
final String imageResourcePath,
final String imageSuffix)
throws IOException {
93 final URLConnection urlConn = IOUtil.getResource(imageResourcePath, context.getClassLoader(), context);
103 public final void setCurrentIdx(
final int idx)
throws IndexOutOfBoundsException {
104 if( 0 > idx || idx >= frames.size() ) {
105 throw new IndexOutOfBoundsException(
"idx shall be within 0 <= "+idx+
" < "+frames.size());
114 public final TextureSequence.TextureFrame
getFrame(
final int idx) {
return frames.get(idx); }
117 for(
int i=frames.size()-1; i>=0; i--) {
118 frames.get(i).getTexture().destroy(gl);
135 return texMinMagFilter;
182 if(
null != backColor ) {
183 aRatioLboxBackColor.
set(backColor);
191 public TextureSequence.TextureFrame
getLastTexture() throws IllegalStateException {
192 return frames.get(frameIdx);
196 public TextureSequence.TextureFrame
getNextTexture(
final GL gl)
throws IllegalStateException {
197 if( !manualStepping ) {
198 frameIdx = ( frameIdx + 1 ) % frames.size();
200 return frames.get(frameIdx);
205 return "// TextTextureSequence: No extensions required\n";
213 private String textureLookupFunctionName =
"myTexture2D";
217 if(useBuildInTexLookup) {
218 textureLookupFunctionName =
"texture2D";
219 }
else if(
null != texLookupFuncName && texLookupFuncName.length()>0) {
220 textureLookupFunctionName = texLookupFuncName;
222 textureFragmentShaderHashCode = 0;
223 return textureLookupFunctionName;
228 return textureLookupFunctionName;
233 if(useBuildInTexLookup) {
239 " return texture2D(image, texCoord);\n"+
246 if( useBuildInTexLookup ) {
256 textureFragmentShaderHashCode = 0;
258 }
else if( 0 == textureFragmentShaderHashCode ) {
260 textureFragmentShaderHashCode = hash;
262 return textureFragmentShaderHashCode;
4D Vector based upon four float components.
Vec4f set(final Vec4f o)
this = o, returns this.
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
Specifies the the OpenGL profile.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Simple TextureSequence implementation allowing existing textures or image streams to be used and repl...
int getTextureTarget()
Returns the texture target used by implementation.
TextureSequence.TextureFrame getNextTexture(final GL gl)
Returns the next texture to be rendered.
String getRequiredExtensionsShaderStub()
In case a shader extension is required, based on the implementation and the runtime GL profile,...
final int getCurrentIdx()
final void addFrame(final GL gl, final Class<?> context, final String imageResourcePath, final String imageSuffix)
TextureSequence.TextureFrame getLastTexture()
Returns the last updated texture.
String getTextureLookupFragmentShaderImpl()
Returns the complete texture2D lookup function code of type.
void destroy(final GL gl)
Vec4f getARatioLetterboxBackColor()
Returns useARatioLetterbox() background color for added letter-box space, defaults to transparent zer...
final TextureSequence.TextureFrame addFrame(final GL gl, final Texture tex)
String getTextureSampler2DType()
Returns either sampler2D or samplerExternalOES depending on getLastTexture().
final boolean isSequenceAnimating()
Returns true if not isManualStepping() and getFrameCount() > 1.
String setTextureLookupFunctionName(final String texLookupFuncName)
Set the desired shader code's texture lookup function name.
boolean useARatioAdjustment()
Returning true indicates texture correction for aspect-ratio in the shader.Graph's Region shader will...
void setParams(final int magFilter, final int minFilter, final int wrapS, final int wrapT)
final TextureSequence.TextureFrame addFrame(final GL gl, final TextureSequence.TextureFrame frame)
void setARatioAdjustment(final boolean v)
Toggles useARatioLetterbox().Default value is implementation specific and toggling is optional....
boolean removeFrame(final TextureFrame tex)
int getTextureUnit()
Return the texture unit used to render the current frame.
int[] getTextureMinMagFilter()
final void setManualStepping(final boolean v)
void setARatioLetterbox(final boolean v, final Vec4f backColor)
Toggles useARatioLetterbox().Default value is implementation specific and toggling is optional....
final TextureSequence.TextureFrame getFrame(final int idx)
String getTextureLookupFunctionName()
Returns the chosen lookup function name, which can be set via setTextureLookupFunctionName(String).
final boolean isManualStepping()
final void setCurrentIdx(final int idx)
int getTextureFragmentShaderHashCode()
Returns the hash code of the string getTextureFragmentShaderHashID().
boolean useARatioLetterbox()
Returns whether useARatioAdjustment() shall add letter-box space to match aspect-ratio,...
ImageSequence(final int textureUnit, final boolean useBuildInTexLookup)
String getTextureFragmentShaderHashID()
Returns the concatenated string representing the following values utilized for getTextureFragmentShad...
final int getFrameCount()
boolean isTextureAvailable()
Returns true if texture source is ready and a texture is available via getNextTexture(GL) and getLast...
Represents the data for an OpenGL texture.
static TextureData newTextureData(final GLProfile glp, final File file, final boolean mipmap, String fileSuffix)
Creates a TextureData from the given file.
Texture holder interface, maybe specialized by implementation to associated related data.
Represents an OpenGL texture object.
void updateImage(final GL gl, final TextureData data)
Updates the entire content area incl.
static final int GL_TEXTURE_MAG_FILTER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_MAG_FILTER" w...
static final int GL_TEXTURE_2D
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_2D" with expr...
static final int GL_TEXTURE_WRAP_S
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_WRAP_S" with ...
static final int GL_TEXTURE_MIN_FILTER
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_MIN_FILTER" w...
static final int GL_TEXTURE_WRAP_T
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_TEXTURE_WRAP_T" with ...
void glTexParameteri(int target, int pname, int param)
Entry point to C language function: void {@native glTexParameteri}(GLenum target,...
static final int GL_NEAREST
GL_ES_VERSION_2_0, GL_VERSION_1_1, GL_VERSION_1_0, GL_VERSION_ES_1_0 Define "GL_NEAREST" with express...
static final int GL_CLAMP_TO_EDGE
GL_ES_VERSION_2_0, GL_VERSION_1_2, GL_VERSION_ES_1_0, GL_SGIS_texture_edge_clamp Alias for: GL_CLAMP_...
Protocol for texture sequences, like animations, movies, etc.