summaryrefslogtreecommitdiff
path: root/src/backends/meta-gles3.c
blob: 98bfd83456ca0923b1c6aab0d7455eeff45a5f1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

/*
 * Copyright (C) 2017 Red Hat
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 */
#include <stdio.h>

#include "config.h"

#include "backends/meta-gles3.h"

#include <dlfcn.h>
#include <gio/gio.h>

#include "backends/meta-gles3-table.h"

struct _MetaGles3
{
  GObject parent;

  MetaEgl *egl;

  MetaGles3Table table;
};

G_DEFINE_TYPE (MetaGles3, meta_gles3, G_TYPE_OBJECT)

MetaGles3Table *
meta_gles3_get_table (MetaGles3 * gles3)
{
  return &gles3->table;
}

void
meta_gles3_ensure_loaded (MetaGles3  *gles3,
                          gpointer   *func,
                          const char *name)
{
  GError *error = NULL;

  if (*func)
    return;

  *func = meta_egl_get_proc_address (gles3->egl, name, &error);
  if (!*func)
    g_error ("Failed to load GLES3 symbol: %s", error->message);
}

static const char *
get_gl_error_str (GLenum gl_error)
{
  switch (gl_error)
    {
    case GL_NO_ERROR:
      return "No error has been recorded.";
    case GL_INVALID_ENUM:
      return "An unacceptable value is specified for an enumerated argument.";
    case GL_INVALID_VALUE:
      return "A numeric argument is out of range.";
    case GL_INVALID_OPERATION:
      return "The specified operation is not allowed in the current state.";
    case GL_INVALID_FRAMEBUFFER_OPERATION:
      return "The framebuffer object is not complete.";
    case GL_OUT_OF_MEMORY:
      return "There is not enough memory left to execute the command.";
    default:
      return "Unknown error";
    }
}

void
meta_gles3_clear_error (MetaGles3 *gles3)
{
  while (TRUE)
    {
      GLenum gl_error = glGetError ();

      if (gl_error == GL_NO_ERROR)
        break;
    }
}

gboolean
meta_gles3_validate (MetaGles3 *gles3,
                     GError   **error)
{
  GLenum gl_error;

  gl_error = glGetError ();
  if (gl_error != GL_NO_ERROR)
    {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           get_gl_error_str (gl_error));
      return FALSE;
    }

  return TRUE;
}

gboolean
meta_gles3_has_extensions (MetaGles3 *gles3,
                           char    ***missing_extensions,
                           char      *first_extension,
                           ...)
{
  va_list var_args;
  const char *extensions_str;
  gboolean has_extensions;

  extensions_str = (const char *) glGetString (GL_EXTENSIONS);
  if (!extensions_str)
    {
      g_warning ("Failed to get string: %s", get_gl_error_str (glGetError ()));
      return FALSE;
    }

  va_start (var_args, first_extension);
  has_extensions =
    meta_extensions_string_has_extensions_valist (extensions_str,
                                                  missing_extensions,
                                                  first_extension,
                                                  var_args);
  va_end (var_args);

  return has_extensions;
}

MetaGles3 *
meta_gles3_new (MetaEgl *egl)
{
  MetaGles3 *gles3;

  gles3 = g_object_new (META_TYPE_GLES3, NULL);
  gles3->egl = egl;

  return gles3;
}

static void
meta_gles3_init (MetaGles3 *gles3)
{
}

static void
meta_gles3_class_init (MetaGles3Class *klass)
{
}