/* Copyright (C) 2015 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <gdkmmconfig.h>
#include <gdkmm/display.h>
#include <gdkmm/window.h>

_DEFS(gdkmm,gdk)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gdk
{

_WRAP_GERROR(GLError, GdkGLError, GDK_GL_ERROR, newin "3,18", decl_prefix GDKMM_API)

/** A Gdk::GLContext is an OpenGL context abstraction. It's a low-level object, used to implement high-level objects such
 * as Gtk::GLArea on the GTK+ level.
 * @newin{3,18}
 */
class GDKMM_API GLContext : public Glib::Object
{
  _CLASS_GOBJECT(GLContext,GdkGLContext,GDK_GL_CONTEXT,Glib::Object,GObject, , , GDKMM_API)

protected:
  _CTOR_DEFAULT

public:
  _WRAP_METHOD(Glib::RefPtr<Display> get_display(), gdk_gl_context_get_display, refreturn, newin "3,18")
  _WRAP_METHOD(Glib::RefPtr<const Display> get_display() const, gdk_gl_context_get_display, refreturn, constversion, newin "3,18")
  _WRAP_METHOD(Glib::RefPtr<Window> get_window(), gdk_gl_context_get_window, refreturn, newin "3,18")
  _WRAP_METHOD(Glib::RefPtr<const Window> get_window() const, gdk_gl_context_get_window, refreturn, constversion, newin "3,18")
  _WRAP_METHOD(Glib::RefPtr<GLContext> get_shared_context(), gdk_gl_context_get_shared_context, refreturn, newin "3,18")
  _WRAP_METHOD(Glib::RefPtr<const GLContext> get_shared_context() const, gdk_gl_context_get_shared_context, refreturn, constversion, newin "3,18")
  _WRAP_METHOD(void get_version(int& major, int& minor) const, gdk_gl_context_get_version, newin "3,18")
  _WRAP_METHOD(bool is_legacy() const, gdk_gl_context_is_legacy)
  _WRAP_METHOD(void get_required_version(int& major, int& minor) const, gdk_gl_context_get_required_version, newin "3,18")
  _WRAP_METHOD(void set_required_version(int major, int minor), gdk_gl_context_set_required_version, newin "3,18")
  _WRAP_METHOD(bool get_debug_enabled() const, gdk_gl_context_get_debug_enabled, newin "3,18")
  _WRAP_METHOD(void set_debug_enabled(bool enabled = true), gdk_gl_context_set_debug_enabled, newin "3,18")
  _WRAP_METHOD(bool get_forward_compatible() const, gdk_gl_context_get_forward_compatible, newin "3,18")
  _WRAP_METHOD(void set_forward_compatible(bool compatible = true), gdk_gl_context_set_forward_compatible, newin "3,18")

  /** Requests that GDK create an OpenGL ES context instead of an OpenGL one,
   * if the platform and windowing system allows it.
   *
   * The %GLContext must not have been realized.
   *
   * By default, GDK will attempt to automatically detect whether the
   * underlying GL implementation is OpenGL or OpenGL ES once the %GLContext
   * is realized.
   *
   * You should check the return value of get_use_es() after
   * calling realize() to decide whether to use the OpenGL or
   * OpenGL ES API, extensions, or shaders.
   *
   * @newin{3,22}
   *
   * @param use_es Whether the context should use OpenGL ES instead of OpenGL.
   */
  _WRAP_METHOD(void set_use_es(bool use_es = true), gdk_gl_context_set_use_es)

  /** Undo a previous call to set_use_es().
   *
   * GDK will attempt to automatically detect whether the underlying
   * GL implementation is OpenGL or OpenGL ES once the %GLContext is realized.
   *
   * @newin{3,24}
   */
  void unset_use_es();

  _WRAP_METHOD(bool get_use_es() const, gdk_gl_context_get_use_es)
  _WRAP_METHOD(bool realize(), gdk_gl_context_realize, errthrow, newin "3,18")
  _WRAP_METHOD(void make_current(), gdk_gl_context_make_current, newin "3,18")
  _WRAP_METHOD(static Glib::RefPtr<GLContext> get_current(), gdk_gl_context_get_current, refreturn, newin "3,18")
  _WRAP_METHOD(static void clear_current(), gdk_gl_context_clear_current, newin "3,18")

  _WRAP_PROPERTY("display", Glib::RefPtr<Display>, newin "3,18")
  _WRAP_PROPERTY("shared-context", Glib::RefPtr<GLContext>, newin "3,18")
  _WRAP_PROPERTY("window", Glib::RefPtr<Window>, newin "3,18")
};

} // namespace Gdk
