krisnye's picture

Differences between ES20.GL and OpenGL.GL

I am using the same source code file to handle my OpenGL rendering and my ES 2.0 rendering.

I just use some conditional compilation at the top, and the rest of the code in the page just refers to GL.SomeMethod.

#if ES20
using OpenTK.Graphics.ES20
using OpenTK.Graphics.OpenGL

GL.VertexAttribArray(...) etc.

This works very well since I am basically sticking to the ES20 subset of functionality which is also supported by standard OpenGL.

The only pain is the instances of the ES20 API that are unnecessarily different from the OpenGL api's . These are often minor things like using REF for a parameter instead of OUT, or using the ALL enumeration instead of a more specific enumeration such as ProgramParameters.

Is there a plan to try to keep the methods as consistent as possible, and to provide the more specific OpenGL enumerations in the ES20 namespace?

I wouldn't mind helping with this effort, since I'm basically merging the differences anyways on my side.

For the lack of enumerations in ES20, I have to use using statements that alias OpenTK.Graphics.ES20.All enumeration. This is all very manageable for me, but it might be nice to merge the two more in order to simplify allowing others to use the same code with a small conditional at the top to compile against both OpenGL and ES20.

Here are some of the differences between the classes that don't seem necessary:

ES20 is missing all of the following Enumerations, so I have to alias them to the ALL enumeration:

using TextureTarget = OpenTK.Graphics.ES20.All;
using TextureParameterName = OpenTK.Graphics.ES20.All;
using EnableCap = OpenTK.Graphics.ES20.All;
using BlendingFactorSrc = OpenTK.Graphics.ES20.All;
using BlendingFactorDest = OpenTK.Graphics.ES20.All;
using PixelStoreParameter = OpenTK.Graphics.ES20.All;
using VertexPointerType = OpenTK.Graphics.ES20.All;
using ColorPointerType = OpenTK.Graphics.ES20.All;
using TexCoordPointerType = OpenTK.Graphics.ES20.All;
using BeginMode = OpenTK.Graphics.ES20.All;
using MatrixMode = OpenTK.Graphics.ES20.All;
using PixelInternalFormat = OpenTK.Graphics.ES20.All;
using PixelFormat = OpenTK.Graphics.ES20.All;
using PixelType = OpenTK.Graphics.ES20.All;
using ShaderType = OpenTK.Graphics.ES20.All;
using VertexAttribPointerType = OpenTK.Graphics.ES20.All;
using ProgramParameter = OpenTK.Graphics.ES20.All;
using ShaderParameter = OpenTK.Graphics.ES20.All;

ES20 GetProgramInfoLog is broken because it uses a string as it's last parameter.
ES20 GetShaderInfoLog is broken because it uses a string as it's last parameter.

Es20 GetProgram method uses a 'ref', opengl uses 'out'.
Es20 GetShader method uses a 'ref', opengl uses 'out'.

Es20 ShaderSource uses different parameters from OpenGL

ES20 GenTextures uses a 'ref', opengl uses 'out'.

ES20 UniformMatrix4 uses different parameters from OpenGL.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Thanks! These issues should be fixed now.

My take on the issue is that it's better to have consistent names even if the don't really stand on its own (e.g. BeginMode in ES 2.0). Most ES developers come from a GL background, so it makes sense to keep the APIs as similar as possible (makes for easier porting, too).

We can still improve the naming scheme through a different avenue: higher-level bindings. I think this will become the "big feature" of OpenTK 2.0, but I hope to release a first preview over the next few weeks.

krisnye's picture

Everything compiles fine now. Keep in mind I'm not using every part of the ES 2.0, but every part that I am using now compiles fine for both OpenGL and ES 2.0 with just the

#if ES20
using OpenTK.Graphics.ES20;
using OpenTK.Graphics.OpenGL;

I am writing a higher level game engine right now. Using OpenTK on every platform where it's available, but using an XNA implementation for XBox360 and as an option on Windows.

I have written an Effect engine that uses Microsofts HLSL and is working within OpenGL and ES 2.0. (I use HLSL2GLSL to create glsl shaders, but then parse the HLSL in order to apply techniques, passes and render states.)

So far my test application is working with the same source code on:
Windows with XNA
Windows with OpenTK/OpenGL
Windows with OpenTK/ES 2.0/Amd ES 2.0 Emulator
iPhoneSimulator/ES 2.0

Should also work on XBox360, Zune, Mac native, Linux and an iPhone natively, but I haven't tested any of these yet.

If you DO write a higher level engine, then it would be awesome if it was abstract enough to be implemented with XNA as well.

qventura's picture

"How long will it be before these changes make it into the Monotouch project?"

Does anyone has an idea ? That's still not in the current Monodroid version ... (Yes, I know, Otc. 2009)