Tuesday, January 28, 2014

opengl es 2.0/opengl4 porting

ES 2.0 is a subset of GL 3/4. We know there is no geometry shader in ES. When I tried to porting my GL4 code to ES 2.0. I found another problem. There is no glVertexAttribIPointer or glVertexAttribLPointer to pass integer buffer to the vertex shaders. All the vertex buffers have to be passed with glVertexAttribPointer with different types. In my code, ivec3/ivec4 will not get correct values from glVertexAttribPointer. I have to use vec3/vec4 to get buffers. And then, cast them to int to use, like int(foo[0]). So far, it works fine, but I am not sure if there is any performance overhead while type casting from float to int, or there is any better solution.

understanding clang cross-compiing

I try to unify the dev environment to clang as I might work on IOS where gcc might not available. So far, clang works for most of my porting. Usually, libs work with gcc by default. clang can replace gcc in most of cases of native compiling, with some minor patches some times. However, crossing compie with clang is not trivial.

I dug into the android-cmake log to find the way of cross-compiling. The procedure seems that clang compile the source code to some bitcode, and then ndk/gcc/as compiles the bitcode to arm binary. clang can not work along to get arm binary.

Maybe I just use gcc for everything to save my live, as I might not work on IOS in a short time.

Update:
I try to manually compile arm binary on x86_64 with following commands:

clang -target armv7a-none-eabi -mcpu=cortex-a8 --sysroot=/opt/android-ndk/platforms/android-19/arch-arm/ -S hello.c

/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as -mfpu=neon -mfloat-abi=softfp -march=armv7-a -mfpu=vfpv3-d16 hello.s -o hello.o

/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld hello.o -o hello -L $ANDROID_NDK/platforms/android-19/arch-arm/usr/lib/ -lc -lm

I got an arm binary, but I can not test it, as my tablet does not allow binary to run natively.

Sunday, January 26, 2014

porting freetype to android

UPDATE: 2.5.3 works with r9d clang4.4 out of box.


//=============Deprecated=======================

I need freetype as libRocket depends on it. The problem is freetype does not compile with clang3.3 in ndk-r9c.

I got these errors:
  "/opt/android-ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/as" -mfpu=neon -mfloat-abi=softfp -march=armv7-a -mfpu=vfpv3-d16 -o CMakeFiles/freetype.dir/src/autofit/autofit.c.o /tmp/autofit-tnCFeA.s
/tmp/autofit-tnCFeA.s: Assembler messages:
/tmp/autofit-tnCFeA.s:1145: Error: width suffixes are invalid in ARM mode -- `add.w r5,r5,#0x8000'

4.8 and 4.6 work fine. However it works with x86_64 clang on my PC. I hold it will with clang in IOS.

Update
uncomment the following line in "freetype-2.5.2/devel/ftoption.h" and "freetype-2.5.2/include/config/ftoption.h",
#define FT_CONFIG_OPTION_NO_ASSEMBLER

clang will compile, both freetype and libRocket then. I have to test if there is any running risks.

Monday, January 20, 2014

archlinux on android/arm, ssh normal user chroot

I tried chroot to use archlinux on an android tablet. The normal user will get socket error while using ssh, but root works fine. In order to use ssh, add a grp and add your user into it.

groupadd -g 3003 aid_inet
gpasswd -a $USER aid_inet

Wednesday, January 15, 2014

c++ log libs

I am considering port a c++ log lib to android ndk. On linux and windows, I use log4cxx in my projects. It works fine. However porting it to android is not trivial. Then, I also searched for some other options.

boost.log
log4cxx, BSD, configure/make, not for android
log4cplus, BSD/MIT, cmake, android setting
google glog, BSD, configure/make, no android
muduo, BSD, cmake, not sure on android
pantheios, BSD, configure, not ready for android

The options might be log4cplus and muduo so far. I have not started trying. My second thought is it is worth porting, as it take time to port and learn the api.

I just leave a note here, and use dummy i/o for logging in my dummy project. Maybe I am back some time.


Sunday, January 12, 2014

android emulator with opengl es 2.0

I googled around, and found a perfect emulator, "Genymotion". It emulates arm android on your windows/mac/linux. You can even install google play on it. I tried angry birds with nvidia 420m (integrated graphics card is slow), and it worked flawless. Then I tested my own arm projects, and they ran again. It is so far a perfect emulator.

PS
Before I found Genymotion, I tried stock emulator, which is said to support es 2.0 on x86 images. But, I can not got it work. Even if I could, it will be x86 with poor performance. I have to re-set up my projects. Android-x86 is another choice, but it is said there is no es 2.0.

Saturday, January 11, 2014

There exists no unified memory access for GPU so far.

I heard that, embedded systems like arm have only one memory pool. CPU and GPU share it. I though there might be some unified memory access there. But I am wrong. Arm (android/ios) GPUs work in the same way as integrated graphic cards in PC. RAM and VRAM are still separated logically. At least there is not such an API to let GPU access main memory directly. Data copying is still required.

AMD kaveri APU seems to break this rules on Jan 14 2014. Let us see.

Friday, January 10, 2014

android-cmake windows

android-cmake is a great solution to build existing libraries, e.g. libpng, for android. In my linux, it works flawlessly. I compiled assimp, libpng, libz, and bullet so far. And then, I can add them to my project in the android.mk, which I attached it to the end.

android-cmake works out-of-box in Linux. In window, there is no softlink, make install will fail. I just copy those target files, such as *.so, *.a, and bin files, to the build folder, and then make install works.

"Could not find any working toolchain in the NDK. Probably your Android NDK is broken" drove me to nut. I got this problem on one PC, but another one works perfectly. I finally found out, android-cmake works only with cmake 2.8.12.2. I updated the old one. Everything works now.

In order to link your prebuilt libs, you have to define your own LOCAL_MODULE and put them in the LOCAL_STATIC_LIBRARIES list



android.mk

LOCAL_PATH := $(call my-dir)

#assimp
include $(CLEAR_VARS)
LOCAL_MODULE := assimp
LOCAL_SRC_FILES := $(ANDROID_TOOLCHAIN)/lib/libassimp.a
LOCAL_EXPORT_C_INCLUDES := $(ANDROID_TOOLCHAIN)/include/assimp
include $(PREBUILT_STATIC_LIBRARY)

#libpng
include $(CLEAR_VARS)
LOCAL_MODULE := libpng
LOCAL_SRC_FILES := $(ANDROID_TOOLCHAIN)/lib/libpng.a
LOCAL_EXPORT_C_INCLUDES := $(ANDROID_TOOLCHAIN)/include/
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := game
LOCAL_C_INCLUDES += $(ANDROID_TOOLCHAIN)/include/eigen3/
LOCAL_SRC_FILES := ../../common/game.cpp jni.cpp assets_file_io.cpp
LOCAL_STATIC_LIBRARIES := assimp libpng
LOCAL_LDLIBS := -lz -lstdc++ -llog -lGLESv2 -lEGL -landroid
include $(BUILD_SHARED_LIBRARY)

Saturday, January 4, 2014

Multi-Player games notes

It is NOT well organized and NO game is made yet.

I just wanna keep a note about my thoughts about a pipeline for creating a multiplayer game. It is not specific to a single game but more a frame work or work flow. I hate reinventing the wheel so I prefer choosing existing tools.

I focus on the pure game itself so far. The external elements, such as log in UI or database, are not discussed here. I wanna describe my demands with keywords. Working along, low budget or no budget, indie, multi-player, real-time,  and cross-platforms.

I would like to have these steps: graphic modeling, logic, and network.

I am using blender and 3ds max for modeling. I used blender at the beginning. It is free, and incredible powerful. It is perfect for all my modeling tasks. When I found out I can get 3ds max and all the related Autodesk software for free as a student, I gave it a try as it is a kind of industry standard and a lot of models online are in max format. And, it should be better somewhere and have better compatibility with other software as it is sold thousands of dollars. However I found out, so far, it is a little better. I still need some work to import max models into unity 3d. On current stage, I would stay on blender for a while, because I am more familiar with it now. Probably I will move to 3ds max.

There are also plenty of game engines, such as blender, unity 3d, unreal,cocos-2dx, and panda 3d. I am using all of those above. unity 3d and unreal is the best in terms of performance, cross-platforms and network support.If you just need a offline game, they are the best to go. blender is good for tiny prototypes on pc. It is still powerful and easy to use, at least to myself. However, I have never seen any serious games out of it, except some demos. For cocos-2dx or panda 3d, there is no GUI, generally speaking. You need to implement your world from sketch.

Networking is kind of new to gaming, as I have not find any game engine has network embedded for dummy users. In other words, you need to program anyway if you need online games. I am not sure if unity or unreal handles server-client either. As on the server side, you probably do not need any rendering but just logic.

To conclude so far. Offline games, go unity 3D or unreal. Online games, any one is ok, and implement your own server.

Wednesday, January 1, 2014

windows/linux/osx,intel/amd,desktop/laptop/pad

I am interested in different platforms. Thus, I spent a day on googleing related information. In order not to waste such time, I decide to write these down.

windows/linux/osx

windows is best optimized on the same hardwares.

I can finish all the same tasks on those OS. They are transparent in terms of software to me. So I am more interesting hardware optimizations, especially on graphics. I thought osx has some magic on optimizations so that they can be overpriced. But, I can not find any evidence to support my hypothesis. In stead, main stream games are optimized for windows at the first place. Although osx versions may catch up years later, they will not do better. Based on my own experience, my windows works smoother than my linux on the same laptop. Even on science computation, windows versions are a little faster, at least no worse. So far, I would say, windows are optimized best, based on the hardwares(based on hackintosh or the same level mac).

intel/amd

amd is never a good solution on desktops, for price, power consuming, or performance. Maybe it is good for laptop in terms of price.

I have no amd chips to test, so all the following comparisons are from google. Cpu of amd seems really sucks nowadays.A saying is that, A10 can only reach i3 for daily use. GPU is better, maybe A10 can match 630. As a result, A10 ($130 bundle) seems a better solution than i3 ($180 bundle) + 630. However, i3+630 level is not for gamers. I would like go i5/i7($250 bundle) + 650ti ($130) at least. A10 can crossfire with 6xxx cards. Higher level cards work better standalone. Also A10 is said to consume more power.

For laptops, the story is a little difference.If you focus on battery life, go macbooks. Nothing can bit them so far. If you pursuit performance, you will get a big box, as heavy as a desktop, with twice of its prices. Neither of them is my target. I am think about a cheap laptop which can handle basic games like WoW. CPU is never my bottle neck. core 2 duo can handle such games without any problems.We assume A10 = i3 + 630m in laptops. A laptop with 630m or above will cost $700 usually and will not consume any less power. A10 ones might cost $400. Also, the coming Kaveri A10 will have unified memory for GPU and CPU, which will benefit GPU computing. If you have a tight budget, A10 laptop may be good choice.

desktop/laptop/pad

powerful desktop + light laptop/pad

Desktops are much powerful than laptops. It is proved by data and my feeling. You will pay a lot to make the performance of a laptop to match that of a desktop. Even if you match the performance, you probably get a large, heavy, and hot laptop, and you need pay more to improve the mobility. My ideal solution is, getting a powerful desktop (if I really need one), and carrying a very light laptop, like yoga2 or air, or even a pad with bluetooth keyboard.