尝试设置无绑定纹理,每当我调用glGetTextureHandleARB()
时,都会导致OpenGL错误GL_INVALID_OPERATION
。This page表示这是因为我指定的纹理对象不完整。在花了(太)多的时间试图弄清楚这里的纹理完整性(并尝试使用glTexParameters()
告诉OpenGL我没有mipmap)之后,我看不出在调用之前我做错了什么,希望得到一些帮助。
texture.c:
# include "texture.h"
# include <glad/glad.h>
# define STB_IMAGE_IMPLEMENTATION
# include <stb/stb_image.h>
struct Texture texture_create_bindless_texture(const char *path) {
struct Texture texture;
int components;
void *data = stbi_load(path, &texture.width, &texture.height, &components,
4);
glGenTextures(1, &texture.id);
glBindTexture(GL_TEXTURE_2D, texture.id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture.width, texture.height,
0, GL_RGBA, GL_UNSIGNED_BYTE, data);
texture.bindless_handle = glGetTextureHandleARB(texture.id);
glMakeTextureHandleResidentARB(texture.bindless_handle);
glBindTexture(GL_TEXTURE_2D, 0);
stbi_image_free(data);
return texture;
}
texture.h:
# ifndef TEXTURE_INCLUDED
# define TEXTURE_INCLUDED
# include <glad/glad.h>
struct Texture {
int width;
int height;
GLuint id;
GLuint64 bindless_handle;
};
struct Texture texture_create_bindless_texture(const char *path);
# endif
2条答案
按热度按时间wecizke31#
我不认为这是一个完整性问题;尝试添加以下代码:
(这是从我的C#项目复制的,但应该是EZ来翻译)
这可能是因为根据documentation,无绑定纹理必须具有以下4种边框颜色之一:(0,0,0,0)、(0,0,0,1)、(1,1,1,0)或(1,1,1,1)。(我很想链接具体的段落,但我不能,所以只需按Ctrl+f并搜索(0,0,0,0)即可找到相关段落)
zqdjd7g92#
我错误地给了
stbi_load()
一个不存在的路径,并且忽略了添加检查返回的指针是否为NULL
(或者该路径是否存在)。我猜某个地方的OpenGL不喜欢这样,但只是在我试图调用glGetTextureHandleARB()
时才告诉我。至少现在我学到了检查别人传给我的东西的教训:)