Menu

Change Antialiasing and Phong Shader

Help
2020-05-11
2020-05-12
  • shine world

    shine world - 2020-05-11

    Hi all,
    I've an issue with chaning of Antialiasing and Materials which uses phong shader.

    User can change Antialiasing level during program use to better meets his needs.
    If in the scene there are mesh with a material library using a shader, in my case
    the Phong shader just after antialiasing change in the render part I've got the
    error 1282.

    I've tried to place Phong shaders Enabled := False but issue continue.
    The only way to work aroud was to Remove all phong shaders from materials
    off all objects, destroy object, change antialiasing, recreate phong object and
    set it in materials.

    I'm a newbie in this matter but is very complicate to do because I've a lot of
    classes which implements scene objects inherited from TGLFreeForm....

    I guess I've mistake something in use of Antialiasing and shaders.

    Thank you for any suggestion !!!

     
  • shine world

    shine world - 2020-05-12

    Sorry in advance if I said something wrong, but I don't know opengl engine...
    Seem that when I change AntiAliasing value the shaders (in this case Phong) need to be remade to follow some internal rendering structur...

    By newbie I've tried many workarounds and this is one that works, but seems an odd solution.

    procedure TGLSceneFrame.SetAntiAliasing(Value: TGLAntiAliasing);
    begin
      if GLSceneViewer.Buffer.Acceleration = chaHardware then
      begin
        if GLSceneViewer.Buffer.AntiAliasing <> Value then
        begin
          // TAKE CARE:
          //
          // If AntiAliasing value is changed, in a scene with objects material which uses shaders, at first scene Redraw an
          // OpenGL 1282 error will be raised. To avoid that, is necessary to remove and delete any shaders binded to
          // scene objects material before to change AntiAliasing value, then re-bind new shaders to objects material when
          // AntiAliasing is changed. Probably a shader is mapped to a specific structure of OpenGL ARB and need to be
          // re-made every something change.
          FVMManager.ShaderEnabled := False;
          try
            GLSceneViewer.Buffer.AntiAliasing := Value;
          finally
            FVMManager.ShaderEnabled := True;
          end;
        end;
      end;
    end;
    
    procedure TVMManager.SetShaderEnabled(Value: Boolean);
    var
      I: Integer;
    begin
      if FShaderEnabled = Value then Exit;
      FShaderEnabled := Value;
    {$IFDEF USE_MATERIAL_LIBRARY}
      if not Value then
      begin
        for I := 0 to FMeshMaterialLibrary.Materials.Count - 1 do
          FMeshMaterialLibrary.Materials.Items[I].Shader := nil;
        SafeFreeAndNil(FMeshPhongShader);
      end
      else
      begin
        FMeshPhongShader := TGLPhongShader.Create(nil);
        for I := 0 to FMeshMaterialLibrary.Materials.Count - 1 do
          FMeshMaterialLibrary.Materials.Items[I].Shader := FMeshPhongShader;
      end;
    {$ENDIF}
    end;
    

    Have you some ideas about ?

     
  • Jerome.D (BeanzMaster)

    Hi Shine what is the TVMManager ?

    Antialiasing is an option witch is attached to the context, so when you change it the context is recreated.
    When you use a Shader, is bind thrue a handle wich is depend on the context. So it is normal that we need reinitialize the scene.
    It's like if you change a pointer's address and you don't re-bind your accessed variables.
    In this case you have no choice.
    Perhaps i'm wrong. I'll take a look to the OpenGL specification about antialiasing options.

    Normally you set this options at the beginning and you don't change it after.

     
  • shine world

    shine world - 2020-05-12

    Hi Jerome,

    Thank you very much for info !
    I will improve structure of objects witch interact with GLScene to avoid future similar issues.
    I'm adding freature after feature trying to get the best from OpenGL->GLScene environment.

    The AntiAliasing is one of graphical parameters of program that user can change few times, but can change if something look ugly.

    TVManager is a class which interact with the TGLScene to manages CNC Virtual Machines (VM).
    It permit me to dynamically add geometries (mesh) representing CNC parts and so describe kinematics of machine.

    TVMManager has a TVMSetupFrame which implements user possibile actions as:
    add/remove/delete geometries
    move geometris to another tree leaf
    change graphical properties like color, texture, transparency, etc
    apply transformations (rotations, offsets, etc).
    enable and set contour angles, etc.

    I'm just now working in materials library to better represent mechanincal parts as Aluminium, Plastic, Rubber, etc.

    This is only the UI part of a full CNC control, however "even the eye must have its share".

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.