how to migrate from libgo2 to libgou ?

Post Reply
trngaje
Posts: 30
Joined: Tue Mar 10, 2020 8:38 pm
languages_spoken: english
ODROIDs: odroid go advance
Has thanked: 0
Been thanked: 1 time
Contact:

how to migrate from libgo2 to libgou ?

Post by trngaje »

I want to replace the code written as libgo2 with libgou.

gou_context3D = gou_context3d_create(gou_display, w, h, &attr);
m_surface = gou_context3D->eglSurface;

Within the libgou library, I cannot see the syntax to initialize eglSurface.

Normally, I can use the function below to obtain the implementation eglsurface value, but i cannnot define "window" on ubuntu without x11.
eglCreateWindowSurface(m_display, m_config, window, NULL);
How do I implement it for eglsurface ?

The reference code is as follows.
https://github.com/OtherCrashOverride/libgou.git
https://github.com/OtherCrashOverride/retrorun-go2.git

crashoverride
Posts: 5748
Joined: Tue Dec 30, 2014 8:42 pm
languages_spoken: english
ODROIDs: C1
Has thanked: 0
Been thanked: 590 times
Contact:

Re: how to migrate from libgo2 to libgou ?

Post by crashoverride »

The 3D pipeline changed with libgou. It uses "surfaceless" contexts that are all off-screen rendered. To obtain a surface, you need to create a pbuffer and copy the data back.

1) Create a 3D context and a gou_surface:

Code: Select all

gou_display* display = gou_display_create();
gou_context3d* context = gou_context3d_create(display, 640, 480, &attr);
gou_surface* surface = gou_surface_create(display, 640, 480, DRM_FORMAT_ABGR8888);
2) Create a pbuffer to act as the EglSurface:

Code: Select all

EGLDisplay egl_display = gou_context3d_egldisplay_get(context);
EGLContext egl_context = gou_context3d_eglcontext_get(context);
int width = gou_surface_width_get(surface);
int height = gou_surface_height_get(surface);

EGLint attrib_list[] = {
    EGL_WIDTH,
    width,
    EGL_HEIGHT,
    height,
    EGL_NONE,
};
EGLSurface egl_surface = eglCreatePbufferSurface(egl_display, config, attrib_list);
if (!egl_surface)
{
  printf("eglCreatePbufferSurface failed.\n");
  abort();
}

eglMakeCurrent(egl_display, egl_surface, egl_surface,  egl_context);
3) Swap and copy the pbuffer to the surface:

Code: Select all

eglSwapBuffers(egl_display, egl_surface);

int width = gou_surface_width_get(surface);
int height = gou_surface_height_get(surface);

glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, gou_surface_map(surface));
4) Display the surface:

Code: Select all

int dw = gou_display_width_get(display);
int dh = gou_display_height_get(display);

int width = gou_surface_width_get(surface);
int height = gou_surface_height_get(surface);

gou_display_present(display, surface, 0, 0, width, height, false, true, 0, 0, dw, dh);
[edit]
Corrected API names.
These users thanked the author crashoverride for the post:
odroid (Wed Nov 16, 2022 9:21 am)

trngaje
Posts: 30
Joined: Tue Mar 10, 2020 8:38 pm
languages_spoken: english
ODROIDs: odroid go advance
Has thanked: 0
Been thanked: 1 time
Contact:

Re: how to migrate from libgo2 to libgou ?

Post by trngaje »

It is displayed well except for the correct resolution.
It cannot be set to 854 resolution because it is aligned to 64.

#if 0
gou_context3D = gou_context3d_create(gou_display, 832, 480, &attr);
gou_surface = gou_surface_create(gou_display, 832, 480, DRM_FORMAT_ABGR8888);
#else
gou_context3D = gou_context3d_create(gou_display, 896, 480, &attr);
gou_surface = gou_surface_create(gou_display, 896, 480, DRM_FORMAT_ABGR8888);
#endif

The libgou library seems to need further improvement.

crashoverride
Posts: 5748
Joined: Tue Dec 30, 2014 8:42 pm
languages_spoken: english
ODROIDs: C1
Has thanked: 0
Been thanked: 590 times
Contact:

Re: how to migrate from libgo2 to libgou ?

Post by crashoverride »

trngaje wrote:
Wed Nov 16, 2022 10:40 pm
It cannot be set to 854 resolution because it is aligned to 64.
The alignment affecting the glReadPixels operation can be controlled with glPixelStorei.
https://registry.khronos.org/OpenGL-Ref ... orei.xhtml
GL_PACK_ALIGNMENT
Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries).
GL_UNPACK_ALIGNMENT
Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment), and 8 (rows start on double-word boundaries).

trngaje
Posts: 30
Joined: Tue Mar 10, 2020 8:38 pm
languages_spoken: english
ODROIDs: odroid go advance
Has thanked: 0
Been thanked: 1 time
Contact:

Re: how to migrate from libgo2 to libgou ?

Post by trngaje »

Although you explained it in detail, there was no expected effect of the function (glPixelStorei). Maybe I don't understand.

crashoverride
Posts: 5748
Joined: Tue Dec 30, 2014 8:42 pm
languages_spoken: english
ODROIDs: C1
Has thanked: 0
Been thanked: 590 times
Contact:

Re: how to migrate from libgo2 to libgou ?

Post by crashoverride »

From the language in the glPixelStorei reference:
glPixelStorei sets pixel storage modes that affect the operation of subsequent glReadPixels as well as the unpacking of texture patterns (see glTexImage2D, glTexImage3D, glTexSubImage2D, glTexSubImage3D).
GL_PACK_ALIGNMENT affects glReadPixels while GL_UNPACK_ALIGNMENT affects glTexImage2D, glTexImage3D, glTexSubImage2D, and glTexSubImage3D.

A value of "1" is used if the image width is the same as the stride.

libgou uses a 64bit alignment so the image width may not be the same as the stride:
https://github.com/OtherCrashOverride/l ... ce.cpp#L71

With a 64bit surface alignment, both GL_PACK_ALIGNMENT and GL_UNPACK_ALIGNMENT should be set to "8" (8 bytes * 8 bits per byte = 64 bit) to allow data to be sent to and from the GPU. Note that you may need to reset it to its previous value if the program uploads image data.

The 64bit surface alignment is necessary to ensure that the CPU, GPU and GE2D scaler can all access the same surface.

Post Reply

Return to “Issues”

Who is online

Users browsing this forum: No registered users and 1 guest