use of com.jogamp.opengl.GL in project jmonkeyengine by jMonkeyEngine.
the class JoglContext method determineMaxSamples.
protected int determineMaxSamples(int requestedSamples) {
GL gl = GLContext.getCurrentGL();
if (gl.hasFullFBOSupport()) {
return gl.getMaxRenderbufferSamples();
} else {
if (gl.isExtensionAvailable("GL_ARB_framebuffer_object") || gl.isExtensionAvailable("GL_EXT_framebuffer_multisample")) {
IntBuffer intBuf1 = IntBuffer.allocate(1);
gl.glGetIntegerv(GL2GL3.GL_MAX_SAMPLES, intBuf1);
return intBuf1.get(0);
} else {
return Integer.MAX_VALUE;
}
}
}
use of com.jogamp.opengl.GL in project jmonkeyengine by jMonkeyEngine.
the class TextureUtil method uploadSubTexture.
/**
* Update the texture currently bound to target at with data from the given Image at position x and y. The parameter
* index is used as the zoffset in case a 3d texture or texture 2d array is being updated.
*
* @param image Image with the source data (this data will be put into the texture)
* @param target the target texture
* @param index the mipmap level to update
* @param x the x position where to put the image in the texture
* @param y the y position where to put the image in the texture
*/
public static void uploadSubTexture(Image image, int target, int index, int x, int y, boolean linearizeSrgb) {
GL gl = GLContext.getCurrentGL();
Image.Format fmt = image.getFormat();
GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb);
ByteBuffer data = null;
if (index >= 0 && image.getData() != null && image.getData().size() > 0) {
data = image.getData(index);
}
int width = image.getWidth();
int height = image.getHeight();
int depth = image.getDepth();
if (data != null) {
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
}
int[] mipSizes = image.getMipMapSizes();
int pos = 0;
// TODO: Remove unneccessary allocation
if (mipSizes == null) {
if (data != null) {
mipSizes = new int[] { data.capacity() };
} else {
mipSizes = new int[] { width * height * fmt.getBitsPerPixel() / 8 };
}
}
int samples = image.getMultiSamples();
for (int i = 0; i < mipSizes.length; i++) {
int mipWidth = Math.max(1, width >> i);
int mipHeight = Math.max(1, height >> i);
int mipDepth = Math.max(1, depth >> i);
if (data != null) {
data.position(pos);
data.limit(pos + mipSizes[i]);
}
// to remove the cumbersome if/then/else stuff below we'll update the pos right here and use continue after each
// gl*Image call in an attempt to unclutter things a bit
pos += mipSizes[i];
int glFmtInternal = glFmt.internalFormat;
int glFmtFormat = glFmt.format;
int glFmtDataType = glFmt.dataType;
if (glFmt.compressed && data != null) {
if (target == GL2ES2.GL_TEXTURE_3D) {
gl.getGL2ES2().glCompressedTexSubImage3D(target, i, x, y, index, mipWidth, mipHeight, mipDepth, glFmtInternal, data.limit(), data);
continue;
}
// all other targets use 2D: array, cubemap, 2d
gl.getGL2ES2().glCompressedTexSubImage2D(target, i, x, y, mipWidth, mipHeight, glFmtInternal, data.limit(), data);
continue;
}
if (target == GL2ES2.GL_TEXTURE_3D) {
gl.getGL2ES2().glTexSubImage3D(target, i, x, y, index, mipWidth, mipHeight, mipDepth, glFmtFormat, glFmtDataType, data);
continue;
}
if (samples > 1) {
throw new IllegalStateException("Cannot update multisample textures");
}
gl.glTexSubImage2D(target, i, x, y, mipWidth, mipHeight, glFmtFormat, glFmtDataType, data);
continue;
}
}
use of com.jogamp.opengl.GL in project artisynth_core by artisynth.
the class GLTextRenderer method replaceSubTexture.
@Override
protected void replaceSubTexture(int x, int y, int width, int height, ByteBuffer buff) {
GL gl = renderer.getGL();
gl.glTexSubImage2D(texture.getTarget(), 0, x, y, width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, buff);
gl.glGenerateMipmap(texture.getTarget());
}
use of com.jogamp.opengl.GL in project artisynth_core by artisynth.
the class GLViewer method init.
/**
* Called any time GL context is switched! e.g. moving window to new display
*/
public void init(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
String renderer = gl.glGetString(GL.GL_RENDERER);
String version = gl.glGetString(GL.GL_VERSION);
Logger logger = Logger.getSystemLogger();
logger.info("GL Renderer: " + renderer);
logger.info("OpenGL Version: " + version);
setMultiSampleEnabled(true);
myActiveColor = ActiveColor.DEFAULT;
}
use of com.jogamp.opengl.GL in project jmonkeyengine by jMonkeyEngine.
the class TextureUtil method uploadTexture.
public static void uploadTexture(Image image, int target, int index, int border, boolean linearizeSrgb) {
GL gl = GLContext.getCurrentGL();
Image.Format fmt = image.getFormat();
GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb);
ByteBuffer data;
if (index >= 0 && image.getData() != null && image.getData().size() > 0) {
data = image.getData(index);
} else {
data = null;
}
int width = image.getWidth();
int height = image.getHeight();
int depth = image.getDepth();
if (data != null) {
if (abgrToRgbaConversionEnabled) {
convertABGRtoRGBA(data);
}
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
}
int[] mipSizes = image.getMipMapSizes();
int pos = 0;
// TODO: Remove unneccessary allocation
if (mipSizes == null) {
if (data != null)
mipSizes = new int[] { data.capacity() };
else
mipSizes = new int[] { width * height * fmt.getBitsPerPixel() / 8 };
}
boolean subtex = false;
int samples = image.getMultiSamples();
for (int i = 0; i < mipSizes.length; i++) {
int mipWidth = Math.max(1, width >> i);
int mipHeight = Math.max(1, height >> i);
int mipDepth = Math.max(1, depth >> i);
if (data != null) {
data.position(pos);
data.limit(pos + mipSizes[i]);
}
if (glFmt.compressed && data != null) {
if (target == GL2ES2.GL_TEXTURE_3D) {
gl.getGL2ES2().glCompressedTexImage3D(target, i, glFmt.internalFormat, mipWidth, mipHeight, mipDepth, data.remaining(), border, data);
} else {
//all other targets use 2D: array, cubemap, 2d
gl.glCompressedTexImage2D(target, i, glFmt.internalFormat, mipWidth, mipHeight, data.remaining(), border, data);
}
} else {
if (target == GL2ES2.GL_TEXTURE_3D) {
gl.getGL2ES2().glTexImage3D(target, i, glFmt.internalFormat, mipWidth, mipHeight, mipDepth, border, glFmt.format, glFmt.dataType, data);
} else if (target == GL2ES3.GL_TEXTURE_2D_ARRAY) {
// or upload slice
if (index == -1) {
gl.getGL2ES2().glTexImage3D(target, 0, glFmt.internalFormat, mipWidth, mipHeight, //# of slices
image.getData().size(), border, glFmt.format, glFmt.dataType, data);
} else {
gl.getGL2ES2().glTexSubImage3D(target, // level
i, // xoffset
0, // yoffset
0, // zoffset
index, // width
width, // height
height, // depth
1, glFmt.format, glFmt.dataType, data);
}
} else {
if (subtex) {
if (samples > 1) {
throw new IllegalStateException("Cannot update multisample textures");
}
gl.glTexSubImage2D(target, i, 0, 0, mipWidth, mipHeight, glFmt.format, glFmt.dataType, data);
} else {
if (samples > 1) {
if (gl.isGL2GL3()) {
gl.getGL3().glTexImage2DMultisample(target, samples, glFmt.internalFormat, mipWidth, mipHeight, true);
}
} else {
gl.glTexImage2D(target, i, glFmt.internalFormat, mipWidth, mipHeight, border, glFmt.format, glFmt.dataType, data);
}
}
}
}
pos += mipSizes[i];
}
}