From: huiyu,eun Date: Thu, 31 Aug 2017 06:12:27 +0000 (+0900) Subject: [SDL/OpenGL ES] Add 4.0 new features guide X-Git-Tag: GitHub/PR#40/tizen-studio~40^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2cd6712b2508976758e48bcc5235dbc451bcbac6;p=sdk%2Fonline-doc.git [SDL/OpenGL ES] Add 4.0 new features guide - Refer [ACR-937]Add opengl es APIs and [ACR-1017]Add new SDL APIs - SDL with OpenGL ES is supported in both mobile applications and wearable applications in Tizen 4.0. - SDL with Vulkan is supported in mobile applications in Tizen 3.0. PS3: Reviewed PS4: Query answers implemented, a few typos and link issues fixed Change-Id: I7e94039a6a7c968791cd56fbb0beddfff0cf1e8b Signed-off-by: huiyu,eun --- diff --git a/org.tizen.guides/html/images/sdl_in_tizen.png b/org.tizen.guides/html/images/sdl_in_tizen.png new file mode 100755 index 0000000..7798a7c Binary files /dev/null and b/org.tizen.guides/html/images/sdl_in_tizen.png differ diff --git a/org.tizen.guides/html/images/sdl_opengles.png b/org.tizen.guides/html/images/sdl_opengles.png new file mode 100755 index 0000000..f324d7a Binary files /dev/null and b/org.tizen.guides/html/images/sdl_opengles.png differ diff --git a/org.tizen.guides/html/images/sdl_statemodel.png b/org.tizen.guides/html/images/sdl_statemodel.png index 0af6b30..0a17195 100755 Binary files a/org.tizen.guides/html/images/sdl_statemodel.png and b/org.tizen.guides/html/images/sdl_statemodel.png differ diff --git a/org.tizen.guides/html/images/vulkan_framework.png b/org.tizen.guides/html/images/vulkan_framework.png index 8045554..6065468 100755 Binary files a/org.tizen.guides/html/images/vulkan_framework.png and b/org.tizen.guides/html/images/vulkan_framework.png differ diff --git a/org.tizen.guides/html/index.htm b/org.tizen.guides/html/index.htm index 7ec898f..b81612e 100644 --- a/org.tizen.guides/html/index.htm +++ b/org.tizen.guides/html/index.htm @@ -350,7 +350,12 @@
  • Advanced Performance
  • -
  • SDL Graphics with Vulkan®
  • +
  • Simple DirectMedia Layer (SDL) + +
  • Notifications and Content Sharing diff --git a/org.tizen.guides/html/native/device/system_n.htm b/org.tizen.guides/html/native/device/system_n.htm index 32f36d5..4829232 100644 --- a/org.tizen.guides/html/native/device/system_n.htm +++ b/org.tizen.guides/html/native/device/system_n.htm @@ -945,6 +945,16 @@ the Tizen reference implementation. bool The platform returns true for this key and the http://tizen.org/feature/opengles key, if the device supports the OpenGL® ES version 3.0. + + http://tizen.org/feature/opengles.version.3_1 + bool + The platform returns true for this key and the http://tizen.org/feature/opengles key, if the device supports the OpenGL® ES version 3.1. + + + http://tizen.org/feature/opengles.version.3_2 + bool + The platform returns true for this key and the http://tizen.org/feature/opengles key, if the device supports the OpenGL® ES version 3.2. +

    The following table lists the platform feature keys.

    diff --git a/org.tizen.guides/html/native/graphics/graphics_cover_n.htm b/org.tizen.guides/html/native/graphics/graphics_cover_n.htm index a790508..ae63725 100644 --- a/org.tizen.guides/html/native/graphics/graphics_cover_n.htm +++ b/org.tizen.guides/html/native/graphics/graphics_cover_n.htm @@ -57,8 +57,8 @@

    You can create OpenGL® ES applications in Tizen with the EGL™ layer. Tizen native applications can use OpenGL® ES not only for creating a 3D scene but also for a 2D scene that requires fast interaction. OpenGL® ES is also good for improving performance and reducing power consumption when the native application performs computation-intensive tasks that can be run in parallel.

  • -
  • SDL Graphics with Vulkan® -

    You can get high-efficiency access to graphics and computing on modern GPUs with Vulkan®. You can use cutting-edge 3D programming tools to create high-quality games and real-time graphics in your applications.

  • +
  • Simple DirectMedia Layer (SDL) +

    Simple DirectMedia Layer (SDL) is a cross-platform development library designed to provide a low-level hardware abstraction layer to computer multimedia hardware components. You can get high-efficiency access to graphics and computing on modern GPUs with Vulkan® or OpenGL® ES. You can use cutting-edge 3D programming tools to create high-quality games and real-time graphics in your applications.

  • diff --git a/org.tizen.guides/html/native/graphics/sdl_n.htm b/org.tizen.guides/html/native/graphics/sdl_n.htm new file mode 100644 index 0000000..cf83310 --- /dev/null +++ b/org.tizen.guides/html/native/graphics/sdl_n.htm @@ -0,0 +1,455 @@ + + + + + + + + + + + + + + Simple DirectMedia Layer (SDL) + + + +
    +
    +

    Mobile native Wearable native

    +
    + + +
    + +
    + +

    Simple DirectMedia Layer (SDL)

    + +

    You can access graphics hardware using Vulkan® and OpenGL® ES through the Simple DirectMedia Layer (SDL), a cross-platform software development library. SDL is used for creating high-performance computer games, multimedia applications, and emulators. It provides a low-level hardware abstraction layer to computer multimedia hardware components. It can run on many operating systems, such as Android™, iOS, Linux, macOS, Windows®, and Tizen. For more information, see the SDL Web site.

    + +

    The main features of the SDL API include:

    + + +

    SDL belongs to the hardware abstraction layer in Tizen. It allows managing video, audio, input devices, threads, and 3D graphics through graphics libraries, such as Vulkan® and OpenGL® ES. For information the comparative merits of Vulkan® and OpenGL®, see Vulkan® vs. OpenGL®. As shown in the following figure, SDL provides the application layer access to low-level 3D rendering API (Vulkan® and OpenGL® ES).

    + +

    Figure: SDL in the Tizen framework

    +

    SDL in the Tizen framework

    + +

    The following SDL features are currently supported in Tizen:

    +
      +
    • SDL basic functions +

      Use the SDL.h, SDL_hints.h, SDL_error.h, SDL_log.h, SDL_assert.h, SDL_version.h, SDL_error.h, and SDL_stdinc.h header files.

    • +
    • Display and window management +

      Use the SDL_video.h and SDL_syswm.h header files.

    • +
    • Event handling +

      Use the SDL_events.h and SDL_keyboard.h header files.

    • +
    • Audio device management +

      Use the SDL_audio.h header file.

    • +
    • Thread and timer management +

      Use the SDL_thread.h, SDL_mutex.h, SDL_atomic.h, and SDL_timer.h header files.

    • +
    • Platform and power information +

      Use the SDL_platform.h and SDL_power.h header files.

    • +
    + +

    For the list of features not currently supported in Tizen, see the SDL API (in mobile and wearable applications). In Tizen, SDL supports the Vulkan and OpenGL® ES graphics libraries only; the SDL_render library is not supported.

    + +
    + Note + The following SDL header files related to the SDL_render library are not included in the Tizen native API: +
      +
    • SDL_render.h
    • +
    • SDL_pixels.h
    • +
    • SDL_rect.h
    • +
    • SDL_surface.h
    • +
    +
    + + +

    Vulkan® vs. OpenGL®

    + +

    When you consider the differences and advantages between Vulkan® and OpenGL®, Vulkan® basically complements OpenGL® by addressing specific users who want to have a quite low-level API with a much better abstraction of the modern hardware giving a lot of control, predictability, and high performance at much greater efficiency. On the other hand, OpenGL® is a much higher-level API that does many things on your behalf inside the driver with less burden on you. It continues to be the API of choice for a wide range of developers who want to have the shortest path to a functionally correct application.

    + +

    When selecting the open graphics API (Vulkan® or OpenGL®) to use for a new application, or when considering the need to migrate an existing application from OpenGL® to Vulkan®, ask yourself the following questions:

    +
      +
    • Do you want to have really low-level access and explicit control over the underlying GPU?
    • +
    • Is your application/driver CPU-bound, too slow, and consuming too much power?
    • +
    • Can your graphic work creation be parallelized and reused?
    • +
    • Can you deal with additional code complexity to squeeze out maximum performance?
    • +
    +

    If your answer to any of the questions is Yes, consider using Vulkan® instead of OpenGL®. However, remember that Vulkan® comes at the cost of taking more responsibility at the application side from the driver.

    + +

    The following table describes the differences and advantages between Vulkan® and OpenGL®.

    + +

    Table: Comparison between Vulkan® and OpenGL®

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Vulkan®OpenGL®
    GPU controlExplicit API allows you to manage the state and resources as per specific application needs, and relieves you from hidden optimizations giving more control on the GPU.Implicit driver manages the state and resources based on heuristics, leading to overhead and inefficiencies. The application has no control.
    Multi-core friendlinessAPI is designed around asynchronous generation of command buffers across multiple threads and feeds them in sequence to a command pipeline, which reflects the realities of the modern hardware.Originally designed for single-threaded architectures and does not allow the generation of graphic commands in parallel to command execution.
    EfficiencyVulkan® greatly reduces the CPU time spent in the driver with external validation and diagnostics layers that can be independently enabled and disabled, as needed. Offloads the render thread by delegating heavy CPU jobs to the application and opt-in layers.Does a lot of redundant excessive validation for each draw call, such as runtime error checking, implicit tracking of resource usage, and synchronization, leading to much CPU overhead.
    Shader portabilityVulkan® mandates the use of the intermediate byte code (SPIR-V) by the driver for shaders. This allows offline shader precompilation, and allows you to write shaders in languages other than GLSL.Only GLSL is supported as a shader language, and the compiler is a part of the driver with vendor-specific semantics. No user control over the front end and higher runtime translation time.
    Code complexityVulkan® is a much more verbose API, offering more control at the cost of more code complexity and responsibility at the application side.OpenGL® driver manages many tasks inside the driver relieving you from the burden of managing these at the application end.
    + + +

    SDL Application Life-cycle in Tizen

    + +

    The Tizen native application model is responsible for the application life-cycle and system events. The SDL application life-cycle is handled by the SDL_PollEvent() function, which manages the main event loop, the application state change events, and basic system events (general and Tizen-specific).

    + +

    Figure: SDL application life-cycle

    +

    SDL application life-cycle

    + +

    The SDL application can be in one of several different states, and the state changes are managed by the underlying framework.

    + +

    Table: SDL application states

    + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    StateDescription
    READYApplication starts the main loop.
    CREATEDApplication is launched.
    RUNNINGApplication is running and visible to the user.
    PAUSEDApplication is running but invisible to the user.
    TERMINATEDApplication is terminated.
    + +

    Typically, the application is launched by the user from the Launcher, or by another application. The application is normally launched as the top window, with focus. When the application loses the focus status, the SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND events are invoked. The application can go into the pause state, which means that it is not terminated but continues to run in the background. The pause state can happen when:

    +
      +
    • A new application is launched by the request of your application.
    • +
    • The user requests to go to the home screen.
    • +
    • A system event (such as an incoming phone call) occurs and causes a resident application with a higher priority to become active and temporarily hide your application.
    • +
    • An alarm is triggered for another application, which becomes the topmost window and hides your application.
    • +
    + +

    When the application becomes visible again, the SDL_APP_WILLENTERFOREGROUND and SDL_APP_DIDENTERFOREGROUND events are invoked. The visibility returns, when:

    +
      +
    • Another application requests your application to run (such as the Task Navigator, which shows all running applications and lets user select any application to run).
    • +
    • All applications on top of your application in the window stack finish.
    • +
    • An alarm is triggered for your application, bringing it to the front and hiding other applications.
    • +
    + +

    When the application starts exiting, the SDL_QUIT and SDL_TERMINATING events are invoked. Your application can start the termination process, when:

    +
      +
    • The application itself requests to exit by calling the ui_app_exit() or service_app_exit() function to terminate the event loop.
    • +
    • The low memory killer is terminating your application in a low memory situation.
    • +
    + +

    Prerequisites

    + +

    Before using graphics libraries in Tizen, make sure you understand the basic functions of OpenGL® ES and Vulkan®. For more information, see SDL Graphics with OpenGL® ES and SDL Graphics with Vulkan®.

    + + +

    Handling General SDL Events

    + +

    To handle general SDL events:

    + +
      +
    1. Call the SDL_PollEvent() function, which polls the currently pending events and returns the SDL_Event instance. Before calling the SDL_PollEvent() function, create an empty SDL_Event structure. +
      +void
      +updateApp(appdata_s* ad)
      +{
      +    /* SDL_Event is a union containing structures for different event types */
      +    SDL_Event event;
      +    while (SDL_PollEvent(&event)) {
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Event type: %x\n", event.type);
      +        handleEvent(&ad, &event);
      +    }
      +}
      +
      +
    2. +
    3. The SDL_PollEvent() function removes the next event from the event queue. If there is no event in the queue, it returns 0. If there is an event, it fills the SDL_Event object with the event information. +

      The SDL_Event object is a union that contains structures for the different event types. The type member specifies the event type, shared with all events. The type member is related to the SDL_EventType enumeration.

      +

      To handle each event type separately, use a switch statement:

      + +
      +void
      +handleEvent(appdata_s** data, SDL_Event* event)
      +{
      +    appdata_s* ad = *data;
      +
      +    switch (event->type) {
      +    case SDL_QUIT:
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Finish main loop ");
      +        ad->game_exit = 1;
      +        break;
      +    case SDL_KEYUP:
      +        char* scancodename = (char *)SDL_GetScancodeName(event->key.keysym.scancode);
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] keyboard scancode: %s", scancodename);
      +        if (event->key.keysym.scancode == SDL_SCANCODE_AC_BACK) {
      +            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Finish main loop ");
      +            ad->game_exit = 1;
      +        }
      +        break;
      +    case SDL_MOUSEBUTTONDOWN:
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL]Mouse Down: %d x %d", event->button.x, event->button.y);
      +        break;
      +    case SDL_MOUSEBUTTONUP:
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL]Mouse Up: %d x %d", event->button.x, event->button.y);
      +        break;
      +    case SDL_MOUSEMOTION:
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL]Mouse Motion: %d x %d", event->motion.x, event->motion.y);
      +        break;
      +    case SDL_ROTATEEVENT:
      +        ad->window_rotation = (int)event->user.data1;
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Rotation degree: %d", ad->window_rotation);
      +        break;
      +    case SDL_WINDOWEVENT:
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL_WINDOWEVENT Event!!");
      +        if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
      +            SDL_Log("SDL_WINDOWEVENT_SIZE_CHANGED!!!");
      +        break;
      +    } /* End switch */
      +}
      +
      +
    4. +
    + +

    Handling Tizen-specific SDL Events

    + +

    To handle SDL events specifically added to the Tizen application framework:

    + +
      +
    • SDL_APP_CONTROL +

      This event is invoked when the application is launched with some parameters.

      + +

      The application framework calls the application's control callback just after the application enters the main loop. This callback is passed to the app_control instance containing the reason why the application was launched. For example, the application can be launched to open a file to handle the request that has been sent by another application. In any case, the application is responsible for checking the app_control content and responding appropriately. The app_control content can be empty, if the application is launched from the launcher.

      +

      In SDL, SDL_APP_CONTROL has been defined as a new SDL_Event event type for the application control. After the application enters the main loop, SDL sends the SDL_APP_CONTROL event to the application. This means that the application can confirm the SDL_Event in the event loop. The event is defined as an SDL_UserEvent, which is in the user member of the SDL_Event union.

      + +

      The user structure contains data1 (app_control) and data2 (user_data).

      + +

      In Tizen, you must include the <app.h> header file to use the application control. For more information, see the Application Controls guide.

      +
      +#include <app.h>
      +
      +case SDL_APP_CONTROL:
      +    app_control_h app_control = event.user.data1;
      +    void *user_data = event.user.data2;
      +
      +    char *operation;
      +    char *uri;
      +
      +    app_control_get_operation(app_control, &operation);
      +    if (!strcmp(operation, APP_CONTROL_OPERATION_VIEW)) {
      +        app_control_get_uri(app_control, &uri);
      +        app_control_get_extra_data(app_control, "action", &action);
      +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Get path: [%s], action: [%s]", uri, action);
      +    }
      +    break;
      +
      +
    • +
    • SDL_APP_LOWBATTERY +

      This event is invoked when the application is low on battery. Use it to reduce power consumption, if possible. In Tizen, this event is called in the _tizen_app_low_battery() function.

      +

      Get the low battery status from the given event info by calling the app_event_get_low_battery_status() function. The app_event_low_battery_status_e (in mobile and wearable applications) is the enumeration for the battery status: APP_EVENT_LOW_BATTERY_POWER_OFF means that the battery charge is under 1% and APP_EVENT_LOW_BATTERY_CRITICAL_LOW under 5%.

      + +
      +#include <app.h>
      +
      +case SDL_APP_LOWBATTERY:
      +    SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] SDL_APP_LOWBATTERY ");
      +
      +    app_event_info_h event_info = event->user.data1;
      +    void *user_data = event->user.data2;
      +
      +    app_event_low_battery_status_e status;
      +    int ret = app_event_get_low_battery_status(event_info, &status);
      +    if (ret == APP_ERROR_NONE) {
      +        if (status == APP_EVENT_LOW_BATTERY_POWER_OFF)
      +            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] The battery status is under 1% ");
      +        else if (status == APP_EVENT_LOW_BATTERY_CRITICAL_LOW)
      +            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] The battery status is under 5% ");
      +    }
      +    break;
      +
      +
    • +
    • SDL_APP_LANGUAGE_CHANGED and SDL_APP_REGION_FORMAT_CHANGED +

      These events are invoked when the displayed language and region are changed by the system.

      +

      The user structure contains data1 (language or region data).

      +
      +/* Displayed language is changed by system */
      +case SDL_APP_LANGUAGE_CHANGED:
      +    SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] SDL_APP_LANGUAGE_CHANGED: %s", (char*)event->user.data1);
      +    break;
      +/* Displayed region is changed by system */
      +case SDL_APP_REGION_CHANGED:
      +    SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] SDL_APP_REGION_CHANGED: %s", (char*)event->user.data1);
      +    break;
      +
      +
    • +
    + +

    Handling Screen Orientation

    +

    Tizen supports portrait and landscape screen orientations. You must take care of how your application responds to screen orientation changes.

    +

    To set the supported screen orientations for the application, use the SDL_SetHint() function with the first parameter set to SDL_HINT_ORIENTATIONS, and the second parameter listing the supported screen orientations as a string.

    + +
    +SDL_SetHint(SDL_HINT_ORIENTATIONS, "Portrait LandscapeLeft LandscapeRight");
    +
    + +

    The following table lists the screen orientations supported in SDL.

    + +

    Table: Screen orientations in SDL

    + + + + + + + + + + + + + + + + + + + +
    OrientationDescription
    LandscapeLeftLandscape, with the top of the device facing left.
    LandscapeRightLandscape, with the top of the device facing right.
    PortraitPortrait, with the top of the device facing up.
    + +

    Showing the Status Bar in Mobile Applications

    + +

    Mobile devices have a status bar at the top of the screen. The status bar can contain icons for battery status or reception, or various notifications. Pulling the status bar down reveals the notification panel, which can display, for example, current downloads, new messages, or missed calls.

    +

    Since Tizen 4.0, you can manage the status bar appearance in SDL applications:

    +
      +
    • To show the status bar, use the SDL_SetWindowBordered() function with the second parameter set to SDL_TRUE: + +
      +SDL_SetWindowBordered(window, SDL_TRUE);
      +
      +
    • +
    • To set the opacity of the status bar, use the SDL_SetHint() function, with the first parameter set to SDL_HINT_TIZEN_INDICATOR_OPACITY and the second parameter containing the desired opacity value as a string: + +
      +SDL_SetHint(SDL_HINT_TIZEN_INDICATOR_OPACITY, "opaque");
      +
      + +

      The following table lists the available status bar opacity values.

      + +

      Table: Status bar opacity values

      + + + + + + + + + + + + + + + + + + + + + + + +
      Opacity valueDescription
      opaqueMakes the status bar opaque.
      translucentMakes the status bar translucent.
      transparentMakes the status bar transparent. This is the default value.
      bg_transparentMakes the status bar background transparent.
      +
    • +
    + + + +
    + +Go to top + + + + + + + diff --git a/org.tizen.guides/html/native/graphics/sdl_opengles_n.htm b/org.tizen.guides/html/native/graphics/sdl_opengles_n.htm new file mode 100644 index 0000000..800b8b9 --- /dev/null +++ b/org.tizen.guides/html/native/graphics/sdl_opengles_n.htm @@ -0,0 +1,397 @@ + + + + + + + + + + + + + + SDL Graphics with OpenGL® ES + + + +
    +
    +

    Mobile native Wearable native

    +
    + +
    +

    Dependencies

    +
      +
    • Tizen 4.0 and Higher for Mobile
    • +
    • Tizen 4.0 and Higher for Wearable
    • +
    +

    Content

    + +

    Related Info

    + +
    +
    + +
    + +

    SDL Graphics with OpenGL® ES

    +

    OpenGL® ES is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. +Tizen supports OpenGL® ES versions 1.1, 2.0, 3.0, 3.1, and 3.2. For general information on OpenGL®ES, and the comparative merits of Vulkan® and OpenGL®, see the official Khronos OpenGL® ES Web site and Vulkan® vs. OpenGL®.

    + +

    Figure: OpenGL® ES in Tizen

    +

    opengles in Tizen

    + +

    The main OpenGL ES API features include rendering 3D objects in an SDL application.

    + +

    Prerequisites

    + +

    To enable your application to use the OpenGL® ES functionality:

    + +
      +
    1. To use OpenGL® ES for 3D rendering, you must create an SDL application, and understand both OpenGL® ES and SDL.
    2. +
    3. Check whether the device supports a specific version of OpenGL® ES. +

      Check for device support using the system_info_get_platform_bool() function, before using the OpenGL ES APIs. If the device can support the specific OpenGL® ES version, the function returns true in the second parameter.

      +
      +bool opengles_support;
      +/* Check support for the OpenGL® ES 2.0 version */
      +system_info_get_platform_bool("http://tizen.org/feature/opengles.version.2_0", &opengles_support);
      +
      +
    4. +
    5. To use the functions and data types of the OpenGL ES (in mobile and wearable applications) and SDL (in mobile and wearable applications) APIs, include the <SDL.h> header file and the appropriate OpenGL® ES version header file in your application: +
      +#include <SDL.h>
      +/* Header file for the OpenGL® ES 2.0 version */
      +#include <GLES2/GLES2.h>
      +
      +
    6. +
    +

    Table: OpenGLĀ® ES feature keys and header files

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    VersionFeature keyHeader file
    OpenGL® ES 1.1http://tizen.org/feature/opengles.version.1_1<GLES/GLES.h> or <SDL_opengles.h>
    OpenGL® ES 2.0http://tizen.org/feature/opengles.version.2_0<GLES2/GLES2.h> or <SDL_opengles2.h>
    OpenGL® ES 3.0http://tizen.org/feature/opengles.version.3_0<GLES3/GLES3.h>
    OpenGL® ES 3.1http://tizen.org/feature/opengles.version.3_1
    OpenGL® ES 3.2http://tizen.org/feature/opengles.version.3_2
    + +

    Rendering a Cube with OpenGL® ES

    + +

    To render a cube using OpenGL® ES in an SDL application:

    + +
      +
    1. Initialize the SDL library and create the SDL window. + +

      Before using any other SDL functions, call the SDL_Init() function to properly initialize the SDL library and start each of its various subsystems. The function accepts as a parameter a set of allowed flags combined using the "|" pipe operation.

      +

      After SDL is initialized successfully, create the SDL_Window instance using the SDL_CreateWindow() function. The parameters define the title of the window, the X and Y position coordinates, width, height, and a set of SDL_WindowFlags combined using the "|" pipe operation.

      + +
      + Note + To use the OpenGL® ES context, use the SDL_WINDOW_OPENGL flag when you create a window. Do not use both SDL_WINDOW_VULKAN and SDL_WINDOW_OPENGL simultaneously. +
      + +

      The SDL_main() function is mandatory for the Tizen framework to initialize the SDL application. You must use the SDL_main() function instead of the usual main() function in your SDL application.

      + +
      +int
      +SDL_main(int argc, char *argv[])
      +{
      +    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS);
      +    demo.sdl_window = SDL_CreateWindow("SDL OpenGL ES Sample", 0, 0, demo.sdl_mode.w, demo.sdl_mode.h,
      +                                       SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL);
      +}
      +
      +
    2. +
    3. Initialize the OpenGL® ES context: +
        +
      1. Set the context properties using the available attributes: + +
        +int
        +initGL(appdata_s* ad)
        +{
        +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
        +    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
        +    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        +    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
        +    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        +    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
        +
        +
      2. +
      3. Create the context: +
        +    /* Create context for OpenGL® window */
        +    ad->gl = SDL_GL_CreateContext(ad->window);
        +    if (ad->gl == NULL) {
        +        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] GL context creation failed!");
        +
        +        return (-1);
        +    }
        +
        +    /* Set context as current */
        +    SDL_GL_MakeCurrent(ad->window, ad->gl);
        +
        +    return (0);
        +}
        +
      4. +
    4. +
    5. Initialize the shaders, identity matrix, and buffer. +

      Shaders are created and compiled in the init_shaders() function, and attached to the glProgram object.

      +

      The generateAndBindBuffer() function creates a vertex buffer object, which is managed using the glGenBuffers(), glBindBuffer(), and glBufferData() functions.

      + +
      +/* Initialize shaders */
      +init_shaders(&ad);
      +
      +/* Initialize matrix for camera view */
      +init_matrix(ad.view);
      +
      +/* Generate and bind vertex buffer object */
      +generateAndBindBuffer(&(ad.vbo));
      +
      +
    6. +
    7. Calculate the view aspect ratio and apply an orthographic matrix. +

      The aspect ratio determines the field of view in the X direction, and is the ratio of X (width) to Y (height).

      +
      +float aspect = (ad.mode.w > ad.mode.h ? (float)ad.mode.w / ad.mode.h : (float)ad.mode.h / ad.mode.w);
      +if (ad.mode.w > ad.mode.h)
      +    view_set_ortho(ad.view, -1.0 * aspect, 1.0 * aspect, -1.0, 1.0, -1.0, 100.0);
      +else
      +    view_set_ortho(ad.view, -1.0, 1.0, -1.0 * aspect, 1.0 * aspect, -1.0, 100.0);
      +
      +
    8. +
    9. To draw the scene: +
        +
      1. Clear the buffer. +

        The glClear() function clears buffers to preset values. The function accepts as a parameter a set of allowed flags, indicating the buffers to be cleared, combined using the "|" pipe operation. The available flags are GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_ACCUM_BUFFER_BIT, and GL_STENCIL_BUFFER_BIT.

        +

        The glClearColor() function specifies the red, green, blue, and alpha values used when the color buffers are cleared.

        + +
        +void
        +drawScene(appdata_s* ad)
        +{
        +    glViewport(0, 0, ad->w, ad->h);
        +    glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
        +    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        +
      2. +
      3. Render the scene: +
        +    init_matrix(ad->model);
        +    rotate_xyz(ad->model, ad->anglePoint.x, ad->anglePoint.y, ad->window_rotation);
        +
        +    multiply_matrix(ad->mvp, ad->view, ad->model);
        +    glUseProgram(ad->program);
        +
        +    glBindBuffer(GL_ARRAY_BUFFER, ad->vbo);
        +    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 6, 0);
        +    glEnableVertexAttribArray(0);
        +
        +    glBindBuffer(GL_ARRAY_BUFFER, ad->vbo);
        +    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 6, (void*)(sizeof(float) * 3));
        +    glEnableVertexAttribArray(1);
        +
        +    glUniformMatrix4fv(glGetUniformLocation(ad->program, "mvpMatrix"), 1, GL_FALSE, ad->mvp);
        +
        +    /* Render primitives from array data*/
        +    glDrawArrays(GL_TRIANGLES, 0, 36);
        +    
        +
      4. +
      5. Update the OpenGL® rendering window: +
        +    SDL_GL_SwapWindow(ad->window);
        +}
        +
      +
    10. + + +
    11. Quit SDL. +

      Before exiting the application, destroy the SDL objects:

      +
      +SDL_Quit();
      +
      +
    12. +
    +

    OpenGL® Context Attributes

    +

    The following table lists the attributes whose values can be set using the SDL_GL_SetAttribute() function.

    +

    Table: OpenGL® context attributes

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    AttributeDescriptionDefault value
    SDL_GL_ACCELERATED_VISUALSet to 1 to require hardware acceleration; set to 0 to force software rendering +

    In Tizen, hardware acceleration is used regardless of the value set to this attribute.

    -
    SDL_GL_ACCUM_ALPHA_SIZEMinimum number of bits for the accumulation buffer alpha channel0
    SDL_GL_ACCUM_BLUE_SIZEMinimum number of bits for the accumulation buffer blue channel
    SDL_GL_ACCUM_GREEN_SIZEMinimum number of bits for the accumulation buffer green channel
    SDL_GL_ACCUM_RED_SIZEMinimum number of bits for the accumulation buffer red channel3
    SDL_GL_ALPHA_SIZEMinimum number of bits for the color buffer alpha channel0
    SDL_GL_BLUE_SIZEMinimum number of bits for the color buffer blue channel2
    SDL_GL_BUFFER_SIZEMinimum number of bits for the frame buffer0
    SDL_GL_CONTEXT_FLAGSCombination of 0 or more elements of the SDL_GLcontextFlag enumeration
    SDL_GL_CONTEXT_MAJOR_VERSIONOpenGL® context major version-
    SDL_GL_CONTEXT_MINOR_VERSIONOpenGL® context minor version
    SDL_GL_CONTEXT_PRIORITYAllow a GL context to be created with a priority hint
    SDL_GL_CONTEXT_PROFILE_MASKType of GL context (Core, Compatibility, ES)Depends on the platform
    SDL_GL_CONTEXT_RELEASE_BEHAVIORSet the context release behavior (since SDL 2.0.4)1
    SDL_GL_DEPTH_SIZEMinimum number of bits for the depth buffer16
    SDL_GL_DOUBLEBUFFERWhether the output is double-buffered1 (Double-buffered)
    SDL_GL_FRAMEBUFFER_SRGB_CAPABLERequest sRGB-capable visuals (since SDL 2.0.1)0
    SDL_GL_GREEN_SIZEMinimum number of bits for the color buffer green channel3
    SDL_GL_MULTISAMPLEBUFFERSNumber of buffers used for multisample anti-aliasing0
    SDL_GL_MULTISAMPLESAMPLESNumber of samples around the current pixel used for multisample anti-aliasing
    SDL_GL_RED_SIZEMinimum number of bits for the color buffer red channel3
    SDL_GL_SHARE_WITH_CURRENT_CONTEXTWhether OpenGL® context sharing is enabled0
    SDL_GL_STENCIL_SIZEMinimum number of bits for the stencil buffer
    SDL_GL_STEREOWhether stereo 3D output is enabledoff
    + + + +
    + +Go to top + + + + + + + diff --git a/org.tizen.guides/html/native/graphics/vulkan_n.htm b/org.tizen.guides/html/native/graphics/vulkan_n.htm index f521681..3a5d2bd 100644 --- a/org.tizen.guides/html/native/graphics/vulkan_n.htm +++ b/org.tizen.guides/html/native/graphics/vulkan_n.htm @@ -28,15 +28,12 @@

    Content

    Related Info

    @@ -47,12 +44,14 @@

    SDL Graphics with Vulkan®

    -

    Vulkan® is a generation API for high-efficiency access to graphics and computing on modern GPUs. It is an open-standard, cross-platform API designed from the ground up by industry experts collaborating under the Khronos consortium. It aims to address the inefficiencies of existing 3D APIs, such as OpenGL®, which are designed for single-core processors and lag to map modern hardware. It provides a much lower-level fine-grained control over the GPU to maximize performance and achieve a consistent user experience across different operating environments. For general information on Vulkan®, and the comparative merits of Vulkan® and OpenGL®, see the official Khronos Vulkan® Web site and OpenGL® vs. Vulkan®.

    -

    The Tizen platform supports the Vulkan API in order to provide the most cutting-edge 3D programming tools for you to create high-quality games and real-time graphics in applications. Vulkan® is especially recommended for performance- or latency-sensitive applications. With Vulkan®, you can achieve a much smoother user experience by parallelizing the rendering job across multiple threads which can feed the GPU in an efficient manner. Applications demanding explicit control on work submission, synchronization, and less power consumption can seriously consider migrating to Vulkan® as well. Tizen allows the use of the Vulkan API through SDL.

    +

    Vulkan® is a generation API for high-efficiency access to graphics and computing on modern GPUs. It is an open-standard, cross-platform API designed from the ground up by industry experts collaborating under the Khronos consortium. It aims to address the inefficiencies of existing 3D APIs, such as OpenGL®, which are designed for single-core processors and lag to map modern hardware. It provides a much lower-level fine-grained control over the GPU to maximize performance and achieve a consistent user experience across different operating environments. For general information on Vulkan®, and the comparative merits of Vulkan® and OpenGL®, see the official Khronos Vulkan® Web site and Vulkan® vs. OpenGL®.

    +

    The Tizen platform supports the Vulkan API in order to provide the most cutting-edge 3D programming tools for you to create high-quality games and real-time graphics in applications. Vulkan® is especially recommended for performance- or latency-sensitive applications. With Vulkan®, you can achieve a much smoother user experience by parallelizing the rendering job across multiple threads which can feed the GPU in an efficient manner. Applications demanding explicit control on work submission, synchronization, and less power consumption can seriously consider migrating to Vulkan® as well. Tizen allows the use of the Vulkan API through SDL.

    Figure: Vulkan® in Tizen

    Vulkan in Tizen

    +

    The main Vulkan API features include rendering 3D objects in an SDL application.

    +

    Before using the Vulkan API in Tizen, make sure that you are familiar with the following key Vulkan® features, which help you to align your application design around Vulkan® concepts and exploit the hardware to the fullest:

    -

    OpenGL® vs. Vulkan®

    - -

    When you consider the differences and advantages between Vulkan® and OpenGL®, Vulkan® basically complements OpenGL® by addressing specific users who want to have a quite low-level API with a much better abstraction of the modern hardware giving a lot of control, predictability, and high performance at much greater efficiency. On the other hand, OpenGL® is a much higher-level API that does many things on your behalf inside the driver with less burden on you. It continues to be the API of choice for a wide range of developers who want to have the shortest path to a functionally correct application.

    - -

    When selecting the open graphics API (Vulkan® or OpenGL®) to use for a new application, or when considering the need to migrate an existing application from OpenGL® to Vulkan®, ask yourself the following questions:

    - -

    If your answer to any of the questions is Yes, consider using Vulkan® instead of OpenGL®. However, remember that Vulkan® comes at the cost of taking more responsibility at the application side from the driver.

    - -

    The following table describes the practical advantages of Vulkan®.

    - -

    Table: Vulkan® advantages

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    OpenGL®Vulkan®
    Better GPU controlImplicit driver manages the state and resources based on heuristics, leading to overhead and inefficiencies. The application has no control.Explicit API allows you to manage the state and resources as per specific application needs, and relieves you from hidden optimizations giving more control on the GPU.
    Multi-core friendlyOriginally designed for single-threaded architectures and does not allow the generation of graphic commands in parallel to command execution.API is designed around asynchronous generation of command buffers across multiple threads and feeds them in sequence to a command pipeline, which reflects the realities of the modern hardware.
    High efficiencyDoes a lot of redundant excessive validation for each draw call, such as runtime error checking, implicit tracking of resource usage, and synchronization, leading to much CPU overhead.Vulkan® greatly reduces the CPU time spent in the driver with external validation and diagnostics layers that can be independently enabled and disabled, as needed. Offloads the render thread by delegating heavy CPU jobs to the application and opt-in layers.
    Shader portabilityOnly GLSL is supported as a shader language, and the compiler is a part of the driver with vendor-specific semantics. No user control over the front end and higher runtime translation time.Vulkan® mandates the use of the intermediate byte code (SPIR-V) by the driver for shaders. This allows offline shader precompilation, and allows you to write shaders in languages other than GLSL.
    Code complexityOpenGL® driver manages many tasks inside the driver relieving you from the burden of managing these at the application end.Vulkan® is a much more verbose API, offering more control at the cost of more code complexity and responsibility at the application side.
    - -

    SDL

    - -

    SDL (Simple DirectMedia Layer) is a cross-platform software development library. In Tizen, it enables access to graphics hardware using Vulkan®. SDL is used for creating high-performance computer games, multimedia applications, and emulators. It provides a low-level hardware abstraction layer to computer multimedia hardware components. It can run on many operating systems, such as Android™, iOS, Linux, macOS, Windows®, and Tizen. For more information, see the SDL Web site.

    - -

    You can manage video, audio, some input devices, threads, and timers with SDL. Tizen supports SDL to provide new means of accessing its 3D APIs (Vulkan), which can currently be accessed only through an EFL wrapper library (Evas GL). For more information on Evas GL, see the OpenGL® ES guide.

    - -

    The following SDL features are currently supported in Tizen:

    - -

    For the list of features not currently supported in Tizen, see the SDL API (in mobile and wearable applications).

    - -

    SDL Application Life-cycle in Tizen

    - -

    The Tizen native application model is responsible for the application life-cycle and system events. The SDL application life-cycle is handled by the SDL_PollEvent() function, which manages the main event loop, the application state change events, and basic system events (general and Tizen-specific).

    - -

    Figure: SDL application life-cycle

    -

    SDL application life-cycle

    - -

    The SDL application can be in one of several different states, and the state changes are managed by the underlying framework.

    - -

    Table: SDL application states

    - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    StateDescription
    READYApplication starts the main loop.
    CREATEDApplication is launched.
    RUNNINGApplication is running and visible to the user.
    PAUSEDApplication is running but invisible to the user.
    TERMINATEDApplication is terminated.
    - - -

    Typically, the application is launched by the user from the Launcher, or by another application. The application is normally launched as the top window, with focus. When the application loses the focus status, the SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND events are invoked. The application can go into the pause state, which means that it is not terminated but continues to run in the background. The pause state can happen when:

    - - -

    When the application becomes visible again, the SDL_APP_WILLENTERFOREGROUND and SDL_APP_DIDENTERFOREGROUND events are invoked. The visibility returns, when:

    - - -

    When the application starts exiting, the SDL_Quit and SDL_TERMINATING events are invoked. Your application can start the termination process, when:

    - -

    Prerequisites

    @@ -256,7 +120,7 @@ SDL_main(int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); demo.sdl_window = SDL_CreateWindow("SDL Vulkan Sample", 0, 0, demo.sdl_mode.w, demo.sdl_mode.h, - SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_VULKAN); + SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_VULKAN); } @@ -505,188 +369,6 @@ SDL_Quit(); -

    Handling General SDL Events

    - -

    To handle general SDL events:

    - -
      -
    1. Call the SDL_PollEvent() function, which polls the currently pending events and returns the SDL_Event instance. Before calling the SDL_PollEvent() function, create an empty SDL_Event structure. -
      -void
      -updateApp(appdata_s* ad)
      -{
      -    /* SDL_Event is a union containing structures for different event types */
      -    SDL_Event event;
      -    while (SDL_PollEvent(&event)) {
      -        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Event type: %x\n", event.type);
      -        handleEvent(&ad, &event);
      -    }
      -}
      -
      -
    2. -
    3. The SDL_PollEvent() function removes the next event from the event queue. If there is no event in the queue, it returns 0. If there is an event, it fills the SDL_Event object with the event information. -

      The SDL_Event object is a union that contains structures for the different event types. The type member specifies the event type, shared with all events. The type member is related to the SDL_EventType enumeration.

      -

      To handle each event type separately, use a switch statement:

      - -
      -void
      -handleEvent(appdata_s** data, SDL_Event* event)
      -{
      -    appdata_s* ad = *data;
      -
      -    switch (event->type) {
      -    case SDL_QUIT:
      -        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Finish main loop ");
      -        ad->game_exit = 1;
      -        break;
      -    case SDL_KEYUP:
      -        char* scancodename = (char *)SDL_GetScancodeName(event->key.keysym.scancode);
      -        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] keyboard scancode: %s", scancodename);
      -        if (event->key.keysym.scancode == SDL_SCANCODE_AC_BACK) {
      -            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Finish main loop ");
      -            ad->game_exit = 1;
      -        }
      -        break;
      -    case SDL_MOUSEBUTTONDOWN:
      -        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL]Mouse Down: %d x %d", event->button.x, event->button.y);
      -        break;
      -    case SDL_MOUSEBUTTONUP:
      -        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL]Mouse Up: %d x %d", event->button.x, event->button.y);
      -        break;
      -    case SDL_MOUSEMOTION:
      -        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL]Mouse Motion: %d x %d", event->motion.x, event->motion.y);
      -        break;
      -    case SDL_ROTATEEVENT:
      -        ad->window_rotation = (int)event->user.data1;
      -        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "[SDL] Rotation degree: %d", ad->window_rotation);
      -        break;
      -    case SDL_WINDOWEVENT:
      -        SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "SDL_WINDOWEVENT Event!!");
      -        if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
      -            SDL_Log("SDL_WINDOWEVENT_SIZE_CHANGED!!!");
      -        break;
      -    } /* End switch */
      -}
      -
      -
    4. -
    - -

    Handling Tizen-specific SDL Events

    - -

    To handle SDl events specifically added to the Tizen application framework:

    - - diff --git a/org.tizen.guides/index.xml b/org.tizen.guides/index.xml index 1e21da2..951c133 100644 --- a/org.tizen.guides/index.xml +++ b/org.tizen.guides/index.xml @@ -244,7 +244,10 @@ - + + + + diff --git a/org.tizen.training/html/native/details/app_filtering_n.htm b/org.tizen.training/html/native/details/app_filtering_n.htm index 173a347..2dbba76 100644 --- a/org.tizen.training/html/native/details/app_filtering_n.htm +++ b/org.tizen.training/html/native/details/app_filtering_n.htm @@ -546,6 +546,19 @@ 2.4 +http://tizen.org/feature/opengles.version.3_1 + Specify this key, if the application requires OpenGL® ES version 3.1. +

    You can specify at most 1 OpenGL® ES version. If you specify multiple versions, only the highest one is considered.

    + + 4.0 + + +http://tizen.org/feature/opengles.version.3_2 + Specify this key, if the application requires OpenGL® ES version 3.2. +

    You can specify at most 1 OpenGL® ES version. If you specify multiple versions, only the highest one is considered.

    + + + http://tizen.org/feature/platform.core.cpu.arch.armv7 Specify this key, if the application requires the ARMv7 CPU architecture. 2.2.1