• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *
3  * Copyright 2010, 2011 BMW Car IT GmbH
4  * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5  *
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 #ifndef _OPENGLES2APP_H
21 #define _OPENGLES2APP_H
22 
23 #include "wayland-client.h"
24 #include "wayland-egl.h"
25 #include <GLES2/gl2.h>
26 
27 #include <ivi-application-client-protocol.h>
28 #include <EGL/egl.h>
29 
30 struct SurfaceConfiguration
31 {
32     unsigned int surfaceId;
33     unsigned int surfaceWidth;
34     unsigned int surfaceHeight;
35     unsigned int sync;
36     bool nosky;
37 };
38 
39 class OpenGLES2App
40 {
41 public:
42     OpenGLES2App(float fps, float animationSpeed, SurfaceConfiguration* config);
43     virtual ~OpenGLES2App();
44 
45     void mainloop();
46 
47     static void registry_handle_global(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version);
48     static void frame_listener_func(void *data, struct wl_callback *callback, uint32_t time);
49 
50 protected:
51     virtual void update(int currentTimeInMs, int elapsedTimeInMs) = 0;
52     virtual void render() = 0;
53     void swapBuffers();
54 
55 private:
56     bool createWLContext(SurfaceConfiguration* config);
57     void destroyWLContext();
58 
59     bool createEGLContext(SurfaceConfiguration* config);
60     void destroyEglContext();
61 
62     unsigned int GetTickCount();
63 
64 protected:
65     float m_framesPerSecond;
66     float m_animationSpeed;
67     unsigned int m_timerIntervalInMs;
68 
69     struct EglContextStruct
70     {
71 	EGLNativeDisplayType nativeDisplay;
72 	EGLNativeWindowType  nativeWindow;
73         EGLDisplay eglDisplay;
74         EGLConfig eglConfig;
75         EGLSurface eglSurface;
76         EGLContext eglContext;
77     };
78 
79     EglContextStruct m_eglContextStruct;
80 
81 public:
82     typedef struct t_wlContextStruct
83     {
84         struct wl_display* wlDisplay;
85         struct wl_registry* wlRegistry;
86         struct wl_compositor* wlCompositor;
87 	struct wl_egl_window* wlNativeWindow;
88         struct wl_surface* wlSurface;
89         struct wl_shell* wlShell;
90         struct wl_shell_surface* wlShellSurface;
91         struct ivi_application* iviApp;
92         struct ivi_surface* iviSurface;
93         int width;
94         int height;
95 
96         uint32_t mask;
97 
98     } WLContextStruct;
99 
100 protected:
101     WLContextStruct m_wlContextStruct;
102 
103     unsigned int m_surfaceId;
104 };
105 
106 #endif /* _OPENGLES2APP_H */
107