2012-08-23 95 views
0

好吧,我已經成功地使用我自己的glwrapper掛鉤了所有的OpenGL函數。我遇到的問題是當談到英特爾/ Nvidia與ATI。我鉤住模型併爲每個模型生成ID,這樣我就可以知道渲染是什麼。掛鉤OpenGL幫助(4 - 5問題)

下面是我目前掌握的信息+的區別:

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) 

我想知道爲什麼還要NULL-ING的bindbuffer呼叫並沒有歸零頂點指針Nvidia的& & Intel網卡,而在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爲null,有沒有辦法使用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; 
    } 
} 

回答

1
glBindBufferARB(GL_ARRAY_BUFFER, 56)   //Intel/Nvidia makes this NULL. 
glVertexPointer(3, GL_FLOAT, 12, 0x00000000) //Intel/NVidia makes this Not 0x00000. 

確實,在您的英特爾/ NVIDIA情況下,程序沒有主動設置這些值。作爲glVertexPointer的數據參數的空值只有在存在綁定的緩衝區對象時纔有意義。但是,如果沒有綁定緩衝區對象,例如通過使用ID爲0的glBindBuffer調用解除綁定,那麼glVertexPointer的數據參數必須是非空指針。

+0

+1我沒有想到這件事,是的它是設置它。嗯,但爲什麼它會在intel/nvidia上做到這一點,但把它放在ati上?這是我不確定的。無論哪種方式,它是同樣的事情,但對嗎? 我不明白的是爲什麼要這麼做或爲什麼將它設置爲0.是否有區別? – Brandon

+0

@CantChooseUsernames:可能將其設置爲零隻是正常操作的一部分,您只是在程序執行時的不同時間看到它,因爲在NVidia或Intel HW上觸發了不同的代碼路徑。尋找調用'glGetString'的程序 - 如果是這樣,它可能會根據硬件(怪癖,解決方法等)對其渲染路徑進行一些更改。另外請注意,如果在版本> = OpenGL-2上,程序也可以請求'glBindBuffer'(不帶ARB) – datenwolf