Trying to setup bindless textures, whenever I call glGetTextureHandleARB()
it results in the OpenGL error GL_INVALID_OPERATION
. This page says this is because my texture object specified is not complete. After spending (too) much time trying to figure out texture completeness here (and trying things with glTexParameters()
to tell OpenGL that I don't have mipmaps), I don't see what I am doing wrong before the call and would appreciate some help.
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
CodePudding user response:
I don't think its a completeness issue; Try adding this code:
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorderArb);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorderArb);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, new float[4]);
(This is copied from my C# project, but it should be ez to translate)
This might work because bindless textures must have either one of these 4 border colors: (0,0,0,0), (0,0,0,1), (1,1,1,0), or (1,1,1,1) according to documentation. (I'd love to link the specific paragraph but I can't, so just ctrl f and search for (0,0,0,0) to find the relevant paragraph)
CodePudding user response:
By mistake I gave stbi_load()
a path that didn't exist, and neglected to add a check if the pointer returned was NULL
(or if the path existed). I guess somewhere OpenGL didn't like that, but only told me about it when I tried to call glGetTextureHandleARB()
. At least now I learned my lesson to check stuff passed to me by someone else :)