好的,所以我已经使用我自己的 glwrapper 成功地连接了所有的 OpenGL 函数。我遇到的问题是英特尔/Nvidia 与 ATI 的对比。我正在连接模型并为每个模型生成 ID,这样我就可以知道正在渲染什么。
以下是我目前拥有的信息+差异:
glPushMatrix()
glMultMatrixf({0.70710671, 0, 0.70710683, 0}
{0, 1, 0, 0}
{-0.70710683, 0, 0.70710671, 0}
{26368, -1125, 28416, 1})
glBindBufferARB(GL_ARRAY_BUFFER, 56)
glBufferSubDataARB(GL_ARRAY_BUFFER, 0, 11544, 0x0B2DF6EC)
glGenBuffersARB(1, 0x0AE6231C)
glBindBufferARB(GL_ARRAY_BUFFER, 65)
glBufferDataARB(GL_ARRAY_BUFFER, 11544, 0x0B2DF6EC, GL_STATIC_DRAW)
glGenBuffersARB(1, 0x0AE6231C)
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 66)
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, 7020, 0x0B2DF6EC, GL_STATIC_DRAW)
//上面的一切都是由两个显卡完成的。下面是问题所在。
glBindBufferARB(GL_ARRAY_BUFFER, 56) //Intel/Nvidia makes this NULL.
glVertexPointer(3, GL_FLOAT, 12, 0x00000000) //Intel/NVidia makes this Not 0x00000.
glEnableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_NORMAL_ARRAY)
glBindBufferARB(GL_ARRAY_BUFFER, 65)
glColorPointer(4, GL_UNSIGNED_BYTE, 12, 0x00000000)
glEnableClientState(GL_COLOR_ARRAY)
glTexCoordPointer(2, GL_FLOAT, 12, 0x00000004)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glDrawElements(GL_TRIANGLES, 3510, GL_UNSIGNED_SHORT, 0x00000000)
我想知道为什么要为 Nvidia && Intel 卡的 bindbuffer 调用清空而不是清空顶点指针,而在 ATI 上,一切都如上所示。
有什么不同?另外我的第二个问题是,如果我存储了指向顶点和索引的指针(保证它们不会被删除),我怎样才能得到每个顶点?
例子:
VBO CurrentBuffer;
std::vector<VBO> Buffers;
Hook_glBufferDataARB(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage)
{
CurrentBuffer.target = target;
CurrentBuffer.size = size;
CurrentBuffer.usage = usage; //To figure out if it's indices array or vertex array.
CurrentBuffer.data = data; //Let us assume that this pointer is never deleted.
(*original_BufferDataArb)(target, size, data, usage);
}
Hook_glVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
{
CurrentBuffer.VNull = (pointer == NULL) ? true : false;
CurrentBuffer.VPointer = pointer; //This can be both null or not null.
CurrentBuffer.VSize = size;
CurrentBuffer.Vtype = type;
CurrentBuffer.Stride = stride;
Buffers.push_back(CurrentBuffer);
(*original_VPointer)(size, type, stride, pointer);
}
void Hook_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
{
if (mode == GL_TRIANGLES)
{
const GLfloat* Pointer = static_cast<const GLfloat*>(Buffers.back().VPointer); //Assuming it isn't NULL.
for (int I = 0; I < count / 3; ++I) //For each triangle.
{
int X = *(reinterpret_cast<const GLfloat*>(reinterpret_cast<const char*>(Pointer)));
int Y = *(reinterpret_cast<const GLfloat*>(reinterpret_cast<const char*>(Pointer) + (Buffers.back().Stride)) + 1);
int Z = *(reinterpret_cast<const GLfloat*>(reinterpret_cast<const char*>(Pointer) + (2 * Buffers.back().Stride)) + 2);
}
}
(*original_DrawElements)(mode, count, type, indices);
}
我是否正确地迭代指针?此外,如果 vertexpointer 为空,有没有办法可以使用 bufferdata 使用来获取每个顶点?我读到我可以做到:
if (CurrentBuffer.VNull)
{
GLfloat* IndexPointer = Buffers[Buffers.size()].data; //Index pointer is GL_Element_Array_Buffer
GLfloat* VertexPointer = Buffers[Buffers.size() - 1].data; //Vertex pointer is GL_Array_Buffer
for (int I = 0; I < TriangleCount; ++I)
{
int X = *VertexPointer[IndexPointer[I]];
int Y = *VertexPointer[IndexPointer[I]] + 1;
int Z = *VertexPointer[IndexPointer[I]] + 2;
}
}