/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#ifndef HEADLESS
#include <stdlib.h>
#include "sun_java2d_opengl_OGLSurfaceData.h"
#include "jlong.h"
#include "jni_util.h"
#include "OGLSurfaceData.h"
/**
* The following methods are implemented in the windowing system (i.e. GLX
* and WGL) source files.
*/
/**
* This table contains the "pixel formats" for all system memory surfaces
* that OpenGL is capable of handling, indexed by the "PF_" constants defined
* in OGLSurfaceData.java. These pixel formats contain information that is
* passed to OpenGL when copying from a system memory ("Sw") surface to
* an OpenGL "Surface" (via glDrawPixels()) or "Texture" (via glTexImage2D()).
*/
4, 1, 0, }, /* 0 - IntArgb */
4, 1, 1, }, /* 1 - IntArgbPre */
4, 0, 1, }, /* 2 - IntRgb */
4, 0, 1, }, /* 3 - IntRgbx */
4, 0, 1, }, /* 4 - IntBgr */
4, 0, 1, }, /* 5 - IntBgrx */
2, 0, 1, }, /* 6 - Ushort565Rgb */
2, 0, 1, }, /* 7 - Ushort555Rgb */
2, 0, 1, }, /* 8 - Ushort555Rgbx*/
1, 0, 1, }, /* 9 - ByteGray */
2, 0, 1, }, /*10 - UshortGray */
1, 0, 1, }, /*11 - ThreeByteBgr */};
/**
* Given a starting value and a maximum limit, returns the first power-of-two
* greater than the starting value. If the resulting value is greater than
* the maximum limit, zero is returned.
*/
{
jint i;
return 0;
}
return i;
}
/**
* Returns true if both given dimensions are a power of two.
*/
static jboolean
{
}
/**
* Initializes an OpenGL texture object.
*
* If the isOpaque parameter is JNI_FALSE, then the texture will have a
* full alpha channel; otherwise, the texture will be opaque (this can
* help save VRAM when translucency is not needed).
*
* If the GL_ARB_texture_non_power_of_two extension is present (texNonPow2
* is JNI_TRUE), the actual texture is allowed to have non-power-of-two
* dimensions, and therefore width==textureWidth and height==textureHeight.
*
* Failing that, if the GL_ARB_texture_rectangle extension is present
* (texRect is JNI_TRUE), the actual texture is allowed to have
* non-power-of-two dimensions, except that instead of using the usual
* GL_TEXTURE_2D target, we need to use the GL_TEXTURE_RECTANGLE_ARB target.
* Note that the GL_REPEAT wrapping mode is not allowed with this target,
* so if that mode is needed (e.g. as is the case in the TexturePaint code)
* one should pass JNI_FALSE to avoid using this extension. Also note that
* when the texture target is GL_TEXTURE_RECTANGLE_ARB, texture coordinates
* must be specified in the range [0,width] and [0,height] rather than
* [0,1] as is the case with the usual GL_TEXTURE_2D target (so take care)!
*
* Otherwise, the actual texture must have power-of-two dimensions, and
* therefore the textureWidth and textureHeight will be the next
* power-of-two greater than (or equal to) the requested width and height.
*/
static jboolean
{
"OGLSD_InitTextureObject: w=%d h=%d opq=%d nonpow2=%d",
"OGLSD_InitTextureObject: ops are null");
return JNI_FALSE;
}
if (texNonPow2) {
// use non-pow2 dimensions with GL_TEXTURE_2D target
} else if (texRect) {
// use non-pow2 dimensions with GL_TEXTURE_RECTANGLE_ARB target
} else {
// find the appropriate power-of-two dimensions
}
" desired texture dimensions: w=%d h=%d max=%d",
// if either dimension is 0, we cannot allocate a texture with the
// requested dimensions
"OGLSD_InitTextureObject: texture dimensions too large");
return JNI_FALSE;
}
// now use a proxy to determine whether we can create a texture with
// the calculated power-of-two dimensions and the given internal format
// if the requested dimensions and proxy dimensions don't match,
// we shouldn't attempt to create the texture
"OGLSD_InitTextureObject: actual (w=%d h=%d) != requested",
return JNI_FALSE;
}
// initialize the texture with some dummy data (this allows us to create
// a texture object once with 2^n dimensions, and then use
// glTexSubImage2D() to provide further updates)
return JNI_TRUE;
}
/**
* Initializes an OpenGL texture, using the given width and height as
* a guide. See OGLSD_InitTextureObject() for more information.
*/
{
"OGLSurfaceData_initTexture: ops are null");
return JNI_FALSE;
}
/*
* We only use the GL_ARB_texture_rectangle extension if it is available
* and the requested bounds are not pow2 (it is probably faster to use
* GL_TEXTURE_2D for pow2 textures, and besides, our TexturePaint
* code relies on GL_REPEAT, which is not allowed for
* GL_TEXTURE_RECTANGLE_ARB targets).
*/
{
"OGLSurfaceData_initTexture: could not init texture object");
return JNI_FALSE;
}
// other fields (e.g. width, height) are set in OGLSD_InitTextureObject()
return JNI_TRUE;
}
/**
* Initializes a framebuffer object based on the given textureID and its
* the depth buffer is fairly simplistic, we hope to find a depth format that
* uses as little VRAM as possible.) If an appropriate depth buffer is found
* and all attachments are successful (i.e. the framebuffer object is
* "complete"), then this method will return JNI_TRUE and will initialize
* the values of fbobjectID and depthID using the IDs created by this method.
* Otherwise, this method returns JNI_FALSE. Note that the caller is only
* responsible for deleting the allocated fbobject and depth renderbuffer
* resources if this method returned JNI_TRUE.
*/
{
};
int i;
// initialize framebuffer object
// attach color texture to framebuffer object
textureTarget, textureID, 0);
// attempt to create a depth renderbuffer of a particular format; we
// will start with the smallest size and then work our way up
for (i = 0; i < 3; i++) {
// initialize depth renderbuffer
// creation of depth buffer could potentially fail, so check for error
error = j2d_glGetError();
if (error != GL_NO_ERROR) {
"OGLSD_InitFBObject: could not create depth buffer: depth=%d error=%x",
continue;
}
// attach depth renderbuffer to framebuffer object
// now check for framebuffer "completeness"
if (status == GL_FRAMEBUFFER_COMPLETE_EXT) {
// we found a valid format, so break out of the loop
" framebuffer is complete: depth=%d", depthSize);
break;
} else {
// this depth format didn't work, so delete and try another format
" framebuffer is incomplete: depth=%d status=%x",
}
}
// unbind the texture and framebuffer objects (they will be bound again
// later as needed)
if (!foundDepth) {
"OGLSD_InitFBObject: could not find valid depth format");
return JNI_FALSE;
}
*fbobjectID = fboTmpID;
*depthID = depthTmpID;
return JNI_TRUE;
}
/**
* Initializes a framebuffer object, using the given width and height as
* a guide. See OGLSD_InitTextureObject() and OGLSD_InitFBObject()
* for more information.
*/
{
"OGLSurfaceData_initFBObject: w=%d h=%d",
"OGLSurfaceData_initFBObject: ops are null");
return JNI_FALSE;
}
// initialize color texture object
{
"OGLSurfaceData_initFBObject: could not init texture object");
return JNI_FALSE;
}
// initialize framebuffer object using color texture created above
{
"OGLSurfaceData_initFBObject: could not init fbobject");
return JNI_FALSE;
}
// other fields (e.g. width, height) are set in OGLSD_InitTextureObject()
// framebuffer objects differ from other OpenGL surfaces in that the
// value passed to glRead/DrawBuffer() must be GL_COLOR_ATTACHMENTn_EXT,
// rather than GL_FRONT (or GL_BACK)
return JNI_TRUE;
}
/**
* Initializes a surface in the backbuffer of a given double-buffered
* onscreen window for use in a BufferStrategy.Flip situation. The bounds of
* the backbuffer surface should always be kept in sync with the bounds of
* the underlying native window.
*/
{
"OGLSurfaceData_initFlipBackbuffer: ops are null");
return JNI_FALSE;
}
"OGLSurfaceData_initFlipBackbuffer: could not init window");
return JNI_FALSE;
}
}
"OGLSurfaceData_initFlipBackbuffer: drawable is not a window");
return JNI_FALSE;
}
// REMIND: for some reason, flipping won't work properly on IFB unless we
// explicitly use BACK_LEFT rather than BACK...
return JNI_TRUE;
}
{
"OGLSurfaceData_getTextureTarget: ops are null");
return 0;
}
}
{
"OGLSurfaceData_getTextureID: ops are null");
return 0L;
}
}
/**
* Initializes nativeWidth/Height fields of the surfaceData object with
* passed arguments.
*/
void
{
return;
}
}
/**
* Deletes native OpenGL resources associated with this surface.
*/
void
{
}
}
}
if (oglsdo->fbobjectID != 0) {
oglsdo->fbobjectID = 0;
}
} else {
// dispose windowing system resources (pbuffer, pixmap, etc)
}
}
/**
* This is the implementation of the general DisposeFunc defined in
* SurfaceData.h and used by the Disposer mechanism. It first flushes all
* native OpenGL resources and then frees any memory allocated within the
* native OGLSDOps structure.
*/
void
{
"dispose", "(JJ)V",
}
/**
* This is the implementation of the general surface LockFunc defined in
*/
{
return SD_FAILURE;
}
/**
* This is the implementation of the general GetRasInfoFunc defined in
*/
void
{
}
/**
* This is the implementation of the general surface UnlockFunc defined in
*/
void
{
}
#endif /* !HEADLESS */