Android NDK OpenGL ES 2.0 纹理间距

发布于 2024-11-15 07:03:51 字数 236 浏览 3 评论 0原文

有没有什么方法可以在 opengl es 2.0 中以与其宽度不同的间距来位图纹理。通常我会通过使用 PBO 或通过 glPixelStore 调整 GL_PACK_ROW_LENGTH 来解决此问题。然而,Android 平台上似乎既不存在用于绑定缓冲区的 GL_PIXEL_UNPACK_BUFFER 也不存在 GL_PACK_ROW_LENGTH 。

glTex(Sub)Image2D 不支持此功能。

有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十年不长 2024-11-22 07:03:51

引用@Halsafar

在某些场景下,可以通过调整纹理坐标来解决。


假设我有一个 512 x 512< /code>纹理间距为 512 * 位深度

但我想要使​​用的数据被定位到256 * 位深度

我继续,glSubTexImage2D仍然,但将纹理坐标调整为 0 至 (256/512),

而不是 01

换句话说,去掉我不使用的纹理部分

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.

吾家有女初长成 2024-11-22 07:03:51

这听起来可能有点矫枉过正(甚至不太符合您的期望),但也许您可以简单地利用光栅化器和帧缓冲区对象:
创建一个带有纹理作为颜色缓冲区的 FBO,然后...通过一个简单的顶点+片段着色器在其中绘制一些纹理四边形:您可以在其中使用简单的 Ortho。在顶点着色器中使用投影矩阵,并在片段着色器中使用点采样纹理采样。

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.

深海夜未眠 2024-11-22 07:03:51

因为我在评论中回答了这个问题,所以这里有一个更直接的答案:

// 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;

现在使用这些 texcoords 进行渲染,您可以将 256x256 纹理粘贴在 512x512 缓冲区中。您要使用的宽度和高度可以是等于或小于最大尺寸的任何尺寸。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文