- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 glTexImage2D()
创建一个不可变的纹理,然后我可以使用 glBindImageTexture()
这是我的 C++ 代码:
GLuint id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
GLint width = 2046;
GLint height = 1086;
// Not sure what to put here 1, 2, 4 or 8 ?
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
GLint levels;
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, &levels);
for (int i = 0; i < levels + 1; i++)
{
glTexImage2D(GL_TEXTURE_2D, i, GL_R32UI, width, height, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
width = glm::max(1, (width / 2));
height = glm::max(1, (height / 2));
// check OpenGL error
GLenum err;
while ((err = glGetError()) != GL_NO_ERROR) {
ALOGE("ERROR_GL_TEXTURE_INIT: %i", err);
}
}
GLint status;
glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_IMMUTABLE_FORMAT,&status);
ALOGE("IMMUTABLE_TEXTURE: %i", status);
glBindTexture(GL_TEXTURE_2D, 0);
glBindImageTexture(0, id, 0, GL_FALSE, 0, GL_READ_WRITE, GL_R32UI);
// check OpenGL error
GLenum err;
while ((err = glGetError()) != GL_NO_ERROR) {
ALOGE("ERROR_GL_TEXTURE_IMG-USE: %i", err);
}
因为我不需要 Mipmap 级别,所以我将 GL_TEXTURE_MAX_LEVEL
设置为 0
。
然后我调用 glTexImage2D()
来设置所有纹理级别(这里只有一个)并且没有出现错误。
不幸的是glGetTexParameteriv(GL_TEXTURE_2D,GL_TEXTURE_IMMUTABLE_FORMAT,&status)
的结果是0
,这意味着纹理不是不可变的 .
现在,当我尝试调用 glBindImageTexture()
时,出现错误 1282,因为它写在 khronos documentation 中,这个 opengl 函数需要一个不可变纹理。
对我做错了什么有什么想法吗?
提前致谢;)
编辑:
感谢你们抽出时间和提供的所有信息,但有些事情我不明白。
这段 glTexStorage2D()
人(khronos documentation)让我很困惑:
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:
for (i = 0; i < levels; i++)
{
glTexImage2D(target, i, internalformat, width, height, 0, format, type, NULL);
width = max(1, (width / 2));
height = max(1, (height / 2));
}
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 ofGL_TEXTURE_IMMUTABLE_FORMAT
becomesGL_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.
我不清楚上面的段落是关于 glTexImage2D()
还是 glTexStorage2D()
。
此外,我的基本问题是:我们可以使用 glBindImageTexture()
绑定(bind)使用 glTexImage2D()
创建的纹理吗?(我看到了这两个函数实际一起使用的代码示例,例如 here)
最佳答案
要分配不可变纹理存储,您可以使用 glTexStorage2D()
而不是 glTexImage2D()
。所以你分配纹理内存的调用变成了:
glTexStorage2D(GL_TEXTURE_2D, levels, GL_R32UI, width, height);
在这种情况下,您可以通过一次调用分配所有 mipmap 级别,因此您不需要当前拥有的循环。
此外,我不确定您对此的期望是什么:
GLint levels;
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, &levels);
在您的代码中,您只是在进行此调用时创建了纹理。所以查询层数是没有意义的。如果你想要一个 mipmap 纹理,你必须根据大小计算你需要的 mipmap 的数量。如果不需要 mipmap,只需将 1
作为第二个参数传递给 glTexStorage2D()
。
因为有一些后续问题是关于是否有其他方法可以创建不可变纹理,例如使用 glTexImage2D()
,答案是否定的。 ES 3.1 规范第 8.17 节标题为“不可变格式纹理图像”,从第 190 页开始,解释了如何创建不可变纹理。该部分中列出的唯一调用是 glTexStorage2D()
和 glTexStorage3D()
。它还特别提到这些调用将 GL_TEXTURE_IMMUTABLE_FORMAT
属性设置为 true。
唯一提到它创建不可变纹理的其他调用是第 171 页第 8.8 节中的 glTexStorage2DMultisample()
。
这意味着 glTexImage2D()
创建的纹理不是 不可变的。确认这是第 194 页标题为“纹理状态”的 8.18 节,其中列出了各种纹理属性的默认值:
In the initial state, [..] The value of TEXTURE_IMMUTABLE_FORMAT is FALSE.
由于 glTexImage2D()
的规范没有提及更改值,因此它将保持为 false。
关于c++ - OpenGL ES 3.1 - 无法使用 glTexImage2D 创建不可变纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38126660/
为什么禁用类型像 type t = A of int | B of string * mutable int 虽然允许此类类型: type t = A of int | B of string * i
我正在寻找一种类似结构的数据结构,我可以从中创建多个实例并具有某种类型提示而不是不可变的。 所以我有这样的东西: class ConnectionConfig(NamedTuple): nam
我需要转到引用的结构: class SearchKnot { var isWord : Bool = false var text : String = "" var to
如sec 10.4.3中所述 当控制进入执行时,执行以下步骤 功能对象F(调用者)中包含的功能代码的上下文 提供thisArg,而调用方提供argumentsList: 如
i make a game that start display Activity indicator And activity indicator bottom display UiLable wi
编辑:我在这里不断获得支持。只是为了记录,我认为这不再重要。自从我发布它以来我就不再需要它了。 我想在 Scala 中执行以下操作... def save(srcPath: String, destP
使用可变对象作为 Hashmap 键是一种不好的做法吗?当您尝试使用已修改足以更改其哈希码的键从 HashMap 中检索值时,会发生什么? 例如,给定 class Key { int a; /
如果您在Kotlin中访问List类型的Java值,则将获得(Mutable)List!类型。 例如。: Java代码: public class Example { public stati
我编写了 str 类(内置)的以下扩展,以便执行以下操作:假设我有字符串 "Ciao" ,通过做"Ciao" - "a"我想要的结果是字符串 "Cio" 。这是执行此操作的代码,并且运行良好: cla
使用可变对象作为 Hashmap 键是一种不好的做法吗?当您尝试使用已修改足以更改其哈希码的键从 HashMap 中检索值时,会发生什么? 例如,给定 class Key { int a; /
我正在为我的公司设计一个数据库来管理商业贷款。每笔贷款都可以有担保人,可以是个人或公司,在借款业务失败时作为财务支持。 我有 3 个表:Loan、Person 和 Company,它们存储明显的信息。
我使用二进制序列化从 C# 类中保存 F# 记录。一切正常: F#: type GameState = { LevelStatus : LevelStatus
import javax.swing.JOptionPane; public class HW { public static void main(String[] args) { Strin
使用 flatbuffer mutable 有多少性能损失? 是否“正确”使用 FlatBuffers 来拥有一个应该可编辑的对象/结构(即游戏状态) 在我的示例中,我现在有以下类: class Ga
std::function create_function (args...) { int x = initial_value (args...); return [x] () mut
我需要在 for 循环中找到用户输入的字符。我通常会这样做 如果(句子[i] == 'e') 但是因为在这里,'e' 将是一个单字母字符变量,我不知道如何获取要比较的值。我不能只输入 if (sent
我有一个这样的算法: let seed: Foo = ... let mut stack: Vec = Vec::new(); stack.push(&seed); while let Some(ne
这个问题可能看起来非常基础,但我很难弄清楚如何做。我有一个整数,我需要使用 for 循环来循环整数次。 首先,我尝试了—— fn main() { let number = 10; // An
如果我有以下结构: struct MyStruct { tuple: (i32, i32) }; 以及以下函数: // This will not compile fn function(&mut s
我希望在每个 session 的基础上指定列的默认值。下面的脚本不起作用,但描述了我想如何使用它。我目前使用的是 MySQL 5.5.28,但如果需要可以升级。 CREATE TABLE my_tbl
我是一名优秀的程序员,十分优秀!