|
64
|
1 |
/*
|
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
3 |
* All rights reserved.
|
|
|
4 |
* This component and the accompanying materials are made available
|
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
|
6 |
* which accompanies this distribution, and is available
|
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
|
8 |
*
|
|
|
9 |
* Initial Contributors:
|
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
|
11 |
*
|
|
|
12 |
* Contributors:
|
|
|
13 |
*
|
|
|
14 |
* Description:
|
|
|
15 |
*
|
|
|
16 |
*/
|
|
|
17 |
#include <stdio.h>
|
|
|
18 |
#include <stdlib.h>
|
|
|
19 |
#include <GLES2/gl2.h>
|
|
|
20 |
#include <math.h>
|
|
|
21 |
#include <string.h>
|
|
|
22 |
|
|
|
23 |
#include "plugininterface.h"
|
|
|
24 |
#include "shader.h"
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
static char* plugindir = 0;
|
|
|
28 |
|
|
|
29 |
static GLuint vertexShader = 0;
|
|
|
30 |
static GLuint fragmentShader = 0;
|
|
|
31 |
static GLuint program = 0;
|
|
|
32 |
|
|
|
33 |
static GLuint vbo = 0;
|
|
|
34 |
static GLuint ibo = 0;
|
|
|
35 |
|
|
|
36 |
static GLint blob1;
|
|
|
37 |
static GLint blob2;
|
|
|
38 |
static GLint blob3;
|
|
|
39 |
|
|
|
40 |
static GLint offset;
|
|
|
41 |
static GLint threshold;
|
|
|
42 |
static GLint aspect;
|
|
|
43 |
|
|
|
44 |
static float time = 0.0f;
|
|
|
45 |
|
|
|
46 |
static int display_w = 0;
|
|
|
47 |
static int display_h = 0;
|
|
|
48 |
|
|
|
49 |
static const GLushort indices[6] =
|
|
|
50 |
{
|
|
|
51 |
0,1,2,0,2,3
|
|
|
52 |
};
|
|
|
53 |
|
|
|
54 |
static const GLfloat vertexattribs[] =
|
|
|
55 |
{
|
|
|
56 |
-1.0f,1.0f,0.0f,
|
|
|
57 |
-1.0f,-1.0f,0.0f,
|
|
|
58 |
1.0f,-1.0f,0.0f,
|
|
|
59 |
1.0f,1.0f,0.0f,
|
|
|
60 |
};
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
const EGLint attrib_list[] =
|
|
|
64 |
{
|
|
|
65 |
EGL_BUFFER_SIZE, 32,
|
|
|
66 |
EGL_DEPTH_SIZE, 16,
|
|
|
67 |
EGL_STENCIL_SIZE, 0,
|
|
|
68 |
EGL_SAMPLE_BUFFERS, 0,
|
|
|
69 |
EGL_SAMPLES, 0,
|
|
|
70 |
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
|
|
71 |
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
|
|
72 |
EGL_NONE
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
const EGLint* getpreferredconfig (void)
|
|
|
76 |
{
|
|
|
77 |
return attrib_list;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
void setdisplaydimensions(int width, int height)
|
|
|
81 |
{
|
|
|
82 |
display_w = width;
|
|
|
83 |
display_h = height;
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
void produceframe(void)
|
|
|
87 |
{
|
|
|
88 |
glUniform3f(blob1,0.76000f+((sin(time))/2.0f),0.30000f+((cos(time*0.4f))/2.0f),4.34000f);
|
|
|
89 |
glUniform3f(blob2,0.44000f+((sin(0.4f*time))/2.0f),0.64000f+((cos(time))/2.0f),2.26000f);
|
|
|
90 |
glUniform3f(blob3,0.30000f+((sin(0.7f*time))/2.0f),0.34000f+((cos(time*0.9f))/2.0f),1.84000f);
|
|
|
91 |
|
|
|
92 |
time+=0.02f;
|
|
|
93 |
glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_SHORT,0);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
int gpuresourcesavailable(int available)
|
|
|
98 |
{
|
|
|
99 |
GLint linkStatus = 0;
|
|
|
100 |
float aspectratio = 0.0f;
|
|
|
101 |
if (available)
|
|
|
102 |
{
|
|
|
103 |
|
|
|
104 |
vertexShader = LoadAndCompileShader(plugindir, "refvertexshader.vsh",GL_VERTEX_SHADER);
|
|
|
105 |
fragmentShader = LoadAndCompileShader(plugindir, "reffragmentshader.fsh",GL_FRAGMENT_SHADER);
|
|
|
106 |
if (!vertexShader || !fragmentShader)
|
|
|
107 |
{
|
|
|
108 |
return -1;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
program = glCreateProgram();
|
|
|
112 |
glAttachShader(program, vertexShader);
|
|
|
113 |
glAttachShader(program, fragmentShader);
|
|
|
114 |
glBindAttribLocation(program, 0, "vPosition");
|
|
|
115 |
|
|
|
116 |
glLinkProgram(program);
|
|
|
117 |
glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
|
|
|
118 |
if (!linkStatus)
|
|
|
119 |
{
|
|
|
120 |
glDeleteProgram(program);
|
|
|
121 |
|
|
|
122 |
return -1;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
glClearColor(0,0,0,0);
|
|
|
126 |
glViewport (0, 0, display_w, display_h);
|
|
|
127 |
|
|
|
128 |
|
|
|
129 |
glGenBuffers( 1, &vbo);
|
|
|
130 |
glGenBuffers( 1, &ibo);
|
|
|
131 |
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
|
132 |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
|
|
|
133 |
|
|
|
134 |
glBufferData(GL_ARRAY_BUFFER,3*4*sizeof(GLfloat),vertexattribs,GL_STATIC_DRAW);
|
|
|
135 |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6*sizeof(GLushort),indices,GL_STATIC_DRAW);
|
|
|
136 |
|
|
|
137 |
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
|
|
138 |
|
|
|
139 |
glEnableVertexAttribArray(0);
|
|
|
140 |
|
|
|
141 |
glUseProgram(program);
|
|
|
142 |
glEnableVertexAttribArray(0);
|
|
|
143 |
|
|
|
144 |
blob1 = glGetUniformLocation(program, "blob1");
|
|
|
145 |
blob2 = glGetUniformLocation(program, "blob2");
|
|
|
146 |
blob3 = glGetUniformLocation(program, "blob3");
|
|
|
147 |
aspect = glGetUniformLocation(program, "aspect");
|
|
|
148 |
|
|
|
149 |
offset = glGetUniformLocation(program, "offset");
|
|
|
150 |
threshold = glGetUniformLocation(program, "threshold");
|
|
|
151 |
|
|
|
152 |
aspectratio = ((float)display_w)/((float)display_h);
|
|
|
153 |
|
|
|
154 |
glUniform1f(offset,34.78935f);
|
|
|
155 |
glUniform1f(threshold,2.49860f);
|
|
|
156 |
glUniform1f(aspect,aspectratio);
|
|
|
157 |
}
|
|
|
158 |
else
|
|
|
159 |
{
|
|
|
160 |
// TODO: free resources...
|
|
|
161 |
}
|
|
|
162 |
return 0;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
int initialize(const char* path, unsigned int maxgpumemusage)
|
|
|
166 |
{
|
|
|
167 |
maxgpumemusage=maxgpumemusage; // not used, just to remove compiler warning
|
|
|
168 |
plugindir = strdup(path);
|
|
|
169 |
return 0;
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
void destroy()
|
|
|
173 |
{
|
|
|
174 |
free(plugindir);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
int extension(int value, void* ptr)
|
|
|
178 |
{
|
|
|
179 |
value=value; ptr=ptr; // not used, just to remove compiler warning
|
|
|
180 |
return 0;
|
|
|
181 |
}
|
|
|
182 |
|
|
|
183 |
EXPORT_C void* getinterface(int version)
|
|
|
184 |
{
|
|
|
185 |
plugin_export_v1_t* interface = NULL;
|
|
|
186 |
if (version == 1)
|
|
|
187 |
{
|
|
|
188 |
interface = (plugin_export_v1_t*)malloc(sizeof(plugin_export_v1_t));
|
|
|
189 |
if (interface)
|
|
|
190 |
{
|
|
|
191 |
memset(interface, 0, sizeof(plugin_export_v1_t));
|
|
|
192 |
|
|
|
193 |
// bind our functions to the interface
|
|
|
194 |
interface->getpreferredconfig = getpreferredconfig;
|
|
|
195 |
interface->setdisplaydimensions = setdisplaydimensions;
|
|
|
196 |
interface->produceframe = produceframe;
|
|
|
197 |
interface->gpuresourcesavailable = gpuresourcesavailable;
|
|
|
198 |
interface->initialize = initialize;
|
|
|
199 |
interface->destroy = destroy;
|
|
|
200 |
interface->desiredsensors = 0;
|
|
|
201 |
interface->receivesensordata = 0;
|
|
|
202 |
interface->setfaded = 0;
|
|
|
203 |
interface->extension = extension;
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
return interface;
|
|
|
207 |
}
|