As title, i want to ask how to create a Sprite or Texture2D from a texture name already with OpenGL.
More details is : I have capture image from Java code then pull it to a SurfaceTexture with input Texture ID so how can i get that texture out with cocos2d-x. ( v3.8.1 )
For now i’m using JNI to transfer image data to cocos2d-x but i think it is not so performance.
save it out as an image file “img.png”, then fire off callback w/JNI to create Sprite normally from image
create class derived from Texture2D, add constructor/init or a method to set the _name field, add JNI support to pass in the GLInt (you may have to pass or set up other aspects of the texture like mipmaps, texParams, etc)
case 1: i do not want to save file and load back ( i can use transfer image data via JNI )
case 2: i’m try but no success. that target is GL_TEXTURE_EXTERNAL_OES and i don’t know how to use it or cocos2d-x support it or not.
You would use a shader with the extension and uniform for the texture.
#extension GL_OES_EGL_image_external : require
// Our WebView's texture! Note that it is NOT (And can't be) sampler2D
uniform samplerExternalOES uniform_texture0;
Using the texture through cocos2d-x API would require custom code since that type is unsupported, but it’s similar to using a Cube Map
// see CCTextureCube.cpp : 193
glGenTextures(1, &handle);
GL::bindTextureN(0, handle, GL_TEXTURE_CUBE_MAP);
// or CCGLProgramState.cpp : 114
case GL_SAMPLER_CUBE:
_glprogram->setUniformLocationWith1i(_uniform->location, _value.tex.textureUnit);
GL::bindTextureN(_value.tex.textureUnit, _value.tex.textureId, GL_TEXTURE_CUBE_MAP);