Skip to content

Commit ccb0cc3

Browse files
committed
Add vertex_submit_ext
1 parent 27f5baa commit ccb0cc3

File tree

5 files changed

+62
-16
lines changed

5 files changed

+62
-16
lines changed

scripts/Builders/yyPrimBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
// @if feature("gl") && (function("draw_primitive_*") || function("draw_vertex*") || function("vertex_*"))
1414

15-
// primitive type translation is shared between draw_primitive_* and vertex_submit
15+
// primitive type translation is shared between draw_primitive_* and vertex_submit(_ext)
1616
var PrimType_POINTLIST = 1,
1717
PrimType_LINELIST = 2,
1818
PrimType_LINESTRIP = 3,

scripts/Builders/yyVBufferBuilder.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,27 @@ function yyVBufferBuilder(_size) {
355355
/// </summary>
356356
// #############################################################################################
357357
/** @this {yyVBufferBuilder} */
358-
this.Submit = function(_primType, _texture) {
358+
this.Submit = function(_primType, _texture, _offset, _number) {
359+
if (_offset === undefined) _offset = 0;
360+
if (_number === undefined) _number = -1;
361+
362+
if (_offset < 0) {
363+
yyError("vertex_submit_ext: offset cannot be a negative number!");
364+
return;
365+
}
366+
367+
var vertexCount = (_number < 0) ? m_vertexCount : _number;
368+
if (_offset + vertexCount > m_vertexCount) {
369+
vertexCount = m_vertexCount - _offset;
370+
}
371+
359372
if (m_frozen) {
360373

361374
// Directly submit the vertex buffer
362375
// (I don't believe a flush is necessary as it shouldn't affect
363376
// the building up of the current in-flight vertex buffer)
364377
if (_texture == -1) {
365-
g_webGL.DispatchVBuffer(_primType,null, m_VBuffer, 0);
378+
g_webGL.DispatchVBuffer(_primType,null, m_VBuffer, _offset, vertexCount);
366379
}
367380
else {
368381
// Check whether the webgl texture has been initialised yet and do so if not
@@ -373,13 +386,13 @@ function yyVBufferBuilder(_size) {
373386
return;
374387
}
375388
}
376-
g_webGL.DispatchVBuffer(_primType, _texture.WebGLTexture.webgl_textureid, m_VBuffer, 0);
389+
g_webGL.DispatchVBuffer(_primType, _texture.WebGLTexture.webgl_textureid, m_VBuffer, _offset, vertexCount);
377390
}
378391
}
379392
else {
380393
var pBuff;
381394
if (_texture == -1) {
382-
pBuff = g_webGL.AllocVerts(_primType, null, m_FVF, m_vertexCount);
395+
pBuff = g_webGL.AllocVerts(_primType, null, m_FVF, vertexCount);
383396
} else {
384397
// Check whether the webgl texture has been initialised yet and do so if not
385398
if (_texture && !_texture.WebGLTexture.webgl_textureid) {
@@ -389,18 +402,18 @@ function yyVBufferBuilder(_size) {
389402
return;
390403
}
391404
}
392-
pBuff = g_webGL.AllocVerts(_primType, _texture.WebGLTexture.webgl_textureid, m_FVF, m_vertexCount);
405+
pBuff = g_webGL.AllocVerts(_primType, _texture.WebGLTexture.webgl_textureid, m_FVF, vertexCount);
393406
}
394407

395408
// Get the data across
396409
var currpos = pBuff.Current * m_vertexFormat.ByteSize;
397410

398411
// Open a data view onto the vertex array to allow for easy copying to the VBuffer vertex data store
399-
var vertexDataView = new Int8Array(m_arrayBuffer, 0, m_vertexCount * m_vertexFormat.ByteSize);
412+
var vertexDataView = new Int8Array(m_arrayBuffer, _offset * m_vertexFormat.ByteSize, vertexCount * m_vertexFormat.ByteSize);
400413

401414
// This buffer copy might seem a bit unnecessary but it's there so that the vertex buffer can be reused
402415
pBuff.VertexData.set(vertexDataView, currpos);
403-
pBuff.Current += m_vertexCount;
416+
pBuff.Current += vertexCount;
404417
}
405418
};
406419

scripts/libWebGL/libWebGL.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,10 +2103,10 @@ function yyWebGL(_canvas, _options) {
21032103
/// </summary>
21042104
// #############################################################################################
21052105
/** @this {yyWebGL} */
2106-
this.DispatchVBuffer = function (_prim, _texture, _vbuffer, _vertexStart) {
2106+
this.DispatchVBuffer = function (_prim, _texture, _vbuffer, _vertexStart, _vertexCount) {
21072107

21082108
yyGL.REQUIRE((_texture == null) || (_texture instanceof yyGLTexture), "Texture is not a yyGLTexture", yyGL.ERRORLEVEL_Development);
2109-
m_VBufferManager.Dispatch(_prim, _texture, _vbuffer, _vertexStart);
2109+
m_VBufferManager.Dispatch(_prim, _texture, _vbuffer, _vertexStart, _vertexCount);
21102110
};
21112111

21122112

scripts/libWebGL/yyVBufferManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ function yyVBufferManager(_commandBuilder,_renderStateManager) {
5151
/// </summary>
5252
// #############################################################################################
5353
/** @this {yyVBufferManager} */
54-
this.Dispatch = function (_prim, _texture, _vbuffer, _vertexStart) {
54+
this.Dispatch = function (_prim, _texture, _vbuffer, _vertexStart, _vertexCount) {
55+
var size = (_vertexCount === undefined)
56+
? _vbuffer.Current - _vertexStart
57+
: _vertexCount;
5558

56-
var size = _vbuffer.Current - _vertexStart;
5759
switch (_prim)
5860
{
5961
case yyGL.PRIM_TRIANGLE:

scripts/yyBufferVertex.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ var vertex_create_buffer,
3939
vertex_ubyte4,
4040
vertex_freeze,
4141
vertex_submit,
42+
vertex_submit_ext,
4243
vertex_get_number,
4344
vertex_get_buffer_size,
4445
vertex_create_buffer_from_buffer,
4546
vertex_create_buffer_from_buffer_ext,
46-
vertex_update_buffer_from_buffer,
47-
vertex_update_buffer_from_vertex,
47+
vertex_update_buffer_from_buffer,
48+
vertex_update_buffer_from_vertex,
4849
draw_flush;
4950

5051
// @if feature("2d")
@@ -70,12 +71,13 @@ var vertex_create_buffer,
7071
vertex_ubyte4 = _stub("vertex_ubyte4");
7172
vertex_freeze = _stub("vertex_freeze");
7273
vertex_submit = _stub("vertex_submit");
74+
vertex_submit_ext = _stub("vertex_submit_ext");
7375
vertex_get_number = _stub("vertex_get_number");
7476
vertex_get_buffer_size = _stub("vertex_get_buffer_size");
7577
vertex_create_buffer_from_buffer = _stub("vertex_create_buffer_from_buffer", -1);
7678
vertex_create_buffer_from_buffer_ext = _stub("vertex_create_buffer_from_buffer_ext", -1);
77-
vertex_update_buffer_from_buffer = _stub("vertex_update_buffer_from_buffer", -1);
78-
vertex_update_buffer_from_vertex = _stub("vertex_update_buffer_from_vertex", -1);
79+
vertex_update_buffer_from_buffer = _stub("vertex_update_buffer_from_buffer", -1);
80+
vertex_update_buffer_from_vertex = _stub("vertex_update_buffer_from_vertex", -1);
7981
draw_flush = ()=>{};
8082
})();
8183
// @endif
@@ -117,6 +119,7 @@ function InitBufferVertexFunctions() {
117119
vertex_ubyte4 = WebGL_vertex_ubyte4_RELEASE;
118120
vertex_freeze = WebGL_vertex_freeze_RELEASE;
119121
vertex_submit = WebGL_vertex_submit_RELEASE;
122+
vertex_submit_ext = WebGL_vertex_submit_ext_RELEASE;
120123
vertex_get_number = WebGL_vertex_get_number_RELEASE;
121124
vertex_get_buffer_size = WebGL_vertex_get_buffer_size_RELEASE;
122125
draw_flush = WebGL_draw_flush_RELEASE;
@@ -707,6 +710,34 @@ function WebGL_vertex_submit_RELEASE(_buffer, _primType, _texture)
707710
}
708711
}
709712

713+
// #############################################################################################
714+
/// Function:<summary>
715+
/// Draw a portion of a vertex buffer
716+
/// </summary>
717+
/// In: <param name="_buffer">Buffer to get count of</param>
718+
/// In: <param name="_primType">Type of primitive to render with</param>
719+
/// In: <param name="_texture">Texture handle to draw with, or -1 for FLAT</param>
720+
/// In: <param name="_offset">The index of the first vertex.</param>
721+
/// In: <param name="_number">Number of vertices to draw.</param>
722+
// #############################################################################################
723+
function WebGL_vertex_submit_ext_RELEASE(_buffer, _primType, _texture, _offset, _number)
724+
{
725+
g_webGL.Flush();
726+
var prim, vertexBuffer = g_vertexBuffers[yyGetInt32(_buffer)];
727+
if (vertexBuffer) {
728+
729+
if (g_CurrentShader != -1) {
730+
var shader = g_shaderPrograms[g_CurrentShader].program;
731+
var pVertexFormat = vertexBuffer.GetFormat();
732+
if (pVertexFormat.Format.length < shader.AttribIndices.length) {
733+
ErrorOnce("Trying to use a vertex buffer with too few inputs for the seleted shader.");
734+
}
735+
}
736+
737+
vertexBuffer.Submit(WebGL_translate_primitive_builder_type(yyGetInt32(_primType)), _texture, yyGetInt32(_offset), yyGetInt32(_number));
738+
}
739+
}
740+
710741
// #############################################################################################
711742
/// Function:<summary>
712743
/// Get the number of vertices in a vertex buffer

0 commit comments

Comments
 (0)