Skip to content

Commit bad1a86

Browse files
committed
assuming npot texture support, auto mipmaps generation, etc, are part of
core gl profile when using gl3
1 parent 5a2967a commit bad1a86

4 files changed

Lines changed: 93 additions & 27 deletions

File tree

core/src/processing/opengl/PGL.java

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public abstract class PGL {
162162
protected static int tex2DShaderContext;
163163
protected static int tex2DVertLoc;
164164
protected static int tex2DTCoordLoc;
165+
protected static int tex2DSamplerLoc;
165166

166167
protected static boolean loadedTexRectShader = false;
167168
protected static int texRectShaderProgram;
@@ -170,6 +171,7 @@ public abstract class PGL {
170171
protected static int texRectShaderContext;
171172
protected static int texRectVertLoc;
172173
protected static int texRectTCoordLoc;
174+
protected static int texRectSamplerLoc;
173175

174176
protected static float[] texCoords = {
175177
// X, Y, U, V
@@ -209,15 +211,17 @@ public abstract class PGL {
209211
"uniform sampler2D textureSampler;\n" +
210212
"varying vec2 vertTexcoord;\n" +
211213
"void main() {\n" +
212-
" gl_FragColor = texture2D(textureSampler, vertTexcoord.st);\n" +
214+
" gl_FragColor = texture2D(textureSampler, vertTexcoord.st);\n" +
215+
// " gl_FragColor = vec4(vertTexcoord.st, 0, 1);\n" +
213216
"}\n",
214217
"#version 150\n" +
215218
SHADER_PREPROCESSOR_DIRECTIVE +
216219
"uniform sampler2D textureSampler;\n" +
217220
"in vec2 vertTexcoord;\n" +
218221
"out vec4 fragColor;\n" +
219222
"void main() {\n" +
220-
" fragColor = texture(textureSampler, vertTexcoord.st);\n" +
223+
// " fragColor = texture(textureSampler, vertTexcoord.st);\n" +
224+
" fragColor = vec4(vertTexcoord.st, 0, 1);\n" +
221225
"}\n"
222226
};
223227

@@ -930,6 +934,7 @@ protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
930934
if (0 < tex2DShaderProgram) {
931935
tex2DVertLoc = getAttribLocation(tex2DShaderProgram, "inVertex");
932936
tex2DTCoordLoc = getAttribLocation(tex2DShaderProgram, "inTexcoord");
937+
tex2DSamplerLoc = getUniformLocation(tex2DShaderProgram, "textureSampler");
933938
}
934939
loadedTex2DShader = true;
935940
tex2DShaderContext = glContext;
@@ -999,16 +1004,15 @@ protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
9991004
enabledTex = true;
10001005
}
10011006
bindTexture(TEXTURE_2D, id);
1007+
uniform1i(tex2DSamplerLoc, 0);
10021008

10031009
texData.position(0);
10041010
bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO);
10051011
bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW);
10061012

1007-
pg.report("HERE 1");
10081013
vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0);
10091014
vertexAttribPointer(tex2DTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT);
10101015

1011-
10121016
// texData.position(0);
10131017
// vertexAttribPointer(tex2DVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT,
10141018
// texData);
@@ -1018,7 +1022,6 @@ protected void drawTexture2D(int id, int texW, int texH, int scrW, int scrH,
10181022
// pg.report("HERE 2");
10191023

10201024
drawArrays(TRIANGLE_STRIP, 0, 4);
1021-
pg.report("HERE 3");
10221025

10231026
bindBuffer(ARRAY_BUFFER, 0); // Making sure that no VBO is bound at this point.
10241027

@@ -1058,6 +1061,7 @@ protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH,
10581061
if (0 < texRectShaderProgram) {
10591062
texRectVertLoc = getAttribLocation(texRectShaderProgram, "inVertex");
10601063
texRectTCoordLoc = getAttribLocation(texRectShaderProgram, "inTexcoord");
1064+
texRectSamplerLoc = getUniformLocation(texRectShaderProgram, "textureSampler");
10611065
}
10621066
loadedTexRectShader = true;
10631067
texRectShaderContext = glContext;
@@ -1127,12 +1131,13 @@ protected void drawTextureRect(int id, int texW, int texH, int scrW, int scrH,
11271131
enabledTex = true;
11281132
}
11291133
bindTexture(TEXTURE_RECTANGLE, id);
1134+
uniform1i(texRectSamplerLoc, 0);
11301135

11311136
texData.position(0);
11321137
bindBuffer(PGL.ARRAY_BUFFER, texGeoVBO);
11331138
bufferData(PGL.ARRAY_BUFFER, 16 * SIZEOF_FLOAT, texData, PGL.STATIC_DRAW);
11341139

1135-
pg.report("HERE 1");
1140+
// pg.report("HERE 1");
11361141
vertexAttribPointer(texRectVertLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 0);
11371142
vertexAttribPointer(texRectTCoordLoc, 2, FLOAT, false, 4 * SIZEOF_FLOAT, 2 * SIZEOF_FLOAT);
11381143

@@ -1634,6 +1639,61 @@ protected boolean hasShaders() {
16341639
}
16351640

16361641

1642+
protected boolean hasNpotTexSupport() {
1643+
int major = getGLVersion()[0];
1644+
if (major < 3) {
1645+
String ext = getString(EXTENSIONS);
1646+
return -1 < ext.indexOf("_texture_non_power_of_two");
1647+
} else {
1648+
return true;
1649+
}
1650+
}
1651+
1652+
1653+
protected boolean hasAutoMipmapGenSupport() {
1654+
int major = getGLVersion()[0];
1655+
if (major < 3) {
1656+
String ext = getString(EXTENSIONS);
1657+
return -1 < ext.indexOf("_generate_mipmap");
1658+
} else {
1659+
return true;
1660+
}
1661+
}
1662+
1663+
1664+
protected boolean hasFboMultisampleSupport() {
1665+
int major = getGLVersion()[0];
1666+
if (major < 3) {
1667+
String ext = getString(EXTENSIONS);
1668+
return -1 < ext.indexOf("_framebuffer_multisample");
1669+
} else {
1670+
return true;
1671+
}
1672+
}
1673+
1674+
1675+
protected boolean hasPackedDepthStencilSupport() {
1676+
int major = getGLVersion()[0];
1677+
if (major < 3) {
1678+
String ext = getString(EXTENSIONS);
1679+
return -1 < ext.indexOf("_packed_depth_stencil");
1680+
} else {
1681+
return true;
1682+
}
1683+
}
1684+
1685+
1686+
protected boolean hasAnisoSamplingSupport() {
1687+
int major = getGLVersion()[0];
1688+
if (major < 3) {
1689+
String ext = getString(EXTENSIONS);
1690+
return -1 < ext.indexOf("_texture_filter_anisotropic");
1691+
} else {
1692+
return true;
1693+
}
1694+
}
1695+
1696+
16371697
protected int maxSamples() {
16381698
intBuffer.rewind();
16391699
getIntegerv(MAX_SAMPLES, intBuffer);
@@ -2140,6 +2200,9 @@ protected interface FontOutline {
21402200
public static int RGBA4;
21412201
public static int RGB5_A1;
21422202
public static int RGB565;
2203+
public static int RGB8;
2204+
public static int RGBA8;
2205+
public static int ALPHA8;
21432206

21442207
public static int READ_ONLY;
21452208
public static int WRITE_ONLY;
@@ -2354,7 +2417,6 @@ protected interface FontOutline {
23542417
public static int READ_FRAMEBUFFER;
23552418
public static int DRAW_FRAMEBUFFER;
23562419

2357-
public static int RGBA8;
23582420
public static int DEPTH24_STENCIL8;
23592421

23602422
public static int DEPTH_COMPONENT;

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6235,16 +6235,11 @@ protected void getGLParameters() {
62356235
OPENGL_EXTENSIONS = pgl.getString(PGL.EXTENSIONS);
62366236
GLSL_VERSION = pgl.getString(PGL.SHADING_LANGUAGE_VERSION);
62376237

6238-
npotTexSupported =
6239-
-1 < OPENGL_EXTENSIONS.indexOf("_texture_non_power_of_two");
6240-
autoMipmapGenSupported =
6241-
-1 < OPENGL_EXTENSIONS.indexOf("_generate_mipmap");
6242-
fboMultisampleSupported =
6243-
-1 < OPENGL_EXTENSIONS.indexOf("_framebuffer_multisample");
6244-
packedDepthStencilSupported =
6245-
-1 < OPENGL_EXTENSIONS.indexOf("_packed_depth_stencil");
6246-
anisoSamplingSupported =
6247-
-1 < OPENGL_EXTENSIONS.indexOf("_texture_filter_anisotropic");
6238+
npotTexSupported = pgl.hasNpotTexSupport();
6239+
autoMipmapGenSupported = pgl.hasAutoMipmapGenSupport();
6240+
fboMultisampleSupported = pgl.hasFboMultisampleSupport();
6241+
packedDepthStencilSupported = pgl.hasPackedDepthStencilSupport();
6242+
anisoSamplingSupported = pgl.hasAnisoSamplingSupport();
62486243

62496244
try {
62506245
pgl.blendEquation(PGL.FUNC_ADD);

core/src/processing/opengl/PJOGL.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ public void keyTyped(com.jogamp.newt.event.KeyEvent e) {
988988

989989
@Override
990990
protected void enableTexturing(int target) {
991-
//if (PROFILE == 2) enable(target);
991+
if (PROFILE == 2) enable(target);
992992
if (target == TEXTURE_2D) {
993993
texturingTargets[0] = true;
994994
} else if (target == TEXTURE_RECTANGLE) {
@@ -999,7 +999,7 @@ protected void enableTexturing(int target) {
999999

10001000
@Override
10011001
protected void disableTexturing(int target) {
1002-
//if (PROFILE == 2) disable(target);
1002+
if (PROFILE == 2) disable(target);
10031003
if (target == TEXTURE_2D) {
10041004
texturingTargets[0] = false;
10051005
} else if (target == TEXTURE_RECTANGLE) {
@@ -1042,6 +1042,7 @@ protected Object getDerivedFont(Object font, float size) {
10421042
protected String[] loadFragmentShader(URL url) {
10431043
try {
10441044
if (2 < PROFILE) {
1045+
// if (false) {
10451046
String[] fragSrc0 = PApplet.loadStrings(url.openStream());
10461047
// PApplet.join(PApplet.loadStrings(url.openStream()), "\n");
10471048
String[] fragSrc = new String[fragSrc0.length + 2];
@@ -1076,6 +1077,7 @@ protected String[] loadFragmentShader(URL url) {
10761077
protected String[] loadVertexShader(URL url) {
10771078
try {
10781079
if (2 < PROFILE) {
1080+
// if (false) {
10791081
String[] vertSrc0 = PApplet.loadStrings(url.openStream());
10801082
String[] vertSrc = new String[vertSrc0.length + 1];
10811083
vertSrc[0] = "#version 150";
@@ -1271,6 +1273,9 @@ public void next() {
12711273
RGBA4 = GL.GL_RGBA4;
12721274
RGB5_A1 = GL.GL_RGB5_A1;
12731275
RGB565 = GL.GL_RGB565;
1276+
RGB8 = GL.GL_RGB8;
1277+
RGBA8 = GL.GL_RGBA8;
1278+
ALPHA8 = GL.GL_ALPHA8;
12741279

12751280
READ_ONLY = GL2GL3.GL_READ_ONLY;
12761281
WRITE_ONLY = GL.GL_WRITE_ONLY;

core/src/processing/opengl/Texture.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
*
3737
*/
3838
public class Texture implements PConstants {
39-
// texture constants
40-
4139
/**
4240
* Texture with normalized UV.
4341
*/
@@ -1438,21 +1436,27 @@ protected void setParameters(Parameters params) {
14381436
throw new RuntimeException("Unknown texture format");
14391437
}
14401438

1439+
boolean mipmaps = params.mipmaps && PGL.MIPMAPS_ENABLED;
1440+
if (mipmaps && !PGraphicsOpenGL.autoMipmapGenSupported) {
1441+
PGraphics.showWarning("Mipmaps were requested but automatic mipmap " +
1442+
"generation is not supported and manual " +
1443+
"generation still not implemented, so mipmaps " +
1444+
"will be disabled.");
1445+
mipmaps = false;
1446+
}
1447+
14411448
if (params.sampling == POINT) {
14421449
glMagFilter = PGL.NEAREST;
14431450
glMinFilter = PGL.NEAREST;
14441451
} else if (params.sampling == LINEAR) {
14451452
glMagFilter = PGL.NEAREST;
1446-
glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
1447-
PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
1453+
glMinFilter = mipmaps ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
14481454
} else if (params.sampling == BILINEAR) {
14491455
glMagFilter = PGL.LINEAR;
1450-
glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
1451-
PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
1456+
glMinFilter = mipmaps ? PGL.LINEAR_MIPMAP_NEAREST : PGL.LINEAR;
14521457
} else if (params.sampling == TRILINEAR) {
14531458
glMagFilter = PGL.LINEAR;
1454-
glMinFilter = params.mipmaps && PGL.MIPMAPS_ENABLED ?
1455-
PGL.LINEAR_MIPMAP_LINEAR : PGL.LINEAR;
1459+
glMinFilter = mipmaps ? PGL.LINEAR_MIPMAP_LINEAR : PGL.LINEAR;
14561460
} else {
14571461
throw new RuntimeException("Unknown texture filtering mode");
14581462
}

0 commit comments

Comments
 (0)