问题标签 [glteximage2d]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
214 浏览

c++ - 使用 C++ 的 OpenGL:将类数组传递给 glTexImage2d 时出现 vtable 问题

Color用float r,float g,float b,float alpha做了一个类。它有一个带有虚拟析构函数的基类

我正在尝试将 Color 数组传递给 opengl 函数glTexImage2D,其GL_RGBA组织类型为 float(这将是 {float r, float g, float b, float alpha} 的数组)。这只需要Color包含 4 个浮点数(大小为 16 个字节)。

但是,由于具有vtable的基类,sizeof(Color)这表明我的类的大小为 20 字节,这要归功于析构函数。Color

如何保留我的 vtable 并仍然将我的 Color 数组传递给glTexImage2D

0 投票
1 回答
5104 浏览

opengl - glBindImageTexture() 和 glBindTexture() 有什么区别?

glBindImageTexture 和 glBindTexture 有什么区别?以及着色器中以下声明之间的区别是什么:

0 投票
1 回答
1368 浏览

c++ - OpenGL ES 3.1 - Unable to create IMMUTABLE Textures with glTexImage2D

I'm trying to create an immutable texture with glTexImage2D() that I can then bind using glBindImageTexture()

Here's my C++ code :

As I don't need Mipmap levels I set GL_TEXTURE_MAX_LEVEL to 0.
Then I call glTexImage2D() to set up all texture's levels (only one here) and I have no errors raised.

Unfortunately the result of
glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_IMMUTABLE_FORMAT,&status) is 0 which means that the texture is not immutable.

Now, when I try to call glBindImageTexture(), error 1282 is raised because as it is written in the khronos documentation, this opengl function needs an immutable texture.

Any ideas on what I'm doing wrong ?

Thanks in advance ;)

EDIT :

Thank you to both of you for your time and for all the information provided but There are things I don't understand.

This paragraph of the glTexStorage2D() man (khronos documentation) confuses me:

The behavior of glTexStorage2D depends on the target parameter. When target is GL_TEXTURE_2D, calling glTexStorage2D is equivalent, assuming no errors are generated, to executing the following pseudo-code:

Since no texture data is actually provided, the values used in the pseudo-code for format and type are irrelevant and may be considered to be any values that are legal for the chosen internalformat enumerant. internalformat must be one of the sized internal formats given in Table 1, or one of the compressed internal formats given in Table 2 below. Upon success, the value of GL_TEXTURE_IMMUTABLE_FORMAT becomes GL_TRUE. The value of GL_TEXTURE_IMMUTABLE_FORMAT may be discovered by calling glGetTexParameter with pname set to GL_TEXTURE_IMMUTABLE_FORMAT. No further changes to the dimensions or format of the texture object may be made. Using any command that might alter the dimensions or format of the texture object (such as glTexImage2D or another call to glTexStorage2D) will result in the generation of a GL_INVALID_OPERATION error, even if it would not, in fact, alter the dimensions or format of the object.

It remains unclear for me wether the paragraph above is about glTexImage2D() or glTexStorage2D().

Moreover, my underlying question is: Can we bind a texture created with glTexImage2D() using glBindImageTexture() ? (I saw code samples where these two functions were actually used together, here for instance)

0 投票
1 回答
209 浏览

ios - gl 纹理采样器在 iOS 上总是返回 vec4(0.,0.,0.,1.) (但在 OSX/Android 上可用)

我的代码只是将一些人为的数据上传到纹理:

以及仅在我的着色器中从该纹理中采样的代码:

在 OSX 和 Android 上,这个纹理在我的着色器中是可读的(通过 sampler2D——没什么花哨的)——它可以工作。在 iOS 上,该 sampler2D 中的任何样本都会返回vec4(0.,0.,0.,1.),而不管输入的数据如何。

(请注意,当我更改GL_ALPHA为时GL_RGBA,将纹理附加到帧缓冲区,然后glReadPixelsglTexImage2D我取回输入的确切数据后调用无论平台如何,功能(或 iOS 上的功能缺失)保持不变。切换到GL_RGBA只需要将它附加到帧缓冲区,这是必要的glReadPixels,我只关心调试目的。tl;博士:我有理由相信数据正在所有平台上正确上传到纹理。)

其他信息:

gl_sim_texture_active_n为 6 和gl_sim_texture_buff_id14(均合法且无错误地获得)。调用glGetError()glCheckFramebufferStatus(GL_FRAMEBUFFER)之前或之后都返回干净。glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS)返回 8(与我的测试 Android 设备上的相同。

我完全不知道为什么这会在 OSX/Android 上运行,而不是在 iOS 上运行。任何方向回复:从这里去哪里都会有帮助!

0 投票
2 回答
880 浏览

android - 使用 GLES20.GlTexImage2D() android xamarin 向 glsurafceview 显示字节数组图像

我必须将字节数组图像绘制到glsurfaceview,该图像连续来自xamarin android项目中的服务器。代码不适用于直接缓冲区绘制,但它适用于位图绘制。

如果我将字节数组转换为位图并绘制,我的代码就可以工作:

如果我在同一代码中输入以下代码,则它不会绘制。我想使用 GLES20.GlTexImage2D() 绘制字节数组。我不工作的代码是:

如何使用 GlTexImage2D 为直接字节数组绘制图像。

0 投票
1 回答
701 浏览

javascript - WebGL texImage2D 问题:如何在单元/对象上获取纹理?

所以我正在寻找一些关于 WebGL 纹理/3D 渲染的帮助。

我的代码的重点(到目前为止我所做的)是创建一个纹理块/立方体的 3D 迷宫,用户可以通过箭头键或 WASD 导航。我遇到的问题只是 texImage2d() 我相信。

我试过像

这不起作用并导致了这个

我也试过

这导致了同样的错误。

我究竟做错了什么?我能修复它吗?

0 投票
1 回答
967 浏览

android - 在 Android 设备上使用 GL_LUMINANCE 和 GL_FLOAT 的 OpenGL ES 2

使用 Android Studio,我的代码将浮点数组渲染为传递给 GLSL 的纹理,每个纹理像素一个浮点数在 0 到 1 的范围内,就像灰度纹理一样。为此,我使用 GL_LUMINANCE 作为 glTexImage2D 的 internalFormat 和格式,使用 GL_FLOAT 作为类型。在 android 设备模拟器上运行应用程序可以正常工作(它使用我的 PC 的 GPU),但在真实设备(三星 Galaxy S7)上调用 glTexImage2D 会出现错误 1282,GL_INVALID_OPERATION。我认为这可能是两个纹理的非幂的问题,但宽度和高度肯定是二的幂。

该代码使用输出网格密度值的Jos Stam 流体模拟 C 代码(使用 NDK 编译,未移植)。

mSizeN 是流体模拟网格的宽度(与高度相同),虽然流体模拟为边界条件在其上加了 2,所以返回的数组的宽度为 mSizeN + 2;在这种情况下为 128。

坐标系设置为正投影,屏幕左上角为 0.0,0.0,右下角为 1.0,1.0。我只是绘制了一个全屏四边形,并使用 GLSL 中四边形的插值位置作为包含密度值的数组的纹理坐标。渲染它的好方法。

这是渲染器类。

这是纹理辅助函数。

片段着色器。

OpenGL ES 2 不支持 GL_FLOAT 和 GL_LUMINANCE 的组合吗?

安卓模拟器图片。

编辑:补充一下,我是否正确地说,当使用 glTexImage2D (等)传输时,每个浮点值将减少为 8 位整数分量,所以大部分浮点精度会丢失?在这种情况下,最好重新考虑模拟器的实现以输出定点。这很容易做到,Stam 甚至在他的论文中进行了描述。

0 投票
1 回答
856 浏览

opengl - OpenGL可以将整数像素数据转换为浮点数或UNORM吗?

glTexImage2D需要internalFormat(指定位数和数据类型/编码),format(没有位数和编码)和type.

例如,是否有可能让 OpenGL 将传递的包含 32 位整数的像素数据从格式GL_RGB_INTEGER和类型GL_INT转换为内部格式GL_RGB32F

wiki 文章https://www.khronos.org/opengl/wiki/Pixel_Transfer#Format_conversion向我建议可以通过说明:

用户指定的像素必须在用户指定的格式(带有格式​和类型​)和图像的图像格式控制的内部表示之间进行转换。

但是我无法从着色器中的浮点采样器中读取数据。

0 投票
0 回答
247 浏览

opengl - glTexSubImage2D 上传 YUV 数据很慢

我正在编写一个视频播放器,我解码了视频帧并使用 3sampler2D秒来接收 YUV 格式的帧数据,它渲染得非常好。

但它有严重的性能问题glTexSubImage2D。我观察到奇怪的行为:

  1. 以 Y、U、V 的顺序上传 YUV 数据,然后上传U随机缓慢(1ms 到 100ms)。
  2. 按 Y、V、U 的顺序上传 YUV 数据,然后上传V随机缓慢(1ms 到 100ms)。
  3. 按 U、V、Y 的顺序上传 YUV 数据,然后上传Y一直很慢(10ms 到 50ms)。

对于其他上传不慢的组件,耗时不到1ms。我glTexSubImage2DinternalFormat=GL_RED, format=GL_RED, dataType=GL_UNSIGNED_BYTE.

这些奇怪行为的可能原因是什么?

0 投票
1 回答
300 浏览

javascript - 获取使用 gl.texImage2D 绘制的纹理的“红色”像素值

我正在使用纹理将 Float32array 发送到我的片段着色器(这里的目标是使用纹理将数据发送到着色器,在着色器中处理此数据,然后将其发送回 javascript)。由于我的数据实际上不是图像,因此我决定通过“gl.R32F”发送它,并且在使用 gl.readPixels 处理后尝试读取这些数据。这是我的代码,例如,尚未处理数据,首先我试图找到一种将数据发送回javascript的方法;

当我尝试将数据写入纹理时,我没有收到任何错误(尽管我不知道数据是否在没有任何更改的情况下发送,因为我无法将其读回)。但是,当我尝试使用 gl.readPixels 将其读回时,出现以下错误,

所以,我的问题是这样的;

  1. 如果我使用纹理发送数据的方式是正确的,并且在此过程中我的数据没有更改,我该如何将其发送回 JavaScript?
  2. 如果我发送数据的方式是错误的,我该如何实现我的目标?

如果你能帮助我解决这个问题,我将不胜感激。谢谢你。

Ps:数据并不总是完美的正方形。