Cheb's Game Engine

Планы, идеология, архитектура и т.п.

Модератор: Модераторы

Re: Cheb's Game Engine

Сообщение Cheb » 17.04.2017 02:07:49

Бооооль.
Конверсия сишных заголовков. Тысяч их.

Код: Выделить всё
const
  libbcm = 'libbcm_host.so';

  procedure TryInitBroadcomEGLExtensionsAndSeeIfThisIsReallyRaspberryPi;
  begin
    pointer(eglCreateGlobalImageBRCM):= GetEGLProcAddress('eglCreateGlobalImageBRCM');
    if not Assigned(pointer(eglCreateGlobalImageBRCM)) then Exit;

    Mother^.State.RaspberryPiDetected:= true;
    if Mother^.Debug.Verbose then AddLog('  Raspberry Pi detected! Loading the rest of Broadcom extensions...');

    if not LoadBroadcomLibrary() then Die(MI_ERROR_OPENGLDLLNOTFOUND,  [libbcm]);

    pointer(bcm_host_init):= GetBroadcomProcAddress('bcm_host_init');
    pointer(bcm_host_deinit):= GetBroadcomProcAddress('bcm_host_deinit');
    pointer(graphics_get_display_size):= GetBroadcomProcAddress('graphics_get_display_size');
    //pointer(vc_dispman_init):= GetBroadcomProcAddress('vc_dispman_init');
    pointer(vc_dispmanx_stop):= GetBroadcomProcAddress('vc_dispmanx_stop');
    pointer(vc_dispmanx_rect_set):= GetBroadcomProcAddress('vc_dispmanx_rect_set');
    pointer(vc_dispmanx_resource_create):= GetBroadcomProcAddress('vc_dispmanx_resource_create');
    pointer(vc_dispmanx_resource_delete):= GetBroadcomProcAddress('vc_dispmanx_resource_delete');
    pointer(vc_dispmanx_display_open):= GetBroadcomProcAddress('vc_dispmanx_display_open');
    pointer(vc_dispmanx_display_open_mode):= GetBroadcomProcAddress('vc_dispmanx_display_open_mode');
    pointer(vc_dispmanx_display_open_offscreen):= GetBroadcomProcAddress('vc_dispmanx_display_open_offscreen');
    pointer(vc_dispmanx_display_reconfigure):= GetBroadcomProcAddress('vc_dispmanx_display_reconfigure');
    pointer(vc_dispmanx_display_set_destination):= GetBroadcomProcAddress('vc_dispmanx_display_set_destination');
    pointer(vc_dispmanx_display_set_background):= GetBroadcomProcAddress('vc_dispmanx_display_set_background');
    pointer(vc_dispmanx_display_get_info):= GetBroadcomProcAddress('vc_dispmanx_display_get_info');
    pointer(vc_dispmanx_display_close):= GetBroadcomProcAddress('vc_dispmanx_display_close');
    pointer(vc_dispmanx_update_start):= GetBroadcomProcAddress('vc_dispmanx_update_start');
    pointer(vc_dispmanx_element_add):= GetBroadcomProcAddress('vc_dispmanx_element_add');
    pointer(vc_dispmanx_element_change_source):= GetBroadcomProcAddress('vc_dispmanx_element_change_source');
    pointer(vc_dispmanx_element_change_layer):= GetBroadcomProcAddress('vc_dispmanx_element_change_layer');
    pointer(vc_dispmanx_element_modified):= GetBroadcomProcAddress('vc_dispmanx_element_modified');
    pointer(vc_dispmanx_element_remove):= GetBroadcomProcAddress('vc_dispmanx_element_remove');
    pointer(vc_dispmanx_update_submit):= GetBroadcomProcAddress('vc_dispmanx_update_submit');
    pointer(vc_dispmanx_update_submit_sync):= GetBroadcomProcAddress('vc_dispmanx_update_submit_sync');
    pointer(vc_dispmanx_query_image_formats):= GetBroadcomProcAddress('vc_dispmanx_query_image_formats');
    pointer(vc_dispmanx_element_change_attributes):= GetBroadcomProcAddress('vc_dispmanx_element_change_attributes');


    //pointer(eglCreateCopyGlobalImageBRCM):= GetEGLProcAddress('eglCreateCopyGlobalImageBRCM ');
    pointer(eglDestroyGlobalImageBRCM ):= GetEGLProcAddress('eglDestroyGlobalImageBRCM');
    pointer(eglQueryGlobalImageBRCM):= GetEGLProcAddress('eglQueryGlobalImageBRCM');
    //pointer(eglInitPerfMonitorBRCM):= GetEGLProcAddress('eglInitPerfMonitorBRCM');
    //pointer(eglTermPerfMonitorBRCM):= GetEGLProcAddress('eglTermPerfMonitorBRCM');
    pointer(eglInitDriverMonitorBRCM ):= GetEGLProcAddress('eglInitDriverMonitorBRCM');
    pointer(eglGetDriverMonitorXMLBRCM ):= GetEGLProcAddress('eglGetDriverMonitorXMLBRCM');
    pointer(eglTermDriverMonitorBRCM ):= GetEGLProcAddress('eglTermDriverMonitorBRCM');
    //pointer(eglPerfStatsResetBRCM):= GetEGLProcAddress('eglPerfStatsResetBRCM');
    //pointer(eglPerfStatsGetBRCM ):= GetEGLProcAddress('eglPerfStatsGetBRCM');
    pointer(eglProcStateValid):= GetEGLProcAddress('eglProcStateValid');
    pointer(eglFlushBRCM ):= GetEGLProcAddress('eglFlushBRCM');
    //pointer(eglProcessMemUsageGetBRCM):= GetEGLProcAddress('eglProcessMemUsageGetBRCM');
    //pointer(eglDirectRenderingPointer):= GetEGLProcAddress('eglDirectRenderingPointer');

  end;

  function LoadBroadcomLibrary: boolean;
  var
   name: TFileNameString;
  begin
    if '' <> v_glinit_egldir then SetCurrentDir(v_glinit_egldir);
    try
     name:= v_glinit_egldir + libbcm;
     if Mother^.Debug.Verbose then AddLog('  Loading %0...', [name]);
     LibBroadcom := dlopen(PAnsiChar(WideToAnsi(FileNameToUnicode(name))), RTLD_NOW);
     Result:= Assigned(LibBroadcom);
     if result then begin
       LibBroadcomName:= GetDLLFileName(LibBroadcom);
       //raspbian surprise
       if LibBroadcomName = '' then LibBroadcomName:= name;
     end;
      if Mother^.Debug.Verbose then
        if not result then AddLogComment('FAILED.' + LoadLibraryErrorText())
                      else AddLogComment('Ok, %0', [LibBroadcomName]);
    finally
      SetCurrentDir(v_glinit_curdir);
    end;
  end;


  function GetBroadcomProcAddress(ProcName: ansistring): Pointer;
  var
    baseaddr: pointer;
    exename: TFileNameString;
  begin
    Result:=dlsym(LibBroadcom, PAnsiChar(ProcName));
    if Mother^.Debug.Verbose then begin
      if Assigned(Result) then begin
        exename:= GetExeFileName(Result);
        if (LibBroadcomName <> exename) and (LibBroadcomName <> '')
          then AddLog('    %0() at %1 in %2 (wrapper %3)', [ProcName, Result, exename, LibBroadcomName])
          else AddLog('    %0() at %1 in %2', [ProcName, Result, exename]);
      end else begin
        AddLog('    %0() NOT FOUND in %1', [ProcName, LibBroadcomName]);
        //Die(MI_ERROR_GL_FUNCTION_NOT_FOUND, [ProcName, '' + LibBroadcomName, '']);
      end;
    end;
  end;
Аватара пользователя
Cheb
энтузиаст
 
Сообщения: 508
Зарегистрирован: 06.06.2005 15:54:34

Re: Cheb's Game Engine

Сообщение Cheb » 19.04.2017 01:14:19

Йййййййесс!

Нарисовало чёрный квадрат Малевича и откомпилировало говношейдер прежде, чем сдохнуть ниже по течению от того,что поддержки GLES, собственно, ещё и нет.

Графический API: OpenGL ES 2.0
устройство VideoCore IV HW
производитель Broadcom
версия драйвера %3
Экранный буфер: 1103x787, красный 8, зелёный 8, синий 8,
альфа 8, глубина 0, трафарет 0.

Код: Выделить всё
Инициализация фреймворка "X11"...
Фреймворк: нативный X11
Starting the window manager...
  Reading from config [video].fullscreen ...
    .. = "0", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0
  Reading from config [video].window_left ...
    .. = "0.1666666716", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0.16666667163372
  Reading from config [video].window_top ...
    .. = "0.1815589368", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0.181558936834335
  Reading from config [video].window_width ...
    .. = "0.5744791627", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0.574479162693024
  Reading from config [video].window_height ...
    .. = "0.729087472", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0.729087471961975
  Reading from config [{$platform}].use_gles_not_gl ...
    .. [ostRaspbian-32].use_gles_not_gl ..
    .. [ostRaspbian].use_gles_not_gl ..
    .. = "1", found in the main INI file /home/cheb/raid2000/chentrah/chentrah.ini
    .. = 1
Init OpenGL ES...
  Searching config for platform-specific list GLES_path ...
    .. [ostRaspbian-32].GLES_path_0 ...
    .. [ostRaspbian].GLES_path_0 ...
    .. = "/opt/vc/lib/", found in the main INI file /home/cheb/raid2000/chentrah/chentrah.ini
    .. = "/opt/vc/lib/"
    .. [ostRaspbian].GLES_path_1 ...
  Searching config for platform-specific list EGL_dll ...
    .. [ostRaspbian-32].EGL_dll_0 ...
    .. [ostRaspbian].EGL_dll_0 ...
    .. = "libEGL.so", found in the main INI file /home/cheb/raid2000/chentrah/chentrah.ini
    .. = "libEGL.so"
    .. [ostRaspbian].EGL_dll_1 ...
  Searching config for platform-specific list GLES_dll ...
    .. [ostRaspbian-32].GLES_dll_0 ...
    .. [ostRaspbian].GLES_dll_0 ...
    .. = "libGLESv2.so", found in the main INI file /home/cheb/raid2000/chentrah/chentrah.ini
    .. = "libGLESv2.so"
    .. [ostRaspbian].GLES_dll_1 ...
  Loading /opt/vc/lib/libGLESv2.so...Ok, /opt/vc/lib/libGLESv2.so
  Loading /opt/vc/lib/libEGL.so...Ok, /opt/vc/lib/libEGL.so
  Loading the procedure addresses from the GL ES DLL ...
    glActiveTexture() at 76744A3Ch in /opt/vc/lib/libGLESv2.so
    glAttachShader() at 76744C90h in /opt/vc/lib/libGLESv2.so
[простыняааа.........]
    glVertexAttribPointer() at 767518C4h in /opt/vc/lib/libGLESv2.so
    glViewport() at 7674F584h in /opt/vc/lib/libGLESv2.so
  Loading the procedure addresses from the EGL DLL ...
    glGetProcAddress() NOT FOUND in /opt/vc/lib/libEGL.so
    eglGetProcAddress() at 7670C998h in /opt/vc/lib/libEGL.so
[простыняааа.........]
    eglCopyBuffers() at 7670C6ACh in /opt/vc/lib/libEGL.so
    eglCreateGlobalImageBRCM() at 7670EAB0h in /opt/vc/lib/libEGL.so
  Raspberry Pi detected! Loading the rest of Broadcom extensions...
  Loading /opt/vc/lib/libbcm_host.so...Ok, /opt/vc/lib/libbcm_host.so
    bcm_host_init() at 766E6AD0h in /opt/vc/lib/libbcm_host.so
    bcm_host_deinit() at 766E6C48h in /opt/vc/lib/libbcm_host.so
    graphics_get_display_size() at 766E6A2Ch in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_stop() at 766F2384h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_rect_set() at 766F251Ch in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_resource_create() at 766F26E4h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_resource_delete() at 766F2A54h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_display_open() at 766F2CF4h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_display_open_mode() at 766F2D54h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_display_open_offscreen() at 766F2F08h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_display_reconfigure() at 766F30BCh in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_display_set_destination() at 766F30E0h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_display_set_background() at 766F3104h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_display_get_info() at 766F3134h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_display_close() at 766F32F4h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_update_start() at 766F3318h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_element_add() at 766F354Ch in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_element_change_source() at 766F3670h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_element_change_layer() at 766F3694h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_element_modified() at 766F36B8h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_element_remove() at 766F370Ch in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_update_submit() at 766F34C4h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_update_submit_sync() at 766F3528h in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_query_image_formats() at 766F252Ch in /opt/vc/lib/libbcm_host.so
    vc_dispmanx_element_change_attributes() at 766F3730h in /opt/vc/lib/libbcm_host.so
    vc_vchi_dispmanx_init() at 766F20F4h in /opt/vc/lib/libbcm_host.so
    eglDestroyGlobalImageBRCM() at 7670EE10h in /opt/vc/lib/libEGL.so
    eglQueryGlobalImageBRCM() at 7670EEE4h in /opt/vc/lib/libEGL.so
    eglInitDriverMonitorBRCM() at 7670E764h in /opt/vc/lib/libEGL.so
    eglGetDriverMonitorXMLBRCM() at 7670E934h in /opt/vc/lib/libEGL.so
    eglTermDriverMonitorBRCM() at 7670EA30h in /opt/vc/lib/libEGL.so
    eglProcStateValid() at 7670C8C4h in /opt/vc/lib/libEGL.so
    eglFlushBRCM() at 7670EFBCh in /opt/vc/lib/libEGL.so
  First stage of EGL initialization...
  ..visual matched: depth=16, bits_per_rgb=8
  ..default color depth=16
    ..Raspberry Pi detected, postponing to after window creation.
Screen rect is 1920x1080(0,0)
The window rect, as read from the config and clipped to the screen rect, should be 1103x787(320,196)
Creating the window...
  Writing to config, [video].fullscreen = "0"... Ok
  Reading from config [video].window_left ...
    .. = "0.1666666716", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0.16666667163372
  Reading from config [video].window_top ...
    .. = "0.1815589368", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0.181558936834335
  Reading from config [video].window_width ...
    .. = "0.5744791627", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0.574479162693024
  Reading from config [video].window_height ...
    .. = "0.729087472", found in the user INI file /home/cheb/raid2000/chentrah/conf/conf.ini
    .. = 0.729087471961975
  the client area is 1103x787(320,196), the entire window including decorations is 1103x787(320,196)
Starting the pen tablet manager...
Listed 3 extended input devices:
  "Virtual core XTEST keyboard" (type=0, id=5)
  "No brand Combo Free KVM" (type=72, id=6)
  "No brand 4 Port KVMSwicther" (type=72, id=8)
Графический планшет: не найден (ни одно из 3 расширенных устройств ввода не распознано как планшет)
  Second stage of OpenGL ES initialization...
    ..Raspberry Pi detected, creating a Broadcom specific surface...
    ..display #0 1920x1080, (неизвестный формат 00h), без поворота
    ..Surface rect calculated as 1103x787(320,196)
  ..display 00000001h
  ..EGL version 1.4
  ..#EGL configs 28
    ..context 00000001h
    ..surface 00000001h
Графический API: OpenGL ES 2.0
  устройство VideoCore IV HW
  производитель Broadcom
  версия драйвера %3 
Экранный буфер: 1103x787,  красный 8, зелёный 8, синий 8,
  альфа 8,  глубина 0, трафарет 0.
  Initializing FFP emulation shader for GLES 2...
  FileGetContents: *I/modules/chentrah/glsl/ES_2_FFP_emul.vert
    ..name resolved to /home/cheb/raid2000/chentrah/modules/chentrah/glsl/ES_2_FFP_emul.vert
    ..read 349 bytes
    Log of компиляции вершинного шейдера : Compiled ; Shader source: #version 100
attribute vec4 position;
attribute vec2 texCoord;
//attribute vec4 color;

uniform mat4 modelView;
uniform mat4 projection;

//varying vec2 texCoordVar;
varying vec4 colorVar;

void main()
{
    vec4 p = modelView * position;
    gl_Position = projection * p;
    //texCoordVar = texCoord;
   //colorVar = color;
}


- обратите таки внимание, что сурфейс создаётся rgba 8888, в то время как формат основного экрана - rgb 565
Так ли это, или наглая ложь - узнаем в следующих сериях.

Добавлено спустя 14 минут 8 секунд:
З.Ы. Для интересующихся сколько крови для этого нужно:

Код: Выделить всё
{$if not defined(cpuarm)}
  {$fatal Yer moron, d00d}
{$endif}
{$ifdef cgekernel}
var
  LibBroadcom: Pointer;
  LibBroadcomName: TFileNameString;
  function LoadBroadcomLibrary: boolean;
  function GetBroadcomProcAddress(ProcName: ansistring): Pointer;
type
  uint32_t = dword;
  puint32_t = pdword;
  int32_t = Longint;
  pint32_t = PLongint;
  uint16_t = word;
  uint8_t = byte;
// ============== /opt/vc/include/EGL/eglext_brcm.h ============================
{
Copyright (c) 2012, Broadcom Europe Ltd
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the copyright holder nor the
      names of its contributors may be used to endorse or promote products
      derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
const
  EGL_NATIVE_PIXMAP_CLIENT_SIDE_BRCM = $99930B0;   //eglCreateImageKHR server-side target
  EGL_IMAGE_FROM_SURFACE_BRCM        = $99930B1; //eglCreateImageKHR server-side target
  //Multimedia target - created by gralloc
  EGL_IMAGE_BRCM_MULTIMEDIA        = $99930B2;
  EGL_IMAGE_BRCM_DUPLICATE         = $99930B3; // a new EGL Image pointing at the same underlying object
  EGL_IMAGE_BRCM_RAW_PIXELS        = $99930B4; // Raw YUV multimedia pixels
// Fastpath for creating greyscale textures from a single plane of a
//  MMAL opaque buffers.
  EGL_IMAGE_BRCM_MULTIMEDIA_Y      = $99930C0;
  EGL_IMAGE_BRCM_MULTIMEDIA_U      = $99930C1;
  EGL_IMAGE_BRCM_MULTIMEDIA_V      = $99930C2;
var
  eglSaneChooseConfigBRCM: function(dpy: EGLDisplay; attrib_list: PEGLint;
     configs: PEGLConfig; config_size: EGLint; num_config: PEGLint
     ) :EGLBoolean ; extdecl = nil;
const
  EGL_PIXEL_FORMAT_ARGB_8888_PRE_BRCM = 0;
  EGL_PIXEL_FORMAT_ARGB_8888_BRCM     = 1;
  EGL_PIXEL_FORMAT_XRGB_8888_BRCM     = 2;
  EGL_PIXEL_FORMAT_RGB_565_BRCM       = 3;
  EGL_PIXEL_FORMAT_A_8_BRCM           = 4;
  EGL_PIXEL_FORMAT_RENDER_GL_BRCM     = 1 shl 3;
  EGL_PIXEL_FORMAT_RENDER_GLES_BRCM   = 1 shl 4;
  EGL_PIXEL_FORMAT_RENDER_GLES2_BRCM  = 1 shl 5;
  EGL_PIXEL_FORMAT_RENDER_VG_BRCM     = 1 shl 6;
  EGL_PIXEL_FORMAT_RENDER_MASK_BRCM   = $78;
  EGL_PIXEL_FORMAT_VG_IMAGE_BRCM      = 1 shl 7;
  EGL_PIXEL_FORMAT_GLES_TEXTURE_BRCM  = 1 shl 8;
  EGL_PIXEL_FORMAT_GLES2_TEXTURE_BRCM = 1 shl 9;
  EGL_PIXEL_FORMAT_TEXTURE_MASK_BRCM  = $380;
  EGL_PIXEL_FORMAT_USAGE_MASK_BRCM    = $3f8;
type
  pEGLboolean = ^EGLboolean;
var
  eglCreateGlobalImageBRCM: procedure(width, height, pixel_format :EGLint;
     data: pointer; data_stride: EGLint; id: pEGLint); extdecl = nil;
  eglDestroyGlobalImageBRCM: function(id: pEGLint): EGLBoolean; extdecl = nil;
  eglQueryGlobalImageBRCM: function(
             id, width_height_pixel_format: pEGLint): EGLBoolean; extdecl = nil;
  eglInitDriverMonitorBRCM: function (
     display: EGLDisplay; hw_bank, l3c_bank: EGLint): EGLBoolean; extdecl = nil;
  eglGetDriverMonitorXMLBRCM: procedure (
     display: EGLDisplay; bufSize:  EGLint; length: pEGLint; xmlStats: PAnsiChar
                                                               ); extdecl = nil;
  eglTermDriverMonitorBRCM: function (
                                display: EGLDisplay): EGLBoolean; extdecl = nil;
  eglProcStateValid: procedure(
                          dpy: EGLDisplay; result: pEGLboolean ); extdecl = nil;
  eglFlushBRCM: procedure; extdecl = nil;
const
  EGL_IMAGE_WRAP_BRCM     = $9993140;
  EGL_IMAGE_WRAP_BRCM_BCG = $9993141;
// ============== /opt/vc/include/vcms_host/vc_vchi_dispmanx.h =================
const
  VC_NUM_HOST_RESOURCES = 64;
  DISPMANX_MSGFIFO_SIZE = 1024;
  DISPMANX_CLIENT_NAME = $50534944; //MAKE_FOURCC("DISP")
  DISPMANX_NOTIFY_NAME = $48445055; // MAKE_FOURCC("UPDH")
//Or with command to indicate we don't need a response
  DISPMANX_NO_REPLY_MASK = 1 shl 31;
type
  pGET_MODES_DATA_T = ^GET_MODES_DATA_T;
  GET_MODES_DATA_T = record
    description: array[0..31] of AnsiChar;
    width,
    height,
    aspect_pixwidth,
    aspect_pixheight,
    fieldrate_num,
    fieldrate_denom,
    fields_per_frame,
    transform : dword;
  end;
  pGET_INFO_DATA_T = ^GET_INFO_DATA_T;
  GET_INFO_DATA_T = record
    response: Longint;
    width,
    height,
    transform,
    input_format: dword;
  end;
const
//Attributes changes flag mask
  ELEMENT_CHANGE_LAYER          = 1 shl 0;
  ELEMENT_CHANGE_OPACITY        = 1 shl 1;
  ELEMENT_CHANGE_DEST_RECT      = 1 shl 2;
  ELEMENT_CHANGE_SRC_RECT       = 1 shl 3;
  ELEMENT_CHANGE_MASK_RESOURCE  = 1 shl 4;
  ELEMENT_CHANGE_TRANSFORM      = 1 shl 5;
// ============== /opt/vc/include/interface/vcms_dispservice_defs.h ===========
  TRANSFORM_HFLIP     = 1 shl 0;
  TRANSFORM_VFLIP     = 1 shl 1;
  TRANSFORM_TRANSPOSE = 1 shl 2;
// ============== /opt/vc/include/interface/vctypes/vc_display_types.h ========
//enums of display input format
  VCOS_DISPLAY_INPUT_FORMAT_INVALID = 0;
  VCOS_DISPLAY_INPUT_FORMAT_RGB888 = 1;
  VCOS_DISPLAY_INPUT_FORMAT_RGB565 = 2;
type
  VCOS_DISPLAY_INPUT_FORMAT_T = dword;
// For backward compatibility
const
  DISPLAY_INPUT_FORMAT_INVALID = VCOS_DISPLAY_INPUT_FORMAT_INVALID;
  DISPLAY_INPUT_FORMAT_RGB888 = VCOS_DISPLAY_INPUT_FORMAT_RGB888;
  DISPLAY_INPUT_FORMAT_RGB565 = VCOS_DISPLAY_INPUT_FORMAT_RGB565;
type
  DISPLAY_INPUT_FORMAT_T = VCOS_DISPLAY_INPUT_FORMAT_T;
// ============== /opt/vc/include/interface/vctypes/vc_image_types.h ==========
  //VC_IMAGE_T //cannot find it defined anywhere
  pVC_IMAGE_T = pointer;
  {$packenum 4}
type
  pVC_RECT_T = ^VC_RECT_T;
  VC_RECT_T = record
    x,
    y,
    width,
    height: Longint;
  end;
  VC_IMAGE_TYPE_T = dword;
const
  VC_IMAGE_MIN = 0; //bounds for error checking
  VC_IMAGE_RGB565 = 1;
  VC_IMAGE_1BPP = 2;
  VC_IMAGE_YUV420 = 3;
  VC_IMAGE_48BPP = 4;
  VC_IMAGE_RGB888 = 5;
  VC_IMAGE_8BPP = 6;
  VC_IMAGE_4BPP = 7;    // 4bpp palettised image
  VC_IMAGE_3D32 = 8;//    // A separated format of 16 colour/light shorts followed by 16 z values
  VC_IMAGE_3D32B = 9;//   // 16 colours followed by 16 z values
  VC_IMAGE_3D32MAT = 10; // // A separated format of 16 material/colour/light shorts followed by 16 z values
  VC_IMAGE_RGB2X9 = 11; //  // 32 bit format containing 18 bits of 6.6.6 RGB, 9 bits per short
  VC_IMAGE_RGB666 = 12; //,   // 32-bit format holding 18 bits of 6.6.6 RGB
//     VC_IMAGE_PAL4_OBSOLETE,     // 4bpp palettised image with embedded palette
//     VC_IMAGE_PAL8_OBSOLETE,     // 8bpp palettised image with embedded palette
  VC_IMAGE_RGBA32 = 15; //   // RGB888 with an alpha byte after each pixel  // xxx: isn't it BEFORE each pixel?
  VC_IMAGE_YUV422 = 16; //   // a line of Y (32-byte padded), a line of U (16-byte padded), and a line of V (16-byte padded)
  VC_IMAGE_RGBA565 = 17;//  // RGB565 with a transparent patch
  VC_IMAGE_RGBA16 = 18; //  // Compressed (4444) version of RGBA32
  VC_IMAGE_YUV_UV = 19; //   // VCIII codec format
  VC_IMAGE_TF_RGBA32 = 20;// // VCIII T-format RGBA8888
  VC_IMAGE_TF_RGBX32 = 21; //  // VCIII T-format RGBx8888
  VC_IMAGE_TF_FLOAT = 22; // // VCIII T-format float
  VC_IMAGE_TF_RGBA16 = 23; // VCIII T-format RGBA4444
  VC_IMAGE_TF_RGBA5551 = 24;// VCIII T-format RGB5551
  VC_IMAGE_TF_RGB565 = 25;  // VCIII T-format RGB565
  VC_IMAGE_TF_YA88 = 26; // VCIII T-format 8-bit luma and 8-bit alpha
  VC_IMAGE_TF_BYTE = 27; // VCIII T-format 8 bit generic sample
  VC_IMAGE_TF_PAL8 = 28; // VCIII T-format 8-bit palette
  VC_IMAGE_TF_PAL4 = 29; // VCIII T-format 4-bit palette
  VC_IMAGE_TF_ETC1 = 30; // VCIII T-format Ericsson Texture Compressed
  VC_IMAGE_BGR888 = 31;  // RGB888 with R & B swapped
  VC_IMAGE_BGR888_NP = 32;  // RGB888 with R & B swapped, but with no pitch, i.e. no padding after each row of pixels
  VC_IMAGE_BAYER = 33;  // Bayer image, extra defines which variant is being used
  VC_IMAGE_CODEC = 34;  // General wrapper for codec images e.g. JPEG from camera
  VC_IMAGE_YUV_UV32 = 35;   // VCIII codec format
  VC_IMAGE_TF_Y8 = 36;   // VCIII T-format 8-bit luma
  VC_IMAGE_TF_A8 = 37;   // VCIII T-format 8-bit alpha
  VC_IMAGE_TF_SHORT = 38;// VCIII T-format 16-bit generic sample
  VC_IMAGE_TF_1BPP = 39; // VCIII T-format 1bpp black/white
  VC_IMAGE_OPENGL = 40;
  VC_IMAGE_YUV444I = 41; // VCIII-B0 HVS YUV 4:4:4 interleaved samples
  VC_IMAGE_YUV422PLANAR = 42;  // Y, U, & V planes separately (VC_IMAGE_YUV422 has them interleaved on a per line basis)
  VC_IMAGE_ARGB8888 = 43;   // 32bpp with 8bit alpha at MS byte, with R, G, B (LS byte)
  VC_IMAGE_XRGB8888 = 44;   // 32bpp with 8bit unused at MS byte, with R, G, B (LS byte)
  VC_IMAGE_YUV422YUYV = 45;  // interleaved 8 bit samples of Y, U, Y, V
  VC_IMAGE_YUV422YVYU = 46;  // interleaved 8 bit samples of Y, V, Y, U
  VC_IMAGE_YUV422UYVY = 47;  // interleaved 8 bit samples of U, Y, V, Y
  VC_IMAGE_YUV422VYUY = 48;  // interleaved 8 bit samples of V, Y, U, Y
  VC_IMAGE_RGBX32 = 49;      // 32bpp like RGBA32 but with unused alpha
  VC_IMAGE_RGBX8888 = 50;    // 32bpp, corresponding to RGBA with unused alpha
  VC_IMAGE_BGRX8888 = 51;    // 32bpp, corresponding to BGRA with unused alpha
  VC_IMAGE_YUV420SP = 52;    // Y as a plane, then UV byte interleaved in plane with with same pitch, half height
  VC_IMAGE_YUV444PLANAR = 53;  // Y, U, & V planes separately 4:4:4
  VC_IMAGE_TF_U8 = 54;   // T-format 8-bit U - same as TF_Y8 buf from U plane
  VC_IMAGE_TF_V8 = 55;   // T-format 8-bit U - same as TF_Y8 buf from V plane
  VC_IMAGE_MAX = 56;     //bounds for error checking
  VC_IMAGE_FORCE_ENUM_16BIT = $ffff;
type
  VC_IMAGE_TRANSFORM_T = dword;
const
  VC_IMAGE_ROT0           = 0;
  VC_IMAGE_MIRROR_ROT0    = TRANSFORM_HFLIP;
  VC_IMAGE_MIRROR_ROT180  = TRANSFORM_VFLIP;
  VC_IMAGE_ROT180         = TRANSFORM_HFLIP or TRANSFORM_VFLIP;
  VC_IMAGE_MIRROR_ROT90   = TRANSFORM_TRANSPOSE;
  VC_IMAGE_ROT270         = TRANSFORM_TRANSPOSE or TRANSFORM_HFLIP;
  VC_IMAGE_ROT90          = TRANSFORM_TRANSPOSE or TRANSFORM_VFLIP;
  VC_IMAGE_MIRROR_ROT270  = TRANSFORM_TRANSPOSE or TRANSFORM_HFLIP
                                                             or TRANSFORM_VFLIP;
type
  VC_IMAGE_BAYER_ORDER_T = dword;
const
  VC_IMAGE_BAYER_RGGB     = 0;
  VC_IMAGE_BAYER_GBRG     = 1;
  VC_IMAGE_BAYER_BGGR     = 2;
  VC_IMAGE_BAYER_GRBG     = 3;
type
  VC_IMAGE_BAYER_FORMAT_T = dword;
const
  VC_IMAGE_BAYER_RAW6     = 0;
  VC_IMAGE_BAYER_RAW7     = 1;
  VC_IMAGE_BAYER_RAW8     = 2;
  VC_IMAGE_BAYER_RAW10    = 3;
  VC_IMAGE_BAYER_RAW12    = 4;
  VC_IMAGE_BAYER_RAW14    = 5;
  VC_IMAGE_BAYER_RAW16    = 6;
  VC_IMAGE_BAYER_RAW10_8  = 7;
  VC_IMAGE_BAYER_RAW12_8  = 8;
  VC_IMAGE_BAYER_RAW14_8  = 9;
  VC_IMAGE_BAYER_RAW10L   = 11;
  VC_IMAGE_BAYER_RAW12L   = 12;
  VC_IMAGE_BAYER_RAW14L   = 13;
  VC_IMAGE_BAYER_RAW16_BIG_ENDIAN = 14;
  VC_IMAGE_BAYER_RAW4     = 15;
// ============== /opt/vc/include/interface/vcms_dispmanx_types.h =============
const
  DISPMANX_NO_ROTATE = 0;
  DISPMANX_ROTATE_90 = 1;
  DISPMANX_ROTATE_180 = 2;
  DISPMANX_ROTATE_270 = 3;
  DISPMANX_FLIP_HRIZ = 1 shl 16;
  DISPMANX_FLIP_VERT = 1 shl 17;
  // invert left/right images
  DISPMANX_STEREOSCOPIC_INVERT =  1 shl 19;
  // extra flags for controlling 3d duplication behaviour
  DISPMANX_STEREOSCOPIC_NONE   =  0 shl 20;
  DISPMANX_STEREOSCOPIC_MONO   =  1 shl 20;
  DISPMANX_STEREOSCOPIC_SBS    =  2 shl 20;
  DISPMANX_STEREOSCOPIC_TB     =  3 shl 20;
  DISPMANX_STEREOSCOPIC_MASK   = 15 shl 20;
  // extra flags for controlling snapshot behaviour
  DISPMANX_SNAPSHOT_NO_YUV = 1 shl 24;
  DISPMANX_SNAPSHOT_NO_RGB = 1 shl 25;
  DISPMANX_SNAPSHOT_FILL = 1 shl 26;
  DISPMANX_SNAPSHOT_SWAP_RED_BLUE = 1 shl 27;
  DISPMANX_SNAPSHOT_PACK = 1 shl 28;
type
  DISPMANX_TRANSFORM_T = dword;
  // Opaque handles
  DISPMANX_DISPLAY_HANDLE_T = ptruint;
  DISPMANX_UPDATE_HANDLE_T = ptruint;
  DISPMANX_ELEMENT_HANDLE_T = ptruint;
  DISPMANX_RESOURCE_HANDLE_T = ptruint;
  DISPMANX_PROTECTION_T = uint32_t;
const
  DISPMANX_NO_HANDLE = 0;
  DISPMANX_PROTECTION_MAX = $0f;
  DISPMANX_PROTECTION_NONE = 0;
  DISPMANX_PROTECTION_HDCP = 11;   // Derived from the WM DRM levels, 101-300
type
  pDISPMANX_MODEINFO_T = ^DISPMANX_MODEINFO_T;
  DISPMANX_MODEINFO_T = record
    width,
    height: int32_t;
    transform: DISPMANX_TRANSFORM_T;
    input_format: DISPLAY_INPUT_FORMAT_T;
    display_num: uint32_t;
  end;
const
    // Bottom 2 bits sets the alpha mode
  DISPMANX_FLAGS_ALPHA_FROM_SOURCE = 0;
  DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS = 1;
  DISPMANX_FLAGS_ALPHA_FIXED_NON_ZERO = 2;
  DISPMANX_FLAGS_ALPHA_FIXED_EXCEED_0X07 = 3;
  DISPMANX_FLAGS_ALPHA_PREMULT = 1 shl 16;
  DISPMANX_FLAGS_ALPHA_MIX = 1 shl 17;
type
  DISPMANX_FLAGS_ALPHA_T = dword;
  pDISPMANX_ALPHA_T = ^DISPMANX_ALPHA_T;
  DISPMANX_ALPHA_T = record
    flags: DISPMANX_FLAGS_ALPHA_T;
    opacity: uint32_t;
    mask: pVC_IMAGE_T;
  end;
  pVC_DISPMANX_ALPHA_T = ^VC_DISPMANX_ALPHA_T;
  VC_DISPMANX_ALPHA_T = record
    flags: DISPMANX_FLAGS_ALPHA_T;
    opacity: uint32_t;
    mask: DISPMANX_RESOURCE_HANDLE_T;
  end;
const
  DISPMANX_FLAGS_CLAMP_NONE = 0;
  DISPMANX_FLAGS_CLAMP_LUMA_TRANSPARENT = 1;
  DISPMANX_FLAGS_CLAMP_TRANSPARENT = 2;
  DISPMANX_FLAGS_CLAMP_REPLACE = 3;
type
  DISPMANX_FLAGS_CLAMP_T = dword;
(*  typedef enum { *)
const
  DISPMANX_FLAGS_KEYMASK_OVERRIDE = 1;
  DISPMANX_FLAGS_KEYMASK_SMOOTH = 1 shl 1;
  DISPMANX_FLAGS_KEYMASK_CR_INV = 1 shl 2;
  DISPMANX_FLAGS_KEYMASK_CB_INV = 1 shl 3;
  DISPMANX_FLAGS_KEYMASK_YY_INV = 1 shl 4;
type
  DISPMANX_FLAGS_KEYMASK_T = dword;
  DISPMANX_CLAMP_KEYS_T = record
    case Integer of
      0: (
        yuv: record
          yy_upper,
          yy_lower,
          cr_upper,
          cr_lower,
          cb_upper,
          cb_lower: uint8_t;
        end);
      1: (
        rgb: record
          red_upper,
          red_lower,
          blue_upper,
          blue_lower,
          green_upper,
          green_lower: uint8_t;
        end;
      );
  end;
  pDISPMANX_CLAMP_T = ^DISPMANX_CLAMP_T;
  DISPMANX_CLAMP_T = record
    mode: DISPMANX_FLAGS_CLAMP_T;
    key_mask: DISPMANX_FLAGS_KEYMASK_T;
    key_value: DISPMANX_CLAMP_KEYS_T;
    replace_value: uint32_t;
  end;
// Update callback.
//  typedef void ( *DISPMANX_CALLBACK_FUNC_T)(DISPMANX_UPDATE_HANDLE_T u, void * arg);
  DISPMANX_CALLBACK_FUNC_T = procedure(
                           u: DISPMANX_UPDATE_HANDLE_T; arg: pointer); extdecl;
// ============== /opt/vc/include/EGL/eglplatform.h ===========================
type
  EGL_DISPMANX_WINDOW_T = record
    element: DISPMANX_ELEMENT_HANDLE_T;
    width, height: cint;
  end;
// ============== /opt/vc/include/interface/vchi/vchi.h
  // Opaque handle for a VCHI instance
  VCHI_INSTANCE_T = pointer;
// ============== /opt/vc/include/bcm_host.h ==================================
var //These ones have to be loaded from libbcm_host.so:
bcm_host_init: procedure; extdecl = nil;
bcm_host_deinit: procedure; extdecl = nil;
graphics_get_display_size: function(
     display_number: uint16_t; width, height: puint32_t):int32_t; extdecl = nil;
// ============== /opt/vc/include/vcms_host/vc_dispmanx.h =================
  vc_dispmanx_stop: procedure;  extdecl = nil;
  vc_dispmanx_rect_set: function(
                     rect: pVC_RECT_T; x_offset, y_offset, width, height: dword
                                                        ): cint;  extdecl = nil;
  vc_dispmanx_resource_create: function( _type: VC_IMAGE_TYPE_T;
                              width, height: dword; native_image_handle: pdword
                                   ): DISPMANX_RESOURCE_HANDLE_T; extdecl = nil;
  vc_dispmanx_resource_delete: function(
                          res: DISPMANX_RESOURCE_HANDLE_T): cint; extdecl = nil;
  vc_dispmanx_display_open: function(
                      device: dword ): DISPMANX_DISPLAY_HANDLE_T; extdecl = nil;
  vc_dispmanx_display_open_mode: function(
              device, mode: uint32_t): DISPMANX_DISPLAY_HANDLE_T; extdecl = nil;
  vc_dispmanx_display_open_offscreen: function(
             dest: DISPMANX_RESOURCE_HANDLE_T; orientation: DISPMANX_TRANSFORM_T
                                    ): DISPMANX_DISPLAY_HANDLE_T; extdecl = nil;
  vc_dispmanx_display_reconfigure: function(
       display: DISPMANX_DISPLAY_HANDLE_T; mode: uint32_t): cint; extdecl = nil;
  vc_dispmanx_display_set_destination: function (
     display: DISPMANX_DISPLAY_HANDLE_T; dest: DISPMANX_RESOURCE_HANDLE_T
                                                         ): cint; extdecl = nil;
  vc_dispmanx_display_set_background: function (
     update: DISPMANX_UPDATE_HANDLE_T;  display: DISPMANX_DISPLAY_HANDLE_T;
                               red, green, blue: uint8_t ): cint; extdecl = nil;
  vc_dispmanx_display_get_info: function(
                 display: DISPMANX_DISPLAY_HANDLE_T; pinfo: pDISPMANX_MODEINFO_T
                                                         ): cint; extdecl = nil;
  vc_dispmanx_display_close: function(
                     display: DISPMANX_DISPLAY_HANDLE_T  ): cint; extdecl = nil;
  vc_dispmanx_update_start: function (
                   priority: int32_t ): DISPMANX_UPDATE_HANDLE_T; extdecl = nil;
  vc_dispmanx_element_add: function (
          update: DISPMANX_UPDATE_HANDLE_T;  display: DISPMANX_DISPLAY_HANDLE_T;
         layer: int32_t; dest_rect: pVC_RECT_T; src: DISPMANX_RESOURCE_HANDLE_T;
                        src_rect: pVC_RECT_T; protection: DISPMANX_PROTECTION_T;
                          alpha: pVC_DISPMANX_ALPHA_T; clamp: pDISPMANX_CLAMP_T;
                                                transform: DISPMANX_TRANSFORM_T
                                    ): DISPMANX_ELEMENT_HANDLE_T; extdecl = nil;
  vc_dispmanx_element_change_source: function(
           update: DISPMANX_UPDATE_HANDLE_T; element: DISPMANX_ELEMENT_HANDLE_T;
                         src: DISPMANX_RESOURCE_HANDLE_T ): cint; extdecl = nil;
  vc_dispmanx_element_change_layer: function (
           update: DISPMANX_UPDATE_HANDLE_T; element: DISPMANX_ELEMENT_HANDLE_T;
                                           layer: int32_t): cint; extdecl = nil;
  vc_dispmanx_element_modified: function(
           update: DISPMANX_UPDATE_HANDLE_T; element: DISPMANX_ELEMENT_HANDLE_T;
                                         rect: pVC_RECT_T): cint; extdecl = nil;
  vc_dispmanx_element_remove: function(
            update: DISPMANX_UPDATE_HANDLE_T; element: DISPMANX_ELEMENT_HANDLE_T
                                                         ): cint; extdecl = nil;
  vc_dispmanx_update_submit: function(
            update: DISPMANX_UPDATE_HANDLE_T; cb_func: DISPMANX_CALLBACK_FUNC_T;
                                          cb_arg: pointer): cint; extdecl = nil;
  vc_dispmanx_update_submit_sync: function(
                        update: DISPMANX_UPDATE_HANDLE_T ): cint; extdecl = nil;
  vc_dispmanx_query_image_formats: function (
                            supported_formats: puint32_t ): cint; extdecl = nil;
  vc_dispmanx_element_change_attributes: function(
                                             update: DISPMANX_UPDATE_HANDLE_T;
                                             element: DISPMANX_ELEMENT_HANDLE_T;
                                             change_flags: uint32_t;
                                             layer: int32_t;
                                             opacity: uint8_t;
                                             dest_rect,
                                             src_rect: pVC_RECT_T;
                                             mask: DISPMANX_RESOURCE_HANDLE_T;
                                             transform: DISPMANX_TRANSFORM_T
                                                         ): cint; extdecl = nil;
  vc_vchi_dispmanx_init: procedure (
         initialise_instance: VCHI_INSTANCE_T; connections: ppointer;//ppVCHI_CONNECTION_T;
                                    num_connections: uint32_t );  extdecl = nil;
type
  TBroadcomHack = class
  protected
    f_nativewindow: EGL_DISPMANX_WINDOW_T;
    dx_dispman_element: DISPMANX_ELEMENT_HANDLE_T;
    dx_display_handle: DISPMANX_DISPLAY_HANDLE_T;
    dx_dispman_update: DISPMANX_UPDATE_HANDLE_T;
    dst_rect, src_rect: VC_RECT_T ;
    myrect: TWindowManagerRect;
    success, display_number, f_vmajo, f_vmino: int32_t;
    f_has_surface, f_has_host: boolean;
    mode_info: DISPMANX_MODEINFO_T;
    function DisplayTransformToStr(t: DISPMANX_TRANSFORM_T): UnicodeString;
    function DisplayFormatToStr(f: DISPLAY_INPUT_FORMAT_T): UnicodeString;
  public
    constructor Create;
    destructor Destroy; override;
    procedure InitEGL(
                             var eDisplay: EGLDisplay; var eConfig: EGLConfig;
                             var eSurface: EGLSurface; var eContext: EGLContext;
                             var assumedpfd: TAssumedPFD
    );
    procedure UpdateWindowPosition;
    function Active: boolean;
  end;
var
  BroadcomHack: TBroadcomHack = nil;
{$endif}


Код: Выделить всё
{$if not defined(cpuarm)}
  {$fatal Yer moron, d00d}
{$endif}

{$ifdef cgekernel}
const
  libbcm = 'libbcm_host.so';

  function LoadBroadcomLibrary: boolean;
  var
   name: TFileNameString;
  begin
    if '' <> v_glinit_egldir then SetCurrentDir(v_glinit_egldir);
    try
     name:= v_glinit_egldir + libbcm;
     if Mother^.Debug.Verbose then AddLog('  Loading %0...', [name]);
     LibBroadcom := dlopen(PAnsiChar(WideToAnsi(FileNameToUnicode(name))), RTLD_NOW);
     Result:= Assigned(LibBroadcom);
     if result then begin
       LibBroadcomName:= GetDLLFileName(LibBroadcom);
       //raspbian surprise
       if LibBroadcomName = '' then LibBroadcomName:= name;
     end;
      if Mother^.Debug.Verbose then
        if not result then AddLogComment('FAILED.' + LoadLibraryErrorText())
                      else AddLogComment('Ok, %0', [LibBroadcomName]);
    finally
      SetCurrentDir(v_glinit_curdir);
    end;
  end;


  function GetBroadcomProcAddress(ProcName: ansistring): Pointer;
  var
    baseaddr: pointer;
    exename: TFileNameString;
  begin
    Result:=dlsym(LibBroadcom, PAnsiChar(ProcName));
    if Mother^.Debug.Verbose then begin
      if Assigned(Result) then begin
        exename:= GetExeFileName(Result);
        if (LibBroadcomName <> exename) and (LibBroadcomName <> '')
          then AddLog('    %0() at %1 in %2 (wrapper %3)', [ProcName, Result, exename, LibBroadcomName])
          else AddLog('    %0() at %1 in %2', [ProcName, Result, exename]);
      end else begin
        AddLog('    %0() NOT FOUND in %1', [ProcName, LibBroadcomName]);
        //Die(MI_ERROR_GL_FUNCTION_NOT_FOUND, [ProcName, '' + LibBroadcomName, '']);
      end;
    end;
  end;

  constructor TBroadcomHack.Create;
  begin
    inherited;

    pointer(eglCreateGlobalImageBRCM):= GetEGLProcAddress('eglCreateGlobalImageBRCM');
    if not Assigned(pointer(eglCreateGlobalImageBRCM)) then Exit;

    Mother^.State.RaspberryPiDetected:= true;
    if Mother^.Debug.Verbose then AddLog('  Raspberry Pi detected! Loading the rest of Broadcom extensions...');

    if not LoadBroadcomLibrary() then Die(MI_ERROR_OPENGLDLLNOTFOUND,  [libbcm]);

    pointer(bcm_host_init):= GetBroadcomProcAddress('bcm_host_init');
    pointer(bcm_host_deinit):= GetBroadcomProcAddress('bcm_host_deinit');
    pointer(graphics_get_display_size):= GetBroadcomProcAddress('graphics_get_display_size');
    //pointer(vc_dispman_init):= GetBroadcomProcAddress('vc_dispman_init');
    pointer(vc_dispmanx_stop):= GetBroadcomProcAddress('vc_dispmanx_stop');
    pointer(vc_dispmanx_rect_set):= GetBroadcomProcAddress('vc_dispmanx_rect_set');
    pointer(vc_dispmanx_resource_create):= GetBroadcomProcAddress('vc_dispmanx_resource_create');
    pointer(vc_dispmanx_resource_delete):= GetBroadcomProcAddress('vc_dispmanx_resource_delete');
    pointer(vc_dispmanx_display_open):= GetBroadcomProcAddress('vc_dispmanx_display_open');
    pointer(vc_dispmanx_display_open_mode):= GetBroadcomProcAddress('vc_dispmanx_display_open_mode');
    pointer(vc_dispmanx_display_open_offscreen):= GetBroadcomProcAddress('vc_dispmanx_display_open_offscreen');
    pointer(vc_dispmanx_display_reconfigure):= GetBroadcomProcAddress('vc_dispmanx_display_reconfigure');
    pointer(vc_dispmanx_display_set_destination):= GetBroadcomProcAddress('vc_dispmanx_display_set_destination');
    pointer(vc_dispmanx_display_set_background):= GetBroadcomProcAddress('vc_dispmanx_display_set_background');
    pointer(vc_dispmanx_display_get_info):= GetBroadcomProcAddress('vc_dispmanx_display_get_info');
    pointer(vc_dispmanx_display_close):= GetBroadcomProcAddress('vc_dispmanx_display_close');
    pointer(vc_dispmanx_update_start):= GetBroadcomProcAddress('vc_dispmanx_update_start');
    pointer(vc_dispmanx_element_add):= GetBroadcomProcAddress('vc_dispmanx_element_add');
    pointer(vc_dispmanx_element_change_source):= GetBroadcomProcAddress('vc_dispmanx_element_change_source');
    pointer(vc_dispmanx_element_change_layer):= GetBroadcomProcAddress('vc_dispmanx_element_change_layer');
    pointer(vc_dispmanx_element_modified):= GetBroadcomProcAddress('vc_dispmanx_element_modified');
    pointer(vc_dispmanx_element_remove):= GetBroadcomProcAddress('vc_dispmanx_element_remove');
    pointer(vc_dispmanx_update_submit):= GetBroadcomProcAddress('vc_dispmanx_update_submit');
    pointer(vc_dispmanx_update_submit_sync):= GetBroadcomProcAddress('vc_dispmanx_update_submit_sync');
    pointer(vc_dispmanx_query_image_formats):= GetBroadcomProcAddress('vc_dispmanx_query_image_formats');
    pointer(vc_dispmanx_element_change_attributes):= GetBroadcomProcAddress('vc_dispmanx_element_change_attributes');
    pointer(vc_vchi_dispmanx_init):= GetBroadcomProcAddress('vc_vchi_dispmanx_init');

    //pointer(eglCreateCopyGlobalImageBRCM):= GetEGLProcAddress('eglCreateCopyGlobalImageBRCM ');
    pointer(eglDestroyGlobalImageBRCM ):= GetEGLProcAddress('eglDestroyGlobalImageBRCM');
    pointer(eglQueryGlobalImageBRCM):= GetEGLProcAddress('eglQueryGlobalImageBRCM');
    //pointer(eglInitPerfMonitorBRCM):= GetEGLProcAddress('eglInitPerfMonitorBRCM');
    //pointer(eglTermPerfMonitorBRCM):= GetEGLProcAddress('eglTermPerfMonitorBRCM');
    pointer(eglInitDriverMonitorBRCM ):= GetEGLProcAddress('eglInitDriverMonitorBRCM');
    pointer(eglGetDriverMonitorXMLBRCM ):= GetEGLProcAddress('eglGetDriverMonitorXMLBRCM');
    pointer(eglTermDriverMonitorBRCM ):= GetEGLProcAddress('eglTermDriverMonitorBRCM');
    //pointer(eglPerfStatsResetBRCM):= GetEGLProcAddress('eglPerfStatsResetBRCM');
    //pointer(eglPerfStatsGetBRCM ):= GetEGLProcAddress('eglPerfStatsGetBRCM');
    pointer(eglProcStateValid):= GetEGLProcAddress('eglProcStateValid');
    pointer(eglFlushBRCM ):= GetEGLProcAddress('eglFlushBRCM');
    //pointer(eglProcessMemUsageGetBRCM):= GetEGLProcAddress('eglProcessMemUsageGetBRCM');
    //pointer(eglDirectRenderingPointer):= GetEGLProcAddress('eglDirectRenderingPointer');

    display_number:= 0; // I do not understand it well but I think you have to
      //provide a differtent number to work with the composite output.
      //I can't find a suitable 3-contact jack anywhere so can't test this.
      //Frustrating because I *do* have a portable b/w CRT TV :(

    success:= 1;

  end;

  destructor TBroadcomHack.Destroy;
  begin
    if f_has_surface then begin
      (*
      dispman_update = vc_dispmanx_update_start( 0 );
            s = vc_dispmanx_element_remove(dispman_update, state->dispman_element);
            assert(s == 0);
            vc_dispmanx_update_submit_sync( dispman_update );
            s = vc_dispmanx_display_close(state->dispman_display);
            assert (s == 0);

            // Release OpenGL resources
            eglMakeCurrent( state->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
            eglDestroyContext( state->display, state->context );
            eglTerminate( state->display );
      *)
    end;


    if f_has_host then begin
      if 0 <> dx_display_handle
        then vc_dispmanx_display_close(dx_display_handle);
      bcm_host_deinit();
    end;
    inherited;
  end;

  procedure TBroadcomHack.InitEGL(var eDisplay: EGLDisplay;
    var eConfig: EGLConfig;  var eSurface: EGLSurface; var eContext: EGLContext;
    var assumedpfd: TAssumedPFD);
  var
    hr: integer;
    num_config: EGLint;
    Attr: array[0..10] of EGLint = (
      EGL_RED_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_BLUE_SIZE, 8,
      EGL_ALPHA_SIZE, 8,
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_NONE);
    CtxAttr:array[0..3] of EGLint = (
      EGL_CONTEXT_CLIENT_VERSION,2,
      EGL_NONE,
      EGL_NONE);
  begin
    try
      if Mother^.Debug.Verbose then AddLog('    ..Raspberry Pi detected, creating a Broadcom specific surface...');

      bcm_host_init();

      dx_display_handle:= vc_dispmanx_display_open(display_number);
        if 0 = dx_display_handle then Die('vc_dispmanx_display_open() returned zero');

      f_has_host:= true;

      hr:= vc_dispmanx_display_get_info(dx_display_handle, @mode_info);
        if hr < 0 then Die('vc_dispmanx_display_get_info() failed');

      if Mother^.Debug.Verbose then AddLog('    ..display #%0 %1x%2, %3%4',
         [display_number, mode_info.width, mode_info.height,
         DisplayFormatToStr(mode_info.input_format),
         DisplayTransformToStr(mode_info.transform)]
      );

      myrect.left:= min(mode_info.width - 255, (max(0, Mother^.Display.WindowClientRect.left)));
      myrect.top:= min(mode_info.height - 255, (max(0, Mother^.Display.WindowClientRect.top)));
      myrect.width:= max(256, min(mode_info.width - myrect.left, Mother^.Display.WindowClientRect.width));
      myrect.height:= max(256, min(mode_info.height - myrect.top, Mother^.Display.WindowClientRect.height));
        if Mother^.Debug.Verbose then AddLog('    ..Surface rect calculated as %0',[RectToStr(myrect)]);

      dst_rect.x:= myrect.left;
      dst_rect.y:= mode_info.height - myrect.top;
      dst_rect.width:= myrect.width;
      dst_rect.height:= myrect.height;

      src_rect.x:= 0;
      src_rect.y:= 0;
      src_rect.width:= myrect.width shl 16;
      src_rect.height:= myrect.height shl 16;

      dx_dispman_update:= vc_dispmanx_update_start( 0 );

      dx_dispman_element:= vc_dispmanx_element_add (
          dx_dispman_update, dx_display_handle,
          0{layer}, @dst_rect, 0{src}, @src_rect,
          DISPMANX_PROTECTION_NONE, nil{alpha}, nil{clamp}, 0{transform}
      );

      f_nativewindow.element:= dx_dispman_element;
      f_nativewindow.width:= myrect.width;
      f_nativewindow.height:= myrect.height;

      vc_dispmanx_update_submit_sync( dx_dispman_update );

      f_has_surface:= true;


      // get an EGL display connection
      eDisplay:= eglGetDisplay(EGL_DEFAULT_DISPLAY);
      if eDisplay = EGL_NO_DISPLAY
        then Die('eglGetDisplay() returned EGL_NO_DISPLAY');
      if Mother^.Debug.Verbose
        then AddLog('  ..display %0',[eDisplay]);

      // initialize the EGL display connection
      if 0 = eglInitialize( eDisplay, @f_vmajo, @f_vmino )
        then Die('eglInitialize() failed: ' + EGlErrorCodeToString(eglGetError()));
        if Mother^.Debug.Verbose
          then AddLog('  ..EGL version %0.%1',[f_vmajo, f_vmino]);

      // get an appropriate EGL frame buffer configuration
      if 0 = eglGetConfigs(eDisplay, nil, 0, @num_config)
        then Die('eglGetConfigs() faled');
      if Mother^.Debug.Verbose
        then AddLog('  ..#EGL configs %0',[num_config]);
      hr:= eglChooseConfig(eDisplay, @Attr[0], @eConfig, 1, @num_config);
      if (EGL_FALSE = hr) or (num_config <> 1)
        then Die('eglChooseConfig() faled');

      assumedpfd.r:= Attr[1];
      assumedpfd.g:= Attr[3];
      assumedpfd.b:= Attr[5];
      assumedpfd.a:= Attr[7];
      assumedpfd.depth:= 0;
      assumedpfd.rect:= myrect;

      // create an EGL rendering context
      eContext:= eglCreateContext(eDisplay, eConfig, EGL_NO_CONTEXT, @CtxAttr[0]);
      if eContext = EGL_NO_CONTEXT
        then Die('eglCreateContext() returned EGL_NO_CONTEXT');
        CheckEGlError();
        if Mother^.Debug.Verbose then AddLog('    ..context %0',[eContext]);

      // create an EGL window surface
      eSurface:= eglCreateWindowSurface(eDisplay, eConfig,
        ptruint(@f_nativewindow), //Dirty! native window type boils to TXID,
        //but that's just a fance name for ptruint (see culong)
        //So yes, X handles are opaque pointers too.
        nil);
        if eSurface = EGL_NO_SURFACE then Die(MI_ERROR_CANTINITOPENGL,['eglCreateWindowSurface() returned EGL_NO_SURFACE']);
        CheckEGlError();
        if Mother^.Debug.Verbose then AddLog('    ..surface %0',[eSurface]);


      if 0 = eglGetConfigs(eDisplay, nil, 0, @num_config)
        then Die(EGlErrorCodeToString(eglGetError()));


    except
      Die(RuEn(
        'Не удалось поставить VideoCore костыль для специфичной EGL от Broadcom',
        'Failed to start the VideoCore hack for the peculiar Broadcom EGL'
      ));
    end;
  end;

  procedure TBroadcomHack.UpdateWindowPosition;
  begin

  end;

  function TBroadcomHack.Active: boolean;
  begin
    Result:= success > 0;
  end;

  function TBroadcomHack.DisplayFormatToStr(f: DISPLAY_INPUT_FORMAT_T): UnicodeString;
  begin
    case f of
      DISPLAY_INPUT_FORMAT_RGB888: Result:= RuEn(
        '24 бита (r8g8b8)',
        '24 bits (r8g8b8)');
      DISPLAY_INPUT_FORMAT_RGB565: Result:= RuEn(
        '16 бит (r5g6b5)',
        '16 bits (r5g6b5)');
    else
      Result:= PervertedFormat(RuEn(
        '(неизвестный формат %0h)',
        '(unknown format %0h)'
        ),[IntToHex(f, 2)]);
    end;
  end;

  function TBroadcomHack.DisplayTransformToStr(t: DISPMANX_TRANSFORM_T): UnicodeString;
  begin
    case t and $ffff of
      DISPMANX_NO_ROTATE: Result:= RuEn(
        ', без поворота',
        ', no rotation');
      DISPMANX_ROTATE_90: Result:= RuEn(
        ', повёрнут на 90°',
        ', rotated 90°');
      DISPMANX_ROTATE_180: Result:= RuEn(
        ', повёрнут на 180°',
        ', rotated 180°');
      DISPMANX_ROTATE_270: Result:= RuEn(
        ', повёрнут на 270°',
        ', rotated 270°');
    end;

    if t and DISPMANX_FLIP_HRIZ > 0
      then Result+= RuEn(
        ', перевёрнут по горизонтали',
        ', flipped horizontally');

    if t and DISPMANX_FLIP_VERT > 0
      then Result+= RuEn(
        ', перевёрнут по вертикали',
        ', flipped vertically');
  end;


{$endif cgekernel}

Аватара пользователя
Cheb
энтузиаст
 
Сообщения: 508
Зарегистрирован: 06.06.2005 15:54:34

Re: Cheb's Game Engine

Сообщение runewalsh » 19.04.2017 03:51:43

>uint8_t
Я сам офигел, когда узнал, но в System уже определены все возможные (p)(u)intЦИФРА.
Аватара пользователя
runewalsh
постоялец
 
Сообщения: 303
Зарегистрирован: 27.04.2010 00:15:25

Re: Cheb's Game Engine

Сообщение Cheb » 20.04.2017 11:38:34

уже определены

Фигасе :shock: Буду знать.

По любому, дошёл до того, что создаётся белый квадрат Малевича (тот самый аппаратный сурфейс поверх всех окон) иии... программа бесславно падает на ровном месте, пытаясь записать флоат в конфиг. Какого?.. :evil:

С обработкой исключений на малине что-то нечисто, или короткие строки глючат, но я получаю в итоге пустые строки вместо Message и ClassName исключения :evil:
Надо проверить эту байду на обычной бубунте, не обращал внимания с тех пор, как перелопатил обработку исключений, а под виндой всё пучком.
Аватара пользователя
Cheb
энтузиаст
 
Сообщения: 508
Зарегистрирован: 06.06.2005 15:54:34

Re: Cheb's Game Engine

Сообщение Cheb » 21.04.2017 22:46:16

З.Ы. Очень интересный случай. Только на платформе ARM, после загрузки и инициализации GLES, работа с плавающей запятой съезжает с глузды, первое же деление бомбит приложение насмерть.

Курил исходники SafeLoadLibrary(), но там только для i386/x86_64

Добавлено спустя 13 минут 31 секунду:
З.Ы. Теперь вааще ничего не понимаю.
Это *точно* не проблема с невалидным указателем.
Это *точно* не проблема с делением как таковым.
Код: Выделить всё
          then with Mother^.Display.WindowRect do try
addlog('>>-------------');
addlog(' %0',[300 / 500]);
addlog(' %0', [RectToStr(Mother^.Display.WindowRect)]);
addlog(' %0, %1', [width, height]);
addlog(' %0', [RectToStr(Mother^.Display.ScreenRect)]);
addlog(' %0, %1', [Mother^.Display.ScreenRect.width, Mother^.Display.ScreenRect.height]);
addlog(' %0',[width / Mother^.Display.ScreenRect.Width]);
addlog(floattostr(1.0 * width / 1.0 * Mother^.Display.ScreenRect.Width));
            Config.Str['video','window_width']:= floattostr(1.0 * width / Mother^.Display.ScreenRect.Width);
//            Config.Float['video', 'window_height']:= height / Mother^.Display.ScreenRect.height;
//            Config.Float['video', 'window_left']:= (left - Mother^.Display.ScreenRect.left) / Mother^.Display.ScreenRect.width;
//            Config.Float['video', 'window_top']:= (top - Mother^.Display.ScreenRect.top) / Mother^.Display.ScreenRect.height;
addlog('<<');
          except

даёт
Код: Выделить всё
[frame #2, 19:03:38.174, Fri, 21.04.2017]
>>-------------
0.6
1152x648(556,405)
1152, 648
1920x1080(0,0)
1920, 1080
<----=* ERROR! ---- (look below for details) *=---->
<----=* ERROR! ---- (look below for details) *=---->
There were unprocessed error messages left:
!!..
Program crashed with an uncaught exception.
EAccessViolation: Access violation
  :773 in chentrah-armv7l
:
  framework_basic.pp:637 (tbasicframework.checkwindowsize)  in chentrah-armv7l
Call stack:
  framework_basic.pp:590 (tbasicframework.checkwindowsize)  in chentrah-armv7l


Добавлено спустя 17 часов 7 минут 38 секунд:
Ну конеееечно. Мои операнды были невыровненными, а GLES при инициализации каким-то образом выставила "бомбить на невыровненных флоатах".

Исправил главный заголовочный файл, поставив костыли {$ifdef cpuarm}{$packrecords 4}{$endif} и {$ifndef cpuarm}packed{$endif} record.
Нет, я ещё могу понять SIMD на x86, но обычные single?.. :(

Это такой же нежданчик как вчера мастер нам сифон ванны менял. Хотели заодно поменять трубу, до того места, где слив от раковины входит - а вот хрен! Порожек под раковиной, с трубами внутре, оказался цельнобетонным, с прочностью как у хорошего бункера. Только плитку зря покоцали :evil:
Аватара пользователя
Cheb
энтузиаст
 
Сообщения: 508
Зарегистрирован: 06.06.2005 15:54:34

Пред.

Вернуться в Разработки на нашем сайте

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2

Рейтинг@Mail.ru