Package processing.opengl
Class Texture
java.lang.Object
processing.opengl.Texture
- All Implemented Interfaces:
PConstants
This class wraps an OpenGL texture.
By Andres Colubri
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
This class stores a buffer copied from the buffer source.static class
This class stores the parameters for a texture: target, internal format, minimization filter and magnification filter. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
Bilinear sampling: both magnification filtering is set to linear and minification either to linear-mipmap-nearest (linear interpolation is used within a mipmap, but not between different mipmaps).protected boolean
protected LinkedList<Texture.BufferData>
protected Object
protected boolean
protected int
protected Method
protected IntBuffer
protected int[]
int
int
int
int
int
int
int
int
int
int
protected boolean
protected boolean
protected static final int
Linear sampling: magnification filtering is nearest, minification set to linearstatic final int
protected static final int
protected float
protected float
protected static final int
protected boolean
Modified portion of the textureprotected int
protected int
protected int
protected int
protected PGraphicsOpenGL
protected PGL
protected int
protected IntBuffer
protected static final int
Point sampling: both magnification and minification filtering are set to nearestprotected int[]
protected int
protected FrameBuffer
protected static final int
Texture with normalized UV.protected static final int
Texture with un-normalized UV.protected static final int
Trilinear sampling: magnification filtering set to linear, minification to linear-mipmap-linear, which offers the best mipmap quality since linear interpolation to compute the value in each of two maps and then interpolates linearly between these two values.protected LinkedList<Texture.BufferData>
protected boolean
protected boolean
int
Fields inherited from interface processing.core.PConstants
ADD, ALPHA, ALT, AMBIENT, ARC, ARGB, ARROW, BACKSPACE, BASELINE, BEVEL, BEZIER_VERTEX, BLEND, BLUR, BOTTOM, BOX, BREAK, BURN, CENTER, CHATTER, CHORD, CLAMP, CLOSE, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CURVE_VERTEX, CUSTOM, DARKEST, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ASYNC_SAVEFRAME, DISABLE_BUFFER_READING, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_KEY_REPEAT, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_OPTIMIZED_STROKE, DISABLE_STROKE_PERSPECTIVE, DISABLE_STROKE_PURE, DISABLE_TEXTURE_MIPMAPS, DODGE, DOWN, DXF, ELLIPSE, ENABLE_ASYNC_SAVEFRAME, ENABLE_BUFFER_READING, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_KEY_REPEAT, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_OPTIMIZED_STROKE, ENABLE_STROKE_PERSPECTIVE, ENABLE_STROKE_PURE, ENABLE_TEXTURE_MIPMAPS, ENTER, EPSILON, ERODE, ESC, EXCLUSION, FX2D, GIF, GRAY, GROUP, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LANDSCAPE, LEFT, LIGHTEST, LINE, LINE_LOOP, LINE_STRIP, LINES, LINUX, MACOS, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MODELVIEW, MOVE, MULTIPLY, NORMAL, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, PIE, platformNames, POINTS, POLYGON, PORTRAIT, POSTERIZE, PROBLEM, PROJECT, PROJECTION, QUAD, QUAD_BEZIER_VERTEX, QUAD_STRIP, QUADRATIC_VERTEX, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RECT, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SHAPE, SHIFT, SOFT_LIGHT, SPAN, SPHERE, SPOT, SQUARE, SUBTRACT, SVG, TAB, TARGA, TAU, TEXT, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, UP, VERTEX, WAIT, WHITESPACE, WINDOWS, X, Y, Z
-
Constructor Summary
ConstructorsConstructorDescriptionTexture
(PGraphicsOpenGL pg, int width, int height) Creates an instance of PTexture with size width x height.Texture
(PGraphicsOpenGL pg, int width, int height, Object params) Creates an instance of PTexture with size width x height and with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
allocate()
Allocates the opengl texture object.boolean
Returns true if the texture has been initialized.void
bind()
boolean
bound()
protected boolean
boolean
void
colorBuffer
(boolean value) protected boolean
protected void
convertToARGB
(int[] pixels) Reorders an OpenGL pixel array (RGBA) into ARGB.protected void
convertToRGBA
(int[] pixels, int format, int w, int h) Reorders a pixel array in the given format into the order required by OpenGL (RGBA) and stores it into rgbaPixels.void
copyBufferFromSource
(Object natRef, ByteBuffer byteBuf, int w, int h) protected void
copyObject
(Texture src) protected void
copyTexture
(int texTarget, int texName, int texWidth, int texHeight, int x, int y, int w, int h, boolean scale) protected void
copyTexture
(Texture tex, int x, int y, int w, int h, boolean scale) int
protected void
dispose()
Marks the texture object for deletion.void
protected void
fillEdges
(int x, int y, int w, int h) protected void
flipArrayOnX
(int[] intArray, int mult) Flips intArray along the X axis.protected void
flipArrayOnY
(int[] intArray, int mult) Flips intArray along the Y axis.void
get
(int[] pixels) Copy texture to pixels.void
getBufferPixels
(int[] pixels) int
int
int
int
protected void
boolean
boolean
void
init
(int width, int height) Sets the size of the image and texture to width x height.void
init
(int width, int height, int glName, int glTarget, int glFormat, int glWidth, int glHeight, int glMinFilter, int glMagFilter, int glWrapS, int glWrapT) Initializes the texture using GL parametersvoid
init
(int width, int height, Texture.Parameters params) Sets the size of the image and texture to width x height, and the parameters of the texture to params.boolean
Returns true if the texture is inverted along the horizontal direction.void
invertedX
(boolean v) Sets the texture as inverted or not along the horizontal direction.boolean
Returns true if the texture is inverted along the vertical direction.void
invertedY
(boolean v) Sets the texture as inverted or not along the vertical direction.boolean
protected void
loadPixels
(int len) protected void
float
Returns the maximum possible value for the texture coordinate U (horizontal).float
Returns the maximum possible value for the texture coordinate V (vertical).void
put
(int texTarget, int texName, int texWidth, int texHeight, int w, int h) void
put
(int texTarget, int texName, int texWidth, int texHeight, int target, int tex, int x, int y, int w, int h) void
void
protected void
protected void
void
resize
(int wide, int high) void
set
(int[] pixels) void
set
(int[] pixels, int format) void
set
(int[] pixels, int x, int y, int w, int h) void
set
(int[] pixels, int x, int y, int w, int h, int format) void
set
(int texTarget, int texName, int texWidth, int texHeight, int w, int h) void
set
(int texTarget, int texName, int texWidth, int texHeight, int target, int tex, int x, int y, int w, int h) void
void
void
setBufferSource
(Object source) void
void
setModified
(boolean m) void
setNative
(int[] pixels) void
setNative
(int[] pixels, int x, int y, int w, int h) void
protected void
setParameters
(Texture.Parameters params) Sets texture target and internal format according to the target and type specified.protected void
setSize
(int w, int h) void
unbind()
protected void
updatePixelBuffer
(int[] pixels) void
void
updateTexels
(int x, int y, int w, int h) protected void
updateTexelsImpl
(int x, int y, int w, int h) boolean
Returns true or false whether or not the texture is using mipmaps.void
usingMipmaps
(boolean mipmaps, int sampling) boolean
Returns true or false whether or not the texture is using repeat wrap mode along either U or V directions.void
usingRepeat
(boolean repeat)
-
Field Details
-
TEX2D
protected static final int TEX2DTexture with normalized UV.- See Also:
-
TEXRECT
protected static final int TEXRECTTexture with un-normalized UV.- See Also:
-
POINT
protected static final int POINTPoint sampling: both magnification and minification filtering are set to nearest- See Also:
-
LINEAR
protected static final int LINEARLinear sampling: magnification filtering is nearest, minification set to linear- See Also:
-
BILINEAR
protected static final int BILINEARBilinear sampling: both magnification filtering is set to linear and minification either to linear-mipmap-nearest (linear interpolation is used within a mipmap, but not between different mipmaps).- See Also:
-
TRILINEAR
protected static final int TRILINEARTrilinear sampling: magnification filtering set to linear, minification to linear-mipmap-linear, which offers the best mipmap quality since linear interpolation to compute the value in each of two maps and then interpolates linearly between these two values.- See Also:
-
MAX_UPDATES
protected static final int MAX_UPDATES- See Also:
-
MIN_MEMORY
protected static final int MIN_MEMORY- See Also:
-
width
public int width -
height
public int height -
glName
public int glName -
glTarget
public int glTarget -
glFormat
public int glFormat -
glMinFilter
public int glMinFilter -
glMagFilter
public int glMagFilter -
glWrapS
public int glWrapS -
glWrapT
public int glWrapT -
glWidth
public int glWidth -
glHeight
public int glHeight -
pg
-
pgl
-
context
protected int context -
colorBuffer
protected boolean colorBuffer -
usingMipmaps
protected boolean usingMipmaps -
usingRepeat
protected boolean usingRepeat -
maxTexcoordU
protected float maxTexcoordU -
maxTexcoordV
protected float maxTexcoordV -
bound
protected boolean bound -
invertedX
protected boolean invertedX -
invertedY
protected boolean invertedY -
rgbaPixels
protected int[] rgbaPixels -
pixelBuffer
-
edgePixels
protected int[] edgePixels -
edgeBuffer
-
tempFbo
-
pixBufUpdateCount
protected int pixBufUpdateCount -
rgbaPixUpdateCount
protected int rgbaPixUpdateCount -
modified
protected boolean modifiedModified portion of the texture -
mx1
protected int mx1 -
my1
protected int my1 -
mx2
protected int mx2 -
my2
protected int my2 -
bufferSource
-
bufferCache
-
usedBuffers
-
disposeBufferMethod
-
MAX_BUFFER_CACHE_SIZE
public static final int MAX_BUFFER_CACHE_SIZE- See Also:
-
-
Constructor Details
-
Texture
-
Texture
Creates an instance of PTexture with size width x height. The texture is initialized (empty) to that size.- Parameters:
width
- intheight
- int
-
Texture
Creates an instance of PTexture with size width x height and with the specified parameters. The texture is initialized (empty) to that size.- Parameters:
width
- intheight
- intparams
- Parameters
-
-
Method Details
-
init
public void init(int width, int height) Sets the size of the image and texture to width x height. If the texture is already initialized, it first destroys the current OpenGL texture object and then creates a new one with the specified size.- Parameters:
width
- intheight
- int
-
init
Sets the size of the image and texture to width x height, and the parameters of the texture to params. If the texture is already initialized, it first destroys the current OpenGL texture object and then creates a new one with the specified size.- Parameters:
width
- intheight
- intparams
- GLTextureParameters
-
init
public void init(int width, int height, int glName, int glTarget, int glFormat, int glWidth, int glHeight, int glMinFilter, int glMagFilter, int glWrapS, int glWrapT) Initializes the texture using GL parameters -
resize
public void resize(int wide, int high) -
available
public boolean available()Returns true if the texture has been initialized.- Returns:
- boolean
-
set
-
set
-
set
public void set(int texTarget, int texName, int texWidth, int texHeight, int w, int h) -
set
public void set(int texTarget, int texName, int texWidth, int texHeight, int target, int tex, int x, int y, int w, int h) -
set
public void set(int[] pixels) -
set
public void set(int[] pixels, int format) -
set
public void set(int[] pixels, int x, int y, int w, int h) -
set
public void set(int[] pixels, int x, int y, int w, int h, int format) -
setNative
public void setNative(int[] pixels) -
setNative
public void setNative(int[] pixels, int x, int y, int w, int h) -
setNative
-
get
public void get(int[] pixels) Copy texture to pixels. Involves video memory to main memory transfer (slow). -
put
-
put
-
put
public void put(int texTarget, int texName, int texWidth, int texHeight, int w, int h) -
put
public void put(int texTarget, int texName, int texWidth, int texHeight, int target, int tex, int x, int y, int w, int h) -
usingMipmaps
public boolean usingMipmaps()Returns true or false whether or not the texture is using mipmaps.- Returns:
- boolean
-
usingMipmaps
public void usingMipmaps(boolean mipmaps, int sampling) -
usingRepeat
public boolean usingRepeat()Returns true or false whether or not the texture is using repeat wrap mode along either U or V directions.- Returns:
- boolean
-
usingRepeat
public void usingRepeat(boolean repeat) -
maxTexcoordU
public float maxTexcoordU()Returns the maximum possible value for the texture coordinate U (horizontal).- Returns:
- float
-
maxTexcoordV
public float maxTexcoordV()Returns the maximum possible value for the texture coordinate V (vertical).- Returns:
- float
-
invertedX
public boolean invertedX()Returns true if the texture is inverted along the horizontal direction.- Returns:
- boolean;
-
invertedX
public void invertedX(boolean v) Sets the texture as inverted or not along the horizontal direction.- Parameters:
v
- boolean;
-
invertedY
public boolean invertedY()Returns true if the texture is inverted along the vertical direction.- Returns:
- boolean;
-
invertedY
public void invertedY(boolean v) Sets the texture as inverted or not along the vertical direction.- Parameters:
v
- boolean;
-
currentSampling
public int currentSampling() -
bind
public void bind() -
unbind
public void unbind() -
bound
public boolean bound() -
isModified
public boolean isModified() -
setModified
public void setModified() -
setModified
public void setModified(boolean m) -
getModifiedX1
public int getModifiedX1() -
getModifiedX2
public int getModifiedX2() -
getModifiedY1
public int getModifiedY1() -
getModifiedY2
public int getModifiedY2() -
updateTexels
public void updateTexels() -
updateTexels
public void updateTexels(int x, int y, int w, int h) -
updateTexelsImpl
protected void updateTexelsImpl(int x, int y, int w, int h) -
loadPixels
protected void loadPixels(int len) -
updatePixelBuffer
protected void updatePixelBuffer(int[] pixels) -
manualMipmap
protected void manualMipmap() -
setBufferSource
-
copyBufferFromSource
-
disposeSourceBuffer
public void disposeSourceBuffer() -
getBufferPixels
public void getBufferPixels(int[] pixels) -
hasBufferSource
public boolean hasBufferSource() -
hasBuffers
public boolean hasBuffers() -
bufferUpdate
protected boolean bufferUpdate() -
getSourceMethods
protected void getSourceMethods() -
flipArrayOnX
protected void flipArrayOnX(int[] intArray, int mult) Flips intArray along the X axis.- Parameters:
intArray
- int[]mult
- int
-
flipArrayOnY
protected void flipArrayOnY(int[] intArray, int mult) Flips intArray along the Y axis.- Parameters:
intArray
- int[]mult
- int
-
convertToRGBA
protected void convertToRGBA(int[] pixels, int format, int w, int h) Reorders a pixel array in the given format into the order required by OpenGL (RGBA) and stores it into rgbaPixels. The width and height parameters are used in the YUV420 to RBGBA conversion.- Parameters:
pixels
- int[]format
- intw
- inth
- int
-
convertToARGB
protected void convertToARGB(int[] pixels) Reorders an OpenGL pixel array (RGBA) into ARGB. The array must be of size width * height.- Parameters:
pixels
- int[]
-
setSize
protected void setSize(int w, int h) -
allocate
protected void allocate()Allocates the opengl texture object. -
dispose
protected void dispose()Marks the texture object for deletion. -
contextIsOutdated
protected boolean contextIsOutdated() -
colorBuffer
public void colorBuffer(boolean value) -
colorBuffer
public boolean colorBuffer() -
copyTexture
-
copyTexture
protected void copyTexture(int texTarget, int texName, int texWidth, int texHeight, int x, int y, int w, int h, boolean scale) -
copyObject
-
releasePixelBuffer
protected void releasePixelBuffer() -
releaseRGBAPixels
protected void releaseRGBAPixels() -
getParameters
-
setParameters
Sets texture target and internal format according to the target and type specified.- Parameters:
target
- intparams
- GLTextureParameters
-
fillEdges
protected void fillEdges(int x, int y, int w, int h)
-