I have some cross-platform code in .cpp
file which converts CVPixelBuffer
to CVOpenGLESTextureRef/CVOpenGLTextureRef
. To make CoreVideo
-related functions cross-platform, I do the following in header file:
#ifdef IOS_SHARED_SUPPORT
#import <OpenGLES/EAGL.h>
#import <CoreVideo/CoreVideo.h>
#import <CoreVideo/CVOpenGLESTexture.h>
#import <CoreVideo/CVOpenGLESTextureCache.h>
#endif // IOS_SHARED_SUPPORT
#ifdef MAC_SHARED_SUPPORT
#import <CoreVideo/CoreVideo.h>
#import <CoreVideo/CVOpenGLTexture.h>
#import <CoreVideo/CVOpenGLTextureCache.h>
#import <AppKit/AppKit.h>
#endif // MAC_SHARED_SUPPORT
#ifdef IOS_SHARED_SUPPORT
typedef CVOpenGLESTextureRef CVOpenGLPlatformTexture;
typedef CVOpenGLESTextureCacheRef CVOpenGLPlatformTextureCache;
typedef CVOpenGLESTextureGetName CVOpenGLPlatformTextureGetName; // error!!!
#endif
#ifdef MAC_SHARED_SUPPORT
typedef CVOpenGLTextureRef CVOpenGLPlatformTexture;
typedef CVOpenGLTextureCacheRef CVOpenGLPlatformTextureCache;
typedef CVOpenGLTextureGetName CVOpenGLPlatformTextureGetName; // error!!!
#endif
It says "Unknown type name 'CVOpenGLESTextureGetName'; did you mean 'CVOpenGLESTextureRef'?", despite of the fact that <CoreVideo/CVOpenGLESTexture.h>
is included, and CVOpenGLESTextureRef
can be used in typedef.
Can't functions be typedef'ed?
Can you suggest some experiments?
Thanks in advance.
Can't functions be typedef'ed?
Functions? No. Function types however may be aliased. You can obtain the function type with the decltype
operator:
typedef decltype(CVOpenGLESTextureGetName) CVOpenGLPlatformTextureGetName;
And CVOpenGLPlatformTextureGetName
will become an alias for GLuint(CVOpenGLESTexture)
, the function type of CVOpenGLESTextureGetName
.
That above of course doesn't do what you want, since I suspect you just want to give another name to the function. You can do that with a constexpr
pointer to it:
constexpr auto* CVOpenGLPlatformTextureGetName = &CVOpenGLESTextureGetName;
And that's it. CVOpenGLPlatformTextureGetName
will be evaluated at compile time as "another name" for the function you initialize it with.