Advertisement
Dr_Davenstein

model_struct VBO generation function

Apr 25th, 2021
2,492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub genVBO( byref model as model_struct )
  2.    
  3.  
  4.     with model
  5.        
  6.  
  7.         redim .vIndex( ubound(.surfaces) )
  8.         redim .vNormal( ubound(.vertices) )
  9.         redim .vUv( ubound(.vertices) )
  10.         redim .vCol( ubound(.vertices) )
  11.        
  12.  
  13.         for s as integer = 0 to ubound(.surfaces)
  14.  
  15.             for t as integer = .surfaces(s).startID to .surfaces(s).endID
  16.  
  17.                 for p as integer = 0 to 2
  18.  
  19.                     with .surfaces(s)
  20.                         redim preserve .vertex_index( ubound(.vertex_index)+1 )
  21.                         .vertex_index( ubound(.vertex_index) ) = model.triangles(t).point_id(p)
  22.                     end with
  23.  
  24.                     .vNormal( .triangles(t).point_id(p) ) = .triangles(t).normal
  25.                     .vUv( .triangles(t).point_id(p) ) = .triangles(t).uv(p)
  26.                     .vCol( .triangles(t).point_id(p) ) = vec3f( rnd*1, rnd*1, rnd*1 )
  27.  
  28.                 next
  29.  
  30.             next
  31.  
  32.         next
  33.        
  34.  
  35.         glGenBuffers( 1, @.VBO )
  36.         glBindBuffer( GL_ARRAY_BUFFER, .VBO )
  37.         glBufferData( GL_ARRAY_BUFFER, (ubound(.vertices)+1)*sizeof(nmathf.vec3f), @.vertices(0).x, GL_STATIC_DRAW )
  38.  
  39.         glGenBuffers( 1, @.normalVBO )
  40.         glBindBuffer( GL_ARRAY_BUFFER, .normalVBO )
  41.         glBufferData( GL_ARRAY_BUFFER, (ubound(.vNormal)+1)*sizeof(nmathf.vec3f), @.vNormal(0).x, GL_STATIC_DRAW )
  42.  
  43.         glGenBuffers( 1, @.uvVBO )
  44.         glBindBuffer( GL_ARRAY_BUFFER, .uvVBO )
  45.         glBufferData( GL_ARRAY_BUFFER, (ubound(.vUv)+1)*sizeof(nmathf.vec2f), @.vUv(0).x, GL_STATIC_DRAW )
  46.  
  47.         glGenBuffers( 1, @.colVBO )
  48.         glBindBuffer( GL_ARRAY_BUFFER, .colVBO )
  49.         glBufferData( GL_ARRAY_BUFFER, (ubound(.vCol)+1)*sizeof(nmathf.vec3f), @.vCol(0).x, GL_DYNAMIC_DRAW )
  50.  
  51.  
  52.         for s as integer = 0 to ubound(.surfaces)
  53.  
  54.             glGenBuffers( 1, @.vIndex(s) )
  55.             glBindBuffer( GL_ARRAY_BUFFER, .vIndex(s) )
  56.             glBufferData( GL_ARRAY_BUFFER, (ubound(.surfaces(s).vertex_index)+1) * sizeof(uinteger), @.surfaces(s).vertex_index(0), GL_DYNAMIC_DRAW )
  57.  
  58.         next
  59.        
  60.  
  61.         glBindBuffer( GL_ARRAY_BUFFER, 0 )
  62.        
  63.  
  64.     end with
  65.    
  66.  
  67. end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement