久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 OpenGL ES 2 中創建和使用 VBO

How to create and use VBOs in OpenGL ES 2(如何在 OpenGL ES 2 中創建和使用 VBO)
本文介紹了如何在 OpenGL ES 2 中創建和使用 VBO的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在尋求有關理解 VBO 的幫助.我已經進行了大量研究并找到了有關該主題的教程,但它們對我來說仍然含糊不清.我有幾個問題:

I am looking for help with understanding VBOs. I have done a ton of research and have found tutorials on the subject, but they are still vague to me. I have a few questions:

應該在哪里創建 VBO,我應該如何創建?

Where should a VBO be created, and how should I create one?

我目前正在使用下面的代碼來初始化我的頂點和索引緩沖區:

I am currently using the code right below to initialize my vertex and index buffers:

    vertices = new float[]
            {
                    p[0].x, p[0].y, 0.0f,
                    p[1].x, p[1].y, 0.0f,
                    p[2].x, p[2].y, 0.0f,
                    p[3].x, p[3].y, 0.0f,
            };

    // The order of vertex rendering for a quad
    indices = new short[] {0, 1, 2, 0, 2, 3};

    ByteBuffer bb = ByteBuffer.allocateDirect(vertices.length * 4);
    bb.order(ByteOrder.nativeOrder());
    vertexBuffer = bb.asFloatBuffer();
    vertexBuffer.put(vertices);
    vertexBuffer.position(0);

    ByteBuffer dlb = ByteBuffer.allocateDirect(indices.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(indices);
    drawListBuffer.position(0);

如果我是正確的,這不是創建 VBO.那么,如果我想制作 VBO,創建 VBO 的代碼會緊跟上面列出的代碼嗎?如果有,如何創建?

If I am correct, this is not creating a VBO. So, if I wanted to make a VBO, would the code to create a VBO go right after the code listed above? If so, how would it be created?

另外,如何將 VBO 渲染和繪制到屏幕上?

Also, how is a VBO rendered and drawn to screen?

它的渲染和繪制方式是否與僅使用頂點和索引數組相同?如果不是,流程是什么?目前,我渲染和繪制我的對象,如下面的代碼所示:

Is it rendered and drawn the same way as just using vertex and index arrays? If not, what is the process? Currently, I render and draw my objects as shown in the code below:

    GLES20.glUseProgram(GraphicTools.sp_SolidColor);

    mPositionHandle =
            GLES20.glGetAttribLocation(GraphicTools.sp_SolidColor, "vPosition");

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    GLES20.glVertexAttribPointer(mPositionHandle, 3,
            GLES20.GL_FLOAT, false,
            0, vertexBuffer);

    mtrxHandle = GLES20.glGetUniformLocation(GraphicTools.sp_SolidColor,
            "uMVPMatrix");

    GLES20.glUniformMatrix4fv(mtrxHandle, 1, false, m, 0);

    GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length,
            GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    GLES20.glDisableVertexAttribArray(mPositionHandle);

如果您有任何問題,請告訴我.提前致謝.

If you have any questions, let me know. Thanks in advance.

推薦答案

A 頂點緩沖區Object 是一個可以存儲頂點數組數據的緩沖區.數據一次性上傳到圖形內存(GPU),可重復用于繪制網格.

A Vertex Buffer Object is a buffer where vertex array data can be stored. The data are uploaded one time to the graphics memory (GPU) and can be used repeatedly to draw a mesh.

首先,您必須創建 2 個緩沖區對象,一個用于頂點,一個用于索引:

First you have to create 2 buffer objects, one for the vertices and one for the indices:

int buffers[] = new int[2];
GLES20.glGenBuffers(2, buffers, 0);
int vbo = buffers[0];
int ibo = buffers[1];

然后你必須綁定緩沖區并傳輸數據

Then you have to bind the buffer and to transfer the data

GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo);
GLES20.glBufferData(
    GLES20.GL_ARRAY_BUFFER,
    vertexBuffer.capacity() * 4, // 4 = bytes per float
    vertexBuffer,
    GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo);
GLES20.glBufferData(
    GLES20.GL_ELEMENT_ARRAY_BUFFER,
    drawListBuffer.capacity() * 2, // 2 = bytes per short
    drawListBuffer,
    GLES20.GL_STATIC_DRAW);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);

如果要繪制網格,則必須定義通用頂點屬性數據數組并綁定索引緩沖區,但不必將任何數據傳輸到 GPU:

If you want to draw the mesh, then you have to define the array of generic vertex attribute data and you have to bind the index buffer, but you don't have to transfer any data to the GPU:

GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vbo);
GLES20.glVertexAttribPointer(
        mPositionHandle, 3,
        GLES20.GL_FLOAT, false,
        0, 0);                        // <----- 0, because "vbo" is bound
GLES20.glEnableVertexAttribArray(mPositionHandle);

GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo);
GLES20.glDrawElements(
    GLES20.GL_TRIANGLES, indices.length,
    GLES20.GL_UNSIGNED_SHORT, 0);     // <----- 0, because "ibo" is bound

GLES20.glDisableVertexAttribArray(mPositionHandle);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);


另見 頂點緩沖區簡介對象(VBO)

這篇關于如何在 OpenGL ES 2 中創建和使用 VBO的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美成人精品一区二区男人看 | 91麻豆精品国产91久久久资源速度 | 91性高湖久久久久久久久_久久99 | 在线成人免费av | 日韩免费福利视频 | 亚洲精品中文字幕中文字幕 | 777zyz色资源站在线观看 | 亚洲精选一区二区 | 亚洲一区亚洲二区 | 久久网一区二区 | 日韩免费激情视频 | 亚洲自拍偷拍免费视频 | 99久久精品国产一区二区三区 | 91综合网 | 精品伦精品一区二区三区视频 | 欧美一区二区三区日韩 | 黄色免费在线观看网站 | 久久黄网 | 久久99精品视频 | 午夜在线小视频 | 久久国产精品免费一区二区三区 | 99国产精品久久久 | 超碰超碰 | 国内精品久久精品 | 婷婷久久一区 | 国产一区二区在线免费视频 | 久久久成人动漫 | 亚洲一卡二卡 | 日本久久精品视频 | 亚洲在线免费观看 | 天天夜碰日日摸日日澡 | 中文字幕视频网 | 成人在线观 | 中文字幕成人av | 中文字幕四虎 | 91精品在线播放 | 国产欧美一区二区久久性色99 | 黄色免费网站在线看 | 久久久久久免费精品一区二区三区 | 日韩欧美中文 | 一区二区三区免费 |