[英]OpenGL Texture Not Complete
嘗試設置無綁定紋理時,每當我調用glGetTextureHandleARB()
時,都會導致 OpenGL 錯誤GL_INVALID_OPERATION
。 這個頁面說這是因為我指定的紋理 object 不完整。 在花了(太多)時間試圖在這里找出紋理完整性之后(並嘗試使用glTexParameters()
告訴 OpenGL 我沒有 mipmaps),我沒有看到我在通話之前做錯了什么,我將不勝感激一些幫助。
紋理.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;
}
紋理.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
我不認為這是一個完整性問題。 嘗試添加此代碼:
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]);
(這是從我的 C# 項目復制的,但應該是 ez 翻譯)
這可能會起作用,因為無綁定紋理必須具有以下 4 個邊框之一 colors:(0,0,0,0)、(0,0,0,1)、(1,1,1,0) 或 (1, 1,1,1) 根據文檔。 (我很想鏈接特定段落,但我不能,所以只需 ctrl+f 並搜索 (0,0,0,0) 即可找到相關段落)
錯誤地我給了stbi_load()
一個不存在的路徑,並且忽略了添加檢查返回的指針是否為NULL
(或者路徑是否存在)。 我猜某處 OpenGL 不喜歡這樣,但只是在我嘗試調用glGetTextureHandleARB()
時才告訴我。 至少現在我學到了檢查別人傳給我的東西的教訓:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.