9

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?

Paul R
  • 208,748
  • 37
  • 389
  • 560
Halsafar
  • 2,540
  • 4
  • 29
  • 52
  • 1
    Answer my own question here. In some scenarios this can be solved by adjusting texture coordinates. Lets say I have a 512x512 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. – Halsafar Jun 15 '11 at 04:20
  • 1
    Can you post your solution as an answer below? Thanks. – Bill the Lizard Jun 15 '11 at 12:34

3 Answers3

2

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.

Community
  • 1
  • 1
Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106
1

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.

Tristan Lorach
  • 471
  • 4
  • 5
0

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.

Halsafar
  • 2,540
  • 4
  • 29
  • 52