0

I am updating a Maya 2016 plugin (C++) to Maya 2017. This plugin is displaying OpenGL shapes (VBOs) in the standard 2.0 ViewPort, and was working perfectly in Maya 2016 with OpenGL 2.1. Now Maya 2017 comes with OpenGL 4.1 and before doing any opengl action, the glErrorString executed in the prepareForDraw function gives Invalid Operation (code 1282).

This seems to come from the fact no OpenGL context is available. Do I need to manually create an OpenGL context or has Maya a function to create it for me, or should I link an existing Maya context to OpenGL ?

I can share some code if need be, but not sure it would be relevant at this stage.

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89
  • It's quite easy to check if there is a OpenGL context active. Just call `wglGetCurrentContext` (assuming you're targeting Windows, there are similar functions for X11/GLX and macOS) to retrieve a handle (or nil handle) to the currently active context. – *My guess is, that your old OpenGL-2.1 code is simply incompatible with GL-4, which deprecated lots of the old stuff and that's why it fails.* – datenwolf Dec 01 '16 at 09:06
  • I am on Mac, so used the `CGLGetCurrentContext` function which is indeed returning a non-nil handle. But should I do anything with this handle ? Now executing the error check right after gives a 0 error, but as soon as I execute another gl-command right after like `glGenVertexArrays(1, &vaoID[0])`, I again get a 1282 error. – Laurent Crivello Dec 01 '16 at 09:43
  • If you have a OpenGL context, you can go to work. However it makes sense to do a few sanity checks first (which OpenGL version does it actually support and so on). What you can and can not do depends on this. Technically I'd strongly recommend, that you create your own OpenGL context for your plugin, to prevent stomping on Maya. You can arbitrarily switch contexts between drawables; just make sure you revert the calling thread to the context it was active with, when you started. – datenwolf Dec 01 '16 at 10:28
  • It's indeed OpenGL 4.1 according to what Maya returns me. So the `CGLGetCurrentContext` returns me a context. How come doing a simple basic `glGenVertexArrays`, which is supposed to be supported by OpenGL 4.1, returns an error ? Should I in any way activate this context before doing something with it ? – Laurent Crivello Dec 01 '16 at 11:15

1 Answers1

2

The issue came from an old define I had:

#ifdef __APPLE__
#define glGenVertexArrays glGenVertexArraysAPPLE
#define glBindVertexArray glBindVertexArrayAPPLE
#define glDeleteVertexArrays glDeleteVertexArraysAPPLE
#endif

removing these lines made the errors disappear

Laurent Crivello
  • 3,809
  • 6
  • 45
  • 89