DirectRendering demo
[platform/core/uifw/dali-demo.git] / examples / drawable-actor / native-renderer.h
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