[Kstars-devel] Re: Planet textures with OpenGL

Alexey Khudyakov alexey.skladnoy at gmail.com
Sun Apr 10 14:50:00 CEST 2011


On 10.04.2011 07:33, Akarsh Simha wrote:
> On Sat, Apr 09, 2011 at 02:30:24PM +0400, Alexey Khudyakov wrote:
>> On 09.04.2011 05:45, Akarsh Simha wrote:
>>>> IMHO the best way to deal with the problem is to aquire texture ID
>>>> when they are used for first time. So they will be generated after
>>>> transfer of ownership.
>>>
>>> There might be a better way. Looking at the code,
>>> QContextPrivate::bindTexture() is supposed to check if the texture
>>> already has a texture ID and then bind it. It does maintain a cache of
>>> textures. If my understanding is correct, ideally, it should
>>> invalidate that cache as well when the context is reset. So maybe it
>>> is best to solve this in QGLContextPrivate itself. I need to ask on
>>> #qt or something and I plan to do it this weekend.
>>>
>> Indeed. QGLContext states:
>>
>> The texture that is generated is cached, so multiple calls to
>> bindTexture() with the same QImage will return the same texture id.
>>
>> So you propose to avoid caching texture IDs at all and rely on Qt to
>> do that, am I right?
>
> Yes, that's what I mean. But then, that doesn't seem to work
> out-of-the-box if I did my experiments right. I suspect that
> QGLContext does not clean its texture cache when it is reset, but I
> need to check that. Need to do some asking around.
>
>>>> Maybe TextureManager should not own context at all and have it
>>>> passed in as parameter. This way we can avoid transfering of context
>>>> at all.
>>>
>>> That sounds good to me! We have a Q_ASSERT( m_context ) whenever we
>>> try to bind a texture and we can have a TextureManager::setContext(
>>> QGLContext * ), and we can pass the context of the QGLWidget.
>>>
>> I think setContext is bad idea. TextureManager do not own context so
>> it should not hold pointer to it. If context is passed as parameter
>> than it's not possible to have incoherence when manager holds one
>> context and caller expect another.
>
> Hmm, okay.
>
> So you plan to instead call something like:
>
> TextureManager::getTexture( "texture", m_widget->getContext() );
>
> But somehow that doesn't look very good to me...
>
Yes, it's too verbose. It's possible to add helper function which will 
call getContext on QGLWidget so it will red

Or it's possible to [ab?]use QGLContext::currectContext. Documentation 
says thet it returns the current context, i.e. the context to which any 
OpenGL commands will currently be directed. Returns 0 if no context is 
current.

getTexture(const QString& name, QGLContext* cxt = 0)
{
   if( cxt == 0 )
     cxt = QLContext::currentContext();
}

This function have rather straightforward semantic: if no context is 
suplied than it uses current. Or parmeter could be removed

Also it should be noop if no context is available.



> I think this is a good idea. Yes, Texture seems to be redundant, and
> texture manager can keep track of it.
>
 > ... <skipped>
>
> Is that what you mean? Sounds good to me. Does Harry have any
> objections?
>
Exactly


More information about the Kstars-devel mailing list