繁体   English   中英

OpenGL 纹理不完整

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM