@@ -268,6 +268,8 @@ private unsafe void CreateMatrixStacks() {
268268 int UserClipPlaneChanged ;
269269 readonly Vector4 [ ] UserClipPlaneWorld = new Vector4 [ Gl46 . HardwareConfig . MAXUSERCLIPPLANES ] ;
270270 readonly Vector4 [ ] UserClipPlaneProj = new Vector4 [ Gl46 . HardwareConfig . MAXUSERCLIPPLANES ] ;
271+ bool UserClipTransformOverride ;
272+ Matrix4x4 UserClipTransform_ = Matrix4x4 . Identity ;
271273 float FogZ ;
272274
273275 private void MarkAllUserClipPlanesDirty ( ) {
@@ -278,7 +280,8 @@ private unsafe void CommitUserClipPlanes() {
278280 if ( ( UserClipPlaneChanged & UserClipPlaneEnabled & ( ( 1 << Gl46 . HardwareConfig . MAXUSERCLIPPLANES ) - 1 ) ) == 0 )
279281 return ;
280282
281- Matrix4x4 worldToProjectionInvTrans = Matrices [ ( int ) MaterialMatrixMode . View ] * Matrices [ ( int ) MaterialMatrixMode . Projection ] ;
283+ Matrix4x4 worldToView = UserClipTransformOverride ? UserClipTransform_ : Matrices [ ( int ) MaterialMatrixMode . View ] ;
284+ Matrix4x4 worldToProjectionInvTrans = worldToView * Matrices [ ( int ) MaterialMatrixMode . Projection ] ;
282285 Matrix4x4 . Invert ( worldToProjectionInvTrans , out worldToProjectionInvTrans ) ;
283286 worldToProjectionInvTrans = Matrix4x4 . Transpose ( worldToProjectionInvTrans ) ;
284287
@@ -1214,15 +1217,19 @@ void ConfigureAttribute(Span<uint> bindings, OpenGL_ShaderInputAttribute attr, V
12141217 else
12151218 glDisableVertexArrayAttrib ( vao , ( uint ) OpenGL_ShaderInputAttribute . Specular ) ;
12161219
1220+ Assert ( format . GetTexCoordDimensionSize ( 6 ) == 0 || ( format & VertexFormat . Wrinkle ) == 0 ) ;
1221+ Assert ( format . GetTexCoordDimensionSize ( 7 ) == 0 || ( ( format & VertexFormat . Specular ) == 0 && ! staticLit ) ) ;
1222+
12171223 Span < VertexElement > texCoordElements = [ VertexElement . TexCoord1D_0 , VertexElement . TexCoord2D_0 , VertexElement . TexCoord3D_0 , VertexElement . TexCoord4D_0 ] ;
12181224 for ( int i = 0 ; i < IMesh . VERTEX_MAX_TEXTURE_COORDINATES ; i ++ ) {
1225+ OpenGL_ShaderInputAttribute location = TexCoordLocation ( i ) ;
12191226 int texCoordSize = format . GetTexCoordDimensionSize ( i ) ;
12201227 if ( texCoordSize > 0 ) {
12211228 VertexElement element = ( VertexElement ) ( ( int ) texCoordElements [ texCoordSize - 1 ] + i ) ;
1222- ConfigureAttribute ( bindings , ( OpenGL_ShaderInputAttribute ) ( ( int ) OpenGL_ShaderInputAttribute . TexCoord0 + i ) , element , texCoordSize ) ;
1229+ ConfigureAttribute ( bindings , location , element , texCoordSize ) ;
12231230 }
1224- else
1225- glDisableVertexArrayAttrib ( vao , ( uint ) ( ( int ) OpenGL_ShaderInputAttribute . TexCoord0 + i ) ) ;
1231+ else if ( location >= OpenGL_ShaderInputAttribute . TexCoord0 )
1232+ glDisableVertexArrayAttrib ( vao , ( uint ) location ) ;
12261233 }
12271234
12281235 if ( ( format & VertexFormat . TangentS ) != 0 )
@@ -1249,15 +1256,25 @@ void ConfigureAttribute(Span<uint> bindings, OpenGL_ShaderInputAttribute attr, V
12491256
12501257 int normalOffset = ( int ) ( VertexElement . Position . GetSize ( ) + VertexElement . Wrinkle . GetSize ( ) ) ;
12511258
1252- glEnableVertexArrayAttrib ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexPosition ) ;
1253- glVertexArrayAttribFormat ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexPosition , 4 , GL_FLOAT , false , 0 ) ;
1254- glVertexArrayAttribBinding ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexPosition , 2 ) ;
1259+ if ( format . GetTexCoordDimensionSize ( OpenGL_ShaderInputAttribute . FlexPosition - OpenGL_ShaderInputAttribute . TexCoord0 ) == 0 ) {
1260+ glEnableVertexArrayAttrib ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexPosition ) ;
1261+ glVertexArrayAttribFormat ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexPosition , 4 , GL_FLOAT , false , 0 ) ;
1262+ glVertexArrayAttribBinding ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexPosition , 2 ) ;
1263+ }
12551264
1256- glEnableVertexArrayAttrib ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexNormal ) ;
1257- glVertexArrayAttribFormat ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexNormal , 3 , GL_FLOAT , false , ( uint ) normalOffset ) ;
1258- glVertexArrayAttribBinding ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexNormal , 2 ) ;
1265+ if ( format . GetTexCoordDimensionSize ( OpenGL_ShaderInputAttribute . FlexNormal - OpenGL_ShaderInputAttribute . TexCoord0 ) == 0 ) {
1266+ glEnableVertexArrayAttrib ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexNormal ) ;
1267+ glVertexArrayAttribFormat ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexNormal , 3 , GL_FLOAT , false , ( uint ) normalOffset ) ;
1268+ glVertexArrayAttribBinding ( vao , ( uint ) OpenGL_ShaderInputAttribute . FlexNormal , 2 ) ;
1269+ }
12591270 }
12601271
1272+ static OpenGL_ShaderInputAttribute TexCoordLocation ( int index ) => index switch {
1273+ 6 => OpenGL_ShaderInputAttribute . Wrinkle ,
1274+ 7 => OpenGL_ShaderInputAttribute . Specular ,
1275+ _ => OpenGL_ShaderInputAttribute . TexCoord0 + index
1276+ } ;
1277+
12611278 public IMesh GetDynamicMesh ( IMaterial material , int hwSkinBoneCount , bool buffered , IMesh ? vertexOverride , IMesh ? indexOverride ) {
12621279 Assert ( material == null || material . IsRealTimeVersion ( ) ) ;
12631280 return MeshMgr . GetDynamicMesh ( material , 0 , hwSkinBoneCount , buffered , vertexOverride , indexOverride ) ;
@@ -3471,7 +3488,12 @@ public void EnableHWMorphing(bool enable) {
34713488 public void EnableShaderShaderMutex ( bool enable ) { }
34723489
34733490 public void EnableUserClipTransformOverride ( bool enable ) {
3474- throw new NotImplementedException ( "Incomplete port of IShaderAPI" ) ;
3491+ if ( UserClipTransformOverride == enable )
3492+ return ;
3493+
3494+ FlushBufferedPrimitives ( ) ;
3495+ UserClipTransformOverride = enable ;
3496+ MarkAllUserClipPlanesDirty ( ) ;
34753497 }
34763498
34773499 public void EndOcclusionQueryDrawing ( ShaderAPIOcclusionQuery_t query ) {
@@ -3847,7 +3869,14 @@ public void TexSetPriority(int priority) {
38473869 }
38483870
38493871 public void UserClipTransform ( in Matrix4x4 worldToView ) {
3850- throw new NotImplementedException ( "Incomplete port of IShaderAPI" ) ;
3872+ Matrix4x4 transform = Matrix4x4 . Transpose ( worldToView ) ;
3873+ if ( UserClipTransform_ == transform )
3874+ return ;
3875+ UserClipTransform_ = transform ;
3876+ if ( UserClipTransformOverride ) {
3877+ FlushBufferedPrimitives ( ) ;
3878+ MarkAllUserClipPlanesDirty ( ) ;
3879+ }
38513880 }
38523881
38533882 public void BindStandardVertexTexture ( VertexTextureSampler sampler , StandardTextureId id ) {
0 commit comments