Commit 826d8e47f5df21bf57582e55b26fcf77dc257aa7
Committed by
Adeel Kazmi
1 parent
998fcb5c
DirectRendering:
- Added drawable-actor example Change-Id: I991c7a28e5c97b56162e018aa0da72e4435c86bb
Showing
10 changed files
with
528 additions
and
0 deletions
build/tizen/CMakeLists.txt
| @@ -337,6 +337,13 @@ ELSEIF( UNIX ) | @@ -337,6 +337,13 @@ ELSEIF( UNIX ) | ||
| 337 | ${REQUIRED_PKGS_LDFLAGS} | 337 | ${REQUIRED_PKGS_LDFLAGS} |
| 338 | -pie | 338 | -pie |
| 339 | ) | 339 | ) |
| 340 | + | ||
| 341 | + IF( ANDROID ) | ||
| 342 | + SET( REQUIRED_LIBS ${REQUIRED_LIBS} -lGLESv3 ) | ||
| 343 | + ELSE() | ||
| 344 | + PKG_CHECK_MODULES( GLESV2 REQUIRED glesv2 ) | ||
| 345 | + SET( REQUIRED_LIBS ${REQUIRED_LIBS} ${GLESV2_LIBRARIES} ) | ||
| 346 | + ENDIF() | ||
| 340 | ENDIF() | 347 | ENDIF() |
| 341 | 348 | ||
| 342 | SET(DALI_DEMO_CFLAGS "-DDEMO_GAME_DIR=${DEMO_GAME_DIR} -DDEMO_IMAGE_DIR=${DEMO_IMAGE_DIR} -DDEMO_VIDEO_DIR=${DEMO_VIDEO_DIR} -DDEMO_MODEL_DIR=${DEMO_MODEL_DIR} -DDEMO_SCRIPT_DIR=${DEMO_SCRIPT_DIR} -DDEMO_SHADER_DIR=${DEMO_SHADER_DIR} -DDEMO_STYLE_DIR=${DEMO_STYLE_DIR} -DDEMO_THEME_PATH=${DEMO_THEME_PATH} -DDEMO_EXAMPLE_BIN=${DEMO_EXAMPLE_BIN} -DDEMO_LOCALE_DIR=${DEMO_LOCALE_DIR} -DDEMO_LANG=${DEMO_LANG} -DDEMO_DATA_RW_DIR=${DEMO_DATA_RW_DIR} -DDEMO_DATA_PUBLIC_RW_DIR=${DEMO_DATA_PUBLIC_RW_DIR} ") | 349 | SET(DALI_DEMO_CFLAGS "-DDEMO_GAME_DIR=${DEMO_GAME_DIR} -DDEMO_IMAGE_DIR=${DEMO_IMAGE_DIR} -DDEMO_VIDEO_DIR=${DEMO_VIDEO_DIR} -DDEMO_MODEL_DIR=${DEMO_MODEL_DIR} -DDEMO_SCRIPT_DIR=${DEMO_SCRIPT_DIR} -DDEMO_SHADER_DIR=${DEMO_SHADER_DIR} -DDEMO_STYLE_DIR=${DEMO_STYLE_DIR} -DDEMO_THEME_PATH=${DEMO_THEME_PATH} -DDEMO_EXAMPLE_BIN=${DEMO_EXAMPLE_BIN} -DDEMO_LOCALE_DIR=${DEMO_LOCALE_DIR} -DDEMO_LANG=${DEMO_LANG} -DDEMO_DATA_RW_DIR=${DEMO_DATA_RW_DIR} -DDEMO_DATA_PUBLIC_RW_DIR=${DEMO_DATA_PUBLIC_RW_DIR} ") |
com.samsung.dali-demo.xml
| @@ -106,6 +106,9 @@ | @@ -106,6 +106,9 @@ | ||
| 106 | <ui-application appid="drag-and-drop.example" exec="/usr/apps/com.samsung.dali-demo/bin/drag-and-drop.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | 106 | <ui-application appid="drag-and-drop.example" exec="/usr/apps/com.samsung.dali-demo/bin/drag-and-drop.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 107 | <label>Drag And Drop</label> | 107 | <label>Drag And Drop</label> |
| 108 | </ui-application> | 108 | </ui-application> |
| 109 | + <ui-application appid="drawable-actor.example" exec="/usr/apps/com.samsung.dali-demo/bin/drawable-actor.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | ||
| 110 | + <label>Drawable Actor</label> | ||
| 111 | + </ui-application> | ||
| 109 | <ui-application appid="effects-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/effects-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> | 112 | <ui-application appid="effects-view.example" exec="/usr/apps/com.samsung.dali-demo/bin/effects-view.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true"> |
| 110 | <label>Effects View</label> | 113 | <label>Effects View</label> |
| 111 | </ui-application> | 114 | </ui-application> |
examples-reel/dali-examples-reel.cpp
| @@ -54,6 +54,7 @@ int DALI_EXPORT_API main(int argc, char** argv) | @@ -54,6 +54,7 @@ int DALI_EXPORT_API main(int argc, char** argv) | ||
| 54 | demo.AddExample(Example("deferred-shading.example", DALI_DEMO_STR_TITLE_DEFERRED_SHADING)); | 54 | demo.AddExample(Example("deferred-shading.example", DALI_DEMO_STR_TITLE_DEFERRED_SHADING)); |
| 55 | demo.AddExample(Example("dissolve-effect.example", DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION)); | 55 | demo.AddExample(Example("dissolve-effect.example", DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION)); |
| 56 | demo.AddExample(Example("drag-and-drop.example", DALI_DEMO_STR_TITLE_DRAG_AND_DROP)); | 56 | demo.AddExample(Example("drag-and-drop.example", DALI_DEMO_STR_TITLE_DRAG_AND_DROP)); |
| 57 | + demo.AddExample(Example("drawable-actor.example", DALI_DEMO_STR_TITLE_DRAWABLE_ACTOR)); | ||
| 57 | demo.AddExample(Example("effects-view.example", DALI_DEMO_STR_TITLE_EFFECTS_VIEW)); | 58 | demo.AddExample(Example("effects-view.example", DALI_DEMO_STR_TITLE_EFFECTS_VIEW)); |
| 58 | demo.AddExample(Example("flex-container.example", DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND)); | 59 | demo.AddExample(Example("flex-container.example", DALI_DEMO_STR_TITLE_FLEXBOX_PLAYGROUND)); |
| 59 | demo.AddExample(Example("frame-callback.example", DALI_DEMO_STR_TITLE_FRAME_CALLBACK)); | 60 | demo.AddExample(Example("frame-callback.example", DALI_DEMO_STR_TITLE_FRAME_CALLBACK)); |
examples/drawable-actor/drawable-actor-example.cpp
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2020 Samsung Electronics Co., Ltd. | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + * | ||
| 16 | + */ | ||
| 17 | + | ||
| 18 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 19 | +#include <dali/public-api/actors/drawable-actor.h> | ||
| 20 | + | ||
| 21 | +#include "native-renderer.h" | ||
| 22 | + | ||
| 23 | +// Include the GLES header | ||
| 24 | +#include <GLES3/gl3.h> | ||
| 25 | +#include <dali/graphics-api/graphics-buffer-create-info.h> | ||
| 26 | + | ||
| 27 | +#include <dali/devel-api/common/stage-devel.h> | ||
| 28 | + | ||
| 29 | +using TextLabel = Dali::Toolkit::TextLabel; | ||
| 30 | +using namespace Dali; | ||
| 31 | + | ||
| 32 | +// This example shows DrawableActor using native GL code to clear screen to red | ||
| 33 | +// and renders TextLabel on top of it. | ||
| 34 | +// | ||
| 35 | +class DrawableActorExampleController : public ConnectionTracker | ||
| 36 | +{ | ||
| 37 | +public: | ||
| 38 | + | ||
| 39 | + explicit DrawableActorExampleController(Application& application) | ||
| 40 | + : mApplication(application) | ||
| 41 | + { | ||
| 42 | + // Connect to the Application's Init signal | ||
| 43 | + mApplication.InitSignal().Connect(this, &DrawableActorExampleController::Create); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + ~DrawableActorExampleController() override = default; // Nothing to do in destructor | ||
| 47 | + | ||
| 48 | + // The Init signal is received once (only) during the Application lifetime | ||
| 49 | + void Create(Application& application) | ||
| 50 | + { | ||
| 51 | + // Get a handle to the window | ||
| 52 | + Window window = application.GetWindow(); | ||
| 53 | + window.SetBackgroundColor(Color::WHITE); | ||
| 54 | + | ||
| 55 | + // Create native renderer | ||
| 56 | + mRenderer = std::make_unique<NativeRenderer>(window.GetSize().GetWidth(), window.GetSize().GetHeight()); | ||
| 57 | + | ||
| 58 | + // Create render callback | ||
| 59 | + mRenderCallback = RenderCallback::New<NativeRenderer>( mRenderer.get(), &NativeRenderer::OnRender ); | ||
| 60 | + | ||
| 61 | + // Create drawable actor | ||
| 62 | + mGLActor = DrawableActor::New( *mRenderCallback ); | ||
| 63 | + | ||
| 64 | + mGLActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); | ||
| 65 | + mGLActor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER ); | ||
| 66 | + | ||
| 67 | + // Set size on the actor (half the window size to show that glClear() and scissor test work together) | ||
| 68 | + mGLActor.SetProperty( Actor::Property::SIZE, Size( window.GetSize() ) * 0.5f); | ||
| 69 | + | ||
| 70 | + // Add actor to the scene | ||
| 71 | + window.Add(mGLActor); | ||
| 72 | + | ||
| 73 | + // Create TextLabel | ||
| 74 | + mTextLabel = TextLabel::New("This text overlays DrawableActor"); | ||
| 75 | + mTextLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); | ||
| 76 | + mTextLabel.SetProperty(Dali::Actor::Property::NAME, "SomeTextLabel"); | ||
| 77 | + window.Add(mTextLabel); | ||
| 78 | + | ||
| 79 | + // Respond to a touch anywhere on the window | ||
| 80 | + window.GetRootLayer().TouchedSignal().Connect(this, &DrawableActorExampleController::OnTouch); | ||
| 81 | + | ||
| 82 | + // Respond to key events | ||
| 83 | + window.KeyEventSignal().Connect(this, &DrawableActorExampleController::OnKeyEvent); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + bool OnTouch(Actor actor, const TouchEvent& touch) | ||
| 87 | + { | ||
| 88 | + // quit the application | ||
| 89 | + mApplication.Quit(); | ||
| 90 | + return true; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + void OnKeyEvent(const KeyEvent& event) | ||
| 94 | + { | ||
| 95 | + if(event.GetState() == KeyEvent::DOWN) | ||
| 96 | + { | ||
| 97 | + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) | ||
| 98 | + { | ||
| 99 | + mApplication.Quit(); | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + TextLabel mTextLabel; | ||
| 105 | + DrawableActor mGLActor; | ||
| 106 | + | ||
| 107 | + std::unique_ptr<RenderCallback> mRenderCallback; | ||
| 108 | + std::unique_ptr<NativeRenderer> mRenderer{nullptr}; | ||
| 109 | + | ||
| 110 | +private: | ||
| 111 | + Application& mApplication; | ||
| 112 | +}; | ||
| 113 | + | ||
| 114 | +int DALI_EXPORT_API main(int argc, char** argv) | ||
| 115 | +{ | ||
| 116 | + Application application = Application::New(&argc, &argv); | ||
| 117 | + DrawableActorExampleController test(application); | ||
| 118 | + application.MainLoop(); | ||
| 119 | + return 0; | ||
| 120 | +} |
examples/drawable-actor/native-renderer.cpp
0 → 100644
| 1 | +// | ||
| 2 | +// Created by adam.b on 15/03/2022. | ||
| 3 | +// | ||
| 4 | +#include "native-renderer.h" | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * Set of math helper functions | ||
| 8 | + */ | ||
| 9 | +namespace | ||
| 10 | +{ | ||
| 11 | + | ||
| 12 | +constexpr GLfloat CUBE_VERTICES[] = {-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f}; | ||
| 13 | + | ||
| 14 | +constexpr GLfloat CUBE_COLOURS[] = {1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f}; | ||
| 15 | + | ||
| 16 | +constexpr GLushort CUBE_INDICES[] = {0, 2, 3, 0, 1, 3, 4, 6, 7, 4, 5, 7, 8, 9, 10, 11, 8, 10, 12, 13, 14, 15, 12, 14, 16, 17, 18, 16, 19, 18, 20, 21, 22, 20, 23, 22}; | ||
| 17 | + | ||
| 18 | +float matrixDegreesToRadians(float degrees) | ||
| 19 | +{ | ||
| 20 | + return M_PI * degrees / 180.0f; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +[[maybe_unused]] void matrixIdentityFunction(float* matrix) | ||
| 24 | +{ | ||
| 25 | + if(matrix == NULL) | ||
| 26 | + { | ||
| 27 | + return; | ||
| 28 | + } | ||
| 29 | + matrix[0] = 1.0f; | ||
| 30 | + matrix[1] = 0.0f; | ||
| 31 | + matrix[2] = 0.0f; | ||
| 32 | + matrix[3] = 0.0f; | ||
| 33 | + matrix[4] = 0.0f; | ||
| 34 | + matrix[5] = 1.0f; | ||
| 35 | + matrix[6] = 0.0f; | ||
| 36 | + matrix[7] = 0.0f; | ||
| 37 | + matrix[8] = 0.0f; | ||
| 38 | + matrix[9] = 0.0f; | ||
| 39 | + matrix[10] = 1.0f; | ||
| 40 | + matrix[11] = 0.0f; | ||
| 41 | + matrix[12] = 0.0f; | ||
| 42 | + matrix[13] = 0.0f; | ||
| 43 | + matrix[14] = 0.0f; | ||
| 44 | + matrix[15] = 1.0f; | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +[[maybe_unused]] void matrixMultiply(float* destination, float* operand1, float* operand2) | ||
| 48 | +{ | ||
| 49 | + float theResult[16]; | ||
| 50 | + int i, j = 0; | ||
| 51 | + for(i = 0; i < 4; i++) | ||
| 52 | + { | ||
| 53 | + for(j = 0; j < 4; j++) | ||
| 54 | + { | ||
| 55 | + theResult[4 * i + j] = operand1[j] * operand2[4 * i] + operand1[4 + j] * operand2[4 * i + 1] + | ||
| 56 | + operand1[8 + j] * operand2[4 * i + 2] + operand1[12 + j] * operand2[4 * i + 3]; | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + for(int i = 0; i < 16; i++) | ||
| 60 | + { | ||
| 61 | + destination[i] = theResult[i]; | ||
| 62 | + } | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +[[maybe_unused]] void matrixTranslate(float* matrix, float x, float y, float z) | ||
| 66 | +{ | ||
| 67 | + float temporaryMatrix[16]; | ||
| 68 | + matrixIdentityFunction(temporaryMatrix); | ||
| 69 | + temporaryMatrix[12] = x; | ||
| 70 | + temporaryMatrix[13] = y; | ||
| 71 | + temporaryMatrix[14] = z; | ||
| 72 | + matrixMultiply(matrix, temporaryMatrix, matrix); | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +[[maybe_unused]] void matrixScale(float* matrix, float x, float y, float z) | ||
| 76 | +{ | ||
| 77 | + float tempMatrix[16]; | ||
| 78 | + matrixIdentityFunction(tempMatrix); | ||
| 79 | + tempMatrix[0] = x; | ||
| 80 | + tempMatrix[5] = y; | ||
| 81 | + tempMatrix[10] = z; | ||
| 82 | + matrixMultiply(matrix, tempMatrix, matrix); | ||
| 83 | +} | ||
| 84 | + | ||
| 85 | +[[maybe_unused]] void matrixRotateX(float* matrix, float angle) | ||
| 86 | +{ | ||
| 87 | + float tempMatrix[16]; | ||
| 88 | + matrixIdentityFunction(tempMatrix); | ||
| 89 | + tempMatrix[5] = cos(matrixDegreesToRadians(angle)); | ||
| 90 | + tempMatrix[9] = -sin(matrixDegreesToRadians(angle)); | ||
| 91 | + tempMatrix[6] = sin(matrixDegreesToRadians(angle)); | ||
| 92 | + tempMatrix[10] = cos(matrixDegreesToRadians(angle)); | ||
| 93 | + matrixMultiply(matrix, tempMatrix, matrix); | ||
| 94 | +} | ||
| 95 | +[[maybe_unused]] void matrixRotateY(float* matrix, float angle) | ||
| 96 | +{ | ||
| 97 | + float tempMatrix[16]; | ||
| 98 | + matrixIdentityFunction(tempMatrix); | ||
| 99 | + tempMatrix[0] = cos(matrixDegreesToRadians(angle)); | ||
| 100 | + tempMatrix[8] = sin(matrixDegreesToRadians(angle)); | ||
| 101 | + tempMatrix[2] = -sin(matrixDegreesToRadians(angle)); | ||
| 102 | + tempMatrix[10] = cos(matrixDegreesToRadians(angle)); | ||
| 103 | + matrixMultiply(matrix, tempMatrix, matrix); | ||
| 104 | +} | ||
| 105 | +[[maybe_unused]] void matrixRotateZ(float* matrix, float angle) | ||
| 106 | +{ | ||
| 107 | + float tempMatrix[16]; | ||
| 108 | + matrixIdentityFunction(tempMatrix); | ||
| 109 | + tempMatrix[0] = cos(matrixDegreesToRadians(angle)); | ||
| 110 | + tempMatrix[4] = -sin(matrixDegreesToRadians(angle)); | ||
| 111 | + tempMatrix[1] = sin(matrixDegreesToRadians(angle)); | ||
| 112 | + tempMatrix[5] = cos(matrixDegreesToRadians(angle)); | ||
| 113 | + matrixMultiply(matrix, tempMatrix, matrix); | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +void matrixFrustum(float* matrix, float left, float right, float bottom, float top, float zNear, float zFar) | ||
| 117 | +{ | ||
| 118 | + float temp, xDistance, yDistance, zDistance; | ||
| 119 | + temp = 2.0 * zNear; | ||
| 120 | + xDistance = right - left; | ||
| 121 | + yDistance = top - bottom; | ||
| 122 | + zDistance = zFar - zNear; | ||
| 123 | + matrixIdentityFunction(matrix); | ||
| 124 | + matrix[0] = temp / xDistance; | ||
| 125 | + matrix[5] = temp / yDistance; | ||
| 126 | + matrix[8] = (right + left) / xDistance; | ||
| 127 | + matrix[9] = (top + bottom) / yDistance; | ||
| 128 | + matrix[10] = (-zFar - zNear) / zDistance; | ||
| 129 | + matrix[11] = -1.0f; | ||
| 130 | + matrix[14] = (-temp * zFar) / zDistance; | ||
| 131 | + matrix[15] = 0.0f; | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | +[[maybe_unused]] void matrixPerspective(float* matrix, float fieldOfView, float aspectRatio, float zNear, float zFar) | ||
| 135 | +{ | ||
| 136 | + float ymax, xmax; | ||
| 137 | + ymax = zNear * tanf(fieldOfView * M_PI / 360.0); | ||
| 138 | + xmax = ymax * aspectRatio; | ||
| 139 | + matrixFrustum(matrix, -xmax, xmax, -ymax, ymax, zNear, zFar); | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | +} // namespace | ||
| 143 | + | ||
| 144 | +NativeRenderer::NativeRenderer(uint32_t width, uint32_t height) | ||
| 145 | +: mWidth(width), | ||
| 146 | + mHeight(height) | ||
| 147 | +{ | ||
| 148 | +} | ||
| 149 | + | ||
| 150 | +bool NativeRenderer::OnRender(const Dali::RenderCallbackInput& input) | ||
| 151 | +{ | ||
| 152 | + if(mState == State::INIT) | ||
| 153 | + { | ||
| 154 | + Setup(mWidth, mHeight); | ||
| 155 | + mState = State::RENDER; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + RenderCube(input); | ||
| 159 | + | ||
| 160 | + return false; | ||
| 161 | +} | ||
| 162 | + | ||
| 163 | +void NativeRenderer::PrepareShader() | ||
| 164 | +{ | ||
| 165 | + static const char glVertexShader[] = | ||
| 166 | + "attribute vec4 vertexPosition;\n" | ||
| 167 | + "attribute vec3 vertexColour;\n" | ||
| 168 | + "varying vec3 fragColour;\n" | ||
| 169 | + "uniform mat4 projection;\n" | ||
| 170 | + "uniform mat4 modelView;\n" | ||
| 171 | + "void main()\n" | ||
| 172 | + "{\n" | ||
| 173 | + " gl_Position = projection * modelView * vertexPosition;\n" | ||
| 174 | + " fragColour = vertexColour;\n" | ||
| 175 | + "}\n"; | ||
| 176 | + | ||
| 177 | + static const char glFragmentShader[] = | ||
| 178 | + "precision mediump float;\n" | ||
| 179 | + "varying vec3 fragColour;\n" | ||
| 180 | + "void main()\n" | ||
| 181 | + "{\n" | ||
| 182 | + " gl_FragColor = vec4(fragColour, 1.0);\n" | ||
| 183 | + "}\n"; | ||
| 184 | + | ||
| 185 | + mProgramId = CreateProgram(glVertexShader, glFragmentShader); | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +void NativeRenderer::Setup(int width, int height) | ||
| 189 | +{ | ||
| 190 | + PrepareShader(); | ||
| 191 | + | ||
| 192 | + mVertexLocation = glGetAttribLocation(mProgramId, "vertexPosition"); | ||
| 193 | + mVertexColourLocation = glGetAttribLocation(mProgramId, "vertexColour"); | ||
| 194 | + mProjectionLocation = glGetUniformLocation(mProgramId, "projection"); | ||
| 195 | + mModelViewLocation = glGetUniformLocation(mProgramId, "modelView"); | ||
| 196 | + | ||
| 197 | + glEnable(GL_DEPTH_TEST); | ||
| 198 | + glViewport(0, 0, width, height); | ||
| 199 | +} | ||
| 200 | + | ||
| 201 | +GLuint NativeRenderer::CreateProgram(const char* vertexSource, const char* fragmentSource) | ||
| 202 | +{ | ||
| 203 | + GLuint vertexShader = LoadShader(GL_VERTEX_SHADER, vertexSource); | ||
| 204 | + if(!vertexShader) | ||
| 205 | + { | ||
| 206 | + return 0; | ||
| 207 | + } | ||
| 208 | + GLuint fragmentShader = LoadShader(GL_FRAGMENT_SHADER, fragmentSource); | ||
| 209 | + if(!fragmentShader) | ||
| 210 | + { | ||
| 211 | + return 0; | ||
| 212 | + } | ||
| 213 | + GLuint program = glCreateProgram(); | ||
| 214 | + if(program) | ||
| 215 | + { | ||
| 216 | + glAttachShader(program, vertexShader); | ||
| 217 | + glAttachShader(program, fragmentShader); | ||
| 218 | + glLinkProgram(program); | ||
| 219 | + GLint linkStatus = GL_FALSE; | ||
| 220 | + glGetProgramiv(program, GL_LINK_STATUS, &linkStatus); | ||
| 221 | + if(linkStatus != GL_TRUE) | ||
| 222 | + { | ||
| 223 | + GLint bufLength = 0; | ||
| 224 | + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength); | ||
| 225 | + if(bufLength) | ||
| 226 | + { | ||
| 227 | + char* buf = (char*)malloc(bufLength); | ||
| 228 | + if(buf) | ||
| 229 | + { | ||
| 230 | + glGetProgramInfoLog(program, bufLength, NULL, buf); | ||
| 231 | + free(buf); | ||
| 232 | + } | ||
| 233 | + } | ||
| 234 | + glDeleteProgram(program); | ||
| 235 | + program = 0; | ||
| 236 | + } | ||
| 237 | + } | ||
| 238 | + return program; | ||
| 239 | +} | ||
| 240 | + | ||
| 241 | +GLuint NativeRenderer::LoadShader(GLenum shaderType, const char* shaderSource) | ||
| 242 | +{ | ||
| 243 | + GLuint shader = glCreateShader(shaderType); | ||
| 244 | + if(shader != 0) | ||
| 245 | + { | ||
| 246 | + glShaderSource(shader, 1, &shaderSource, NULL); | ||
| 247 | + glCompileShader(shader); | ||
| 248 | + GLint compiled = 0; | ||
| 249 | + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); | ||
| 250 | + if(compiled != GL_TRUE) | ||
| 251 | + { | ||
| 252 | + GLint infoLen = 0; | ||
| 253 | + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen); | ||
| 254 | + | ||
| 255 | + if(infoLen > 0) | ||
| 256 | + { | ||
| 257 | + char* logBuffer = (char*)malloc(infoLen); | ||
| 258 | + | ||
| 259 | + if(logBuffer != NULL) | ||
| 260 | + { | ||
| 261 | + glGetShaderInfoLog(shader, infoLen, NULL, logBuffer); | ||
| 262 | + free(logBuffer); | ||
| 263 | + logBuffer = NULL; | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + glDeleteShader(shader); | ||
| 267 | + shader = 0; | ||
| 268 | + } | ||
| 269 | + } | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + return shader; | ||
| 273 | +} | ||
| 274 | + | ||
| 275 | +void NativeRenderer::RenderCube(const Dali::RenderCallbackInput& input) | ||
| 276 | +{ | ||
| 277 | + static float angle = 0.0f; | ||
| 278 | + | ||
| 279 | + auto x = float(mWidth - input.size.width) * 0.5f; | ||
| 280 | + auto y = float(mHeight - input.size.height) * 0.5f; | ||
| 281 | + auto w = input.size.width; | ||
| 282 | + auto h = input.size.height; | ||
| 283 | + | ||
| 284 | + matrixPerspective(mProjectionMatrix, 45, (float)w / (float)h, 0.1f, 100); | ||
| 285 | + | ||
| 286 | + glEnable(GL_SCISSOR_TEST); | ||
| 287 | + glScissor(x, y, w, h); | ||
| 288 | + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | ||
| 289 | + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); | ||
| 290 | + matrixIdentityFunction(mModelViewMatrix); | ||
| 291 | + matrixScale(mModelViewMatrix, 0.5f, 0.5f, 0.5f); | ||
| 292 | + matrixRotateX(mModelViewMatrix, angle); | ||
| 293 | + matrixRotateY(mModelViewMatrix, angle); | ||
| 294 | + matrixTranslate(mModelViewMatrix, 0.0f, 0.0f, -10.0f); | ||
| 295 | + glUseProgram(mProgramId); | ||
| 296 | + glVertexAttribPointer(mVertexLocation, 3, GL_FLOAT, GL_FALSE, 0, CUBE_VERTICES); | ||
| 297 | + glEnableVertexAttribArray(mVertexLocation); | ||
| 298 | + glVertexAttribPointer(mVertexColourLocation, 3, GL_FLOAT, GL_FALSE, 0, CUBE_COLOURS); | ||
| 299 | + glEnableVertexAttribArray(mVertexColourLocation); | ||
| 300 | + glUniformMatrix4fv(mProjectionLocation, 1, GL_FALSE, mProjectionMatrix); | ||
| 301 | + glUniformMatrix4fv(mModelViewLocation, 1, GL_FALSE, mModelViewMatrix); | ||
| 302 | + glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, CUBE_INDICES); | ||
| 303 | + angle += 1; | ||
| 304 | + if(angle > 360) | ||
| 305 | + { | ||
| 306 | + angle -= 360; | ||
| 307 | + } | ||
| 308 | +} |
examples/drawable-actor/native-renderer.h
0 → 100644
| 1 | +#ifndef DALI_PROJECT_NATIVE_RENDERER_H | ||
| 2 | +#define DALI_PROJECT_NATIVE_RENDERER_H | ||
| 3 | + | ||
| 4 | +/* | ||
| 5 | + * Copyright (c) 2020 Samsung Electronics Co., Ltd. | ||
| 6 | + * | ||
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 8 | + * you may not use this file except in compliance with the License. | ||
| 9 | + * You may obtain a copy of the License at | ||
| 10 | + * | ||
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 12 | + * | ||
| 13 | + * Unless required by applicable law or agreed to in writing, software | ||
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 16 | + * See the License for the specific language governing permissions and | ||
| 17 | + * limitations under the License. | ||
| 18 | + * | ||
| 19 | + */ | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * This is demo that doesn't use DALi directly as if it's | ||
| 23 | + * a separate non-DALi app (so not using DALi math etc.) | ||
| 24 | + */ | ||
| 25 | + | ||
| 26 | +#include <dali/public-api/signals/render-callback.h> | ||
| 27 | + | ||
| 28 | +#include <cmath> | ||
| 29 | +#include <GLES3/gl3.h> | ||
| 30 | + | ||
| 31 | +class NativeRenderer | ||
| 32 | +{ | ||
| 33 | +public: | ||
| 34 | + | ||
| 35 | + NativeRenderer( uint32_t width, uint32_t height); | ||
| 36 | + | ||
| 37 | + bool OnRender( const Dali::RenderCallbackInput& input ); | ||
| 38 | + | ||
| 39 | + void PrepareShader(); | ||
| 40 | + | ||
| 41 | + void Setup( int width, int height); | ||
| 42 | + | ||
| 43 | + void RenderCube( const Dali::RenderCallbackInput& input ); | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * Creates GL program from shader sources | ||
| 47 | + */ | ||
| 48 | + GLuint CreateProgram(const char* vertexSource, const char* fragmentSource); | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * Loads shader | ||
| 52 | + */ | ||
| 53 | + GLuint LoadShader(GLenum shaderType, const char* shaderSource); | ||
| 54 | + | ||
| 55 | + enum class State | ||
| 56 | + { | ||
| 57 | + INIT, | ||
| 58 | + RENDER | ||
| 59 | + }; | ||
| 60 | + | ||
| 61 | +private: | ||
| 62 | + | ||
| 63 | + State mState {State::INIT}; | ||
| 64 | + | ||
| 65 | + GLuint mProgramId{0u}; | ||
| 66 | + | ||
| 67 | + GLint mVertexLocation{}; | ||
| 68 | + GLint mVertexColourLocation{}; | ||
| 69 | + GLint mProjectionLocation{}; | ||
| 70 | + GLint mModelViewLocation{}; | ||
| 71 | + | ||
| 72 | + float mModelViewMatrix[16]; | ||
| 73 | + float mProjectionMatrix[16]; | ||
| 74 | + | ||
| 75 | + uint32_t mWidth; | ||
| 76 | + uint32_t mHeight; | ||
| 77 | +}; | ||
| 78 | + | ||
| 79 | +#endif // DALI_PROJECT_NATIVE_RENDERER_H |
packaging/com.samsung.dali-demo.spec
| @@ -24,6 +24,8 @@ BuildRequires: pkgconfig(dali2-adaptor) | @@ -24,6 +24,8 @@ BuildRequires: pkgconfig(dali2-adaptor) | ||
| 24 | BuildRequires: pkgconfig(dali2-toolkit) | 24 | BuildRequires: pkgconfig(dali2-toolkit) |
| 25 | BuildRequires: pkgconfig(dali2-scene-loader) | 25 | BuildRequires: pkgconfig(dali2-scene-loader) |
| 26 | BuildRequires: pkgconfig(libtzplatform-config) | 26 | BuildRequires: pkgconfig(libtzplatform-config) |
| 27 | +BuildRequires: pkgconfig(gles20) | ||
| 28 | +BuildRequires: pkgconfig(glesv2) | ||
| 27 | 29 | ||
| 28 | %description | 30 | %description |
| 29 | The OpenGLES Canvas Core Demo is a collection of examples and demonstrations | 31 | The OpenGLES Canvas Core Demo is a collection of examples and demonstrations |
resources/po/en_GB.po
| @@ -79,6 +79,9 @@ msgstr "Dissolve Effect" | @@ -79,6 +79,9 @@ msgstr "Dissolve Effect" | ||
| 79 | msgid "DALI_DEMO_STR_TITLE_DRAG_AND_DROP" | 79 | msgid "DALI_DEMO_STR_TITLE_DRAG_AND_DROP" |
| 80 | msgstr "Drag and Drop" | 80 | msgstr "Drag and Drop" |
| 81 | 81 | ||
| 82 | +msgid "DALI_DEMO_STR_TITLE_DRAWABLE_ACTOR" | ||
| 83 | +msgstr "DrawableActor" | ||
| 84 | + | ||
| 82 | msgid "DALI_DEMO_STR_TITLE_EFFECTS_VIEW" | 85 | msgid "DALI_DEMO_STR_TITLE_EFFECTS_VIEW" |
| 83 | msgstr "Effects View" | 86 | msgstr "Effects View" |
| 84 | 87 |
resources/po/en_US.po
| @@ -79,6 +79,9 @@ msgstr "Dissolve Effect" | @@ -79,6 +79,9 @@ msgstr "Dissolve Effect" | ||
| 79 | msgid "DALI_DEMO_STR_TITLE_DRAG_AND_DROP" | 79 | msgid "DALI_DEMO_STR_TITLE_DRAG_AND_DROP" |
| 80 | msgstr "Drag and Drop" | 80 | msgstr "Drag and Drop" |
| 81 | 81 | ||
| 82 | +msgid "DALI_DEMO_STR_TITLE_DRAWABLE_ACTOR" | ||
| 83 | +msgstr "DrawableActor" | ||
| 84 | + | ||
| 82 | msgid "DALI_DEMO_STR_TITLE_EFFECTS_VIEW" | 85 | msgid "DALI_DEMO_STR_TITLE_EFFECTS_VIEW" |
| 83 | msgstr "Effects View" | 86 | msgstr "Effects View" |
| 84 | 87 |
shared/dali-demo-strings.h
| @@ -62,6 +62,7 @@ extern "C" | @@ -62,6 +62,7 @@ extern "C" | ||
| 62 | #define DALI_DEMO_STR_TITLE_CUBE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CUBE_TRANSITION") | 62 | #define DALI_DEMO_STR_TITLE_CUBE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_CUBE_TRANSITION") |
| 63 | #define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION") | 63 | #define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION") |
| 64 | #define DALI_DEMO_STR_TITLE_DRAG_AND_DROP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DRAG_AND_DROP") | 64 | #define DALI_DEMO_STR_TITLE_DRAG_AND_DROP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DRAG_AND_DROP") |
| 65 | +#define DALI_DEMO_STR_TITLE_DRAWABLE_ACTOR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_DRAWABLE_ACTOR") | ||
| 65 | #define DALI_DEMO_STR_TITLE_EFFECTS_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EFFECTS_VIEW") | 66 | #define DALI_DEMO_STR_TITLE_EFFECTS_VIEW dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EFFECTS_VIEW") |
| 66 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EMOJI_TEXT") | 67 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_EMOJI_TEXT") |
| 67 | #define DALI_DEMO_STR_TITLE_FPP_GAME dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FPP_GAME") | 68 | #define DALI_DEMO_STR_TITLE_FPP_GAME dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_FPP_GAME") |
| @@ -170,6 +171,7 @@ extern "C" | @@ -170,6 +171,7 @@ extern "C" | ||
| 170 | #define DALI_DEMO_STR_TITLE_DEFERRED_SHADING "Deferred Shading" | 171 | #define DALI_DEMO_STR_TITLE_DEFERRED_SHADING "Deferred Shading" |
| 171 | #define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION "Dissolve Effect" | 172 | #define DALI_DEMO_STR_TITLE_DISSOLVE_TRANSITION "Dissolve Effect" |
| 172 | #define DALI_DEMO_STR_TITLE_DRAG_AND_DROP "Drag and Drop" | 173 | #define DALI_DEMO_STR_TITLE_DRAG_AND_DROP "Drag and Drop" |
| 174 | +#define DALI_DEMO_STR_TITLE_DRAWABLE_ACTOR "DrawableActor" | ||
| 173 | #define DALI_DEMO_STR_TITLE_EFFECTS_VIEW "Effects View" | 175 | #define DALI_DEMO_STR_TITLE_EFFECTS_VIEW "Effects View" |
| 174 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" | 176 | #define DALI_DEMO_STR_TITLE_EMOJI_TEXT "Emoji Text" |
| 175 | #define DALI_DEMO_STR_TITLE_FPP_GAME "First Person Game" | 177 | #define DALI_DEMO_STR_TITLE_FPP_GAME "First Person Game" |