DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

haiku_gl.cpp (2013B)


      1 // Copyright 2012-2022 David Robillard <d@drobilla.net>
      2 // Copyright 2021-2022 Filipe Coelho <falktx@falktx.com>
      3 // SPDX-License-Identifier: ISC
      4 
      5 #include "../pugl-upstream/src/stub.h"
      6 #include "haiku.h"
      7 
      8 #include "pugl/pugl.h"
      9 
     10 #include <stdio.h>
     11 #include <stdlib.h>
     12 
     13 #include <GL/gl.h>
     14 #include <opengl/GLView.h>
     15 
     16 typedef struct {
     17   BGLView* view;
     18 } PuglHaikuGlSurface;
     19 
     20 static PuglStatus
     21 puglHaikuGlConfigure(PuglView* view)
     22 {
     23   PuglInternals* const impl = view->impl;
     24 
     25   PuglHaikuGlSurface* const surface =
     26     (PuglHaikuGlSurface*)calloc(1, sizeof(PuglHaikuGlSurface));
     27   impl->surface = surface;
     28 
     29   return PUGL_SUCCESS;
     30 }
     31 
     32 PUGL_WARN_UNUSED_RESULT
     33 static PuglStatus
     34 puglHaikuGlEnter(PuglView* const view, const PuglExposeEvent* PUGL_UNUSED(expose))
     35 {
     36   PuglHaikuGlSurface* const surface = (PuglHaikuGlSurface*)view->impl->surface;
     37   if (!surface || !surface->view) {
     38     return PUGL_FAILURE;
     39   }
     40 
     41   surface->view->LockGL();
     42   return PUGL_SUCCESS;
     43 }
     44 
     45 PUGL_WARN_UNUSED_RESULT
     46 static PuglStatus
     47 puglHaikuGlLeave(PuglView* const view, const PuglExposeEvent* const expose)
     48 {
     49   PuglHaikuGlSurface* const surface = (PuglHaikuGlSurface*)view->impl->surface;
     50   if (!surface || !surface->view) {
     51     return PUGL_FAILURE;
     52   }
     53 
     54   if (expose)
     55       surface->view->SwapBuffers();
     56 
     57   surface->view->UnlockGL();
     58   return PUGL_SUCCESS;
     59 }
     60 
     61 static PuglStatus
     62 puglHaikuGlCreate(PuglView* view)
     63 {
     64   return PUGL_SUCCESS;
     65 }
     66 
     67 static void
     68 puglHaikuGlDestroy(PuglView* view)
     69 {
     70   PuglHaikuGlSurface* surface = (PuglHaikuGlSurface*)view->impl->surface;
     71   if (surface) {
     72     free(surface);
     73     view->impl->surface = NULL;
     74   }
     75 }
     76 
     77 const PuglBackend*
     78 puglGlBackend(void)
     79 {
     80   static const PuglBackend backend = {puglHaikuGlConfigure,
     81                                       puglHaikuGlCreate,
     82                                       puglHaikuGlDestroy,
     83                                       puglHaikuGlEnter,
     84                                       puglHaikuGlLeave,
     85                                       puglStubGetContext};
     86   return &backend;
     87 }