2 Simple DirectMedia Layer
3 Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
4 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
22 #include "../../SDL_internal.h"
24 #if SDL_VIDEO_OPENGL_EGL
26 #include "SDL_tizenvideo.h"
27 #include "SDL_tizenopengles.h"
28 #include "SDL_tizenwindow.h"
29 #include "SDL_tizenevents_c.h"
31 #include "SDL_ecore_ipc.h"
35 #include "SDL_opengl.h"
36 #endif /* SDL_VIDEO_OPENGL */
38 #if SDL_VIDEO_OPENGL_ES
39 #include "SDL_opengles.h"
40 #endif /* SDL_VIDEO_OPENGL_ES */
42 /* GL and GLES2 headers conflict on Linux 32 bits */
43 #if SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL
44 #include "SDL_opengles2.h"
45 #endif /* SDL_VIDEO_OPENGL_ES2 && !SDL_VIDEO_OPENGL */
48 GLfloat vVertices[18]={
57 GLfloat vCoord[12] = {
66 /* EGL implementation of SDL OpenGL ES support */
67 typedef struct GLES2_Context
69 #define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
70 #include "../../render/opengles2/SDL_gles2funcs.h"
77 Tizen_GLES_LoadLibrary(_THIS, const char *path)
81 ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)ecore_wl_display_get());
85 static int LoadContext(GLES2_Context * data)
87 #define SDL_PROC(ret,func,params) \
89 data->func = SDL_GL_GetProcAddress(#func); \
90 if ( ! data->func ) { \
91 return SDL_SetError("Couldn't load GLES2 function %s: %s\n", #func, SDL_GetError()); \
95 #include "../../render/opengles2/SDL_gles2funcs.h"
101 static GLuint LoadShader(GLES2_Context* Mainctx, const char *shaderSrc, GLenum type)
106 shader = Mainctx->glCreateShader(type);
107 SDL_Log("shader == %d", shader);
110 Mainctx->glShaderSource(shader, 1, &shaderSrc, NULL);
111 Mainctx->glCompileShader(shader);
112 Mainctx->glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
116 Mainctx->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
119 char* infoLog = (char*)(malloc(sizeof(char) * infoLen));
120 Mainctx->glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
121 SDL_Log("Error compiling shader: %s", infoLog );
124 Mainctx->glDeleteShader(shader);
131 SharedFileInfo fileInfo;
133 unsigned int textureID;
134 unsigned int indicator_vbo[4], indicator_ibo[4];
135 unsigned short indicator_index;
138 void Tizen_glTexImage2d()
141 GLES2_Context Mainctx;
142 LoadContext(&Mainctx);
144 Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
145 Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,
146 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address);
149 static int Indicator_GLES_Init(SDL_Window* window)
151 SDL_WindowData *wind = window->driverdata;
152 ecore_wl_indicator_visible_type_set(wind->window, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
153 ecore_wl_window_indicator_opacity_set(wind->window, ECORE_WL_INDICATOR_OPAQUE);
154 ecore_wl_window_indicator_state_set(wind->window, ECORE_WL_INDICATOR_STATE_ON);
156 Ecore_Ipc_Server* IpcServer = serverConnection("elm_indicator", &fileInfo);
159 SDL_Log("Fail to connect elm_indicator!\n");
163 GLchar vShaderStr[] =
164 "attribute vec4 vVertices;\n"
165 "attribute vec2 vCoord;\n"
166 "varying vec2 Coord;\n"
169 " gl_Position = vVertices;\n"
173 GLchar fShaderStr[] =
174 "precision mediump float;\n"
175 "varying vec2 Coord;\n"
176 "uniform sampler2D s_texture;\n"
179 " gl_FragColor = texture2D(s_texture,Coord);\n"
182 ecore_main_loop_iterate();
185 GLuint fragmentShader;
189 GLES2_Context Mainctx;
190 LoadContext(&Mainctx);
192 vertexShader = LoadShader(&Mainctx, vShaderStr, GL_VERTEX_SHADER);
193 fragmentShader = LoadShader(&Mainctx, fShaderStr, GL_FRAGMENT_SHADER);
194 SDL_Log("The vertex shader is %d", vertexShader);
195 SDL_Log("The fragment shader is %d", fragmentShader);
197 programObject = Mainctx.glCreateProgram();
198 if(programObject == 0)
201 Mainctx.glAttachShader(programObject, vertexShader);
202 Mainctx.glAttachShader(programObject, fragmentShader);
204 Mainctx.glBindAttribLocation(programObject, 0, "vVertices");
205 Mainctx.glBindAttribLocation(programObject, 1, "vCoord");
207 Mainctx.glLinkProgram(programObject);
208 Mainctx.glGetProgramiv(programObject, GL_LINK_STATUS, &linked);
213 Mainctx.glGetProgramiv(programObject, GL_INFO_LOG_LENGTH, &infoLen);
216 char* infoLog = (char*)(malloc(sizeof(char) * infoLen));
217 Mainctx.glGetProgramInfoLog(programObject, infoLen, NULL, infoLog);
218 SDL_Log("Error linking program: %s", infoLog);
221 Mainctx.glDeleteProgram(programObject);
226 Mainctx.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
227 Mainctx.glEnable(GL_DEPTH_TEST);
229 /* Generate buffer object names */
230 Mainctx.glGenBuffers(4, indicator_vbo);
231 /* Bind a named buffer object */
232 Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[0]);
233 /* Ceates and initializes a buffer object's data store */
234 Mainctx.glBufferData(GL_ARRAY_BUFFER, 18 * 4, vVertices, GL_STATIC_DRAW);
236 /* Generate buffer object names */
237 Mainctx.glGenBuffers(4, indicator_ibo);
238 /* Bind a named buffer object */
239 Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[0]);
240 /* Ceates and initializes a buffer object's data store */
241 Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW);
245 Mainctx.glGenTextures(1, &textureID);
246 Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
248 Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
249 Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
250 Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
251 Mainctx.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
253 Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address);
255 window->indicator_show = SDL_TRUE;
256 window->last_indicator_showtime = SDL_GetTicks();
261 Tizen_GLES_CreateContext(_THIS, SDL_Window *window)
263 SDL_GLContext context;
265 context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
267 if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS))
269 if(!Indicator_GLES_Init(window))
271 SDL_Log("Indicator GLES init error!");
279 Tizen_GLES_SwapWindow(_THIS, SDL_Window *window)
281 SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata;
282 if (wdata->received_rotation == 1) {
283 ecore_wl_window_rotation_change_done_send(wdata->window);
284 wdata->received_rotation = 0;
287 if(window->last_indicator_showtime + 3000 < SDL_GetTicks())
289 window->indicator_show = SDL_FALSE;
292 if(!(window->flags & SDL_WINDOW_FULLSCREEN) && !(window->flags & SDL_WINDOW_BORDERLESS) && window->indicator_show)
294 GLES2_Context Mainctx;
295 LoadContext(&Mainctx);
296 Mainctx.glUseProgram(programObject);
298 Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[window->indicator_type]);
299 Mainctx.glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
301 Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[window->indicator_type]);
302 Mainctx.glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
304 Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address);
305 Mainctx.glEnableVertexAttribArray(0);
306 Mainctx.glEnableVertexAttribArray(1);
307 Mainctx.glDrawArrays(GL_TRIANGLES, 0, 6);
310 SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
315 Tizen_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
319 if (window && context) {
320 ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
322 ret = SDL_EGL_MakeCurrent(_this, NULL, NULL);
329 Tizen_GLES_DeleteContext(_THIS, SDL_GLContext context)
331 SDL_EGL_DeleteContext(_this, context);
335 SDL_IndicatorProcessEvent(SDL_Event * event, SDL_Window *window)
337 GLES2_Context Mainctx;
338 LoadContext(&Mainctx);
340 if(event->type == SDL_ROTATEEVENT)
342 window->indicator_type = ((int)event->user.data1) / 90;
343 if( window->indicator_type == 0)
345 SDL_Log("===rotate 0 degree!\n");
348 vVertices[3] = -1.0f;
349 vVertices[4] = 0.92f;
351 vVertices[7] = 0.92f;
353 vVertices[10] = 1.0f;
354 vVertices[12] = -1.0f;
355 vVertices[13] = 1.0f;
356 vVertices[15] = -1.0f;
357 vVertices[16] = 0.92f;
373 else if(window->indicator_type == 1)
375 SDL_Log("===rotate 90 degree!\n");
376 vVertices[0] = -0.86f;
378 vVertices[3] = -0.86f;
379 vVertices[4] = -1.0f;
380 vVertices[6] = -1.0f;
382 vVertices[9] = -1.0f;
383 vVertices[10] = -1.0f;
384 vVertices[12] = -0.86f;
385 vVertices[13] = -1.0f;
386 vVertices[15] = -1.0f;
387 vVertices[16] = 1.0f;
402 else if(window->indicator_type == 2)
404 SDL_Log("===rotate 180 degree!\n");
405 vVertices[0] = -1.0f;
406 vVertices[1] = -1.0f;
407 vVertices[3] = -1.0f;
408 vVertices[4] = -0.92f;
410 vVertices[7] = -1.0f;
412 vVertices[10] = -0.92f;
413 vVertices[12] = -1.0f;
414 vVertices[13] = -0.92f;
415 vVertices[15] = 1.0f;
416 vVertices[16] = -1.0f;
431 else if(window->indicator_type == 3)
433 SDL_Log("===rotate 270 degree!\n");
436 vVertices[3] = 0.86f;
439 vVertices[7] = -1.0f;
440 vVertices[9] = 0.86f;
441 vVertices[10] = -1.0f;
442 vVertices[12] = 0.86f;
443 vVertices[13] = 1.0f;
444 vVertices[15] = 1.0f;
445 vVertices[16] = -1.0f;
461 Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_vbo[window->indicator_type]);
462 Mainctx.glBufferData(GL_ARRAY_BUFFER, 18 * 4, vVertices, GL_STATIC_DRAW);
463 Mainctx.glBindBuffer(GL_ARRAY_BUFFER, indicator_ibo[window->indicator_type]);
464 Mainctx.glBufferData(GL_ARRAY_BUFFER, 12 * 4, vCoord, GL_STATIC_DRAW);
466 Mainctx.glBindTexture(GL_TEXTURE_2D, textureID);
468 Mainctx.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fileInfo.ImageWidth, fileInfo.ImageHeight,0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char*)fileInfo.sharedFile->address);
469 window->indicator_show = SDL_TRUE;
470 window->last_indicator_showtime = SDL_GetTicks();
474 #endif /* SDL_VIDEO_DRIVER_TIZEN && SDL_VIDEO_OPENGL_EGL */
476 /* vi: set ts=4 sw=4 expandtab: */