OPENGL-ES之頂點索引繪圖
在學習OpenGLES時遇到一個概念,索引快取。網上查資料大部分程式碼均是針對安卓或者桌面平臺的,而且大部分的程式碼拷貝下來不能達到效果。經過幾天的努力,終於瞭解了索引繪圖的概念,所謂索引繪圖是一種在繪製大網格(mesh)時的一種可以高效繪圖的一種方式,普通的繪製三角形需要為每個三角形在array_buffer裡面分配三個頂點的位置,每個頂點至少需要sizeof(glfloat)*3的記憶體,其實在網格里面很多頂點都是共享的,也就是說不需要為重複的頂點再分配記憶體,需要找到一種方法為gpu指定繪圖時繪製哪一個點,這就是索引繪圖的用處。使用索引繪圖,array_buffer裡面的頂點會預設的根據頂點在頂點陣列裡面的位置設定索引,,我們在繪圖之前指定gpu繪圖的索引順序,當繪圖時呼叫gldrawelement(),gpu就可以按照我們指定的頂點順序繪圖.下面是程式碼片段,簡單的設定ViewController為GLKViewController並且設定self.view為GLKView就可以執行
GLKView *view = (GLKView *)self.view;
NSAssert([view isKindOfClass:[GLKView class]],
@"View controller's view is not a GLKView");
// Create an OpenGL ES 2.0 context and provide it to the
// view
view.context = [[EAGLContext alloc]
initWithAPI:kEAGLRenderingAPIOpenGLES2];
// Make the new context current
[EAGLContext setCurrentContext:view.context];
// Create a base effect that provides standard OpenGL ES 2.0
// Shading Language programs and set constants to be used for
// all subsequent rendering
self.baseEffect = [[GLKBaseEffect alloc] init];
self.baseEffect.useConstantColor = GL_TRUE;
self.baseEffect.constantColor = GLKVector4Make(
1.0f, // Red
1.0f, // Green
1.0f, // Blue
1.0f);// Alpha
// Set the background color stored in the current context
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // background color
// Generate, bind, and initialize contents of a buffer to be
// stored in GPU memory
glGenBuffers(1, // STEP 1
&vertexBufferID);
glBindBuffer(GL_ARRAY_BUFFER, // STEP 2
vertexBufferID);
glBufferData( // STEP 3
GL_ARRAY_BUFFER, // Initialize buffer contents
sizeof(vertices), // Number of bytes to copy
vertices, // Address of bytes to copy
GL_STATIC_DRAW); // Hint: cache in GPU memory
GLuint index;
glGenBuffers(1, &index);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indexs), indexs, GL_STATIC_DRAW);
相關文章
- 使用索引繪圖(轉)索引繪圖
- Oracle索引——點陣圖索引Oracle索引
- 點陣圖索引(Bitmap Index)——從B*樹索引到點陣圖索引索引Index
- 點陣圖索引(Bitmap Index)——索引共用索引Index
- 【Android繪圖】繪圖之基礎篇(一)Android繪圖
- 點陣圖索引.sql索引SQL
- 【基礎知識】索引--點陣圖索引索引
- 點陣圖索引(Bitmap Index)——點陣圖索引與資料DML鎖定索引Index
- Oracle-點陣圖索引Oracle索引
- markdown 繪圖利器之granphviz繪圖
- canvas繪圖之鐘表Canvas繪圖
- R繪圖(7): 把散點圖的點換成扇形繪圖
- ATL中使用點陣圖資源繪圖繪圖
- oracle 點陣圖索引(bitmap index)Oracle索引Index
- 點陣圖索引:原理(BitMap index)索引Index
- 點陣圖索引(bitmap-index)索引Index
- 中國地圖繪製-點選事件地圖事件
- python繪圖之matplotlibPython繪圖
- Qt之自繪製餅圖QT
- 【點陣圖索引】在點陣圖索引列上進行更新操作的鎖代價研究索引
- R繪圖(3): 散點圖新增文字註釋繪圖
- 圖形影像處理之繪圖基礎繪圖
- Python點陣圖索引學習Python索引
- 點陣圖索引的工作原理 - Richard索引
- bitmap index點陣圖索引系列(一)Index索引
- CAD繪圖工具中的點命令繪圖
- Python matplotlib繪製散點圖Python
- 資料流圖的繪製要點
- Flutter Canvas學習之繪圖篇FlutterCanvas繪圖
- Android繪圖之Path總結Android繪圖
- B樹索引和點陣圖索引的結構介紹索引
- 【索引】Bitmap點陣圖索引與普通的B-Tree索引鎖的比較索引
- 第三個OpenGL程式,shaders _ 後續 之 moreAttribute (設定頂點位置屬性 顏色位置屬性),從頂點資料中傳入頂點資料,頂點顏色
- ## matplotlib.pyplot庫的知識點之bar函式——繪製條形圖函式
- matplotlib 繪圖視覺化知識點整理繪圖視覺化
- iOS繪圖iOS繪圖
- Android 中 Canvas 繪圖之 Shader 使用圖文詳解AndroidCanvas繪圖
- Android中Canvas繪圖之Shader使用圖文詳解AndroidCanvas繪圖