mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
added texture wrapping to the API
This commit is contained in:
@@ -782,7 +782,7 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
final boolean supportsGLES2 = configurationInfo.reqGlEsVersion >= 0x20000;
|
||||
|
||||
if (!supportsGLES2) {
|
||||
throw new RuntimeException("P3D: OpenGL ES 2.0 is not supported by this device.");
|
||||
throw new RuntimeException("OpenGL ES 2.0 is not supported by this device.");
|
||||
}
|
||||
|
||||
surfaceHolder = getHolder();
|
||||
@@ -7329,6 +7329,11 @@ public class PApplet extends Activity implements PConstants, Runnable {
|
||||
}
|
||||
|
||||
|
||||
public void textureWrap(int wrap) {
|
||||
g.textureWrap(wrap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set texture image for current shape.
|
||||
* Needs to be called between @see beginShape and @see endShape
|
||||
|
||||
@@ -346,6 +346,14 @@ public interface PConstants {
|
||||
static final int IMAGE = 2;
|
||||
|
||||
|
||||
// texture wrapping modes
|
||||
|
||||
/** textures are clamped to their edges */
|
||||
public static final int CLAMP = 0;
|
||||
/** textures wrap around when uv values go outside 0..1 range */
|
||||
public static final int REPEAT = 1;
|
||||
|
||||
|
||||
// text placement modes
|
||||
|
||||
/**
|
||||
|
||||
@@ -942,6 +942,11 @@ public class PGraphics extends PImage implements PConstants {
|
||||
this.textureMode = mode;
|
||||
}
|
||||
|
||||
|
||||
public void textureWrap(int wrap) {
|
||||
showMissingWarning("textureWrap");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set texture image for current shape.
|
||||
|
||||
@@ -306,8 +306,8 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
|
||||
// Texturing:
|
||||
|
||||
public int textureWrap = Texture.CLAMP;
|
||||
public int textureSampling = Texture.TRILINEAR;
|
||||
protected int textureWrap = CLAMP;
|
||||
protected int textureSampling = Texture.TRILINEAR;
|
||||
|
||||
// ........................................................
|
||||
|
||||
@@ -5538,6 +5538,9 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
if (tex.hasBuffers()) {
|
||||
tex.bufferUpdate();
|
||||
}
|
||||
|
||||
checkTexture(tex);
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
@@ -5595,6 +5598,26 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
}
|
||||
|
||||
|
||||
protected void checkTexture(Texture tex) {
|
||||
if (tex.usingMipmaps == hints[DISABLE_TEXTURE_MIPMAPS]) {
|
||||
if (hints[DISABLE_TEXTURE_MIPMAPS]) {
|
||||
tex.usingMipmaps(false, textureSampling);
|
||||
} else {
|
||||
tex.usingMipmaps(true, textureSampling);
|
||||
}
|
||||
}
|
||||
|
||||
if ((tex.usingRepeat && textureWrap == CLAMP) ||
|
||||
(!tex.usingRepeat && textureWrap == REPEAT)) {
|
||||
if (textureWrap == CLAMP) {
|
||||
tex.usingRepeat(false);
|
||||
} else {
|
||||
tex.usingRepeat(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected PImage wrapTexture(Texture tex) {
|
||||
// We don't use the PImage(int width, int height, int mode) constructor to
|
||||
// avoid initializing the pixels array.
|
||||
|
||||
@@ -63,11 +63,6 @@ public class Texture implements PConstants {
|
||||
* interpolation to compute the value in each of two maps and then interpolates linearly
|
||||
* between these two value. */
|
||||
public static final int TRILINEAR = 5;
|
||||
|
||||
/** This constant identifies the clamp-to-edge wrapping mode */
|
||||
public static final int CLAMP = 0;
|
||||
/** This constant identifies the repeat wrapping mode */
|
||||
public static final int REPEAT = 1;
|
||||
|
||||
public int width, height;
|
||||
|
||||
@@ -86,7 +81,8 @@ public class Texture implements PConstants {
|
||||
protected PGL pgl; // The interface between Processing and OpenGL.
|
||||
protected PGL.Context context; // The context that created this texture.
|
||||
|
||||
protected boolean usingMipmaps;
|
||||
protected boolean usingMipmaps;
|
||||
protected boolean usingRepeat;
|
||||
protected float maxTexcoordU;
|
||||
protected float maxTexcoordV;
|
||||
protected boolean bound;
|
||||
@@ -527,7 +523,8 @@ public class Texture implements PConstants {
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
// Get OpenGL parameters
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns true or false whether or not the texture is using mipmaps.
|
||||
* @return boolean
|
||||
@@ -535,6 +532,76 @@ public class Texture implements PConstants {
|
||||
public boolean usingMipmaps() {
|
||||
return usingMipmaps;
|
||||
}
|
||||
|
||||
|
||||
public void usingMipmaps(boolean mipmaps, int sampling) {
|
||||
if (mipmaps) {
|
||||
if (glMinFilter != PGL.LINEAR_MIPMAP_NEAREST && glMinFilter != PGL.LINEAR_MIPMAP_LINEAR) {
|
||||
if (sampling == POINT) {
|
||||
glMagFilter = PGL.NEAREST;
|
||||
glMinFilter = PGL.NEAREST;
|
||||
} else if (sampling == LINEAR) {
|
||||
glMagFilter = PGL.NEAREST;
|
||||
glMinFilter = PGL.MIPMAPS_ENABLED ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
|
||||
} else if (sampling == BILINEAR) {
|
||||
glMagFilter = PGL.LINEAR;
|
||||
glMinFilter = PGL.MIPMAPS_ENABLED ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
|
||||
} else if (sampling == TRILINEAR) {
|
||||
glMagFilter = PGL.LINEAR;
|
||||
glMinFilter = PGL.MIPMAPS_ENABLED ? PGL.LINEAR_MIPMAP_LINEAR : PGL.LINEAR;
|
||||
} else {
|
||||
throw new RuntimeException("Unknown texture filtering mode");
|
||||
}
|
||||
}
|
||||
|
||||
usingMipmaps = true;
|
||||
} else {
|
||||
if (glMinFilter == PGL.LINEAR_MIPMAP_NEAREST || glMinFilter == PGL.LINEAR_MIPMAP_LINEAR) {
|
||||
glMinFilter = PGL.LINEAR;
|
||||
}
|
||||
usingMipmaps = false;
|
||||
}
|
||||
|
||||
bind();
|
||||
pgl.texParameteri(glTarget, PGL.TEXTURE_MIN_FILTER, glMinFilter);
|
||||
pgl.texParameteri(glTarget, PGL.TEXTURE_MAG_FILTER, glMagFilter);
|
||||
if (usingMipmaps) {
|
||||
if (PGraphicsOpenGL.autoMipmapGenSupported) {
|
||||
pgl.generateMipmap(glTarget);
|
||||
} else {
|
||||
// TODO: need manual generation here..
|
||||
}
|
||||
}
|
||||
unbind();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true or false whether or not the texture is using repeat wrap mode
|
||||
* along either U or V directions.
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean usingRepeat() {
|
||||
return usingRepeat;
|
||||
}
|
||||
|
||||
|
||||
public void usingRepeat(boolean repeat) {
|
||||
if (repeat) {
|
||||
glWrapS = PGL.REPEAT;
|
||||
glWrapT = PGL.REPEAT;
|
||||
usingRepeat = true;
|
||||
} else {
|
||||
glWrapS = PGL.CLAMP_TO_EDGE;
|
||||
glWrapT = PGL.CLAMP_TO_EDGE;
|
||||
usingRepeat = false;
|
||||
}
|
||||
|
||||
bind();
|
||||
pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_S, glWrapS);
|
||||
pgl.texParameteri(glTarget, PGL.TEXTURE_WRAP_T, glWrapT);
|
||||
unbind();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -1225,7 +1292,8 @@ public class Texture implements PConstants {
|
||||
glWidth= src.glWidth;
|
||||
glHeight = src.glHeight;
|
||||
|
||||
usingMipmaps = src.usingMipmaps;
|
||||
usingMipmaps = src.usingMipmaps;
|
||||
usingRepeat = src.usingRepeat;
|
||||
maxTexcoordU = src.maxTexcoordU;
|
||||
maxTexcoordV = src.maxTexcoordV;
|
||||
|
||||
@@ -1347,6 +1415,8 @@ public class Texture implements PConstants {
|
||||
usingMipmaps = glMinFilter == PGL.LINEAR_MIPMAP_NEAREST ||
|
||||
glMinFilter == PGL.LINEAR_MIPMAP_LINEAR;
|
||||
|
||||
usingRepeat = glWrapS == PGL.REPEAT || glWrapT == PGL.REPEAT;
|
||||
|
||||
flippedX = false;
|
||||
flippedY = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user