OpenGL API question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

OpenGL API question

David Faught
Okay, here it is.  How do I pass a null pointer to an OpenGL function,
as in the last parameter of:

ogl glTexImage2D(GLTexture2d, 0, GLRgba8,  fboWidth, fboHeight, 0,
GLRgba, GLUnsignedByte, (IntegerArray with: nil)).

By passing a null pointer as the last value, this causes this function
to allocate the texture memory on its own, which is what I want for an
FBO.  I have tried a variety of semi-logical choices including nil, 0,
and (IntegerArray new) and actually I get the best results from the
(IntergerArray with: nil) but only after an error from the
IntegerArray not being able to add a nil.  What is the right way?

Extra credit meta-question:  Where do I put the question mark for the
question starting in the first line above to promote better
understanding?

Thanks for your help.

Dave
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL API question

Andreas.Raab
Use nil. Everything else is incorrect.

Cheers,
    - Andreas

David Faught wrote:

> Okay, here it is.  How do I pass a null pointer to an OpenGL function,
> as in the last parameter of:
>
> ogl glTexImage2D(GLTexture2d, 0, GLRgba8,  fboWidth, fboHeight, 0,
> GLRgba, GLUnsignedByte, (IntegerArray with: nil)).
>
> By passing a null pointer as the last value, this causes this function
> to allocate the texture memory on its own, which is what I want for an
> FBO.  I have tried a variety of semi-logical choices including nil, 0,
> and (IntegerArray new) and actually I get the best results from the
> (IntergerArray with: nil) but only after an error from the
> IntegerArray not being able to add a nil.  What is the right way?
>
> Extra credit meta-question:  Where do I put the question mark for the
> question starting in the first line above to promote better
> understanding?
>
> Thanks for your help.
>
> Dave
>
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL API question

David Faught
Okay, that was my first choice and the first thing that I tried.  It
does not work properly.  When nil is used, it appears that the GPU
memory does not get allocated although the function returns no errors.

The process I am trying to do is to attach this GPU texture memory to
a FramebufferObject, render into it, and then use the resulting
texture mapped onto some geometry in a second rendering to the normal
display.

When nil is used, the FBO texture ends up with random memory garbage
in it, not the rendering.  When (IntegerArray with: nil) is used,
after the error the FBO texture gets properly rendered into and
appears correctly in the second rendering.

I will see if I can come up with a more simple case that causes the
same failure.

Dave

On 8/16/07, Andreas Raab <[hidden email]> wrote:

> Use nil. Everything else is incorrect.
>
> Cheers,
>    - Andreas
>
> David Faught wrote:
> > Okay, here it is.  How do I pass a null pointer to an OpenGL function,
> > as in the last parameter of:
> >
> > ogl glTexImage2D(GLTexture2d, 0, GLRgba8,  fboWidth, fboHeight, 0,
> > GLRgba, GLUnsignedByte, (IntegerArray with: nil)).
> >
> > By passing a null pointer as the last value, this causes this function
> > to allocate the texture memory on its own, which is what I want for an
> > FBO.  I have tried a variety of semi-logical choices including nil, 0,
> > and (IntegerArray new) and actually I get the best results from the
> > (IntergerArray with: nil) but only after an error from the
> > IntegerArray not being able to add a nil.  What is the right way?
> >
> > Extra credit meta-question:  Where do I put the question mark for the
> > question starting in the first line above to promote better
> > understanding?
> >
> > Thanks for your help.
> >
> > Dave
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL API question

Andreas.Raab
The only value that is coerced to NULL is nil. Period. If it doesn't
work properly then the problem is elsewhere. Just as a side note, we
have been using these exact calls for years and never had any problems.

Also, "IntegerArray with: nil" makes absolutely no sense. IntegerArrays
store integers, not pointers and any attempt to store a pointer will
fail. And I don't know what you had to hack into to make that error go
away but it is an EXTREMELY bad idea to do that. You are doing stuff
that you don't understand and that's dangerous. In this case, when you
pass anything other than nil the array reference will be interpreted as
pointing to data of specified size. In other words you are passing a
rogue pointer to OpenGL which *will* crash before too long.

Cheers,
   - Andreas

David Faught wrote:

> Okay, that was my first choice and the first thing that I tried.  It
> does not work properly.  When nil is used, it appears that the GPU
> memory does not get allocated although the function returns no errors.
>
> The process I am trying to do is to attach this GPU texture memory to
> a FramebufferObject, render into it, and then use the resulting
> texture mapped onto some geometry in a second rendering to the normal
> display.
>
> When nil is used, the FBO texture ends up with random memory garbage
> in it, not the rendering.  When (IntegerArray with: nil) is used,
> after the error the FBO texture gets properly rendered into and
> appears correctly in the second rendering.
>
> I will see if I can come up with a more simple case that causes the
> same failure.
>
> Dave
>
> On 8/16/07, Andreas Raab <[hidden email]> wrote:
>> Use nil. Everything else is incorrect.
>>
>> Cheers,
>>    - Andreas
>>
>> David Faught wrote:
>>> Okay, here it is.  How do I pass a null pointer to an OpenGL function,
>>> as in the last parameter of:
>>>
>>> ogl glTexImage2D(GLTexture2d, 0, GLRgba8,  fboWidth, fboHeight, 0,
>>> GLRgba, GLUnsignedByte, (IntegerArray with: nil)).
>>>
>>> By passing a null pointer as the last value, this causes this function
>>> to allocate the texture memory on its own, which is what I want for an
>>> FBO.  I have tried a variety of semi-logical choices including nil, 0,
>>> and (IntegerArray new) and actually I get the best results from the
>>> (IntergerArray with: nil) but only after an error from the
>>> IntegerArray not being able to add a nil.  What is the right way?
>>>
>>> Extra credit meta-question:  Where do I put the question mark for the
>>> question starting in the first line above to promote better
>>> understanding?
>>>
>>> Thanks for your help.
>>>
>>> Dave
>>>
>
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL API question

David Faught
On 8/17/07, Andreas Raab <[hidden email]> wrote:
> The only value that is coerced to NULL is nil. Period. If it doesn't
> work properly then the problem is elsewhere.

By keeping these words of yours in mind and by building a more simple
case, I was able to get this working properly.  My biggest mistake
(besides trying "IntegerArray with: nil" ;-) was not unbinding the
FBO's texture from the display framebuffer before rebinding and
rerendering into the FBO.

> Also, "IntegerArray with: nil" makes absolutely no sense. IntegerArrays
> store integers, not pointers and any attempt to store a pointer will
> fail. And I don't know what you had to hack into to make that error go
> away but it is an EXTREMELY bad idea to do that.

I agree that it doesn't make any sense, and I did not make the error
go away in any way other than to close the error requestor when it
came up.  I expected "unpredictable results".

> You are doing stuff
> that you don't understand and that's dangerous. In this case, when you
> pass anything other than nil the array reference will be interpreted as
> pointing to data of specified size. In other words you are passing a
> rogue pointer to OpenGL which *will* crash before too long.

Thanks for the warning.  Since I'm probably not going to stop doing
things like this very soon, maybe I should start putting together a
list of recommended safety precautions for experimenting with OpenGL
in an image-based system.  What do you think?

Dave

>
> Cheers,
>   - Andreas
>
> David Faught wrote:
> > Okay, that was my first choice and the first thing that I tried.  It
> > does not work properly.  When nil is used, it appears that the GPU
> > memory does not get allocated although the function returns no errors.
> >
> > The process I am trying to do is to attach this GPU texture memory to
> > a FramebufferObject, render into it, and then use the resulting
> > texture mapped onto some geometry in a second rendering to the normal
> > display.
> >
> > When nil is used, the FBO texture ends up with random memory garbage
> > in it, not the rendering.  When (IntegerArray with: nil) is used,
> > after the error the FBO texture gets properly rendered into and
> > appears correctly in the second rendering.
> >
> > I will see if I can come up with a more simple case that causes the
> > same failure.
> >
> > Dave
> >
> > On 8/16/07, Andreas Raab <[hidden email]> wrote:
> >> Use nil. Everything else is incorrect.
> >>
> >> Cheers,
> >>    - Andreas
> >>
> >> David Faught wrote:
> >>> Okay, here it is.  How do I pass a null pointer to an OpenGL function,
> >>> as in the last parameter of:
> >>>
> >>> ogl glTexImage2D(GLTexture2d, 0, GLRgba8,  fboWidth, fboHeight, 0,
> >>> GLRgba, GLUnsignedByte, (IntegerArray with: nil)).
> >>>
> >>> By passing a null pointer as the last value, this causes this function
> >>> to allocate the texture memory on its own, which is what I want for an
> >>> FBO.  I have tried a variety of semi-logical choices including nil, 0,
> >>> and (IntegerArray new) and actually I get the best results from the
> >>> (IntergerArray with: nil) but only after an error from the
> >>> IntegerArray not being able to add a nil.  What is the right way?
> >>>
> >>> Extra credit meta-question:  Where do I put the question mark for the
> >>> question starting in the first line above to promote better
> >>> understanding?
> >>>
> >>> Thanks for your help.
> >>>
> >>> Dave
> >>>
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL API question

Andreas.Raab
David Faught wrote:
>> Also, "IntegerArray with: nil" makes absolutely no sense. IntegerArrays
>> store integers, not pointers and any attempt to store a pointer will
>> fail. And I don't know what you had to hack into to make that error go
>> away but it is an EXTREMELY bad idea to do that.
>
> I agree that it doesn't make any sense, and I did not make the error
> go away in any way other than to close the error requestor when it
> came up.  I expected "unpredictable results".

Do you realize that when you close that requestor the following
computations aren't even executed? Like here:

IntegerArray with: nil. "will raise error"
Transcript show: 'Yo ho'. "won't be executed"

So whatever happened after that call would not be executed. This is in
particular true for calls so that in your example,

   ogl glTexImage2D(GLTexture2d, 0, GLRgba8,  fboWidth, fboHeight, 0,
                    GLRgba, GLUnsignedByte, (IntegerArray with: nil)).


the actual call to glTexImage2D would never be executed.

> Thanks for the warning.  Since I'm probably not going to stop doing
> things like this very soon, maybe I should start putting together a
> list of recommended safety precautions for experimenting with OpenGL
> in an image-based system.  What do you think?

Sounds great.

Cheers,
   - Andreas