core/stream: change read_byte return type to Int
[nit.git] / lib / egl.nit
index 69df8e5..5d8f4f9 100644 (file)
@@ -42,12 +42,7 @@ extern class EGLDisplay `{ EGLDisplay `}
        fun is_valid: Bool `{ return self != EGL_NO_DISPLAY; `}
 
        fun initialize: Bool `{
-               EGLBoolean r = eglInitialize(self, NULL, NULL);
-               if (r == EGL_FALSE) {
-                       fprintf(stderr, "Unable to eglInitialize");
-                       return 0;
-               }
-               return 1;
+               return eglInitialize(self, NULL, NULL);
        `}
 
        fun major_version: Int `{
@@ -88,7 +83,7 @@ extern class EGLDisplay `{ EGLDisplay `}
                }
 
                configs = (EGLConfig*)malloc(sizeof(EGLConfig)*n_configs);
+
                r = eglChooseConfig(self, c_attribs, configs, n_configs, &n_configs);
 
                if (r == EGL_FALSE) {
@@ -103,6 +98,12 @@ extern class EGLDisplay `{ EGLDisplay `}
                }
        `}
 
+       private fun report_egl_error(cmsg: CString)
+       do
+               var msg = cmsg.to_s
+               print "libEGL error: {msg}"
+       end
+
        # Can be used directly, but it is preferable to use a `EGLConfigAttribs`
        fun config_attrib(config: EGLConfig, attribute: Int): Int `{
                EGLint val;
@@ -130,11 +131,7 @@ extern class EGLDisplay `{ EGLDisplay `}
        `}
 
        fun make_current(draw, read: EGLSurface, context: EGLContext): Bool `{
-               if (eglMakeCurrent(self, draw, read, context) == EGL_FALSE) {
-                       fprintf(stderr, "Unable to eglMakeCurrent");
-                       return 0;
-               }
-               return 1;
+               return eglMakeCurrent(self, draw, read, context);
        `}
 
        # Can be used directly, but it is preferable to use a `EGLSurfaceAttribs`
@@ -167,15 +164,15 @@ extern class EGLDisplay `{ EGLDisplay `}
                end
        end
 
-       private fun query_string(name: Int): String import NativeString.to_s `{
-               return NativeString_to_s((char *)eglQueryString(self, name));
+       private fun query_string(name: Int): String import CString.to_s `{
+               return CString_to_s((char *)eglQueryString(self, name));
        `}
 
        fun vendor: String do return query_string(0x3053)
 
        fun version: String do return query_string(0x3054)
 
-       fun extensions: Array[String] do return query_string(0x3055).split_with(" ")
+       fun extensions: Array[String] do return query_string(0x3055).trim.split_with(" ")
 
        fun client_apis: Array[String] do return query_string(0x308D).split_with(" ")
 
@@ -219,6 +216,8 @@ class EGLConfigAttribs
        fun red_size: Int do return display.config_attrib(config, 0x3024)
        fun depth_size: Int do return display.config_attrib(config, 0x3025)
        fun stencil_size: Int do return display.config_attrib(config, 0x3026)
+       fun samples: Int do return display.config_attrib(config, 0x3031)
+       fun sample_buffers: Int do return display.config_attrib(config, 0x3032)
 
        fun native_visual_id: Int do return display.config_attrib(config, 0x302E)
        fun native_visual_type: Int do return display.config_attrib(config, 0x302F)
@@ -430,7 +429,8 @@ class EGLConfigChooser
        fun alpha_size=(size: Int) do insert_attrib_with_val(0x3021, size)
        fun depth_size=(size: Int) do insert_attrib_with_val(0x3025, size)
        fun stencil_size=(size: Int) do insert_attrib_with_val(0x3026, size)
-       fun sample_buffers=(size: Int) do insert_attrib_with_val(0x3031, size)
+       fun samples=(count: Int) do insert_attrib_with_val(0x3031, count)
+       fun sample_buffers=(size: Int) do insert_attrib_with_val(0x3032, size)
 
        fun caveat=(caveat: EGLConfigCaveat) do insert_attrib_with_val(0x3050, caveat.to_i)
 
@@ -443,14 +443,6 @@ class EGLConfigChooser
        end
 end
 
-redef class Object
-       private fun report_egl_error(cmsg: NativeString)
-       do
-               var msg = cmsg.to_s
-               print "libEGL error: {msg}"
-       end
-end
-
 fun egl_bind_opengl_api: Bool `{ return eglBindAPI(EGL_OPENGL_API); `}
 fun egl_bind_opengl_es_api: Bool `{ return eglBindAPI(EGL_OPENGL_ES_API); `}
 fun egl_bind_openvg_api: Bool `{ return eglBindAPI(EGL_OPENVG_API); `}