C ++ How to replace a function, but still use the original function in it?

I want to change the glBindTexture () function to track previously bound texture ids. At the moment, I just created a new function for it, but then I realized that if I use other codes that use glBindTexture: then my whole system can go down to the toilet.

So how do I do this?

Edit: Now that I have thought about this, checking if I need to bind the texture or not is completely useless, since opengl probably does it already. But I still need to track the previously used texture.

+3
source share
6

glBindTexture:

#define glBindTexture(target, texture) myGlBindTexture(target, texture)

, , :

(glBindTexture)(someTarget, someTexture);

, , .

, , , DLL, ..

0

, , . , - , gnu linker ( ), :

--wrap glBindTexture

( gcc, ):

-Wl,--wrap,glBindTexture

, (: "" - , , ).

"" :

void * __wrap_glBindTexture (GLenum target, GLuint texture) {
   printf ("glBindTexture wrapper\n");
   return __real_glBindTexture (target,texture);
}
+7

. LD_PRELOAD. , glBindTexture. , dlopen OpenGL dlsym .

LD_PRELOAD , OpenGL .

.

+3

glBindTexture. DLL OpenGL, OpenGL, , DLL OpenGL. , , ...

, GLIntercept .

+1

OpenGL, , . glBindTexture , . , glBindTexture , , , , glBindTexture. , -, , , .

0

, . , , .

However, this is even the best idea for separating problems: let low-level openGL cope with low-level materials, and your (thin, thick, as you want) layer of abstraction will make the material of a higher level.

So, create an oglWrapper :: BindTexture function that does if (), but you should not play with LD, even if it is technically possible.

[EDIT] This is actually not in the ogl specification, but still.

0
source

Source: https://habr.com/ru/post/1759913/


All Articles