Felix Kühling wrote:
On Mon, 10 Mar 2003 22:23:07 +0000
José Fonseca <[EMAIL PROTECTED]> wrote:
[snip]

As I said above this can be done in C++, and without damage to
efficiency.

Imagine you have a TnL abstract class:

class TNL {
// A OpenGL function
virtual void Coord3f(GLfloat x, GLfloat y, GLfloat z) = 0;
// Activate
virtual void activate() = 0;


 protected:
   struct dispatch_table *my_dispatch_table;
} ;

and then you have two inherited classes for software and hardware
rendering:

class SoftwareTNL : public TNL {
 // The software version. Note the _inline_
 inline void Coord3f(x, y, z) {
   _mesa_swrast_deal_with_this_vertex(x, y, z);
 }
};

class HardwareTNL : public TNL {
 // The hardware version. Note the _inline_
 inline void Coord3f(x, y, z) {
   _add_vertex_to_DMA_buffer(x, y, z);
 }
};

and then the C-callable versions for the glapi disptach table:

void softwareCoord3f(GLcontext *ctx, GLfloat x, GLfloat y, GLfloat z) {
 Driver::Context *context = ctx;
 Driver::SoftwareTNL &tnl = ctx->tnl;

 // There will be no call as the function will be expanded inline
 tnl.Coord3F(x, y, z);
}


Here you're converting a GLcontext * to a Driver::Context *. Can you do
that because Mesa::Context has GLcontext as first member? Anyway, if
that didn't work you could always do some fancy pointer arithmetics with
the offset of the GLcontext in Driver::Context.

There's a slight misconception happening here -- the 'ctx' argument doesn't exist. The function should read something like:


        void swv3f( GLfloat x, GLfloat y, GLfloat z )
        {
                GET_CONTEXT_FROM_THREAD_LOCAL_STORE( ctx )
                // get tnl somehow
        
                tnl->v3f( x, y, z )
        }

But why bother? tnl->v3f isn't virtual, so what's the point of having the implementation somewhere else? Why not just do it here?

Keith



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Dri-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dri-devel

Reply via email to