あるスレッドでテクスチャを作成し、それを別のスレッドで使用する必要があります。共有コンテキストを使用してみましたが、テクスチャが共有されていないようです。このサンプル(Wiktorさんが投稿したコード)を使ってeglCreateImageKHR
使って みました
eglCreateImageKHR
返品中EGL_NO_IMAGE_KHR
です。
また、拡張機能を使用しているときに、コードをコンパイルするために eglext.h と gl2ext.h をインクルードする前に定義する#define EGL_EGLEXT_PROTOTYPES
必要
#define GL_GLEXT_PROTOTYPES
がありました。これは間違っていますか?これらは他のヘッダーで定義する必要がありますか?
それが役立つ場合は、テクスチャを作成するスレッドのコードを次に示します。私が間違っているのは、OpenGL から返されたテクスチャ ハンドルを に渡し、eglCreateImageKHR
それを にキャストすることだと思いますEGLClientBuffer
。(また、サンプルからコピーしただけなので、reinterpret_castが何をするのかわかりません。しかし、サンプルはこの部分についてあまり明確ではありません。)
GLuint framebuffer;
GLuint depthRenderbuffer;
GLuint texture;
GLint texWidth = 256, texHeight = 256;
const EGLint attribs[] = {
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 8,
EGL_STENCIL_SIZE, 0,
EGL_NONE
};
const EGLint pbuf_attribs[] = {
EGL_WIDTH, 512,
EGL_HEIGHT, 512,
EGL_NONE};
EGLSurface psurface;
EGLContext context;
EGLConfig config;
EGLint numConfigs;
EGLDisplay display;
const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION,2, EGL_NONE };
if ((display = eglGetDisplay(EGL_DEFAULT_DISPLAY)) == EGL_NO_DISPLAY) {
LOG_ERROR("Tex eglGetDisplay() returned error %d", eglGetError());
return false;
}
if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs)) {
LOG_ERROR("eglChooseConfig() returned error %d", eglGetError());
destroy();
return false;
}
if (!(context = eglCreateContext(display, config, 0, contextAttribs))) {
LOG_ERROR("Tex eglCreateContext() returned error %d", eglGetError());
destroy();
return false;
}
if (!(psurface = eglCreatePbufferSurface(display, config, pbuf_attribs))) {
LOG_ERROR("Tex eglCreatePbufferSurface() returned error %d", eglGetError());
destroy();
return false;
}
LOGI("About to make current. Display %p surface %p context %p",display, psurface, context);
if (!eglMakeCurrent(display, psurface, psurface, context)) {
LOG_ERROR("Tex eglMakeCurrent() returned error %d", eglGetError());
destroy();
return false;
}
checkGlError("make current");
glGenFramebuffers(1, &framebuffer);
glGenRenderbuffers(1, &depthRenderbuffer);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texWidth, texHeight,
0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, NULL);
glBindTexture(GL_TEXTURE_2D, 0); //FIXME Should this be here?? Tried with and without
EGLint imageAttributes[] = { EGL_GL_TEXTURE_LEVEL_KHR, 0,
EGL_IMAGE_PRESERVED_KHR, EGL_FALSE, EGL_NONE };
LOGI("Before CreateImage display %p context %p texture %d",display, context, texture);
_eglImage = eglCreateImageKHR(display, context,
EGL_GL_TEXTURE_2D_KHR, reinterpret_cast<EGLClientBuffer>(texture),
0);
if(_eglImage == EGL_NO_IMAGE_KHR){
LOGE("eglCreateImageKHR failed");
}