I have problems generating a Float texture with depth data in it.
Since I think its more an OpenGL ES (OES 2.0) problem instead of the the SDK i am using, I try to get help here considering the OpenGL ES part.
The error i am getting is just that my app crashes, this is why I think, that the error is a wrong Texture and/or wrong usage of the float Texture.
Just a few annotations about the data i am using:
-The depthFrame I am getting is in Float
-With the use of depthInMillimeters, it is possible to get actual mm values in Float
-Since i am working on an iPhone 5 GL_HALF_FLOAT_OES should be available to use
-If someone wants to know, the data comes from the StructureSensor
This is my function to generate the Texture from the streamed depth data. I am using nearly the same function to generate RGB Textures from images, but with other data input and values.
-(GLuint) generateDepthTexture: (STDepthFrame*)depthFrame{
//data from depth in mm
NSData *data = [NSData dataWithBytes:depthFrame.depthInMillimeters length:depthFrame.width*depthFrame.height*4];
//data to texture
UIImage* depthImage = [[UIImage alloc] initWithData:data];
CGImageRef spriteImage = [depthImage CGImage];
if(!spriteImage){
NSLog(@"Failed to load image depth");
exit(1);
}
size_t width = CGImageGetWidth(spriteImage);
size_t height = CGImageGetHeight(spriteImage);
GLubyte * spriteData = (GLubyte *) calloc(width*height*4, sizeof(GLubyte)); // *4
CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width*4,
CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), spriteImage);
CGContextRelease(spriteContext);
GLuint texName;
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_FLOAT, (GLsizei)width,(GLsizei)height, 0, GL_FLOAT, GL_HALF_FLOAT_OES, spriteData);
free(spriteData);
return texName;
}
This is the important part of my render method:
//depth
//depthFrame is given every call
_depthTexture = [self generateDepthTexture:depthFrame];
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, _depthTexture);
glUniform1i(_depthUniform, 2);
I am using it in the shader with this:
//texture
uniform sampler2D DepthTexture;
//usage of the Texture
mediump vec4 depthV = texture2D(DepthTexture,TexCoordsIn);
I am not sure about the right usage here, because i would rather get the values in a float, than in a vec4.
And again, i would like to get some help considering the OpenGL ES part with the float texture. If its completely right, the problem must be with the data I am getting. If thats the case, I will ask the people working with the sensor.
The error might be only a wrong texture size or memory.
I really hope, someone has an answer to this.