know
know

Reputation: 3

How to initialize nifty after update to 1.4.2

I updated Nifty to v.1.4.2, Jogamp to v.2.4.0., Java to jdk-11.0.2. Code before update:

public class ISOView extends Object2D
{
  private IViewManipulation viewerInteraction;
  private IRenderEvent renderEvent;
  private ISOViewNiftyController isoNiftyController;
  private JoglInputSystem inputSystem;
  private Nifty nifty;

  public ISOView(IViewManipulation viewerInteraction, IRenderEvent renderEvent) 
  {
    super(RenderOption.TOP);
    this.renderEvent = renderEvent;
    this.viewerInteraction = viewerInteraction;
  }

  @Override
  public void render(GL gl, RenderParameters params, boolean selection)
  {
    if( params == null || params.getCamera() == null || !params.getCamera().hasFrustum() )
      return;
    
    GL2 gl2 = OpenGLUtil.getMinGL(gl);
    renderNifty(gl2, selection);
    isoNiftyController.update();
  }

  private void renderNifty(GL2 gl2, boolean selection)
  {
    if (ISOViewNiftyController.isNiftyUsed()) {
      // some code
    }
  }

  private void initNifty()
  {
    Logger.getLogger("de.lessvoid").setLevel(Level.OFF);
    inputSystem = new JoglInputSystem();
    nifty = new Nifty(new JoglRenderDevice(), new NullSoundDevice(), inputSystem, new AccurateTimeProvider());
    // other code
  }

  @Override
  public void cleanUp(GL gl)
  {
    // TODO Auto-generated method stub

  }

  public JoglInputSystem getInputSystem()
  {
    return inputSystem;
  }

  @Override
  public boolean belongsToScene(SceneType type)
  {
    // some code
  }
  
  @Override
  public void dispose( BaseViewer baseViewer )
  {
    // some code
  }
}

Now I have 2 problems:

New code:

private void initNifty(){
  Logger.getLogger("de.lessvoid").setLevel(Level.OFF);
  com.jogamp.newt.Window newtWindow = null;//Fix!!!
  inputSystem = new JoglInputSystem(newtWindow);
  de.lessvoid.nifty.spi.render.RenderDevice renderDevice = null;//Fix!!!
  nifty = new Nifty(renderDevice, new NullSoundDevice(), inputSystem, new AccurateTimeProvider());
  // some code
}

Can anyone help, please? Using Eclipse IDE for RCP and RAP Developers, Version: 2020-06 (4.16.0), Win 10

I did try:

GLCapabilities caps = new GLCapabilities(GLProfile.getMaxProgrammable(true));

GLWindow glW = GLWindow.create(caps);// implements com.jogamp.newt.Window
inputSystem = new JoglInputSystem(glW);

There is created some JoglInputSystem, I don't know if correct one. But I don't know, how to create a Nifty. To create it, I need RenderDevice. That's interface implemented by only 2 classes. So I create ScalingRenderDevice. To do so, I need NiftyRenderEngine. And for that I need NiftyRenderEngineImpl and I came to beginning, because I need RenderDevice again.

Nifty(RenderDevice newRenderDevice, SoundDevice newSoundDevice, InputSystem newInputSystem, TimeProvider newTimeProvider) 
    Interface RenderDevice - All Known Implementing Classes:
        BatchRenderDevice
            BatchRenderDevice(BatchRenderBackend renderBackend)
            BatchRenderDevice(BatchRenderBackend renderBackend, BatchRenderConfiguration renderConfig)
        ScalingRenderDevice
            ScalingRenderDevice(NiftyRenderEngine renderEngine, RenderDevice interal)
                Interface NiftyRenderEngine - All Known Implementing Classes:
                    NiftyRenderEngineImpl(RenderDevice renderDeviceParam)

Upvotes: 0

Views: 56

Answers (1)

void256
void256

Reputation: 1356

We have example code available here: JOGLNiftyRunner.java#L123 that shows how to initialize Nifty using the BatchRenderBackend implementation provided by the nifty-render-jogl project for JOGL.

The BatchRenderDevice provided by Nifty is a RenderDevice implementation that uses the BatchRenderBackend interface to talk to a specific graphics API. The idea was to provide the common batching logic in BatchRenderDevice and use BatchRenderBackend to connect to different graphics APIs. So for a new graphics API one doesn't need to implement the full RenderDevice interface but only BatchRenderBackend.

The goal was to make it simpler to connect to different graphics APIs .. but in the end we ended up with a cumbersome and complicated mess of the old style (complete RenderDevice implementations) and the new style (based on BatchRenderBackend implementations that require the use of the BatchRenderDevice that Nifty provides itself).

It might have been smarter to skip all of this mess and simply make BatchRenderBackend the new RenderDevice and just use batching internally as the new default maybe changing the old RenderDevice into some private, internal Nifty API instead of a public one.

KISS and Principle of Least Surprise and all of these other principles that Nifty likes to violate so much, unfortunately. I'm still sorry about it to be honest :/

ScalingRenderDevice on the other hand is a wrapper RenderDevice that automatically applies some global scaling. The idea here was to use ScalingRenderDevice to wrap an existing RenderDevice implementation to add the scaling feature to any RenderDevice.

Upvotes: 0

Related Questions