I just tried using IssuePluginEvent() to call glEnable/glScissor right before Graphics.DrawMeshNow(), but the result was an access violation when Unity tried to actually draw the mesh. If I’m reading the crash dump correctly, the access violation seems to be coming from this:
GfxDeviceGLES::smile:rawBuffers(class GfxBuffer *,struct VertexStreamSource const *,int,struct DrawBuffersRange const *,int,class VertexDeclaration *,class ChannelAssigns const &),
The calls to glEnable/glScissor complete without crashing, and I don’t see how calls to those functions could cause an access violation =/
Edit1:
Simply calling GL.InvalidateState() causes Unity to crash as well.
Edit2:
Calling GL.InvalidateState() causes unity to freeze on MacOS.(IssuePluginEvent has the same behavior).
So at this point, GL.InvalidateState() appears to be the problem(or maybe where I’m calling it?)
Calling GL.InvalidateState() causes Unity to crash on windows, and freeze on MacOS. Using GL.IssuePluginEvent() to call an empty function causes the same behavior on both OSes. So does Unity implicitly call GL.InvalidateState() at some point after I’ve issued a plugin event? What else could cause InvalidateState to crash? Because the function simply being broken on all platforms without anyone noticing seems unlikely.
I’m calling these functions in OnPostRender().
Edit3:
Switching out my rendering code(GL.* and DrawMeshNow) for the following doesn’t crash, but doesn’t apply the scissor rect either. glGetError() says everything is fine.
CommandBuffer cb = new CommandBuffer();
cb.IssuePluginEvent(NativePlugin.GetRenderEventFunc(), 1); // enable scissor test and set rect
cb.DrawMesh(mesh, mtx, material, 0, 0);
cb.IssuePluginEvent(NativePlugin.GetRenderEventFunc(), 0); // disable scissor test
Graphics.ExecuteCommandBuffer(cb);