在 OpenGL ES 中使用 glBufferSubData 和 glMultiDrawArrays Android
Using glBufferSubData and glMultiDrawArrays in OpenGL ES Android
我正在将 C++ 点和多边形绘图移植到 Android.Initially 它直接期待将代码移植到 java style.I 可以使用以下代码绘制点。
//POINT
public class MyPoint
{
public float x,y,z;
}
//Points in x,y,z format are parsed and stored here
public static ArrayList<MyPoint> m_vPoints;
public static float [] fPointVertices ={};//Float array
public static FloatBuffer mPointVerticesFloatBuffer;//Buffer for rendering
int m_drawCount=0;
//Converting to float array
//AND
//Converting to FloatBuffer
public static void FormatPointDataAsGLBuffer()
{
fPointVertices=new float[m_vPoints.size()*3];
int count=0;
for(int i=0;i<m_vPoints.size();i++)
{
fPointVertices[count]=m_vPoints.get(i).x;
fPointVertices[count+1]=0.0f;
fPointVertices[count+2]=m_vPoints.get(i).y;
count=count+3;
}
m_drawCount=count;
//Convert vertices to OpenGL ES compatible format
mPointVerticesFloatBuffer= ByteBuffer.allocateDirect(fPointVertices.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
mPointVerticesFloatBuffer.put(fPointVertices).position(0);
}
public void DrawPoints()
{
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mPointVerticesFloatBuffer);
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, m_drawCount);
GLES20.glDisableVertexAttribArray(mPositionHandle);
}
我还不确定如何使用单个浮点数绘制多边形 array.In 尽管 C++ 版本使用 glBufferSubData 创建 VBO 并使用了对 glMultiDrawArrays 的单次调用,如下面的 SE 查询中所述。
多边形相关脚本如下所示
//POLYGON
public static ArrayList<MyPolygon> m_vPolygons;
public static class MyPolygon
{
public ArrayList<MyPoint> vPointList;
}
public static void FormatPolygonDataAsGLBuffer()
{
for(int i=0;i<vPolygons.size();i++)
{
for(int j=0;j<vPolygons.get(i).vPointList.size();j++)
{
fPointVertices[count]=vPolygons.get(i).vPointList.get(i).x;
fPointVertices[count+1]=0.0f;
fPointVertices[count+2]=-vPolygons.get(i).vPointList.get(i).y;//Negating since y is outwards from the screen and z is upwards
count=count+3;
}
}
}
public void DrawPolygons()
{
//WHAT IS THE RIGHT WAY HERE???
//glBufferSubData
//Draw the lines
//glMultiDrawArrays(GLES20.GL_LINE_LOOP, startIndices,endIndices,nPolygonCount);
}
glBufferSubData
函数仍然存在,所以它应该仍然像以前一样工作。 glMultiDrawArrays
函数在 GLES 中不存在,所以您只需要对 glDrawArrays()
进行多次单独调用,每个对象调用一次。
我正在将 C++ 点和多边形绘图移植到 Android.Initially 它直接期待将代码移植到 java style.I 可以使用以下代码绘制点。
//POINT
public class MyPoint
{
public float x,y,z;
}
//Points in x,y,z format are parsed and stored here
public static ArrayList<MyPoint> m_vPoints;
public static float [] fPointVertices ={};//Float array
public static FloatBuffer mPointVerticesFloatBuffer;//Buffer for rendering
int m_drawCount=0;
//Converting to float array
//AND
//Converting to FloatBuffer
public static void FormatPointDataAsGLBuffer()
{
fPointVertices=new float[m_vPoints.size()*3];
int count=0;
for(int i=0;i<m_vPoints.size();i++)
{
fPointVertices[count]=m_vPoints.get(i).x;
fPointVertices[count+1]=0.0f;
fPointVertices[count+2]=m_vPoints.get(i).y;
count=count+3;
}
m_drawCount=count;
//Convert vertices to OpenGL ES compatible format
mPointVerticesFloatBuffer= ByteBuffer.allocateDirect(fPointVertices.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
mPointVerticesFloatBuffer.put(fPointVertices).position(0);
}
public void DrawPoints()
{
GLES20.glEnableVertexAttribArray(mPositionHandle);
GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, 0, mPointVerticesFloatBuffer);
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, m_drawCount);
GLES20.glDisableVertexAttribArray(mPositionHandle);
}
我还不确定如何使用单个浮点数绘制多边形 array.In 尽管 C++ 版本使用 glBufferSubData 创建 VBO 并使用了对 glMultiDrawArrays 的单次调用,如下面的 SE 查询中所述。
多边形相关脚本如下所示
//POLYGON
public static ArrayList<MyPolygon> m_vPolygons;
public static class MyPolygon
{
public ArrayList<MyPoint> vPointList;
}
public static void FormatPolygonDataAsGLBuffer()
{
for(int i=0;i<vPolygons.size();i++)
{
for(int j=0;j<vPolygons.get(i).vPointList.size();j++)
{
fPointVertices[count]=vPolygons.get(i).vPointList.get(i).x;
fPointVertices[count+1]=0.0f;
fPointVertices[count+2]=-vPolygons.get(i).vPointList.get(i).y;//Negating since y is outwards from the screen and z is upwards
count=count+3;
}
}
}
public void DrawPolygons()
{
//WHAT IS THE RIGHT WAY HERE???
//glBufferSubData
//Draw the lines
//glMultiDrawArrays(GLES20.GL_LINE_LOOP, startIndices,endIndices,nPolygonCount);
}
glBufferSubData
函数仍然存在,所以它应该仍然像以前一样工作。 glMultiDrawArrays
函数在 GLES 中不存在,所以您只需要对 glDrawArrays()
进行多次单独调用,每个对象调用一次。