|
|
|
@ -71,7 +71,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
private static final Logger logger = Logger.getLogger(GLRenderer.class.getName()); |
|
|
|
|
private static final boolean VALIDATE_SHADER = false; |
|
|
|
|
private static final Pattern GLVERSION_PATTERN = Pattern.compile(".*?(\\d+)\\.(\\d+).*"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250); |
|
|
|
|
private final StringBuilder stringBuf = new StringBuilder(250); |
|
|
|
|
private final IntBuffer intBuf1 = BufferUtils.createIntBuffer(1); |
|
|
|
@ -81,7 +81,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
private final NativeObjectManager objManager = new NativeObjectManager(); |
|
|
|
|
private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class); |
|
|
|
|
private final EnumMap<Limits, Integer> limits = new EnumMap<Limits, Integer>(Limits.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// private int vertexTextureUnits;
|
|
|
|
|
// private int fragTextureUnits;
|
|
|
|
|
// private int vertexUniforms;
|
|
|
|
@ -110,7 +110,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
private final GLExt glext; |
|
|
|
|
private final GLFbo glfbo; |
|
|
|
|
private final TextureUtil texUtil; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GLRenderer(GL gl, GLFbo glfbo) { |
|
|
|
|
this.gl = gl; |
|
|
|
|
this.gl2 = gl instanceof GL2 ? (GL2)gl : null; |
|
|
|
@ -129,7 +129,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
public EnumSet<Caps> getCaps() { |
|
|
|
|
return caps; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Not making public yet ...
|
|
|
|
|
public EnumMap<Limits, Integer> getLimits() { |
|
|
|
|
return limits; |
|
|
|
@ -142,7 +142,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
return extensionSet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int extractVersion(String version) { |
|
|
|
|
Matcher m = GLVERSION_PATTERN.matcher(version); |
|
|
|
|
if (m.matches()) { |
|
|
|
@ -162,17 +162,17 @@ public class GLRenderer implements Renderer { |
|
|
|
|
private boolean hasExtension(String extensionName) { |
|
|
|
|
return extensions.contains(extensionName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadCapabilitiesES() { |
|
|
|
|
caps.add(Caps.GLSL100); |
|
|
|
|
caps.add(Caps.OpenGLES20); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Important: Do not add OpenGL20 - that's the desktop capability!
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadCapabilitiesGL2() { |
|
|
|
|
int oglVer = extractVersion(gl.glGetString(GL.GL_VERSION)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (oglVer >= 200) { |
|
|
|
|
caps.add(Caps.OpenGL20); |
|
|
|
|
if (oglVer >= 210) { |
|
|
|
@ -194,9 +194,9 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int glslVer = extractVersion(gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (glslVer) { |
|
|
|
|
default: |
|
|
|
|
if (glslVer < 400) { |
|
|
|
@ -222,27 +222,27 @@ public class GLRenderer implements Renderer { |
|
|
|
|
caps.add(Caps.GLSL100); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Workaround, always assume we support GLSL100 & GLSL110
|
|
|
|
|
// Supporting OpenGL 2.0 means supporting GLSL 1.10.
|
|
|
|
|
caps.add(Caps.GLSL110); |
|
|
|
|
caps.add(Caps.GLSL100); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fix issue in TestRenderToMemory when GL.GL_FRONT is the main
|
|
|
|
|
// buffer being used.
|
|
|
|
|
context.initialDrawBuf = getInteger(GL2.GL_DRAW_BUFFER); |
|
|
|
|
context.initialReadBuf = getInteger(GL2.GL_READ_BUFFER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// XXX: This has to be GL.GL_BACK for canvas on Mac
|
|
|
|
|
// Since initialDrawBuf is GL.GL_FRONT for pbuffer, gotta
|
|
|
|
|
// change this value later on ...
|
|
|
|
|
// initialDrawBuf = GL.GL_BACK;
|
|
|
|
|
// initialReadBuf = GL.GL_BACK;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadCapabilitiesCommon() { |
|
|
|
|
extensions = loadExtensions(gl.glGetString(GL.GL_EXTENSIONS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
limits.put(Limits.VertexTextureUnits, getInteger(GL.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS)); |
|
|
|
|
if (limits.get(Limits.VertexTextureUnits) > 0) { |
|
|
|
|
caps.add(Caps.VertexTextureFetch); |
|
|
|
@ -262,7 +262,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
limits.put(Limits.TextureSize, getInteger(GL.GL_MAX_TEXTURE_SIZE)); |
|
|
|
|
limits.put(Limits.CubemapSize, getInteger(GL.GL_MAX_CUBE_MAP_TEXTURE_SIZE)); |
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_ARB_draw_instanced") && |
|
|
|
|
if (hasExtension("GL_ARB_draw_instanced") && |
|
|
|
|
hasExtension("GL_ARB_instanced_arrays")) { |
|
|
|
|
caps.add(Caps.MeshInstancing); |
|
|
|
|
} |
|
|
|
@ -270,43 +270,43 @@ public class GLRenderer implements Renderer { |
|
|
|
|
if (hasExtension("GL_OES_element_index_uint") || gl2 != null) { |
|
|
|
|
caps.add(Caps.IntegerIndexBuffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_ARB_texture_buffer_object")) { |
|
|
|
|
caps.add(Caps.TextureBuffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// == texture format extensions ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasFloatTexture = false; |
|
|
|
|
|
|
|
|
|
hasFloatTexture = hasExtension("GL_OES_texture_half_float") && |
|
|
|
|
hasFloatTexture = hasExtension("GL_OES_texture_half_float") && |
|
|
|
|
hasExtension("GL_OES_texture_float"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasFloatTexture) { |
|
|
|
|
hasFloatTexture = hasExtension("GL_ARB_texture_float") && |
|
|
|
|
hasExtension("GL_ARB_half_float_pixel"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasFloatTexture) { |
|
|
|
|
hasFloatTexture = caps.contains(Caps.OpenGL30); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasFloatTexture) { |
|
|
|
|
caps.add(Caps.FloatTexture); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_OES_depth_texture") || gl2 != null) { |
|
|
|
|
caps.add(Caps.DepthTexture); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: GL_OES_depth24
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_OES_rgb8_rgba8") || |
|
|
|
|
hasExtension("GL_ARM_rgba8") || |
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_OES_rgb8_rgba8") || |
|
|
|
|
hasExtension("GL_ARM_rgba8") || |
|
|
|
|
hasExtension("GL_EXT_texture_format_BGRA8888")) { |
|
|
|
|
caps.add(Caps.Rgba8); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (caps.contains(Caps.OpenGL30) || hasExtension("GL_OES_packed_depth_stencil")) { |
|
|
|
|
caps.add(Caps.PackedDepthStencilBuffer); |
|
|
|
|
} |
|
|
|
@ -321,35 +321,35 @@ public class GLRenderer implements Renderer { |
|
|
|
|
caps.add(Caps.FloatDepthBuffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ((hasExtension("GL_EXT_packed_float") && hasFloatTexture) || |
|
|
|
|
if ((hasExtension("GL_EXT_packed_float") && hasFloatTexture) || |
|
|
|
|
caps.contains(Caps.OpenGL30)) { |
|
|
|
|
// Either OpenGL3 is available or both packed_float & half_float_pixel.
|
|
|
|
|
caps.add(Caps.PackedFloatColorBuffer); |
|
|
|
|
caps.add(Caps.PackedFloatTexture); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_EXT_texture_shared_exponent") || caps.contains(Caps.OpenGL30)) { |
|
|
|
|
caps.add(Caps.SharedExponentTexture); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_EXT_texture_compression_s3tc")) { |
|
|
|
|
caps.add(Caps.TextureCompressionS3TC); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_ARB_ES3_compatibility")) { |
|
|
|
|
caps.add(Caps.TextureCompressionETC2); |
|
|
|
|
caps.add(Caps.TextureCompressionETC1); |
|
|
|
|
} else if (hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) { |
|
|
|
|
caps.add(Caps.TextureCompressionETC1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// == end texture format extensions ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_ARB_vertex_array_object") || caps.contains(Caps.OpenGL30)) { |
|
|
|
|
caps.add(Caps.VertexBufferArray); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_ARB_texture_non_power_of_two") || |
|
|
|
|
if (hasExtension("GL_ARB_texture_non_power_of_two") || |
|
|
|
|
hasExtension("GL_OES_texture_npot") || |
|
|
|
|
caps.contains(Caps.OpenGL30)) { |
|
|
|
|
caps.add(Caps.NonPowerOfTwoTextures); |
|
|
|
@ -358,7 +358,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
+ "support non-power-of-2 textures. " |
|
|
|
|
+ "Some features might not work."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (caps.contains(Caps.OpenGLES20)) { |
|
|
|
|
// OpenGL ES 2 has some limited support for NPOT textures
|
|
|
|
|
caps.add(Caps.PartialNonPowerOfTwoTextures); |
|
|
|
@ -374,14 +374,14 @@ public class GLRenderer implements Renderer { |
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_EXT_framebuffer_object")) { |
|
|
|
|
caps.add(Caps.FrameBuffer); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
limits.put(Limits.RenderBufferSize, getInteger(GLExt.GL_MAX_RENDERBUFFER_SIZE_EXT)); |
|
|
|
|
limits.put(Limits.FrameBufferAttachments, getInteger(GLExt.GL_MAX_COLOR_ATTACHMENTS_EXT)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_EXT_framebuffer_blit")) { |
|
|
|
|
caps.add(Caps.FrameBufferBlit); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (hasExtension("GL_EXT_framebuffer_multisample")) { |
|
|
|
|
caps.add(Caps.FrameBufferMultisample); |
|
|
|
|
limits.put(Limits.FrameBufferSamples, getInteger(GLExt.GL_MAX_SAMPLES_EXT)); |
|
|
|
@ -419,9 +419,9 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
caps.add(Caps.Multisample); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Supports sRGB pipeline.
|
|
|
|
|
if ( (hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB")) |
|
|
|
|
if ( (hasExtension("GL_ARB_framebuffer_sRGB") && hasExtension("GL_EXT_texture_sRGB")) |
|
|
|
|
|| caps.contains(Caps.OpenGL30) ) { |
|
|
|
|
caps.add(Caps.Srgb); |
|
|
|
|
} |
|
|
|
@ -430,24 +430,24 @@ public class GLRenderer implements Renderer { |
|
|
|
|
if (hasExtension("GL_ARB_seamless_cube_map") || caps.contains(Caps.OpenGL32)) { |
|
|
|
|
caps.add(Caps.SeamlessCubemap); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (hasExtension("GL_ARB_get_program_binary")) {
|
|
|
|
|
// int binaryFormats = getInteger(GLExt.GL_NUM_PROGRAM_BINARY_FORMATS);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Print context information
|
|
|
|
|
logger.log(Level.INFO, "OpenGL Renderer Information\n" + |
|
|
|
|
" * Vendor: {0}\n" + |
|
|
|
|
" * Renderer: {1}\n" + |
|
|
|
|
" * OpenGL Version: {2}\n" + |
|
|
|
|
" * GLSL Version: {3}", |
|
|
|
|
new Object[]{ |
|
|
|
|
gl.glGetString(GL.GL_VENDOR), |
|
|
|
|
new Object[]{ |
|
|
|
|
gl.glGetString(GL.GL_VENDOR), |
|
|
|
|
gl.glGetString(GL.GL_RENDERER), |
|
|
|
|
gl.glGetString(GL.GL_VERSION), |
|
|
|
|
gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION) |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Print capabilities (if fine logging is enabled)
|
|
|
|
|
if (logger.isLoggable(Level.FINE)) { |
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
@ -458,10 +458,10 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
logger.log(Level.FINE, sb.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
texUtil.initialize(caps); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadCapabilities() { |
|
|
|
|
if (gl2 != null) { |
|
|
|
|
loadCapabilitiesGL2(); |
|
|
|
@ -470,22 +470,22 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
loadCapabilitiesCommon(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getInteger(int en) { |
|
|
|
|
intBuf16.clear(); |
|
|
|
|
gl.glGetInteger(en, intBuf16); |
|
|
|
|
return intBuf16.get(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean getBoolean(int en) { |
|
|
|
|
gl.glGetBoolean(en, nameBuf); |
|
|
|
|
return nameBuf.get(0) != (byte)0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("fallthrough") |
|
|
|
|
public void initialize() { |
|
|
|
|
loadCapabilities(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize default state..
|
|
|
|
|
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); |
|
|
|
|
} |
|
|
|
@ -579,7 +579,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (state.isDepthTest() && !context.depthTestEnabled) { |
|
|
|
|
gl.glEnable(GL.GL_DEPTH_TEST); |
|
|
|
|
gl.glEnable(GL.GL_DEPTH_TEST); |
|
|
|
|
gl.glDepthFunc(convertTestFunction(context.depthFunc)); |
|
|
|
|
context.depthTestEnabled = true; |
|
|
|
|
} else if (!state.isDepthTest() && context.depthTestEnabled) { |
|
|
|
@ -718,7 +718,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
break; |
|
|
|
|
case Screen: |
|
|
|
|
gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_COLOR); |
|
|
|
|
break; |
|
|
|
|
break; |
|
|
|
|
case Exclusion: |
|
|
|
|
gl.glBlendFunc(GL.GL_ONE_MINUS_DST_COLOR, GL.GL_ONE_MINUS_SRC_COLOR); |
|
|
|
|
break; |
|
|
|
@ -1043,12 +1043,12 @@ public class GLRenderer implements Renderer { |
|
|
|
|
|
|
|
|
|
boolean gles2 = caps.contains(Caps.OpenGLES20); |
|
|
|
|
String language = source.getLanguage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (gles2 && !language.equals("GLSL100")) { |
|
|
|
|
throw new RendererException("This shader cannot run in OpenGL ES 2. " |
|
|
|
|
+ "Only GLSL 1.00 shaders are supported."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Upload shader source.
|
|
|
|
|
// Merge the defines and source code.
|
|
|
|
|
stringBuf.setLength(0); |
|
|
|
@ -1075,14 +1075,14 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (linearizeSrgbImages) { |
|
|
|
|
stringBuf.append("#define SRGB 1\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stringBuf.append(source.getDefines()); |
|
|
|
|
stringBuf.append(source.getSource()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
intBuf1.clear(); |
|
|
|
|
intBuf1.put(0, stringBuf.length()); |
|
|
|
|
gl.glShaderSource(id, new String[]{ stringBuf.toString() }, intBuf1); |
|
|
|
@ -1140,7 +1140,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
// If using GLSL 1.5, we bind the outputs for the user
|
|
|
|
|
// For versions 3.3 and up, user should use layout qualifiers instead.
|
|
|
|
|
boolean bindFragDataRequired = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (ShaderSource source : shader.getSources()) { |
|
|
|
|
if (source.isUpdateNeeded()) { |
|
|
|
|
updateShaderSourceData(source); |
|
|
|
@ -1412,7 +1412,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} else if (attachmentSlot < 0 || attachmentSlot >= 16) { |
|
|
|
|
throw new UnsupportedOperationException("Invalid FBO attachment slot: " + attachmentSlot); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return GLExt.GL_COLOR_ATTACHMENT0_EXT + attachmentSlot; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1422,7 +1422,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
if (image.isUpdateNeeded()) { |
|
|
|
|
// Check NPOT requirements
|
|
|
|
|
checkNonPowerOfTwo(tex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateTexImageData(image, tex.getType(), 0); |
|
|
|
|
|
|
|
|
|
// NOTE: For depth textures, sets nearest/no-mips mode
|
|
|
|
@ -1583,7 +1583,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
|
|
|
|
|
// update viewport to reflect framebuffer's resolution
|
|
|
|
|
setViewPort(0, 0, fb.getWidth(), fb.getHeight()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (context.boundFBO != fb.getId()) { |
|
|
|
|
glfbo.glBindFramebufferEXT(GLExt.GL_FRAMEBUFFER_EXT, fb.getId()); |
|
|
|
|
statistics.onFrameBufferUse(fb, true); |
|
|
|
@ -1656,7 +1656,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) { |
|
|
|
|
readFrameBufferWithGLFormat(fb, byteBuf, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void readFrameBufferWithGLFormat(FrameBuffer fb, ByteBuffer byteBuf, int glFormat, int dataType) { |
|
|
|
|
if (fb != null) { |
|
|
|
|
RenderBuffer rb = fb.getColorBuffer(); |
|
|
|
@ -1678,8 +1678,8 @@ public class GLRenderer implements Renderer { |
|
|
|
|
|
|
|
|
|
gl.glReadPixels(vpX, vpY, vpW, vpH, glFormat, dataType, byteBuf); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) { |
|
|
|
|
|
|
|
|
|
public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) { |
|
|
|
|
GLImageFormat glFormat = texUtil.getImageFormatWithError(format, false); |
|
|
|
|
readFrameBufferWithGLFormat(fb, byteBuf, glFormat.format, glFormat.dataType); |
|
|
|
|
} |
|
|
|
@ -1716,10 +1716,10 @@ public class GLRenderer implements Renderer { |
|
|
|
|
\*********************************************************************/ |
|
|
|
|
private int convertTextureType(Texture.Type type, int samples, int face) { |
|
|
|
|
if (samples > 1 && !caps.contains(Caps.TextureMultisample)) { |
|
|
|
|
throw new RendererException("Multisample textures are not supported" + |
|
|
|
|
throw new RendererException("Multisample textures are not supported" + |
|
|
|
|
" by the video hardware."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (type) { |
|
|
|
|
case TwoDimensional: |
|
|
|
|
if (samples > 1) { |
|
|
|
@ -1739,7 +1739,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
case ThreeDimensional: |
|
|
|
|
if (!caps.contains(Caps.OpenGL20)) { |
|
|
|
|
throw new RendererException("3D textures are not supported" + |
|
|
|
|
throw new RendererException("3D textures are not supported" + |
|
|
|
|
" by the video hardware."); |
|
|
|
|
} |
|
|
|
|
return GL2.GL_TEXTURE_3D; |
|
|
|
@ -1823,11 +1823,11 @@ public class GLRenderer implements Renderer { |
|
|
|
|
int target = convertTextureType(tex.getType(), image != null ? image.getMultiSamples() : 1, -1); |
|
|
|
|
|
|
|
|
|
boolean haveMips = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (image != null) { |
|
|
|
|
haveMips = image.isGeneratedMipmapsRequired() || image.hasMipmaps(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// filter things
|
|
|
|
|
if (image.getLastTextureState().magFilter != tex.getMagFilter()) { |
|
|
|
|
int magFilter = convertMagFilter(tex.getMagFilter()); |
|
|
|
@ -1850,7 +1850,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
context.seamlessCubemap = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tex.getAnisotropicFilter() > 1) { |
|
|
|
|
if (caps.contains(Caps.TextureFilterAnisotropic)) { |
|
|
|
|
gl.glTexParameterf(target, |
|
|
|
@ -1862,7 +1862,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
if (context.pointSprite) { |
|
|
|
|
return; // Attempt to fix glTexParameter crash for some ATI GPUs
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// repeat modes
|
|
|
|
|
switch (tex.getType()) { |
|
|
|
|
case ThreeDimensional: |
|
|
|
@ -1891,7 +1891,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
// R to Texture compare mode
|
|
|
|
|
if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off) { |
|
|
|
|
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_R_TO_TEXTURE); |
|
|
|
|
gl2.glTexParameteri(target, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY); |
|
|
|
|
gl2.glTexParameteri(target, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY); |
|
|
|
|
if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual) { |
|
|
|
|
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_FUNC, GL.GL_GEQUAL); |
|
|
|
|
} else { |
|
|
|
@ -1899,7 +1899,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
}else{ |
|
|
|
|
//restoring default value
|
|
|
|
|
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE); |
|
|
|
|
gl2.glTexParameteri(target, GL2.GL_TEXTURE_COMPARE_MODE, GL.GL_NONE); |
|
|
|
|
} |
|
|
|
|
tex.compareModeUpdated(); |
|
|
|
|
} |
|
|
|
@ -1908,10 +1908,10 @@ public class GLRenderer implements Renderer { |
|
|
|
|
/** |
|
|
|
|
* Validates if a potentially NPOT texture is supported by the hardware. |
|
|
|
|
* <p> |
|
|
|
|
* Textures with power-of-2 dimensions are supported on all hardware, however |
|
|
|
|
* Textures with power-of-2 dimensions are supported on all hardware, however |
|
|
|
|
* non-power-of-2 textures may or may not be supported depending on which |
|
|
|
|
* texturing features are used. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param tex The texture to validate. |
|
|
|
|
* @throws RendererException If the texture is not supported by the hardware |
|
|
|
|
*/ |
|
|
|
@ -1920,19 +1920,19 @@ public class GLRenderer implements Renderer { |
|
|
|
|
// Texture is power-of-2, safe to use.
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (caps.contains(Caps.NonPowerOfTwoTextures)) { |
|
|
|
|
// Texture is NPOT but it is supported by video hardware.
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Maybe we have some / partial support for NPOT?
|
|
|
|
|
if (!caps.contains(Caps.PartialNonPowerOfTwoTextures)) { |
|
|
|
|
// Cannot use any type of NPOT texture (uncommon)
|
|
|
|
|
throw new RendererException("non-power-of-2 textures are not " |
|
|
|
|
+ "supported by the video hardware"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Partial NPOT supported..
|
|
|
|
|
if (tex.getMinFilter().usesMipMapLevels()) { |
|
|
|
|
throw new RendererException("non-power-of-2 textures with mip-maps " |
|
|
|
@ -1959,10 +1959,10 @@ public class GLRenderer implements Renderer { |
|
|
|
|
throw new UnsupportedOperationException("unrecongized texture type"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Uploads the given image to the GL driver. |
|
|
|
|
* |
|
|
|
|
* |
|
|
|
|
* @param img The image to upload |
|
|
|
|
* @param type How the data in the image argument should be interpreted. |
|
|
|
|
* @param unit The texture slot to be used to upload the image, not important |
|
|
|
@ -1986,7 +1986,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
gl.glActiveTexture(GL.GL_TEXTURE0 + unit); |
|
|
|
|
context.boundTextureUnit = unit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.glBindTexture(target, texId); |
|
|
|
|
context.boundTextures[unit] = img; |
|
|
|
|
|
|
|
|
@ -2029,12 +2029,12 @@ public class GLRenderer implements Renderer { |
|
|
|
|
throw new RendererException("Multisample textures are not supported by the video hardware"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if graphics card doesn't support depth textures
|
|
|
|
|
if (img.getFormat().isDepthFormat() && !caps.contains(Caps.DepthTexture)) { |
|
|
|
|
throw new RendererException("Depth textures are not supported by the video hardware"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (target == GL.GL_TEXTURE_CUBE_MAP) { |
|
|
|
|
// Check max texture size before upload
|
|
|
|
|
int cubeSize = limits.get(Limits.CubemapSize); |
|
|
|
@ -2065,12 +2065,12 @@ public class GLRenderer implements Renderer { |
|
|
|
|
if (!caps.contains(Caps.TextureArray)) { |
|
|
|
|
throw new RendererException("Texture arrays not supported by graphics hardware"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<ByteBuffer> data = img.getData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -1 index specifies prepare data for 2D Array
|
|
|
|
|
texUtil.uploadTexture(img, target, -1, linearizeSrgbImages); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < data.size(); i++) { |
|
|
|
|
// upload each slice of 2D array in turn
|
|
|
|
|
// this time with the appropriate index
|
|
|
|
@ -2101,7 +2101,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) { |
|
|
|
|
// Check NPOT requirements
|
|
|
|
|
checkNonPowerOfTwo(tex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateTexImageData(image, tex.getType(), unit); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2222,7 +2222,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
//statistics.onVertexBufferUse(vb, false);
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int usage = convertUsage(vb.getUsage()); |
|
|
|
|
vb.getData().rewind(); |
|
|
|
|
|
|
|
|
@ -2311,7 +2311,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
if (context.boundShaderProgram <= 0) { |
|
|
|
|
throw new IllegalStateException("Cannot render mesh without shader bound"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Attribute attrib = context.boundShader.getAttribute(vb.getBufferType()); |
|
|
|
|
int loc = attrib.getLocation(); |
|
|
|
|
if (loc == -1) { |
|
|
|
@ -2441,7 +2441,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
// What is this?
|
|
|
|
|
throw new RendererException("Unexpected format for index buffer: " + indexBuf.getFormat()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (indexBuf.isUpdateNeeded()) { |
|
|
|
|
updateBufferData(indexBuf); |
|
|
|
|
} |
|
|
|
@ -2556,7 +2556,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
if (interleavedData != null && interleavedData.isUpdateNeeded()) { |
|
|
|
|
updateBufferData(interleavedData); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (instanceData != null) { |
|
|
|
|
setVertexAttrib(instanceData, null); |
|
|
|
|
} |
|
|
|
@ -2606,11 +2606,11 @@ public class GLRenderer implements Renderer { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void renderMeshDefault(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Here while count is still passed in. Can be removed when/if
|
|
|
|
|
// the method is collapsed again. -pspeed
|
|
|
|
|
count = Math.max(mesh.getInstanceCount(), count); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData); |
|
|
|
|
if (interleavedData != null && interleavedData.isUpdateNeeded()) { |
|
|
|
|
updateBufferData(interleavedData); |
|
|
|
@ -2628,7 +2628,7 @@ public class GLRenderer implements Renderer { |
|
|
|
|
setVertexAttrib(vb, null); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (VertexBuffer vb : mesh.getBufferList().getArray()) { |
|
|
|
|
if (vb.getBufferType() == Type.InterleavedData |
|
|
|
|
|| vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
|
|
|
|
@ -2696,12 +2696,12 @@ public class GLRenderer implements Renderer { |
|
|
|
|
// Gamma correction
|
|
|
|
|
if (!caps.contains(Caps.Srgb)) { |
|
|
|
|
// Not supported, sorry.
|
|
|
|
|
logger.warning("sRGB framebuffer is not supported " + |
|
|
|
|
"by video hardware, but was requested."); |
|
|
|
|
|
|
|
|
|
logger.warning("sRGB framebuffer is not supported " + |
|
|
|
|
"by video hardware, but was requested."); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setFrameBuffer(null); |
|
|
|
|
|
|
|
|
|
if (enableSrgb) { |
|
|
|
|