diff options
author | Kenneth Russel <[email protected]> | 2006-01-03 02:36:17 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2006-01-03 02:36:17 +0000 |
commit | b69f8b201ba3767020d33a7ebe066466f00d4223 (patch) | |
tree | ac4c77e5256026f4c1de771e49d89941645e60e2 /make | |
parent | 6b4308e8b3dc41d588ff9e7519da813705a3cd94 (diff) |
Added checks on number of remaining elements and bytes for Buffers and
arrays passed to certain APIs. Default is to not emit such range
checks. The checks are currently most fully implemented for image- and
texture-related APIs. Verified with debugging code and with demos that
all textures used in demos are properly checked.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@509 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'make')
-rw-r--r-- | make/gl-common.cfg | 45 | ||||
-rw-r--r-- | make/gl-impl-CustomJavaCode.java | 96 |
2 files changed, 141 insertions, 0 deletions
diff --git a/make/gl-common.cfg b/make/gl-common.cfg index ab8af9e09..dfe01cc05 100644 --- a/make/gl-common.cfg +++ b/make/gl-common.cfg @@ -331,6 +331,51 @@ BufferObjectKind Element glDrawElements BufferObjectKind Element glDrawRangeElements BufferObjectKind Element glDrawRangeElementsEXT +# Range check directives for various routines +# FIXME: some of these are really the bare minimum and won't catch +# many classes of errors. Should extend the DebugGL to perform much +# more error checking with e.g. glDrawElements. +RangeCheck glColorPointer 3 1 +RangeCheck glDrawElements 3 {1} +RangeCheck glDrawRangeElements 5 {3} +RangeCheck glEdgeFlagPointer 1 1 +RangeCheck glElementPointerATI 1 1 +RangeCheck glFogCoordPointer 2 1 +RangeCheck glFogCoordPointerEXT 2 1 +RangeCheck glInterleavedArrays 2 1 +RangeCheck glMatrixIndexPointerARB 3 1 +RangeCheck glNormalPointer 2 1 +RangeCheck glSecondaryColorPointer 3 1 +RangeCheck glSecondaryColorPointerEXT 3 1 +RangeCheck glTexCoordPointer 3 1 +RangeCheck glVariantPointerEXT 3 1 +RangeCheck glVertexPointer 3 1 +RangeCheck glVertexAttribPointer 5 1 +RangeCheck glVertexAttribPointerARB 5 1 +RangeCheck glWeightPointerARB 3 1 + +# Range check directives for various image-related routines +RangeCheckBytes glColorTable 5 imageSizeInBytes({3}, {4}, {2} , 1 , 1) +RangeCheckBytes glColorTableEXT 5 imageSizeInBytes({3}, {4}, {2} , 1 , 1) +RangeCheckBytes glConvolutionFilter1D 5 imageSizeInBytes({3}, {4}, {2} , 1 , 1) +RangeCheckBytes glConvolutionFilter2D 6 imageSizeInBytes({4}, {5}, {2} , {3} , 1) +RangeCheckBytes glDrawPixels 4 imageSizeInBytes({2}, {3}, {0} , {1} , 1) +RangeCheckBytes glReadPixels 6 imageSizeInBytes({4}, {5}, {2} , {3} , 1) +RangeCheckBytes glTexImage1D 7 imageSizeInBytes({5}, {6}, {3} + (2 * {4}), 1 , 1) +RangeCheckBytes glTexImage2D 8 imageSizeInBytes({6}, {7}, {3} + (2 * {5}), {4} + (2 * {5}), 1) +RangeCheckBytes glTexImage3D 9 imageSizeInBytes({7}, {8}, {3} + (2 * {6}), {4} + (2 * {6}), {5} + (2 * {6})) +RangeCheckBytes glTexSubImage1D 6 imageSizeInBytes({4}, {5}, {3} , 1 , 1) +RangeCheckBytes glTexSubImage2D 8 imageSizeInBytes({6}, {7}, {4} , {5} , 1) +RangeCheckBytes glTexSubImage3D 10 imageSizeInBytes({8}, {9}, {5} , {6} , {7}) +# Note we don't support glTexImage4DSGIS / glTexSubImage4DSGIS + +# Not simple to produce good range checks for these as we would need +# to query the pipeline to see the size of the returned data before +# fetching it +# RangeCheckBytes glGetTexImage + + + # Javadoc for the GL class ClassJavadoc GL /** ClassJavadoc GL * <P> The basic interface to OpenGL, providing access to core diff --git a/make/gl-impl-CustomJavaCode.java b/make/gl-impl-CustomJavaCode.java index 3d927d271..7f4902c83 100644 --- a/make/gl-impl-CustomJavaCode.java +++ b/make/gl-impl-CustomJavaCode.java @@ -37,6 +37,102 @@ public Object getPlatformGLExtensions() { return _context.getPlatformGLExtensions(); } +// +// Helpers for ensuring the correct amount of texture data +// + +/** Returns the number of bytes required to fill in the appropriate + texture. This is regrettably a lower bound as in certain + circumstances OpenGL state such as unpack alignment can cause more + data to be required. However this should be close enough that it + should catch most crashes. The logic in this routine is based on + code in the SGI OpenGL sample implementation. */ + +private int imageSizeInBytes(int format, int type, int w, int h, int d) { + int elements = 0; + int esize = 0; + + if (w < 0) return 0; + if (h < 0) return 0; + if (d < 0) return 0; + switch (format) { + case GL_COLOR_INDEX: + case GL_STENCIL_INDEX: + elements = 1; + break; + case GL_RED: + case GL_GREEN: + case GL_BLUE: + case GL_ALPHA: + case GL_LUMINANCE: + case GL_DEPTH_COMPONENT: + elements = 1; + break; + case GL_LUMINANCE_ALPHA: + elements = 2; + break; + case GL_RGB: + case GL_BGR: + elements = 3; + break; + case GL_RGBA: + case GL_BGRA: + case GL_ABGR_EXT: + elements = 4; + break; + case GL_HILO_NV: + elements = 2; + break; + default: + return 0; + } + switch (type) { + case GL_BITMAP: + if (format == GL_COLOR_INDEX) { + return (d * (h * ((w+7)/8))); + } else { + return 0; + } + case GL_BYTE: + case GL_UNSIGNED_BYTE: + esize = 1; + break; + case GL_UNSIGNED_BYTE_3_3_2: + case GL_UNSIGNED_BYTE_2_3_3_REV: + esize = 1; + elements = 1; + break; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + esize = 2; + break; + case GL_UNSIGNED_SHORT_5_6_5: + case GL_UNSIGNED_SHORT_5_6_5_REV: + case GL_UNSIGNED_SHORT_4_4_4_4: + case GL_UNSIGNED_SHORT_4_4_4_4_REV: + case GL_UNSIGNED_SHORT_5_5_5_1: + case GL_UNSIGNED_SHORT_1_5_5_5_REV: + esize = 2; + elements = 1; + break; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + esize = 4; + break; + case GL_UNSIGNED_INT_8_8_8_8: + case GL_UNSIGNED_INT_8_8_8_8_REV: + case GL_UNSIGNED_INT_10_10_10_2: + case GL_UNSIGNED_INT_2_10_10_10_REV: + esize = 4; + elements = 1; + break; + default: + return 0; + } + return (elements * esize * w * h * d); +} + private int[] bufTmp = new int[1]; private void checkBufferObject(String extension1, String extension2, |