Introduced properties

fun assert_no_egl_error

egl :: EGLDisplay :: assert_no_egl_error

Utility method for easier debugging
fun choose_configs(attribs: Array[Int]): nullable Array[EGLConfig]

egl :: EGLDisplay :: choose_configs

Returns some configs compatible with the specified attributes
fun config_attrib(config: EGLConfig, attribute: Int): Int

egl :: EGLDisplay :: config_attrib

Can be used directly, but it is preferable to use a EGLConfigAttribs
fun create_context(config: EGLConfig): EGLContext

egl :: EGLDisplay :: create_context

TODO add share_context
init new(handle: Pointer): EGLDisplay

egl :: EGLDisplay :: new

fun query_surface(surface: EGLSurface, attribute: Int): Int

egl :: EGLDisplay :: query_surface

Can be used directly, but it is preferable to use a EGLSurfaceAttribs

Redefined properties

redef type SELF: EGLDisplay

egl $ EGLDisplay :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun address_is_null: Bool

core :: Pointer :: address_is_null

Is the address behind this Object at NULL?
fun assert_no_egl_error

egl :: EGLDisplay :: assert_no_egl_error

Utility method for easier debugging
fun choose_configs(attribs: Array[Int]): nullable Array[EGLConfig]

egl :: EGLDisplay :: choose_configs

Returns some configs compatible with the specified attributes
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun config_attrib(config: EGLConfig, attribute: Int): Int

egl :: EGLDisplay :: config_attrib

Can be used directly, but it is preferable to use a EGLConfigAttribs
fun create_context(config: EGLConfig): EGLContext

egl :: EGLDisplay :: create_context

TODO add share_context
fun free

core :: Pointer :: free

Free the memory pointed by this pointer
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
init new(handle: Pointer): EGLDisplay

egl :: EGLDisplay :: new

init nul: Pointer

core :: Pointer :: nul

C NULL pointer
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun query_surface(surface: EGLSurface, attribute: Int): Int

egl :: EGLDisplay :: query_surface

Can be used directly, but it is preferable to use a EGLSurfaceAttribs
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram egl::EGLDisplay EGLDisplay core::Pointer Pointer egl::EGLDisplay->core::Pointer core::Object Object core::Pointer->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

extern class Pointer

core :: Pointer

Pointer classes are used to manipulate extern C structures.

Class definitions

egl $ EGLDisplay
extern class EGLDisplay `{ EGLDisplay `}
	new current `{ return eglGetCurrentDisplay(); `}
	new(handle: Pointer) `{ return eglGetDisplay(handle); `}

	fun is_valid: Bool `{ return self != EGL_NO_DISPLAY; `}

	fun initialize: Bool `{
		return eglInitialize(self, NULL, NULL);
	`}

	fun major_version: Int `{
		EGLint val;
		eglInitialize(self, &val, NULL);
		return val;
	`}
	fun minor_version: Int `{
		EGLint val;
		eglInitialize(self, NULL, &val);
		return val;
	`}

	# TODO if useful
	# Returns all configs supported by the hardware
	#fun get_configs: nullable Array[EGLConfig] import Array[EGLConfig].with_native `{

	# Returns some configs compatible with the specified `attributes`
	fun choose_configs(attribs: Array[Int]): nullable Array[EGLConfig] import Array[Int].length, Array[Int].[], Array[EGLConfig], Array[EGLConfig].add, Array[EGLConfig].as nullable, report_egl_error `{
		EGLConfig *configs;
		int n_configs;
		int n_attribs = Array_of_Int_length(attribs);
		int i;
		int *c_attribs = malloc(sizeof(int)*n_attribs);
		for (i = 0; i < n_attribs; i ++) {
			c_attribs[i] = Array_of_Int__index(attribs, i);
		}

		// get number of configs
		EGLBoolean r = eglChooseConfig(self, c_attribs, NULL, 0, &n_configs);

		if (r == EGL_FALSE) {
			EGLDisplay_report_egl_error(self, "failed to get number of available configs.");
			return null_Array_of_EGLConfig();
		} else if (n_configs == 0) {
			EGLDisplay_report_egl_error(self, "no config available.");
			return null_Array_of_EGLConfig();
		}

		configs = (EGLConfig*)malloc(sizeof(EGLConfig)*n_configs);

		r = eglChooseConfig(self, c_attribs, configs, n_configs, &n_configs);

		if (r == EGL_FALSE) {
			EGLDisplay_report_egl_error(self, "failed to load config.");
			return null_Array_of_EGLConfig();
		} else {
			Array_of_EGLConfig array = new_Array_of_EGLConfig();
			for (i=0; i < n_configs; i++)
				Array_of_EGLConfig_add(array, configs[i]);

			return Array_of_EGLConfig_as_nullable(array);
		}
	`}

	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;
		EGLBoolean r = eglGetConfigAttrib(self, config, attribute, &val);
		if (r == EGL_FALSE)
			return -1;
		else
			return val;
	`}

	fun terminate: Bool `{
		return eglTerminate(self) == EGL_TRUE;
	`}

	fun create_window_surface(config: EGLConfig, native_window: Pointer, attribs: Array[Int]): EGLSurface `{
		EGLSurface surface = eglCreateWindowSurface(self, config, (EGLNativeWindowType)native_window, NULL);
		return surface;
	`}

	# TODO add share_context
	fun create_context(config: EGLConfig): EGLContext `{
		EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE}; // TODO move out!
		EGLContext context = eglCreateContext(self, config, EGL_NO_CONTEXT, context_attribs);
		return context;
	`}

	fun make_current(draw, read: EGLSurface, context: EGLContext): Bool `{
		return eglMakeCurrent(self, draw, read, context);
	`}

	# Can be used directly, but it is preferable to use a `EGLSurfaceAttribs`
	fun query_surface(surface: EGLSurface, attribute: Int): Int `{
		int val;
		EGLBoolean r = eglQuerySurface(self, surface, attribute, &val);
		if (r == EGL_FALSE)
			return -1;
		else
			return val;
	`}

	fun destroy_context(context: EGLContext): Bool `{
		return eglDestroyContext(self, context);
	`}

	fun destroy_surface(surface: EGLSurface): Bool `{
		return eglDestroySurface(self, surface);
	`}

	fun error: EGLError `{ return eglGetError(); `}

	# Utility method for easier debugging
	fun assert_no_egl_error
	do
		var error = self.error
		if not error.is_success then
			print "EGL error: {error}"
			abort
		end
	end

	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).trim.split_with(" ")

	fun client_apis: Array[String] do return query_string(0x308D).split_with(" ")

	fun swap_buffers(surface: EGLSurface) `{ eglSwapBuffers(self, surface); `}
end
lib/egl/egl.nit:38,1--180,3