Recent

Author Topic: Vertex arrays aren't compatible with vertex buffer object?  (Read 1360 times)

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 694
Vertex arrays aren't compatible with vertex buffer object?
« on: August 21, 2020, 12:56:26 pm »
I'm trying to revive my old project, that is retro game engine with maximum backwards compatibility. My current problem - vertex arrays refuse to work with vertex buffer object, even if I extract data from it via glGetBufferSubData instead of using glMapBuffer. I checked buffer data and it looks correctly, but all of sudden I get blank screen instead of picture. Disabling one of two feature helps.

May be I'm missing something? Docs say, that I should use glVertexAttribPointer with glDrawArrays, but it's OpenGL 2.0 feature or part of GL_ARB_vertex_program extension, that is related to shaders. And glDrawArrays is part of OpenGL 1.1, so therefore there should be way to make it work using 1.1 features only.

May be I need to create 1.5 compatibility context or something like that?
30.04.2021 - DynamicData 4.0 is released and migration to it is completed.
It's more Lazarus-friendly, but still requires full Delphi 2009 support to be ported to Lazarus.
It's time to finally do it, because Delphi 2009 is 12 years old.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9541
  • FPC developer.
Re: Vertex arrays aren't compatible with vertex buffer object?
« Reply #1 on: August 21, 2020, 01:03:24 pm »
I don't understand your problem exactly, but I had bad experiences reviving old opengl code.

It turned out that the old code left textures enabled while trying to draw lines etc. Make sure your enabling/disabling is nicely balanced.

Afaik all Windows 7-10 drivers will also support newer opengl, and other OSes are legacy. (and even windows 7 is, strictly)

That said, I don't use the Lazarus opengl headers, but dglopengl.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 694
Re: Vertex arrays aren't compatible with vertex buffer object?
« Reply #2 on: August 21, 2020, 01:19:50 pm »
I don't understand your problem exactly, but I had bad experiences reviving old opengl code.

It turned out that the old code left textures enabled while trying to draw lines etc. Make sure your enabling/disabling is nicely balanced.

Afaik all Windows 7-10 drivers will also support newer opengl, and other OSes are legacy. (and even windows 7 is, strictly)

That said, I don't use the Lazarus opengl headers, but dglopengl.
Problem is following:
glVertex/glColor on plain memory arrays - work
glDrawArrays on plain memory arrays - work
glVertex/glColor on glBufferData/glMapBuffer - work
glDrawArray on glBufferData/glMapBuffer - doesn't work, just blank screen

And I can't find reason for this, because even glGetBufferSubData doesn't help. I tried to exclude all possible problems:
glMapBuffer memory doesn't suit for glDrawArrays
glDrawArrays has some delayed processing, so I shouldn't unmap or free memory till some later moment

Nothing helps.
« Last Edit: August 21, 2020, 01:24:47 pm by Mr.Madguy »
30.04.2021 - DynamicData 4.0 is released and migration to it is completed.
It's more Lazarus-friendly, but still requires full Delphi 2009 support to be ported to Lazarus.
It's time to finally do it, because Delphi 2009 is 12 years old.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9541
  • FPC developer.
Re: Vertex arrays aren't compatible with vertex buffer object?
« Reply #3 on: August 21, 2020, 01:29:21 pm »
glGetBufferSubData is for reading vextexbuffers?

My vertex (modification) code looks like:

Code: Pascal  [Select][+][-]
  1. lBindVertexArray(vao);
  2.  
  3.   glBindBuffer(GL_ARRAY_BUFFER, vbo);
  4.   glBufferSubData(GL_ARRAY_BUFFER, 0,length(vertices)*sizeof(vertices[0]), @vertices[0]);
  5. {  err:=glGetError;
  6.   if err<>GL_NO_ERROR then
  7.     onlog(5,'reload :'+inttostr(err),4);}
  8.   if length(indexdata)>0 then
  9.     begin
  10.      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
  11.      glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0,length(indices)*sizeof(indices[0]), @indices[0]);
  12.     end;
  13.  
  14.   glBindVertexArray(0);

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 694
Re: Vertex arrays aren't compatible with vertex buffer object?
« Reply #4 on: August 21, 2020, 02:15:59 pm »
Solved this problem! Verifying data has shown, that there is no data corruption happens. So there is just one thing left, that could cause problem. glBindBuffer. Looks like some sort of interference with newer extensions, that expect additional parameters via glVertexAttribPointer, if buffer is bound. So unbinding buffer before calling glDrawArrays helped.
30.04.2021 - DynamicData 4.0 is released and migration to it is completed.
It's more Lazarus-friendly, but still requires full Delphi 2009 support to be ported to Lazarus.
It's time to finally do it, because Delphi 2009 is 12 years old.

 

TinyPortal © 2005-2018