- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在Android 系统中开发一个基于Qt 5.4 的应用程序。我正在生成多个 OES 纹理并在 Qt FBO TEXTURE_2D
中渲染通过着色器。每个 OES 纹理都有自己的 eglcontext,每个人都有相同的 sharedContext。 OES 纹理是一张一张使用的,我的意思是,我不想同时渲染多个,但我需要创建多个,因为我必须能够在同一时间渲染多个 future 。
这是我必须更新时使用的代码:
m_program->bind();
glActiveTexture(GL_TEXTURE0 + textureId);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureId);
/* my code to fill shader attr and glDraw*() */
glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
m_program->release();
问题是,出于某种原因,我只能渲染创建的第一个 OES 纹理,因为我得到了 W/Adreno-ES20(28468): <core_glActiveTexture:348>: GL_INVALID_ENUM
。当尝试 glActiveTexture 第二个时。因此,目标纹理被填充为黑色。
我已经检查了所有这些并且是正确的:
我有点迷茫,我不确定这是我的代码中的限制还是错误。
有什么想法吗?
编辑:在其他设备上尝试,应用程序工作正常,所以我认为问题与设备限制有关..
最佳答案
生成纹理时,您无法保证 ID 将从零开始或递增 1。因此您可能不会期望值会是 [0, 1, 2,...] 并且不能将 Activity 纹理用作 GL_TEXTURE0 + textureID
。您需要创建自己的自动增量系统,最好通过创建某种纹理对象来生成纹理、分配两个 ID 等等。
要增加内部 ID,您需要做的就是使用一个静态整数值,该值会随着您生成的每个纹理而增加。这是最基本的系统,您将在某个时间只加载一些纹理,然后假设它们都不应该被释放和重用,然后重用它们。其他系统需要包括对已释放纹理的某种跟踪,并能够重用空槽。
因此对于基础知识,您将拥有一个对象/类,例如:
static GLint currentActiveTextureID = GL_TEXTURE0;
class ActiveTextureObject {
GLuint textureID;
GLenum activeTextureID;
void generateNew() {
activeTextureID = currentActiveTextureID++;
useActive();
glGenTextures(1, &activeTextureID);
}
void useActive() {
glActiveTexture(activeTextureID);
}
void bind() {
glBindTexture(GL_TEXTURE_2D, textureID);
}
void bindAndUseActive() {
useActive();
bind();
}
};
这现在包含您在代码段中发布的所有功能。如果您愿意,也可以在构造函数中调用方法 generateNew
。如您所见,该对象将纹理和 Activity 纹理绑定(bind)在一起,因此您可以简单地调用 bindAndUseActive
来完成这两项操作。
对于更复杂的系统,您可以使用一个元素数组来表示 Activity 纹理的插槽。然后您可以遍历数组以找到一个空槽。
class ActiveTexturePool {
static const GLint maximumActiveTextures = 16; // number of maximum units
GLint currentActiveTextureID[maximumActiveTextures]; // have the container
ActiveTexturePool() { // a constructor is needed to reset the data
memset(currentActiveTextureID, 0, sizeof(currentActiveTextureID)); // sets all to zero
}
class ActiveTextureObject {
public:
GLuint textureID;
GLenum activeTextureID;
void generateNew() {
useActive();
glGenTextures(1, &activeTextureID);
}
void useActive() {
glActiveTexture(activeTextureID);
}
void bind() {
glBindTexture(GL_TEXTURE_2D, textureID);
}
void bindAndUseActive() {
useActive();
bind();
}
};
ActiveTextureObject getNewTextureObject() {
ActiveTextureObject toReturn;
for(GLint i=0; i<maximumActiveTextures; i++) {
if(currentActiveTextureID[i] == 0) {
GLenum activeTexture = GL_TEXTURE0 + i;
currentActiveTextureID[i] = activeTexture;
toReturn.activeTextureID = activeTexture;
return toReturn;;
}
}
return NULL; // the pool is full, you may not create another active texture!
}
void recycleTexture(ActiveTextureObject texture) { // remove from the pool
for(GLint i=0; i<maximumActiveTextures; i++) {
if(currentActiveTextureID[i] == texture.activeTextureID) {
currentActiveTextureID[i] = 0;
texture.activeTextureID = 0;
// you may also delete the data here but that should most likely be handled by the ActiveTextureObject
break;
}
}
}
};
现在在这种情况下,您宁愿在某处创建一个池来处理纹理。您可能很容易拥有一个或多个可用于多个上下文的池。最后,最好创建一个包含主要上下文并具有纹理池的类。然后上下文对象还可以为您正在生成的每个纹理创建共享上下文,并且还负责删除、回收纹理和上下文。
关于android - opengl es,glActiveTexture时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34798281/
我只想对默认的 OpenGL 行为进行一些说明。据我了解,默认事件纹理单元为 0 (GL_TEXTURE0),除非通过 glActiveTexture 明确更改,否则将保持不变。 我问这个是因为我遇到
线路 glActiveTexture(GL_TEXTURE0+32); 抛出 GL_INVALID_ENUM (因为我发现运行 glGetError()),而 glActiveTexture(GL_T
我开始接触 libGDX 游戏引擎。我复制了this示例并尝试运行。它作为 android 应用程序运行正常,但是当我希望它作为 java 应用程序运行时,它会抛出以下错误。 Exception in
在我的 iOS 8 测试中,一切似乎都运行良好,但现在我的 OpenGLES 框架出现问题,其中存在 gl 头文件,但出于某种原因,它说 GL_TEXTURE0 定义(以及各种其他定义)找不到。 gl
大家好,我在这里遇到了一个错误,似乎 C++ 没有找到 glActiveTextureARB(GL_TEXTURE0_ARB);我使用代码块并且我有 glext.h 所以每当我右键单击 glActiv
据我所知,glActiveTexture设置事件的“纹理单元”。每个纹理单元可以有多个纹理目标(通常是 GL_TEXTURE_1D、2D、3D 或 CUBE_MAP)。 如果我理解正确,您必须调用gl
如何关闭纹理单元,或者至少在绑定(bind)纹理时防止其状态发生变化?我正在使用着色器,所以我认为没有 glDisable 。问题是事件链可能看起来像这样: Create texture 1 (imp
我正在尝试编写一个简单的着色器,它会添加附加到 FBO 的纹理。 FBO初始化等没有问题(我已经测试过了)。问题是我相信glActiveTexture(GL_TEXTURE0)。它似乎什么也没做——这
我已经开始了一个新项目,我想在其中使用多纹理。我以前做过多重纹理,我的 OpenGL 版本支持 在标题中我有: GLuint m_TerrainTexture[3];//heightmap, tex
好吧,所以这些纹理真的让我很困惑。我一直在看this教程(我认为这很棒),特别是标题为“您可以定义多达 32 个纹理单元,但每个着色器最多只能定义 8 个纹理。”的图像。据我了解,它是这样工作的: 你
我是一名优秀的程序员,十分优秀!