Xamarin/Mac, OpenGL MSAA: getting started?

I have spent hours trying to get started with OpenGL / MSAA using Xamarin.Mac.

Here is the code I have tried:

    internal const string Library = "/System/Library/Frameworks/OpenGL.framework/OpenGL";

    [System.Security.SuppressUnmanagedCodeSecurity()]
    [System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glTexImage2DMultisample", ExactSpelling = true)]
    public extern static void glTexImage2DMultisample(MonoMac.OpenGL.TextureTargetMultisample target, Int32 samples, MonoMac.OpenGL.PixelInternalFormat internalformat, Int32 width, Int32 height, bool fixedsamplelocations);

    // Shared initialization code
    void Initialize ()
    {
        NSOpenGLPixelFormat _pNSOpenGLPixelFormat = null;
        NSOpenGLContext _pNSOpenGLContext = null;
        try
        {
            var _attribs = new object [] {
                NSOpenGLPixelFormatAttribute.Accelerated,

                NSOpenGLPixelFormatAttribute.NoRecovery,
                NSOpenGLPixelFormatAttribute.ClosestPolicy,

                NSOpenGLPixelFormatAttribute.Multisample,
                NSOpenGLPixelFormatAttribute.SampleAlpha,
                NSOpenGLPixelFormatAttribute.SampleBuffers, 1,
                NSOpenGLPixelFormatAttribute.Samples, 8, 

                NSOpenGLPixelFormatAttribute.ColorSize, 32,
                NSOpenGLPixelFormatAttribute.DepthSize, 16 };
            _pNSOpenGLPixelFormat = new NSOpenGLPixelFormat (_attribs);
            //
            //
            _pNSOpenGLContext = new NSOpenGLContext (_pNSOpenGLPixelFormat, null);

            // Synchronize buffer swaps with vertical refresh rate
            _pNSOpenGLContext.SwapInterval = true;

            _pNSOpenGLContext.MakeCurrentContext ();

            GL.Enable(EnableCap.Multisample);

            ErrorCode _error = GL.GetError();

            GL.Enable(EnableCap.Multisample);
            _error = GL.GetError();

            int _texture = GL.GenTexture();
            _error = GL.GetError();

            GL.BindTexture(TextureTarget.Texture2DMultisample, _texture);
            _error = GL.GetError();

            {
                string _version = GL.GetString(StringName.Version);

                int _major = 0;
                GL.GetInteger(GetPName.MajorVersion, out _major);
                int _minor = 0;
                GL.GetInteger(GetPName.MinorVersion, out _minor);
                int _samples = 0;
                GL.GetInteger(GetPName.Samples, out _samples);

                int _colorTextureSamples = 0;
                GL.GetInteger(GetPName.MaxColorTextureSamples, out _colorTextureSamples);

                int _maxIntegerSamples = 0;
                GL.GetInteger(GetPName.MaxIntegerSamples, out _maxIntegerSamples);

                int _maxDepthTextureSamples = 0;
                GL.GetInteger(GetPName.MaxDepthTextureSamples, out _maxDepthTextureSamples);

                int _maxTextureSize = 0;
                GL.GetInteger(GetPName.MaxTextureSize, out _maxTextureSize);
                int _depthBits = 0;
                GL.GetInteger(GetPName.DepthBits, out _depthBits);

                Debug.Write(string.Format("_version='{0}' Version={1}.{2} _samples={3} _colorTextureSamples={4} _maxTextureSize={5} _depthBits={6} _maxIntegerSamples={7} _maxDepthTextureSamples={8}", 
                    _version, _major, _minor, _samples, _colorTextureSamples, _maxTextureSize, _depthBits, _maxIntegerSamples, _maxDepthTextureSamples));
            }

            {
                int _samples = 4;
                int _width = 1024;
                int _height = 1024;
                _error = GL.GetError();
                glTexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, _samples, MonoMac.OpenGL.PixelInternalFormat.Rgba8, _width, _height, false);
                _error = GL.GetError();
                Debug.Write(string.Format("glTexImage2DMultisample -> {0}", _error));
            }

        }
        catch (Exception E) 
        {
            string _msg = E.Message;
        }
        finally
        {
        }
    }

which produces the following output:

[0:] _version='2.1 ATI-1.14.21' Version=0.0 _samples=8 _colorTextureSamples=0 _maxTextureSize=16384 _depthBits=16 _maxIntegerSamples=0 _maxDepthTextureSamples=0
[0:] glTexImage2DMultisample -> InvalidOperation

A few comments:

1) glTexImage2DMultisample is missing in the MonoMac API
2) I have tried many combinations of parameters to produce a 'decent' NSOpenGLPixelFormat format,
all producing the same 'results'
3) GetInteger with GetPName.MajorVersion/.MinorVersion produce 0.0
5) GetInteger(GetPName.Samples) -> 8, 'good boy', but GetInteger(GetPName.MaxColorTextureSamples) -> 0: 'want a spanking?'
4) OpenGL is a supreme pain to work with :-)

Any comment would be appreciated!

BTW, the report procuded by GLView on my iMac, running Maverick:

Renderer: ATI Radeon HD 5750 OpenGL
Engine
Vendor: ATI Technologies Inc.

Memory: 1024 MB

Version: 4.1 ATI-1.14.21

Device: iMac11,3

Shading language version: 4.10



Max texture size: 16384 x 16384

Max vertex texture image units: 16

Max texture image units: 16

Max geometry texture units: 16

Max anisotropic filtering value: 16

Max viewport size: 16384 x 16384

Max Viewports: 16

Max Clip Distances: 8

Max samples: 8




Extensions: 43

GL_APPLE_client_storage
GL_APPLE_container_object_shareable
GL_APPLE_flush_render
GL_APPLE_object_purgeable
GL_APPLE_rgb_422
GL_APPLE_row_bytes
GL_APPLE_texture_range
GL_ARB_blend_func_extended
GL_ARB_draw_buffers_blend
GL_ARB_draw_indirect
GL_ARB_ES2_compatibility
GL_ARB_explicit_attrib_location
GL_ARB_gpu_shader5
GL_ARB_instanced_arrays
GL_ARB_internalformat_query
GL_ARB_occlusion_query2
GL_ARB_sample_shading
GL_ARB_sampler_objects
GL_ARB_separate_shader_objects
GL_ARB_shader_bit_encoding
GL_ARB_shader_subroutine
GL_ARB_shading_language_include
GL_ARB_tessellation_shader
GL_ARB_texture_buffer_object_rgb32
GL_ARB_texture_cube_map_array
GL_ARB_texture_gather
GL_ARB_texture_query_lod
GL_ARB_texture_rgb10_a2ui
GL_ARB_texture_storage
GL_ARB_texture_swizzle
GL_ARB_timer_query
GL_ARB_transform_feedback2
GL_ARB_transform_feedback3
GL_ARB_vertex_type_2_10_10_10_rev
GL_ARB_viewport_array
GL_ATI_texture_mirror_once
GL_EXT_debug_label
GL_EXT_debug_marker
GL_EXT_texture_compression_s3tc
GL_EXT_texture_filter_anisotropic
GL_EXT_texture_mirror_clamp
GL_EXT_texture_sRGB_decode
GL_NV_texture_barrier


Core features
v3.0 (100 % - 23/23)

v3.1 (100 % - 8/8)

v3.2 (100 % - 10/10)

v3.3 (100 % - 10/10)

v4.0 (100 % - 14/14)

v4.1 (100 % - 7/7)

v4.2 (16 % - 2/12)

v4.3 (0 % - 0/18)

v4.4 (0 % - 0/10)


Sign In or Register to comment.