Can I use glu with Android NDK - android

I can't seem to include glu.h in my Android NDK project.
I'm trying to port existing C++ code to NDK, and it uses glu in a few places (notably gluErrorString).
Does OpenGLES not have glu?
Is there a port I can use?
If not I can probably remove the calls to things like gluPerspective and so on, but what do I do about gluErrorString?

Does OpenGL ES not have glu?
No, it doesn't. Look at this: Platform OpenGL Includes collection. Under Android there are only the following headers:
OpenGL ES 1.1:
#include <GLES/gl.h>
#include <GLES/glext.h>
OpenGL ES 2.0:
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
Is there a port I can use?
Yes, there is a partial port of GLU for Android - GLU ES (it supports gluErrorString, gluPerspective and numerous other functions):
GLU 1.3 partitial port (libutil and libtess components only) for
OpenGL ES 1.x (CM - Common profile) and above.
This port supports:
Quadrics: gluNewQuadric(), gluDeleteQuadric(), gluQuadricCallback(),
gluQuadricNormals(), gluQuadricTexture(), gluQuadricOrientation(),
gluQuadricDrawStyle(), gluCylinder(), gluDisk(), gluPartialDisk(),
gluSphere().
Registry: gluGetString(), gluCheckExtension(),
gluErrorString().
Projection matrix manipulation: gluOrtho2D(),
gluPerspective(), gluLookAt(), gluProject(), gluUnProject(),
gluUnProject4(), gluPickMatrix(). 2D Mipmaps: gluScaleImage(),
gluBuild2DMipmapLevels(), gluBuild2DMipmaps().
Tesselation:
gluBeginPolygon(), gluDeleteTess(), gluEndPolygon(),
gluGetTessProperty(), gluNewTess(), gluNextContour(),
gluTessBeginContour(), gluTessBeginPolygon(), gluTessCallback(),
gluTessEndContour(), gluTessEndPolygon(), gluTessNormal(),
gluTessProperty(), gluTessVertex().

Related

GLES 2 Functions Not Working in Visual Studio

I'm using Visual Studio Community 2017, but the native-activity in this version is the same as in Visual Studio Community 2015.
I have just created a new native activity project in Visual Studio 2017, using the default program that loads with this project choice. However, whenever I try to use a function exclusive to open gl es 2, Visual Studio responds with an error like "error : undefined reference to 'glCreateShader' " for each open gl es 2 function that I use. Strangely, the following code works, even though I deleted the line in the pch file that includes open gl es 1:
glClearColor(200, 200, 200, 1);
glClear(GL_COLOR_BUFFER_BIT);
The following function if put into the default native activity project (even after including GLES2/gl2.h, GLES2/gl2ext.h, and GLES2/gl2platform.h) results in the error described above:
int prepareShader(GLuint shaderType, const char * shaderCode) {
GLuint shader = glCreateShader(shaderType);
int len = strlen(shaderCode);
glShaderSource(shader, 1, &shaderCode, &len);
}
I remember a similar error occurring in Android Studio, which was fixed by adding the following to cmakelists.txt:
find_library(gl-lib
GLESv2 )
find_library(egl-lib
EGL )
target_link_libraries( # Specifies the target library.
native-lib
${egl-lib}
${gl-lib})
My Visual Studio project does not use CMake, however.
Can somebody please tell me how to successfully use open gl es 2 in Visual Studio 2017?
The solution to my problem is to load the open gl functions using eglGetProcAddress. This just means that each opengl es function must be set to a pointer before using them because GLES2/gl2.h does not define the functions (the functions are defined at run time).
Doing something like this for each function solves the problem. (However, I needed to delete the function prototypes in GLES2/gl2.h for this to work).
typedef GLuint(GL_APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
PFNGLCREATESHADERPROC glCreateShader = (PFNGLCREATESHADERPROC)eglGetProcAddress("glCreateShader");

How does Android source building #ifdefs work in compilation

I'm familiar with Android kernel programming but I'm a newbie at building the Android source. I'm wondering how to enable the #ifdefs in android source building. Are there any defconfig file in android source like in android kernel to choose what we want to compile in the compilation?.. How can i enable the codings defined with #ifdef to get compile during the Android source compilation?
Ex:
#ifdef USE_ION
int alloc_map_ion_memory(OMX_U32 buffer_size,
OMX_U32 alignment, struct ion_allocation_data *alloc_data,
struct ion_fd_data *fd_data,int flag);
void free_ion_memory(struct vdec_ion *buf_ion_info);
#else
bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
OMX_U32 alignment);
#endif
I want to make sure the ion part is being compiled not the pmem part.
Try add the line:
#error "USE_ION"
after #ifdef USE_ION
Build again, if the build failed, USE_ION is defined.

Checking processor capabilities in android

I'm using FFMPEG in an app, and I'm using the following configuration:
--extra-cflags=' -march=armv7-a -mfloat-abi=softfp -mfpu=neon'
I'm targeting 4.0+ so I believe armv7-a should be supported by most non Intel devices, and I'm sure the neon extension is supported in most devices as well, but I'm not sure how I can find that out for all 2000+ devices.
Is there a way to check in Android the processor type and extensions and/or in the Google Play Store to limit the apk to devices with certain processors?
I'll answer you last question first: you can limit the apk to devices with certain processors on the Play Store, but not with the granularity you're looking for.
In short: if you upload an apk containing native libs only for armv7-a, it won't be downloadable from an x86, mips or armv6 device. But the choice stops there: both NEON and non-NEON devices are considered armv7-a devices, so that does not solve your problem. The check has to be done at runtime.
Checking the processor architecture and capabilities in Java on Android is not easy to do: there's no API for that.
On the other side, this can easily be done using the NDK, which contains a cpufeatures module (you can find documentation on it in your NDK install folder). This module lets you:
find the architecture of the device using android_getCpuFamily()
get additional details using android_getCpuFeatures(): this is what you're looking for, as these details contain the ANDROID_CPU_ARM_FEATURE_NEON flag indicating NEON compatibility!
In practice, implementing a JNI function such as the following one and calling it from Java should do the trick:
#include <jni.h>
#include <cpu-features.h>
jboolean
Java_com_my_namespace_MyClass_isNeon
(JNIEnv *env, jclass class) {
uint64_t features = android_getCpuFeatures();
if ((android_getCpuFamily() != ANDROID_CPU_FAMILY_ARM) ||
((features & ANDROID_CPU_ARM_FEATURE_NEON) == 0 )) {
return JNI_FALSE;
}
else {
return JNI_TRUE;
}
}
it will return true if the device is ARMv7 and features NEON, false otherwise!

enable arm neon for bullet physics engine demo on android

I'm building a demo with bullet physics engine library for android phone(NDK).
From 2.81 version, Bullet physics engine supports arm neon optimization, but only for apple devices.
My question is how to enable arm neon for android?
The flag for arm neon is defined in btScalar.h file, code is as below:
#if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
#if defined (__i386__) || defined (__x86_64__)
#define BT_USE_SSE
#define BT_USE_SSE_IN_AP
#elif defined( __armv7__ )
#ifdef __clang__
#define BT_USE_NEON 1
#if defined BT_USE_NEON && defined (__clang__)
#include <arm_neon.h>
……
As we can see in the code, flag BT_USE_NEON is defined in the condition of it is compiled for apple device, if I drop this code and define this flag by myself, some error occurs when compiling, something like bad alignment--vld1.f32 {d26},[r4:128].
What should I do for my demo to enable arm neon?
I had the same issues few days ago:)
The problem was assembly code defined in btVector3 (vld1q_f32_aligned_postincrement). As far as I know, syntax such as [r3, :128] is used in GAS - I guess it is used in iOS environment, but not sure. Modifying it to [%1, #128] may remove those errors.
By the way, from my experience, it is usually slow than plain implementation. I think the bullet neon intrinsics are not optimized for android, as you can see an assembly code(probably optimized) on the other side(defined as APPLE).

Android Native OGLES2: esLoadProgram not declared

I have following commands:
// Load the shaders and get a linked program object
userData->programObject = esLoadProgram( vShaderStr, fShaderStr );
...
// Generate the vertex data
userData->numIndices = esGenCube( 1.0, &userData->vertices,NULL, NULL, &userData->indices );
The program is in native C++ for Android 4, using only NativeActivity. So, project has no /src and java classes.
I put the information to NDK OGLES 2.0 about the version running as EGL_OPENGL_ES2_BIT, and Android.mk was also setup to -lGLESv2. In the file is also included:
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <EGL/egl.h>
#include <GLES2/gl2.h>
And also AndroidManifest was informed that it runs OGLES 2.0.
When asked to run, the program gives the following message:
'esLoadProgram' was not declared in this scope
'esGenCube' was not declared in this scope
For some reason these commands that belong to OGLES 2 are not visible. Any suggestion why this?
All comments are highly appreciated.
esLoadProgram and esGenCube are not a part of OpenGL ES or EGL. They are just a helper functions (probably from http://code.google.com/p/opengles-book-samples/)
PS. I would not suggest to mix also GLES and GLES2 headers. If you want GL ES 2.0, then include only from <GLES2/...> (not <GLES/...>)

Categories

Resources