aybe's picture

GL.GetAttachedShaders overload is bloated

Project:The Open Toolkit library
Version:1.1-2014-01-02
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

At least one overload should provide count parameter as int.

Here is all the code needed just for this :

        /// <summary>
        /// Returns IDs of attached shaders.
        /// </summary>
        public unsafe int[] AttachedShaders
        {
            get
            {
                // Get number of attached shaders
                int maxCount;
                GL.GetProgram(_id, ProgramParameter.AttachedShaders, out maxCount);
 
                // Get IDs of attached shaders
                IntPtr ptr = Marshal.AllocHGlobal(sizeof(int));
                void* pointer = ptr.ToPointer();
                int* count = (int*)pointer;
                int written;
 
                int[] shaders = new int[maxCount];
                GL.GetAttachedShaders(_id, maxCount, count, shaders);
 
                // Get the number of IDs written
                written = *count;
 
                Marshal.FreeHGlobal(ptr);
 
                return shaders;
            }
        }

Thread I opened first on forum : Using GL.GetAttachedShaders

Thanks !


Comments

Comment viewing options

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

#1

Version:1.0-2010-10-06» 1.1-dev
Status:open» fixed

You can now use:

int maxCount;
GL.GetProgram(id, ProgramParameter.AttachedShaders, out maxCount);
 
int count;
int[] shaders = new int[maxCount];
GL.GetAttachedShaders(id, shaders.Length, out count, shaders);

No need for unsafe code or unmanaged memory allocations.

the Fiddler's picture

#2

Version:1.1-dev» 1.1-2014-01-02
Status:fixed» closed

Closing bugs fixed in OpenTK 1.1.

If this is still an issue please file a new bug report at https://github.com/opentk/opentk/issues