Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opengl glext private #4310

Closed

Conversation

devel0
Copy link
Contributor

@devel0 devel0 commented Jul 16, 2020

What does the pull request do?

Allow to write custom extension well prototyped, hiding entrypoint (private) property with a public method that forward to that.

What is the current behavior?

Can't declare entrypoint as private, it must public and that makes 2 member visible when using intellisense ( property and method ).

What is the updated/expected behavior with this PR?

With this I can write something like the follow to implement my own extension with method documentation:

using System;
using System.Runtime.CompilerServices;
using Avalonia.OpenGL;

namespace SearchAThing.OpenGL
{

    public unsafe partial class GlInterface : GlInterfaceBase<Avalonia.OpenGL.GlInterface.GlContextInfo>
    {
        public GlInterface(Avalonia.OpenGL.GlInterface GL) : base(GL.GetProcAddress, GL.ContextInfo)
        {
        }
       
        delegate void _glActiveShaderProgram(uint pipeline, uint program);
        [GlEntryPoint("glActiveShaderProgram")]
        _glActiveShaderProgram _ActiveShaderProgram { get; }

        /// <summary>
        /// glActiveShaderProgram sets the linked program named by program            to be the active program for the program pipeline object pipeline. The active            program in the active program pipeline object is the target of calls to glUniform            when no program has been made current through a call to glUseProgram.
        /// </summary>
        /// <param name="pipeline">Specifies the program pipeline object to set the active program object for.</param>
        /// <param name="program">Specifies the program object to set as the active program pipeline object pipeline.</param>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void ActiveShaderProgram(uint pipeline, uint program) => _ActiveShaderProgram(pipeline, program);

    }

}

and use them like this example

        SearchAThing.OpenGL.GlInterface GL;

        /// <summary>
        /// GL INIT
        /// </summary>
        protected unsafe override void OnOpenGlInit(Avalonia.OpenGL.GlInterface _GL, int fb)
        {
            GL = new SearchAThing.OpenGL.GlInterface(_GL);
        // ...

Checklist

Breaking changes

Fixed issues

@devel0 devel0 mentioned this pull request Jul 16, 2020
2 tasks
@devel0
Copy link
Contributor Author

devel0 commented Jul 16, 2020

@kekekeks note that Avalonia.Native package may not used directly by the Linux platform, ok, but if not generated there will be errors during restore because some other packages still refers it as described in #4148 (comment) ; btw I can revert that commit if this will be addressed in future.

@@ -2,7 +2,7 @@

<PropertyGroup>
<IsPackable>false</IsPackable>
<IsPackable Condition="'$([MSBuild]::IsOSPlatform(OSX))' == 'True'">true</IsPackable>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is here for a reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but that not address the issue #4148 (comment)

@@ -23,7 +23,7 @@ public class GlInterfaceBase<TContext>
public GlInterfaceBase(Func<string, IntPtr> getProcAddress, TContext context)
{
_getProcAddress = getProcAddress;
foreach (var prop in this.GetType().GetProperties())
foreach (var prop in this.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initializing static properties from an instance constructor is usually a bad idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is other way to access to private members ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right, thanks for clarification.

@devel0
Copy link
Contributor Author

devel0 commented Jul 20, 2020

@kekekeks I ended up using Silk.NET as api for GL so there is no need for me to add more api with private delegates.

Its not a clean solution like the OpenGLControlBase of Avalonia that uses framebuffer, btw everything worked as expected apart the fact that in X11 I got crashes if I close a modal window or if I use a tooltip ( may related to #3536 ), in general every time time that another window created while in Windows there is no issues.

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  4 (X_DestroyWindow)
  Resource id in failed request:  0x56001e2
  Serial number of failed request:  2625
  Current serial number in output stream:  2627

Note that if I not open the silkNet window ( by commenting this the problem not appears ), so there are many possibilities that this is caused by my mistake in interleaving windowing mode but hopefully this could be of help to you to check against some robustness of the Avalonia.X11

If you want to look at the example just checkout the source:

git clone https://github.com/devel0/netcore-sci.git
cd netcore-sci
git checkout 097f3978a3a95d96c1060f99b973eca1fdc94a17
dotnet build
dotnet run --project examples/0002

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants