|
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 "javax_microedition_m3g_Graphics3D.h" |
|
18 |
|
19 /* |
|
20 * Must be executed in UI thread |
|
21 */ |
|
22 JNIEXPORT jboolean JNICALL Java_javax_microedition_m3g_Graphics3D__1isProperRenderer |
|
23 (JNIEnv* /*aEnv*/, jclass) |
|
24 { |
|
25 /* EGLContext ctx; |
|
26 EGLConfig config; |
|
27 EGLSurface surf; |
|
28 EGLint attrib[5]; |
|
29 EGLint numConfigs; |
|
30 bool isProperRenderer; |
|
31 |
|
32 // initialize EGL and create a temporary surface & context for reading |
|
33 // the renderer string |
|
34 eglInitialize(eglGetDisplay(EGL_DEFAULT_DISPLAY), NULL, NULL); |
|
35 |
|
36 attrib[0] = EGL_SURFACE_TYPE; |
|
37 attrib[1] = EGL_PBUFFER_BIT; |
|
38 attrib[2] = EGL_NONE; |
|
39 |
|
40 eglChooseConfig(eglGetDisplay(0), attrib, &config, 1, &numConfigs); |
|
41 |
|
42 ctx = eglCreateContext(eglGetDisplay(0), config, NULL, NULL); |
|
43 |
|
44 attrib[0] = EGL_WIDTH; |
|
45 attrib[1] = 2; |
|
46 attrib[2] = EGL_HEIGHT; |
|
47 attrib[3] = 2; |
|
48 attrib[4] = EGL_NONE; |
|
49 |
|
50 surf = eglCreatePbufferSurface(eglGetDisplay(0), config, attrib); |
|
51 eglMakeCurrent(eglGetDisplay(0), surf, surf, ctx); |
|
52 |
|
53 // We check if proper renderer is used and return value which is stored |
|
54 // on java side and passed to fuctions where is decided if m3g renders |
|
55 // into mutable off-screen image or into framebuffer (see |
|
56 // Java_javax_microedition_m3g_Graphics3D__1bindGraphics and |
|
57 // releaseGraphicsTarget). |
|
58 const GLubyte *info; |
|
59 info = glGetString(GL_RENDERER); // get the renderer string |
|
60 |
|
61 // check if "MBX" substring is found |
|
62 if ( !info || strstr((const char *)info, "MBX")) |
|
63 { |
|
64 // HW renderer detected. |
|
65 // If "MBX" HW is detected we must reset alpha for mutable off-screen |
|
66 // images by hand (see releaseGraphicsTarget). |
|
67 isProperRenderer = false; |
|
68 } |
|
69 else |
|
70 { |
|
71 // Other renderers can use m3g core API m3gSetAlphaWrite without |
|
72 // performance drop. |
|
73 isProperRenderer = true; |
|
74 } |
|
75 |
|
76 // destroy the temporary surface & context |
|
77 eglMakeCurrent(eglGetDisplay(0), NULL, NULL, NULL); |
|
78 eglDestroySurface(eglGetDisplay(0), surf); |
|
79 eglDestroyContext(eglGetDisplay(0), ctx); |
|
80 |
|
81 return isProperRenderer;*/ |
|
82 return false; |
|
83 } |
|
84 |
|
85 /* |
|
86 * Must be executed in UI thread |
|
87 */ |
|
88 JNIEXPORT jboolean JNICALL Java_javax_microedition_m3g_Graphics3D__1bindGraphics |
|
89 (JNIEnv* aEnv, jclass, jint aCtx, |
|
90 jint aSurfaceHandle, jint aClipX, jint aClipY, jint aClipW, jint aClipH, |
|
91 jboolean aDepth, jint aHintBits, jboolean aIsProperRenderer) |
|
92 { |
|
93 M3GRenderContext ctx = (M3GRenderContext)aCtx; |
|
94 |
|
95 // Fetch the native peer of our target object |
|
96 Java::GFX::WindowSurface* wsurf = reinterpret_cast<Java::GFX::WindowSurface*>(aSurfaceHandle); |
|
97 |
|
98 wsurf->bind(Java::GFX::WsTypeQtImage | Java::GFX::WsTypeEglSurface); |
|
99 jboolean isImageTarget = false; /*cmidGraphics->IsImageTarget();*/ |
|
100 |
|
101 M3G_DO_LOCK |
|
102 |
|
103 /* |
|
104 * Get the physical screen size and pass it to m3gcore. This affects (improves) the performance |
|
105 * as the canvas frambuffer (rendering target) is larger than the physical screen size in |
|
106 * devices that have more than one screen orientation, causing extra copying operations. |
|
107 * |
|
108 * This will improve m3g performance and suppresses extra bitmap copying. |
|
109 */ |
|
110 |
|
111 //TRect screenRect = CCoeEnv::Static()->ScreenDevice()->SizeInPixels(); |
|
112 |
|
113 eglWaitNative(EGL_CORE_NATIVE_ENGINE); |
|
114 |
|
115 if (m3gSetRenderBuffers((M3GRenderContext)aCtx, aDepth ? |
|
116 M3G_COLOR_BUFFER_BIT|M3G_DEPTH_BUFFER_BIT : |
|
117 M3G_COLOR_BUFFER_BIT) && m3gSetRenderHints((M3GRenderContext)aCtx, aHintBits)) |
|
118 { |
|
119 |
|
120 switch (wsurf->getType()) |
|
121 { |
|
122 case Java::GFX::WsTypeQtImage: |
|
123 { |
|
124 QImage* bitmap = wsurf->getQtImage(); |
|
125 M3GPixelFormat format = mapQtPixelformat(bitmap->format()); |
|
126 m3gBindMemoryTarget((M3GRenderContext)aCtx, bitmap->bits(), (M3Guint)bitmap->width(), (M3Guint)bitmap->height(), format, (M3Guint)(bitmap->width() * 4), NULL); |
|
127 break; |
|
128 } |
|
129 case Java::GFX::WsTypeEglSurface: |
|
130 { |
|
131 if( eglQueryAPI() != EGL_OPENGL_ES_API ) |
|
132 { |
|
133 eglMakeCurrent( EGL_DEFAULT_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ); |
|
134 eglBindAPI( EGL_OPENGL_ES_API ); |
|
135 } |
|
136 m3gBindEGLSurfaceTarget((M3GRenderContext)aCtx, wsurf->getEglSurface() ); |
|
137 break; |
|
138 } |
|
139 default: |
|
140 M3G_RAISE_EXCEPTION(aEnv, "java/lang/IllegalArgumentException"); |
|
141 break; |
|
142 } |
|
143 |
|
144 // Pass the physical screen size to m3gcore |
|
145 //m3gSetDisplayArea(aCtx, screenRect.Width(), screenRect.Height()); |
|
146 |
|
147 m3gSetClipRect((M3GRenderContext)aCtx, aClipX, aClipY, aClipW, aClipH); |
|
148 m3gSetViewport((M3GRenderContext)aCtx, aClipX, aClipY, aClipW, aClipH); |
|
149 } |
|
150 |
|
151 M3G_DO_UNLOCK(aEnv) |
|
152 |
|
153 if (isImageTarget && aIsProperRenderer) |
|
154 { |
|
155 m3gSetAlphaWrite(ctx, M3G_FALSE); |
|
156 } |
|
157 |
|
158 return isImageTarget; |
|
159 } |
|
160 |
|
161 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1setViewport |
|
162 (JNIEnv* aEnv, jclass, jint aHContext, jint aX, jint aY, |
|
163 jint aWidth, jint aHeight) |
|
164 { |
|
165 M3G_DO_LOCK |
|
166 m3gSetViewport((M3GRenderContext)aHContext, aX, aY, aWidth, aHeight); |
|
167 M3G_DO_UNLOCK(aEnv) |
|
168 } |
|
169 |
|
170 |
|
171 static void releaseTarget(M3GRenderContext aCtx) |
|
172 { |
|
173 eglWaitGL(); |
|
174 m3gReleaseTarget(aCtx); |
|
175 } |
|
176 |
|
177 |
|
178 /* |
|
179 static void releaseGraphicsTarget(M3GRenderContext aCtx, CMIDGraphics *aGraphics, |
|
180 TBool aIsImageTarget, TBool aIsProperRenderer ) |
|
181 { |
|
182 releaseTarget(aCtx); |
|
183 |
|
184 // clear alpha for only mutable off-screen images (not for canvas/GameCanvas |
|
185 // framebuffer) those images are indetified by aIsImageTarget argument |
|
186 if (aIsImageTarget) |
|
187 { |
|
188 if ( aIsProperRenderer ) |
|
189 { |
|
190 m3gSetAlphaWrite(aCtx, M3G_TRUE); |
|
191 } |
|
192 else |
|
193 { |
|
194 CFbsBitmap *bitmap = aGraphics->Bitmap(); |
|
195 |
|
196 const TInt width = bitmap->SizeInPixels().iWidth; |
|
197 const TInt height = bitmap->SizeInPixels().iHeight; |
|
198 TInt stride = bitmap->ScanLineLength(width, bitmap->DisplayMode()); |
|
199 |
|
200 bitmap->LockHeap(); |
|
201 |
|
202 for (TInt i = 0; i < height; i++) |
|
203 { |
|
204 const void *srcAddr = |
|
205 ((const char *) bitmap->DataAddress()) + i * stride; |
|
206 unsigned char *src = (unsigned char *) srcAddr; |
|
207 TInt count = width; |
|
208 while (count--) |
|
209 { |
|
210 src += 3; //jump to last byte - alpha channel |
|
211 //setting FF to alpha channel for non-canvas image targets |
|
212 *src |= 0xff; |
|
213 src++; |
|
214 } |
|
215 } |
|
216 |
|
217 bitmap->UnlockHeap(); |
|
218 } |
|
219 } |
|
220 } |
|
221 */ |
|
222 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1releaseGraphics |
|
223 (JNIEnv* aEnv, jclass, jint aHandle, |
|
224 jint aSurfaceHandle, jboolean /*aIsImageTarget*/, jboolean /*aIsProperRenderer*/) |
|
225 { |
|
226 M3G_DO_LOCK |
|
227 |
|
228 releaseTarget((M3GRenderContext)aHandle); |
|
229 |
|
230 // Release used target surface |
|
231 Java::GFX::WindowSurface* surf = reinterpret_cast<Java::GFX::WindowSurface*>(aSurfaceHandle); |
|
232 surf->release(); |
|
233 |
|
234 /* |
|
235 CMIDGraphics *cmidGraphics = MIDUnhandObject<CMIDGraphics>(aGraphicsHandle); |
|
236 |
|
237 CJavaM3GEventSource* eventSource = |
|
238 JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle); |
|
239 eventSource->ExecuteV(&releaseGraphicsTarget, ((M3GRenderContext) aHandle), |
|
240 cmidGraphics, ((TBool) aIsImageTarget), ((TBool) aIsProperRenderer) ); |
|
241 */ |
|
242 M3G_DO_UNLOCK(aEnv) |
|
243 } |
|
244 |
|
245 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1setCamera |
|
246 (JNIEnv* aEnv, jclass, jint aHContext, jint aHCamera, jbyteArray aTransform) |
|
247 { |
|
248 M3GMatrix *transform = NULL; |
|
249 if (aTransform) |
|
250 { |
|
251 transform = (Matrix *)(aEnv->GetByteArrayElements(aTransform, NULL)); |
|
252 if (transform == NULL) |
|
253 { |
|
254 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
255 return; |
|
256 } |
|
257 } |
|
258 |
|
259 M3G_DO_LOCK |
|
260 m3gSetCamera((M3GRenderContext) aHContext, (M3GCamera) aHCamera, transform); |
|
261 M3G_DO_UNLOCK(aEnv) |
|
262 |
|
263 if (transform) |
|
264 { |
|
265 aEnv->ReleaseByteArrayElements(aTransform, (jbyte*)transform, JNI_ABORT); |
|
266 } |
|
267 } |
|
268 |
|
269 /* |
|
270 static void renderWorld(M3GRenderContext aHContext, |
|
271 M3GWorld aHWorld) |
|
272 { |
|
273 m3gRenderWorld(aHContext, aHWorld); |
|
274 } |
|
275 */ |
|
276 |
|
277 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1renderWorld |
|
278 (JNIEnv* aEnv, jclass, jint aHContext, jint aHWorld) |
|
279 { |
|
280 M3G_DO_LOCK |
|
281 |
|
282 m3gRenderWorld((M3GRenderContext) aHContext, (M3GWorld) aHWorld); |
|
283 |
|
284 /* |
|
285 CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle); |
|
286 eventSource->ExecuteV(&renderWorld, |
|
287 (M3GRenderContext) aHContext, |
|
288 (M3GWorld) aHWorld); |
|
289 */ |
|
290 M3G_DO_UNLOCK(aEnv) |
|
291 } |
|
292 |
|
293 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1ctor |
|
294 (JNIEnv* aEnv, jclass, jint aM3g) |
|
295 { |
|
296 M3G_DO_LOCK |
|
297 M3GRenderContext ctx = m3gCreateContext((M3GInterface)aM3g); |
|
298 M3G_DO_UNLOCK(aEnv) |
|
299 |
|
300 return (jint)ctx; |
|
301 } |
|
302 |
|
303 struct RenderStruct |
|
304 { |
|
305 M3GVertexBuffer hVertices; |
|
306 M3GIndexBuffer hIndices; |
|
307 M3GAppearance hAppearance; |
|
308 const M3GMatrix *transform; |
|
309 }; |
|
310 |
|
311 /* |
|
312 static void renderImmediate(M3GRenderContext aHContext, RenderStruct *aR, jint aScope) |
|
313 { |
|
314 m3gRender(aHContext, |
|
315 aR->hVertices, |
|
316 aR->hIndices, |
|
317 aR->hAppearance, |
|
318 aR->transform, 1.0f, aScope); |
|
319 } |
|
320 */ |
|
321 |
|
322 /* |
|
323 * Must be executed in UI thread |
|
324 */ |
|
325 |
|
326 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1render |
|
327 (JNIEnv* aEnv, jclass, jint aHContext, |
|
328 jint aHVertices, jint aHIndices, jint aHAppearance, jbyteArray aTransform, jint aScope) |
|
329 { |
|
330 M3GMatrix *transform = NULL; |
|
331 if (aTransform) |
|
332 { |
|
333 transform = (M3GMatrix *)aEnv->GetByteArrayElements(aTransform, NULL); |
|
334 if (transform == NULL) |
|
335 { |
|
336 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
337 return; |
|
338 } |
|
339 } |
|
340 |
|
341 /* |
|
342 RenderStruct r; |
|
343 r.hVertices = (M3GVertexBuffer) aHVertices; |
|
344 r.hIndices = (M3GIndexBuffer) aHIndices; |
|
345 r.hAppearance = (M3GAppearance) aHAppearance; |
|
346 r.transform = transform; |
|
347 */ |
|
348 |
|
349 |
|
350 M3G_DO_LOCK |
|
351 |
|
352 m3gRender((M3GRenderContext) aHContext, (M3GVertexBuffer) aHVertices, (M3GIndexBuffer) aHIndices, (M3GAppearance) aHAppearance, |
|
353 transform, 1.0f, aScope); |
|
354 |
|
355 /* |
|
356 CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle); |
|
357 eventSource->ExecuteV(&renderImmediate, ((M3GRenderContext) aHContext), &r, aScope); |
|
358 */ |
|
359 M3G_DO_UNLOCK(aEnv) |
|
360 |
|
361 |
|
362 if (transform) |
|
363 { |
|
364 aEnv->ReleaseByteArrayElements(aTransform, (jbyte*)transform, JNI_ABORT); |
|
365 } |
|
366 } |
|
367 |
|
368 /* |
|
369 static void clear(M3GRenderContext aHContext, M3GBackground aHBackground) |
|
370 { |
|
371 m3gClear(aHContext, aHBackground); |
|
372 } |
|
373 */ |
|
374 |
|
375 /* |
|
376 * Must be executed in UI thread |
|
377 */ |
|
378 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1clear |
|
379 (JNIEnv* aEnv, jclass, jint aCtx, jint aBg) |
|
380 { |
|
381 M3G_DO_LOCK |
|
382 m3gClear((M3GRenderContext)aCtx, (M3GBackground)aBg); |
|
383 |
|
384 /* |
|
385 CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle); |
|
386 eventSource->ExecuteV(&clear, (M3GRenderContext)aCtx, (M3GBackground)aBg); |
|
387 */ |
|
388 M3G_DO_UNLOCK(aEnv) |
|
389 } |
|
390 |
|
391 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1releaseImage |
|
392 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
393 { |
|
394 M3G_DO_LOCK |
|
395 |
|
396 releaseTarget((M3GRenderContext)aHCtx); |
|
397 |
|
398 /* |
|
399 CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle); |
|
400 eventSource->ExecuteV(&releaseTarget, (M3GRenderContext)aHCtx); |
|
401 */ |
|
402 M3G_DO_UNLOCK(aEnv) |
|
403 } |
|
404 |
|
405 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1addRef |
|
406 (JNIEnv* aEnv, jclass, jint aObject) |
|
407 { |
|
408 M3G_DO_LOCK |
|
409 m3gAddRef((M3GObject) aObject); |
|
410 M3G_DO_UNLOCK(aEnv) |
|
411 } |
|
412 |
|
413 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1addLight |
|
414 (JNIEnv* aEnv, jclass, jint aHContext, jint aHLight, jbyteArray aTransform) |
|
415 { |
|
416 M3GMatrix *transform = NULL; |
|
417 if (aTransform) |
|
418 { |
|
419 transform = (M3GMatrix *)(aEnv->GetByteArrayElements(aTransform, NULL)); |
|
420 if (transform == NULL) |
|
421 { |
|
422 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
423 return 0; |
|
424 } |
|
425 } |
|
426 M3G_DO_LOCK |
|
427 int idx = m3gAddLight((M3GRenderContext) aHContext, (M3GLight) aHLight, transform); |
|
428 M3G_DO_UNLOCK(aEnv) |
|
429 |
|
430 if (transform) |
|
431 { |
|
432 aEnv->ReleaseByteArrayElements(aTransform, (jbyte*)transform, JNI_ABORT); |
|
433 } |
|
434 |
|
435 return idx; |
|
436 } |
|
437 |
|
438 /* |
|
439 static void bindImage(M3GRenderContext hCtx, M3GImage hImg, M3Gbool depth, M3Gbitmask hintBits) |
|
440 { |
|
441 if (m3gSetRenderBuffers(hCtx, depth ? M3G_COLOR_BUFFER_BIT|M3G_DEPTH_BUFFER_BIT : M3G_COLOR_BUFFER_BIT) && m3gSetRenderHints(hCtx, hintBits)) { |
|
442 m3gBindImageTarget(hCtx, hImg); |
|
443 } |
|
444 } |
|
445 */ |
|
446 |
|
447 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1bindImage |
|
448 (JNIEnv* aEnv, jclass, jint aHCtx, jint aImageHandle, jboolean aDepth, jint aHintBits) |
|
449 { |
|
450 M3G_DO_LOCK |
|
451 |
|
452 if (m3gSetRenderBuffers((M3GRenderContext)aHCtx, (M3Gbool)aDepth ? M3G_COLOR_BUFFER_BIT|M3G_DEPTH_BUFFER_BIT : M3G_COLOR_BUFFER_BIT) && m3gSetRenderHints((M3GRenderContext)aHCtx, (M3Gbitmask)aHintBits)) |
|
453 { |
|
454 m3gBindImageTarget((M3GRenderContext)aHCtx, (M3GImage)aImageHandle); |
|
455 } |
|
456 |
|
457 //CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle); |
|
458 //eventSource->ExecuteV(&bindImage, (M3GRenderContext)aHCtx, (M3GImage)aImageHandle, (M3Gbool)aDepth, (M3Gbitmask)aHintBits); |
|
459 M3G_DO_UNLOCK(aEnv) |
|
460 } |
|
461 |
|
462 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1resetLights |
|
463 (JNIEnv* aEnv, jclass, jint aHContext) |
|
464 { |
|
465 M3G_DO_LOCK |
|
466 m3gClearLights((M3GRenderContext) aHContext); |
|
467 M3G_DO_UNLOCK(aEnv) |
|
468 } |
|
469 |
|
470 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1setDepthRange |
|
471 (JNIEnv* aEnv, jclass, jint aHContext, jfloat aDepthNear, jfloat aDepthFar) |
|
472 { |
|
473 M3G_DO_LOCK |
|
474 m3gSetDepthRange((M3GRenderContext) aHContext, aDepthNear, aDepthFar); |
|
475 M3G_DO_UNLOCK(aEnv) |
|
476 } |
|
477 |
|
478 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1setLight |
|
479 (JNIEnv* aEnv, jclass, jint aHContext, jint aLightIndex, jint aHLight, jbyteArray aTransform) |
|
480 { |
|
481 M3GMatrix *transform = NULL; |
|
482 if (aTransform) |
|
483 { |
|
484 transform = (M3GMatrix *)(aEnv->GetByteArrayElements(aTransform, NULL)); |
|
485 if (transform == NULL) |
|
486 { |
|
487 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
488 return; |
|
489 } |
|
490 } |
|
491 |
|
492 M3G_DO_LOCK |
|
493 m3gSetLight((M3GRenderContext) aHContext, aLightIndex, (M3GLight) aHLight, transform); |
|
494 M3G_DO_UNLOCK(aEnv) |
|
495 |
|
496 if (transform) |
|
497 { |
|
498 aEnv->ReleaseByteArrayElements(aTransform, (jbyte*)transform, JNI_ABORT); |
|
499 } |
|
500 } |
|
501 |
|
502 /* |
|
503 static void renderNode(M3GRenderContext aHCtx, |
|
504 M3GNode aHNode, |
|
505 const M3GMatrix *aMtx) |
|
506 { |
|
507 m3gRenderNode(aHCtx, aHNode, aMtx); |
|
508 } |
|
509 */ |
|
510 |
|
511 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1renderNode |
|
512 (JNIEnv* aEnv, jclass, jint aHCtx, jint aHNode, jbyteArray aTransform) |
|
513 { |
|
514 M3GMatrix *transform = NULL; |
|
515 if (aTransform) |
|
516 { |
|
517 transform = (M3GMatrix *)(aEnv->GetByteArrayElements(aTransform, NULL)); |
|
518 if (transform == NULL) |
|
519 { |
|
520 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
521 return; |
|
522 } |
|
523 } |
|
524 |
|
525 M3G_DO_LOCK |
|
526 |
|
527 m3gRenderNode((M3GRenderContext)aHCtx, (M3GNode)aHNode, (const M3GMatrix *)transform); |
|
528 |
|
529 //CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle); |
|
530 //eventSource->ExecuteV(&renderNode, (M3GRenderContext)aHCtx, (M3GNode)aHNode, (const M3GMatrix *)transform); |
|
531 M3G_DO_UNLOCK(aEnv) |
|
532 |
|
533 if (aTransform) |
|
534 { |
|
535 aEnv->ReleaseByteArrayElements(aTransform, (jbyte*)transform, JNI_ABORT); |
|
536 } |
|
537 } |
|
538 |
|
539 #if defined(M3G_ENABLE_PROFILING) |
|
540 |
|
541 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1getStatistics |
|
542 (JNIEnv* aEnv, jclass, jintArray aStatArray) |
|
543 { |
|
544 const M3Gint *statArray = (M3Gint *)(aStatArray != NULL ? aEnv->GetIntArrayElements(aStatArray, NULL) : NULL); |
|
545 jint statArrayLength = aStatArray ? aEnv->GetArrayLength(aStatArray) : 0; |
|
546 |
|
547 if (statArray != NULL && statArrayLength >= sizeof(m3gs_statistic)) |
|
548 { |
|
549 m3gCopy((void*)statArray, m3gs_statistic, sizeof(m3gs_statistic)); |
|
550 } |
|
551 |
|
552 M3G_DO_LOCK |
|
553 m3gZero(m3gs_statistic, sizeof(m3gs_statistic)); |
|
554 M3G_DO_UNLOCK(aEnv) |
|
555 |
|
556 if (statArray) |
|
557 { |
|
558 aEnv->ReleaseIntArrayElements(aStatArray, (jint*)statArray, 0); |
|
559 } |
|
560 |
|
561 return sizeof(m3gs_statistic); |
|
562 } |
|
563 |
|
564 #endif /* M3G_ENABLE_PROFILING */ |
|
565 |
|
566 |
|
567 |
|
568 /* M3G 1.1 JNI Calls */ |
|
569 |
|
570 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Graphics3D__1getViewTransform |
|
571 (JNIEnv* aEnv, jclass, jint aHCtx, jbyteArray aTransform) |
|
572 { |
|
573 M3GMatrix *transform = NULL; |
|
574 if (aTransform) |
|
575 { |
|
576 transform = (M3GMatrix *)(aEnv->GetByteArrayElements(aTransform, NULL)); |
|
577 if (transform == NULL) |
|
578 { |
|
579 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
580 return; |
|
581 } |
|
582 } |
|
583 |
|
584 M3G_DO_LOCK |
|
585 m3gGetViewTransform((M3GRenderContext) aHCtx, transform); |
|
586 M3G_DO_UNLOCK(aEnv) |
|
587 |
|
588 if (transform) |
|
589 { |
|
590 /* copy array to Java side and release arrays */ |
|
591 aEnv->ReleaseByteArrayElements(aTransform, (jbyte*)transform, 0); |
|
592 } |
|
593 } |
|
594 |
|
595 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1getCamera |
|
596 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
597 { |
|
598 M3G_DO_LOCK |
|
599 jint camera = (jint)m3gGetCamera((M3GRenderContext)aHCtx); |
|
600 M3G_DO_UNLOCK(aEnv) |
|
601 |
|
602 return camera; |
|
603 } |
|
604 |
|
605 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1getLightTransform |
|
606 (JNIEnv* aEnv, jclass, jint aHCtx, jint aLightIndex, jbyteArray aTransform) |
|
607 { |
|
608 M3GMatrix *transform = NULL; |
|
609 if (aTransform) |
|
610 { |
|
611 transform = (M3GMatrix *)(aEnv->GetByteArrayElements(aTransform, NULL)); |
|
612 if (transform == NULL) |
|
613 { |
|
614 M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError"); |
|
615 return 0; |
|
616 } |
|
617 } |
|
618 M3G_DO_LOCK |
|
619 int lightTransform = (M3Guint)m3gGetLightTransform((M3GRenderContext)aHCtx, aLightIndex, transform); |
|
620 M3G_DO_UNLOCK(aEnv) |
|
621 |
|
622 if (transform) |
|
623 { |
|
624 aEnv->ReleaseByteArrayElements(aTransform, (jbyte*)transform, 0); |
|
625 } |
|
626 |
|
627 return (jint)lightTransform; |
|
628 } |
|
629 |
|
630 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1getLightCount |
|
631 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
632 { |
|
633 M3G_DO_LOCK |
|
634 jint lightCount = (jint)m3gGetLightCount((M3GRenderContext)aHCtx); |
|
635 M3G_DO_UNLOCK(aEnv) |
|
636 |
|
637 return lightCount; |
|
638 } |
|
639 |
|
640 JNIEXPORT jfloat JNICALL Java_javax_microedition_m3g_Graphics3D__1getDepthRangeNear |
|
641 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
642 { |
|
643 float depthNear = 0; |
|
644 float depthFar = 0; |
|
645 |
|
646 M3G_DO_LOCK |
|
647 m3gGetDepthRange((M3GRenderContext) aHCtx, &depthNear, &depthFar); |
|
648 M3G_DO_UNLOCK(aEnv) |
|
649 |
|
650 return (jfloat)depthNear; |
|
651 } |
|
652 |
|
653 JNIEXPORT jfloat JNICALL Java_javax_microedition_m3g_Graphics3D__1getDepthRangeFar |
|
654 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
655 { |
|
656 float depthNear = 0; |
|
657 float depthFar = 0; |
|
658 |
|
659 M3G_DO_LOCK |
|
660 m3gGetDepthRange((M3GRenderContext) aHCtx, &depthNear, &depthFar); |
|
661 M3G_DO_UNLOCK(aEnv) |
|
662 |
|
663 return (jfloat)depthFar; |
|
664 } |
|
665 |
|
666 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1getViewportX |
|
667 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
668 { |
|
669 int viewport[4]; |
|
670 |
|
671 M3G_DO_LOCK |
|
672 m3gGetViewport((M3GRenderContext)aHCtx, &viewport[0], |
|
673 &viewport[1], |
|
674 &viewport[2], |
|
675 &viewport[3]); |
|
676 M3G_DO_UNLOCK(aEnv) |
|
677 |
|
678 return (jint)viewport[0]; |
|
679 } |
|
680 |
|
681 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1getViewportY |
|
682 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
683 { |
|
684 int viewport[4]; |
|
685 |
|
686 M3G_DO_LOCK |
|
687 m3gGetViewport((M3GRenderContext)aHCtx, &viewport[0], |
|
688 &viewport[1], |
|
689 &viewport[2], |
|
690 &viewport[3]); |
|
691 M3G_DO_UNLOCK(aEnv) |
|
692 |
|
693 return (jint)viewport[1]; |
|
694 } |
|
695 |
|
696 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1getViewportWidth |
|
697 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
698 { |
|
699 int viewport[4]; |
|
700 |
|
701 M3G_DO_LOCK |
|
702 m3gGetViewport((M3GRenderContext)aHCtx, &viewport[0], |
|
703 &viewport[1], |
|
704 &viewport[2], |
|
705 &viewport[3]); |
|
706 M3G_DO_UNLOCK(aEnv) |
|
707 |
|
708 return (jint)viewport[2]; |
|
709 } |
|
710 |
|
711 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Graphics3D__1getViewportHeight |
|
712 (JNIEnv* aEnv, jclass, jint aHCtx) |
|
713 { |
|
714 int viewport[4]; |
|
715 |
|
716 M3G_DO_LOCK |
|
717 m3gGetViewport((M3GRenderContext)aHCtx, &viewport[0], |
|
718 &viewport[1], |
|
719 &viewport[2], |
|
720 &viewport[3]); |
|
721 M3G_DO_UNLOCK(aEnv) |
|
722 |
|
723 return (jint)viewport[3]; |
|
724 } |
|
725 |
|
726 JNIEXPORT jboolean JNICALL Java_javax_microedition_m3g_Graphics3D__1isAASupported |
|
727 (JNIEnv* /*aEnv*/, jclass, jint aM3g) |
|
728 { |
|
729 M3Gbool aaSupport = M3G_FALSE; |
|
730 |
|
731 aaSupport = m3gIsAntialiasingSupported((M3GInterface)aM3g); |
|
732 |
|
733 return (jboolean)aaSupport; |
|
734 } |