PDA

View Full Version : A mess in glClipPlane() documentation???

sansan
04-13-2009, 07:10 AM
Can anybody explain me the following piece of OpenGL documentation related to glClipPlane() function:

void glClipPlane( GLenum plane, const GLdouble * equation);

Parameters
plane
Specifies which clipping plane is being positioned. Symbolic names of the form GL_CLIP_PLANEi, where i is an integer between 0 and <u>GL_MAX_CLIP_PLANES</u>-1, are accepted.

...

Description
... To determine the maximum number of additional clipping planes, call <u>glGetIntegerv</u> with argument <u>GL_MAX_CLIP_PLANES</u>.

I am pretty sure the correct way to determine the maximum number of supported clipping planes is calling glGetIntegerv(), but I am also sure that meaningful value for "plane" parameter above also varies from GL_CLIP_PLANE0 to GL_CLIP_PLANEn,
where n = glGetIntegerv(GL_MAX_CLIP_PLANES) - 1.
Is it true or not?

Apart from that, what is the correct way to iterate through all supported clipping plane IDs among the two ones below:

a.

for ( int i = 0, n = glGetIntegerv(GL_MAX_CLIP_PLANES); i < n; i++ ) {
int clipPlaneId = GL_CLIP_PLANE0 + i;
// Setup clipPlaneId-th clipping plane
...
}

or

b.

for ( int i = 0, n = GL_MAX_CLIP_PLANES; i < n; i++ ) {
int clipPlaneId = GL_CLIP_PLANE0 + i;
// Setup clipPlaneId-th clipping plane
...
}

Jan
04-13-2009, 08:35 AM
Question 1: true

Query n with n = glGetIntegerv(GL_MAX_CLIP_PLANES)

Then use GL_CLIP_PLANE0 ... GL_CLIP_PLANE(n-1)

Question 2: a

GL_MAX_CLIP_PLANES is an OpenGL enum, it will be something really huge (> 1000 possibly). It has no meaningful value to you, so code b would give you errors or even crash.

a is correct, but i would not query n every time, but once at startup (though you knew that probably already).

Hope that helps,
Jan.

martinsm
04-13-2009, 08:51 AM
I thought that all GL_MAX_xxx enums are not huge. They contain minimum needed count of specific feature (clip plane for example) that is needed to be supported on all OpenGL implementations. For example, GL_MAX_LIGHTS = 8, and so on...
Is that not right?

overlay
04-13-2009, 09:21 AM
To martinsm: very wrong. GL_MAX_xxx are keys to query state values.

Example:

gl.h has:
#define GL_MAX_TEXTURE_SIZE 0x0D33

Spec 2.1 page 298, Table 6.33 Implementation Dependent Values:

minimum value returned for key GL_MAX_TEXTURE_SIZE should be 64.

On my machine, the following code:
{
GLint ivalue;
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&ivalue);
}

feeds ivalue with 8192.

(this is confirmed with "glxinfo -l" (on Linux) )

martinsm
04-13-2009, 10:15 AM
Oh, sorry. Of course they are to be used for glGet calls. I don't know why I forgot that.. It seems it's been some time since I had need for that.

sansan
04-13-2009, 11:07 AM
Thanks to everybody!

It seems that glClipPlane() function description in OpenGL docs needs some clarification, indeed.

Currently, the above-mentioned piece of OpenGL documentation with mixed values of GL_MAX_CLIP_PLANES and glGetIntegerv(GL_MAX_CLIP_PLANES) is duplicated in other popular resources (e.g. OpenGL articles in MSDN) and I believe this is not at all good.