Class SimpleBufferBuilder
- All Implemented Interfaces:
- Closeable,- AutoCloseable
Not bound to any specific format, ideally should be held onto for re-use.
 Can be used for 'immediate mode' style rendering using draw(), or
 upload to external vertex arrays for proper instancing using finishAndUpload().
 
 This is a Triangles only buffer, all data uploaded is in Triangles.
 Quads are converted to triangles using 0, 1, 2, 0, 2, 3.
 
 Any given SimpleBufferBuilder.Format should have its individual SimpleBufferBuilder.Element components
 buffered in the order specified by the SimpleBufferBuilder.Format,
 followed by an endVertex() call to prepare for the next vertex.
 
 It is illegal to buffer primitives in any format other than the one specified to
 begin(Format, Mode).
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumSpecifies a vertex element with a specific data type, number of primitives and a size in bytes.static enumSpecifies a combination of vertex elements.static enumRepresents a primitive mode that this builder is capable of buffering in.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate static final org.lwjgl.system.MemoryUtil.MemoryAllocatorprivate ByteBufferprivate longprivate booleanprivate static intprivate static intprivate intprivate SimpleBufferBuilder.Formatprivate intprivate SimpleBufferBuilder.Modeprivate static final int[]private static final int[]private static final int[]private int
- 
Constructor SummaryConstructorsConstructorDescriptionSimpleBufferBuilder(int capacity) Create a new SimpleBufferBuilder with an initial capacity.
- 
Method SummaryModifier and TypeMethodDescriptionbegin(SimpleBufferBuilder.Format format, SimpleBufferBuilder.Mode mode) Start building a new set of vertex data in the given format and mode.voidclose()Clear this builder's cached buffer.colour(byte r, byte g, byte b, byte a) Buffer a color element.colour(float r, float g, float b, float a) Buffer a color element.colour(int packedColor) static voiddestroy()voiddraw()Upload and draw this buffer using one of a number of re-usable set of buffers.End building the current vertex and prepare for the next.private static voidensureElementBufferLength(int vertices) private voidensureSpace(int newBytes) intUpload the current buffer.pos(float x, float y) Buffer a position element.tex(float u, float v) Buffer a texture element.
- 
Field Details- 
ALLOCATORprivate static final org.lwjgl.system.MemoryUtil.MemoryAllocator ALLOCATOR
- 
VERTEX_ARRAYSprivate static final int[] VERTEX_ARRAYS
- 
VERTEX_BUFFERSprivate static final int[] VERTEX_BUFFERS
- 
VERTEX_BUFFER_LENGTHSprivate static final int[] VERTEX_BUFFER_LENGTHS
- 
elementBufferprivate static int elementBuffer
- 
elementBufferVertexLengthprivate static int elementBufferVertexLength
- 
bufferAddrprivate long bufferAddr
- 
buffer
- 
format
- 
mode
- 
buildingprivate boolean building
- 
elementIndexprivate int elementIndex
- 
indexprivate int index
- 
verticesprivate int vertices
 
- 
- 
Constructor Details- 
SimpleBufferBuilderpublic SimpleBufferBuilder(int capacity) Create a new SimpleBufferBuilder with an initial capacity.The buffer will be doubled as required. Generally picking a small number, around 128/256 should be a safe bet. Provided you cache your buffers, it should not mean much overall. - Parameters:
- capacity- The initial capacity in bytes.
 
 
- 
- 
Method Details- 
destroypublic static void destroy()
- 
ensureElementBufferLengthprivate static void ensureElementBufferLength(int vertices) 
- 
beginStart building a new set of vertex data in the given format and mode.- Parameters:
- format- The format to start building in.
- mode- The mode to start building in.
 
- 
posBuffer a position element.- Parameters:
- x- The x.
- y- The y.
- z- The z.
- Returns:
- The same builder.
 
- 
texBuffer a texture element.- Parameters:
- u- The u.
- v- The v.
- Returns:
- The same builder.
 
- 
colourBuffer a color element.- Parameters:
- r- The red component. (0-1)
- g- The green component. (0-1)
- b- The blue component. (0-1)
- a- The alpha component. (0-1)
- Returns:
- The same buffer.
 
- 
colour- Parameters:
- packedColor- an ABGR packed int
- Returns:
- the same buffer.
- See Also:
 
- 
colourBuffer a color element.- Parameters:
- r- The red component. (0-255)
- g- The green component. (0-255)
- b- The blue component. (0-255)
- a- The alpha component. (0-255)
- Returns:
- The same buffer.
 
- 
endVertexEnd building the current vertex and prepare for the next.- Returns:
- The same builder.
 
- 
ensureSpaceprivate void ensureSpace(int newBytes) 
- 
finishAndUploadpublic int finishAndUpload()Upload the current buffer.This will bind a GL15C.GL_ARRAY_BUFFERandGL15C.GL_ELEMENT_ARRAY_BUFFERThe vertex data and index data is uploaded to their respective buffers. Uploading the buffers finishes drawing and resets for the next buffer operation. This should not be called in conjunction with draw()- Returns:
- The number of indexes that were uploaded.
 
- 
drawpublic void draw()Upload and draw this buffer using one of a number of re-usable set of buffers.This will immediately upload the buffer, resetting this builder for the next buffer operation, and draw the uploaded data. You will need to bind shaders, textures, etc, before calling this function. 
- 
closepublic void close()Clear this builder's cached buffer.If you are completely done, call destroy()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
 
-