gpt4 book ai didi

c++ - 创建GL_TEXTURE_2D_ARRAY后违反访问

转载 作者:行者123 更新时间:2023-12-02 10:03:56 25 4
gpt4 key购买 nike

在此纹理初始化之后,每一次gl调用都会遇到访问冲突(实际上最后一个GLCALL(glBindTexture(m_Target, bound));也会导致访问冲突,因此顶部的代码可能是导致访问冲突的原因):

Texture2D::Texture2D(unsigned int format, unsigned int width, unsigned int height, unsigned int unit, unsigned int mimapLevels, unsigned int layers)
: Texture(GL_TEXTURE_2D_ARRAY, unit)
{
unsigned int internalFormat;
if (format == GL_DEPTH_COMPONENT)
{
internalFormat = GL_DEPTH_COMPONENT32;
}
else
{
internalFormat = format;
}
m_Format = format;
m_Width = width;
m_Height = height;
unsigned int bound = 0;
glGetIntegerv(GL_TEXTURE_BINDING_2D_ARRAY, (int*)&bound);
GLCALL(glGenTextures(1, &m_ID));
GLCALL(glActiveTexture(GL_TEXTURE0 + m_Unit));
GLCALL(glBindTexture(m_Target, m_ID));
GLCALL(glTexParameteri(m_Target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLCALL(glTexParameteri(m_Target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLCALL(glTexStorage3D(m_Target, mimapLevels, internalFormat, width, height, layers));
for (size_t i = 0; i < layers; i++)
{
glTexSubImage3D(m_Target, 0, 0, 0, i, m_Width, m_Height, 1, m_Format, s_FormatTypeMap[internalFormat], NULL);
}
GLCALL(glBindTexture(m_Target, bound));
}

OGL指针在程序开始时很高兴地初始化:
        if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}

而且这仅发生在 GL_TEXTURE_2D_ARRAY上,即使这是我的代码的第一行(类(class)初始化之后),例如代码:
auto t = Texture2D(GL_DEPTH_COMPONENT, 1024, 1024, 10, 1, 4);

知道是什么原因造成的吗?

提前致谢!

最佳答案

您正在为NULL的最后一个参数传递glTexSubImage3D,但是OpenGL不允许这样做:

TexSubImage*D and TextureSubImage*D arguments width, height, depth, format, type, and data match the corresponding arguments to the corresponding TexImage*D command (where those arguments exist), meaning that they accept the same values, and have the same meanings. The exception is that a NULL data pointer does not represent unspecified image contents.



...并且没有允许 NULL指针的文本,因此您不能传递 NULL

目前尚不清楚您想要通过这些 glTexSubImage3D调用实现什么。由于您使用的是不变纹理( glTexStorage3D),因此您无需执行任何其他操作。相反,如果您要清除纹理,则可以使用 glClearTexSubImage,而 确实接受NULL作为数据,表示“用零清除”。

关于c++ - 创建GL_TEXTURE_2D_ARRAY后违反访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61198229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com