Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/togles/linuxwin/glmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ class GLMContext
IDirect3DVertexDeclaration9 *m_pVertDecl;
D3DStreamDesc m_streams[ D3D_MAX_STREAMS ];
uint64 m_vtxAttribMap[2];
uint m_nBaseVertex; // browser build: base vertex baked into the attrib pointers
};

CurAttribs_t m_CurAttribs;
Expand All @@ -1523,6 +1524,7 @@ class GLMContext
memset( m_CurAttribs.m_streams, 0, sizeof( m_CurAttribs.m_streams ) );
m_CurAttribs.m_vtxAttribMap[0] = 0xBBBBBBBBBBBBBBBBULL;
m_CurAttribs.m_vtxAttribMap[1] = 0xBBBBBBBBBBBBBBBBULL;
m_CurAttribs.m_nBaseVertex = 0xFFFFFFFF;
}

FORCEINLINE void ReleasedShader() { NullProgram(); }
Expand Down
4 changes: 3 additions & 1 deletion togles/linuxwin/dxabstract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5636,7 +5636,9 @@ HRESULT IDirect3DDevice9::DrawIndexedPrimitive( D3DPRIMITIVETYPE Type,INT BaseVe

this->FlushIndexBindings( );
this->FlushVertexBindings( BaseVertexIndex );
m_ctx->FlushDrawStates( MinVertexIndex, MinVertexIndex + NumVertices - 1, 0 );
// FlushDrawStates builds the GL vertex attribs from the bound streams, and
// on the web it applies BaseVertexIndex to them (see glmgr_flush.inl).
m_ctx->FlushDrawStates( MinVertexIndex, MinVertexIndex + NumVertices - 1, BaseVertexIndex );

if (gl.m_FogEnable)
{
Expand Down
14 changes: 13 additions & 1 deletion togles/linuxwin/glmgr_flush.inl
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,11 @@ FORCEINLINE void GLMContext::FlushDrawStates( uint nStartIndex, uint nEndIndex,
( m_CurAttribs.m_pVertDecl != m_pDevice->m_pVertDecl ) ||
( m_CurAttribs.m_vtxAttribMap[0] != reinterpret_cast<const uint64 *>(m_pDevice->m_vertexShader->m_vtxAttribMap)[0] ) ||
( m_CurAttribs.m_vtxAttribMap[1] != reinterpret_cast<const uint64 *>(m_pDevice->m_vertexShader->m_vtxAttribMap)[1] ) ||
( memcmp( m_CurAttribs.m_streams, m_pDevice->m_streams, sizeof( m_pDevice->m_streams ) ) != 0 ) )
( memcmp( m_CurAttribs.m_streams, m_pDevice->m_streams, sizeof( m_pDevice->m_streams ) ) != 0 )
#ifdef __EMSCRIPTEN__
|| ( m_CurAttribs.m_nBaseVertex != nBaseVertex )
#endif
)
{
// This branch is taken 52.2% of the time in the L4D2 test1 (long) timedemo.

Expand All @@ -515,6 +519,7 @@ FORCEINLINE void GLMContext::FlushDrawStates( uint nStartIndex, uint nEndIndex,
m_CurAttribs.m_vtxAttribMap[0] = reinterpret_cast<const uint64 *>(m_pDevice->m_vertexShader->m_vtxAttribMap)[0];
m_CurAttribs.m_vtxAttribMap[1] = reinterpret_cast<const uint64 *>(m_pDevice->m_vertexShader->m_vtxAttribMap)[1];
memcpy( m_CurAttribs.m_streams, m_pDevice->m_streams, sizeof( m_pDevice->m_streams ) );
m_CurAttribs.m_nBaseVertex = nBaseVertex;

unsigned char *pVertexShaderAttribMap = m_pDevice->m_vertexShader->m_vtxAttribMap;
const int nMaxVertexAttributesToCheck = m_drawingProgram[ kGLMVertexProgram ]->m_maxVertexAttrs;
Expand Down Expand Up @@ -570,6 +575,13 @@ FORCEINLINE void GLMContext::FlushDrawStates( uint nStartIndex, uint nEndIndex,
{
nBufOffset += pBuf->m_nPersistentBufferStartOffset;
}
#ifdef __EMSCRIPTEN__
// WebGL 2 has no glDrawRangeElementsBaseVertex, so the base vertex
// is applied here by starting every attribute that many vertices
// into its stream. (It used to be dropped entirely: every draw with
// a non-zero base vertex read the wrong vertices.)
nBufOffset += nBaseVertex * pStream->m_stride;
#endif

SetBufAndVertexAttribPointer( nIndex, pBuf->GetHandle(),
pStream->m_stride, pDeclElem->m_gldecl.m_datatype, pDeclElem->m_gldecl.m_normalized, pDeclElem->m_gldecl.m_nCompCount,
Expand Down
Loading