Question

Is there any way to blit a texture in opengl es 2.0 with a pitch that differs from its width. Normally I would fix this by using a PBO or adjusting the GL_PACK_ROW_LENGTH via glPixelStore. However it seems neither GL_PIXEL_UNPACK_BUFFER for binding a buffer to or GL_PACK_ROW_LENGTH exist on the Android platform.

glTex(Sub)Image2D does not support this.

Any tips?

Was it helpful?

Solution 3

Since I answered it in a comment here is a more direct answer:

// width and height is 256 and max is 512
// texture coordinates
float uMax = (width / max);
float vMax = (height / max);

_texCoords[0] = 0.0; _texCoords[1] =  vMax;
_texCoords[2] = uMax; _texCoords[3] =  vMax;
_texCoords[4] = 0.0; _texCoords[5] =  0.0;
_texCoords[6] = uMax; _texCoords[7] =  0.0;

Now use these texcoords to render and you can stick a 256x256 texture in a 512x512 buffer. The width and height you want to use can be any size equal to or below your max size.

OTHER TIPS

Quoting @Halsafar

In some scenarios, this can be solved by adjusting texture coordinates.


Lets say I have a 512 x 512 texture pitched at 512 * bitdepth

but the data I want to use is pitched to 256 * bitdepth

I go ahead and glSubTexImage2D still but adjust the texture coords to be 0 to (256/512)

instead of 0 to 1.

In other words strip off the part of the texture I'm not using.

it might sound a bit overkill (or even not so fitting to your expectation), but maybe you could simply take advantage of the rasterizer and Frame-buffer objects : create a FBO with the texture as the color buffer and... draw in it some textured quad(s) thanks to a trivial vertex+fragment shader : where you would use a simple Ortho. projection matrix in the vertex shader and use a Point-sampling texture sampling in the fragment shader.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top