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