mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
assuming npot texture support, auto mipmaps generation, etc, are part of
core gl profile when using gl3
This commit is contained in:
@@ -162,6 +162,7 @@ public abstract class PGL {
|
||||
protected static int tex2DShaderContext;
|
||||
protected static int tex2DVertLoc;
|
||||
protected static int tex2DTCoordLoc;
|
||||
protected static int tex2DSamplerLoc;
|
||||
|
||||
protected static boolean loadedTexRectShader = false;
|
||||
protected static int texRectShaderProgram;
|
||||
@@ -170,6 +171,7 @@ public abstract class PGL {
|
||||
protected static int texRectShaderContext;
|
||||
protected static int texRectVertLoc;
|
||||
protected static int texRectTCoordLoc;
|
||||
protected static int texRectSamplerLoc;
|
||||
|
||||
protected static float[] texCoords = {
|
||||
// X, Y, U, V
|
||||
@@ -209,7 +211,8 @@ public abstract class PGL {
|
||||
"uniform sampler2D textureSampler;\n" +
|
||||
"varying vec2 vertTexcoord;\n" +
|
||||
"void main() {\n" +
|
||||
" gl_FragColor = texture2D(textureSampler, vertTexcoord.st);\n" +
|
||||
" gl_FragColor = texture2D(textureSampler, vertTexcoord.st);\n" +
|
||||
// " gl_FragColor = vec4(vertTexcoord.st, 0, 1);\n" +
|
||||
"}\n",
|
||||
"#version 150\n" +
|
||||
SHADER_PREPROCESSOR_DIRECTIVE +
|
||||
@@ -217,7 +220,8 @@ public abstract class PGL {
|
||||
"in vec2 vertTexcoord;\n" +
|
||||
"out vec4 fragColor;\n" +
|
||||
"void main() {\n" +
|
||||
" fragColor = texture(textureSampler, vertTexcoord.st);\n" +
|
||||
// " fragColor = texture(textureSampler, vertTexcoord.st);\n" +
|
||||
" fragColor = vec4(vertTexcoord.st, 0, 1);\n" +
|
||||
"}\n"
|
||||
};
|
||||
|
||||
@@ -930,6 +934,7 @@ public abstract class PGL {
|
||||
if (0 < tex2DShaderProgram) {
|
||||
tex2DVertLoc = getAttribLocation(tex2DShaderProgram, "inVertex");
|
||||
tex2DTCoordLoc = getAttribLocation(tex2DShaderProgram, "inTexcoord");
|
||||
tex2DSamplerLoc = getUniformLocation(tex2DShaderProgram, "textureSampler");
|
||||
}
|
||||
loadedTex2DShader = true;
|
||||
tex2DShaderContext = glContext;
|
||||
@@ -999,16 +1004,15 @@ public abstract class PGL {
|
||||
enabledTex = true;
|
||||
}
|
||||
bindTexture(TEXTURE_2D, id);
|
||||
uniform1i(tex2DSamplerLoc, 0);
|
||||
|
||||
texData.position(0);
|
||||
bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO);
|
||||
bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW);
|
||||
|
||||
pg.report("HERE 1");
|
||||
vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0);
|
||||
vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT);
|
||||
|
||||
|
||||
// texData.position(0);
|
||||
// vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
|
||||
// texData);
|
||||
@@ -1018,7 +1022,6 @@ public abstract class PGL {
|
||||
// pg.report("HERE 2");
|
||||
|
||||
drawArrays(TRIANGLE_STRIP, 0, 4);
|
||||
pg.report("HERE 3");
|
||||
|
||||
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
|
||||
|
||||
@@ -1058,6 +1061,7 @@ public abstract class PGL {
|
||||
if (0 < texRectShaderProgram) {
|
||||
texRectVertLoc = getAttribLocation(texRectShaderProgram, "inVertex");
|
||||
texRectTCoordLoc = getAttribLocation(texRectShaderProgram, "inTexcoord");
|
||||
texRectSamplerLoc = getUniformLocation(texRectShaderProgram, "textureSampler");
|
||||
}
|
||||
loadedTexRectShader = true;
|
||||
texRectShaderContext = glContext;
|
||||
@@ -1127,12 +1131,13 @@ public abstract class PGL {
|
||||
enabledTex = true;
|
||||
}
|
||||
bindTexture(TEXTURE_RECTANGLE, id);
|
||||
uniform1i(texRectSamplerLoc, 0);
|
||||
|
||||
texData.position(0);
|
||||
bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO);
|
||||
bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW);
|
||||
|
||||
pg.report("HERE 1");
|
||||
// pg.report("HERE 1");
|
||||
vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0);
|
||||
vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT);
|
||||
|
||||
@@ -1634,6 +1639,61 @@ public abstract class PGL {
|
||||
}
|
||||
|
||||
|
||||
protected boolean hasNpotTexSupport() {
|
||||
int major = getGLVersion()[0];
|
||||
if (major < 3) {
|
||||
String ext = getString(EXTENSIONS);
|
||||
return -1 < ext.indexOf("_texture_non_power_of_two");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean hasAutoMipmapGenSupport() {
|
||||
int major = getGLVersion()[0];
|
||||
if (major < 3) {
|
||||
String ext = getString(EXTENSIONS);
|
||||
return -1 < ext.indexOf("_generate_mipmap");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean hasFboMultisampleSupport() {
|
||||
int major = getGLVersion()[0];
|
||||
if (major < 3) {
|
||||
String ext = getString(EXTENSIONS);
|
||||
return -1 < ext.indexOf("_framebuffer_multisample");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean hasPackedDepthStencilSupport() {
|
||||
int major = getGLVersion()[0];
|
||||
if (major < 3) {
|
||||
String ext = getString(EXTENSIONS);
|
||||
return -1 < ext.indexOf("_packed_depth_stencil");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected boolean hasAnisoSamplingSupport() {
|
||||
int major = getGLVersion()[0];
|
||||
if (major < 3) {
|
||||
String ext = getString(EXTENSIONS);
|
||||
return -1 < ext.indexOf("_texture_filter_anisotropic");
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected int maxSamples() {
|
||||
intBuffer.rewind();
|
||||
getIntegerv(MAX_SAMPLES, intBuffer);
|
||||
@@ -2140,6 +2200,9 @@ public abstract class PGL {
|
||||
public static int RGBA4;
|
||||
public static int RGB5_A1;
|
||||
public static int RGB565;
|
||||
public static int RGB8;
|
||||
public static int RGBA8;
|
||||
public static int ALPHA8;
|
||||
|
||||
public static int READ_ONLY;
|
||||
public static int WRITE_ONLY;
|
||||
@@ -2354,7 +2417,6 @@ public abstract class PGL {
|
||||
public static int READ_FRAMEBUFFER;
|
||||
public static int DRAW_FRAMEBUFFER;
|
||||
|
||||
public static int RGBA8;
|
||||
public static int DEPTH24_STENCIL8;
|
||||
|
||||
public static int DEPTH_COMPONENT;
|
||||
|
||||
@@ -6235,16 +6235,11 @@ public class PGraphicsOpenGL extends PGraphics {
|
||||
OPENGL_EXTENSIONS = pgl.getString(PGL.EXTENSIONS);
|
||||
GLSL_VERSION = pgl.getString(PGL.SHADING_LANGUAGE_VERSION);
|
||||
|
||||
npotTexSupported =
|
||||
-1 < OPENGL_EXTENSIONS.indexOf("_texture_non_power_of_two");
|
||||
autoMipmapGenSupported =
|
||||
-1 < OPENGL_EXTENSIONS.indexOf("_generate_mipmap");
|
||||
fboMultisampleSupported =
|
||||
-1 < OPENGL_EXTENSIONS.indexOf("_framebuffer_multisample");
|
||||
packedDepthStencilSupported =
|
||||
-1 < OPENGL_EXTENSIONS.indexOf("_packed_depth_stencil");
|
||||
anisoSamplingSupported =
|
||||
-1 < OPENGL_EXTENSIONS.indexOf("_texture_filter_anisotropic");
|
||||
npotTexSupported = pgl.hasNpotTexSupport();
|
||||
autoMipmapGenSupported = pgl.hasAutoMipmapGenSupport();
|
||||
fboMultisampleSupported = pgl.hasFboMultisampleSupport();
|
||||
packedDepthStencilSupported = pgl.hasPackedDepthStencilSupport();
|
||||
anisoSamplingSupported = pgl.hasAnisoSamplingSupport();
|
||||
|
||||
try {
|
||||
pgl.blendEquation(PGL.FUNC_ADD);
|
||||
|
||||
@@ -988,7 +988,7 @@ public class PJOGL extends PGL {
|
||||
|
||||
@Override
|
||||
protected void enableTexturing(int target) {
|
||||
//if (PROFILE == 2) enable(target);
|
||||
if (PROFILE == 2) enable(target);
|
||||
if (target == TEXTURE_2D) {
|
||||
texturingTargets[0] = true;
|
||||
} else if (target == TEXTURE_RECTANGLE) {
|
||||
@@ -999,7 +999,7 @@ public class PJOGL extends PGL {
|
||||
|
||||
@Override
|
||||
protected void disableTexturing(int target) {
|
||||
//if (PROFILE == 2) disable(target);
|
||||
if (PROFILE == 2) disable(target);
|
||||
if (target == TEXTURE_2D) {
|
||||
texturingTargets[0] = false;
|
||||
} else if (target == TEXTURE_RECTANGLE) {
|
||||
@@ -1042,6 +1042,7 @@ public class PJOGL extends PGL {
|
||||
protected String[] loadFragmentShader(URL url) {
|
||||
try {
|
||||
if (2 < PROFILE) {
|
||||
// if (false) {
|
||||
String[] fragSrc0 = PApplet.loadStrings(url.openStream());
|
||||
// PApplet.join(PApplet.loadStrings(url.openStream()), "\n");
|
||||
String[] fragSrc = new String[fragSrc0.length + 2];
|
||||
@@ -1076,6 +1077,7 @@ public class PJOGL extends PGL {
|
||||
protected String[] loadVertexShader(URL url) {
|
||||
try {
|
||||
if (2 < PROFILE) {
|
||||
// if (false) {
|
||||
String[] vertSrc0 = PApplet.loadStrings(url.openStream());
|
||||
String[] vertSrc = new String[vertSrc0.length + 1];
|
||||
vertSrc[0] = "#version 150";
|
||||
@@ -1271,6 +1273,9 @@ public class PJOGL extends PGL {
|
||||
RGBA4 = GL.GL_RGBA4;
|
||||
RGB5_A1 = GL.GL_RGB5_A1;
|
||||
RGB565 = GL.GL_RGB565;
|
||||
RGB8 = GL.GL_RGB8;
|
||||
RGBA8 = GL.GL_RGBA8;
|
||||
ALPHA8 = GL.GL_ALPHA8;
|
||||
|
||||
READ_ONLY = GL2GL3.GL_READ_ONLY;
|
||||
WRITE_ONLY = GL.GL_WRITE_ONLY;
|
||||
|
||||
@@ -36,8 +36,6 @@ import java.util.NoSuchElementException;
|
||||
*
|
||||
*/
|
||||
public class Texture implements PConstants {
|
||||
// texture constants
|
||||
|
||||
/**
|
||||
* Texture with normalized UV.
|
||||
*/
|
||||
@@ -1438,21 +1436,27 @@ public class Texture implements PConstants {
|
||||
throw new RuntimeException("Unknown texture format");
|
||||
}
|
||||
|
||||
boolean mipmaps = params.mipmaps && PGL.MIPMAPS_ENABLED;
|
||||
if (mipmaps && !PGraphicsOpenGL.autoMipmapGenSupported) {
|
||||
PGraphics.showWarning("Mipmaps were requested but automatic mipmap " +
|
||||
"generation is not supported and manual " +
|
||||
"generation still not implemented, so mipmaps " +
|
||||
"will be disabled.");
|
||||
mipmaps = false;
|
||||
}
|
||||
|
||||
if (params.sampling == POINT) {
|
||||
glMagFilter = PGL.NEAREST;
|
||||
glMinFilter = PGL.NEAREST;
|
||||
} else if (params.sampling == LINEAR) {
|
||||
glMagFilter = PGL.NEAREST;
|
||||
glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
|
||||
PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
|
||||
glMinFilter = mipmaps ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
|
||||
} else if (params.sampling == BILINEAR) {
|
||||
glMagFilter = PGL.LINEAR;
|
||||
glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
|
||||
PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
|
||||
glMinFilter = mipmaps ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
|
||||
} else if (params.sampling == TRILINEAR) {
|
||||
glMagFilter = PGL.LINEAR;
|
||||
glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
|
||||
PGL.LINEAR_MIPMAP_LINEAR : PGL.LINEAR;
|
||||
glMinFilter = mipmaps ? PGL.LINEAR_MIPMAP_LINEAR : PGL.LINEAR;
|
||||
} else {
|
||||
throw new RuntimeException("Unknown texture filtering mode");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user