使用OpenGL时如何修复ig9icd32.dll中的崩溃

时间:2019-07-19 10:36:14

标签: c++ opengl

我正在使用OpenGL编写图形API。我发现'GLCall(glDrawElements(GL_TRIANGLES, entity->GetIBCount(), GL_UNSIGNED_INT, NULL));'会导致错误。该如何解决?

我尝试使用变量进行更改,但没有用。

void Renderer::Draw(GraphicsEntity * entity, const Shader& shader) const
{
    shader.Bind();
    entity->BindBuffers();

    GLCall(glDrawElements(GL_TRIANGLES, entity->GetIBCount(), GL_UNSIGNED_INT, NULL));
}

void VertexArray::AddBuffer(const VertexBuffer & vb, const VertexBufferLayout layout)
{
    Bind();
    vb.Bind();
    const auto& elements = layout.GetElements();
    unsigned int offset = 0;
    for (unsigned int i = 0; i < elements.size(); i++) 
    {
        const auto& element = elements[i];
        GLCall(glEnableVertexAttribArray(i));
        GLCall(glVertexAttribPointer(i, element.count, element.type, 
            element.normalized, layout.GetStride(), (const void*)offset));
        offset += element.count * VertexBufferElements::GetSizeOfType(element.type);
    }

}

void IndexBuffer::DynamicConstruct(const unsigned int* data, unsigned int count)
{
    m_Count = count;

    ASSERT(sizeof(unsigned int) == sizeof(GLuint));

    GLCall(glGenBuffers(1, &m_RendererID));
    GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID));
    GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW));
}

VertexBuffer::VertexBuffer(const void * data, unsigned int size)
{
    GLCall(glGenBuffers(1, &m_RendererID));
    GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_RendererID));
    GLCall(glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW));
}


class GraphicsEntity
{
public:
    GraphicsEntity() = default;
    GraphicsEntity(const VertexBuffer& vb, const IndexBuffer& ib, bool textured, std::string texturePath, DF_Color color);
    GraphicsEntity(float x, float y, float w, float h, bool textured, std::string texturePath, DF_Color color);

    ~GraphicsEntity();

    //virtual void Update() = 0;
    void UpdateBuffers();
    void BindBuffers();
    void UnbindBuffers();


    inline unsigned int GetIBCount() { return m_IB.GetCount(); }

private:

    IndexBuffer m_IB;
    VertexArray m_VA;

    float m_X, m_Y, m_Width, m_Height;
};

GraphicsEntity::GraphicsEntity(float x, float y, float w, float h, bool textured, std::string texturePath, DF_Color color)
    :m_Textured(textured), m_TexturePath(texturePath), m_Color(color)
{
    m_Active = true;

    float TempPositions[] = {
            x, y, 0.0f, 0.0f,//0
            x + w, y, 1.0f, 0.0f,//1
            x + y, y + h, 1.0f, 1.0f,//2
            x, y + h, 0.0f, 1.0f //3
    };
    unsigned int TempIndices[] = {
        0, 1, 2,
        2, 3, 0
    };

    VertexBuffer vb(TempPositions, 4 * 4 * sizeof(float));
    VertexBufferLayout layout;
    layout.Push<float>(2);
    layout.Push<float>(2);
    m_VA.AddBuffer(vb, layout);

    m_IB.DynamicConstruct(TempIndices, 6);

    if (m_Textured == true)
    {
        m_Texture.Set(m_TexturePath);
    }


    m_DubX = m_X;
    m_DubY = m_Y;
    m_DubWidth = m_Width;
    m_DubHeight = m_Height;
    m_ModelMatrix = glm::mat4(1.0f);
}

GetIBCount()返回索引缓冲区中的索引计数。 所有Bind()函数都使用glBindBuffer(),glBindArrayBuffer等。

它只是崩溃了,Visual Studio告诉我'g9icd32.PDB包含查找模块ig9icd32.dll的源所需的调试信息'

0 个答案:

没有答案