Skip to content

Commit

Permalink
openmw building on Android with Opengl es
Browse files Browse the repository at this point in the history
  • Loading branch information
sandstranger committed Nov 23, 2015
1 parent 3fe38e3 commit 69acace
Show file tree
Hide file tree
Showing 14 changed files with 656 additions and 71 deletions.
44 changes: 30 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,20 @@ include(OpenMWMacros)

if (ANDROID)
set(CMAKE_FIND_ROOT_PATH ${OPENMW_DEPENDENCIES_DIR} "${CMAKE_FIND_ROOT_PATH}")
set(OSG_PLUGINS_DIR ${OSG_PLUGINS_DIR})
add_definitions (-DOSG_PLUGINS_DIR)
set(OPENGLES TRUE CACHE BOOL "enable opengl es support for android" FORCE)
endif (ANDROID)

option(OPENGLES "enable opengl es support" FALSE )

if (OPENGLES)
INCLUDE(cmake/FindOpenGLES.cmake)
INCLUDE(cmake/FindOpenGLES2.cmake)
add_definitions (-DOPENGLES)
INCLUDE_DIRECTORIES(${OPENGLES_INCLUDE_DIR})
endif (OPENGLES)

# doxygen main page

configure_file ("${OpenMW_SOURCE_DIR}/docs/mainpage.hpp.cmake" "${OpenMW_BINARY_DIR}/docs/mainpage.hpp")
Expand Down Expand Up @@ -145,21 +157,21 @@ if (WIN32)
endif()

# Dependencies
if (NOT ANDROID)
set(DESIRED_QT_VERSION 4 CACHE STRING "The QT version OpenMW should use (4 or 5)")
message(STATUS "Using Qt${DESIRED_QT_VERSION}")

set(DESIRED_QT_VERSION 4 CACHE STRING "The QT version OpenMW should use (4 or 5)")
message(STATUS "Using Qt${DESIRED_QT_VERSION}")

if (DESIRED_QT_VERSION MATCHES 4)
find_package(Qt4 REQUIRED COMPONENTS QtCore QtGui QtNetwork QtOpenGL)
else()
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5OpenGL REQUIRED)
# Instruct CMake to run moc automatically when needed.
#set(CMAKE_AUTOMOC ON)
if (DESIRED_QT_VERSION MATCHES 4)
find_package(Qt4 REQUIRED COMPONENTS QtCore QtGui QtNetwork QtOpenGL)
else()
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5OpenGL REQUIRED)
# Instruct CMake to run moc automatically when needed.
#set(CMAKE_AUTOMOC ON)
endif()
endif()

# Fix for not visible pthreads functions for linker with glibc 2.15
if (UNIX AND NOT APPLE)
find_package (Threads)
Expand Down Expand Up @@ -189,7 +201,11 @@ IF(BOOST_STATIC)
set(Boost_USE_STATIC_LIBS ON)
endif()

find_package(OpenSceneGraph 3.2.0 REQUIRED osgDB osgViewer osgText osgGA osgAnimation osgParticle osgQt osgUtil osgFX)
if (NOT ANDROID)
find_package(OpenSceneGraph 3.2.0 REQUIRED osgDB osgViewer osgText osgGA osgAnimation osgParticle osgQt osgUtil osgFX)
else()
find_package(OpenSceneGraph 3.2.0 REQUIRED osgDB osgViewer osgText osgGA osgAnimation osgParticle osgUtil osgFX)
endif()
include_directories(${OPENSCENEGRAPH_INCLUDE_DIRS})

if(OSG_STATIC)
Expand Down
34 changes: 33 additions & 1 deletion apps/openmw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,50 @@ target_link_libraries(openmw
)

if (ANDROID)
set (OSG_PLUGINS
-Wl,--whole-archive
${OSG_PLUGINS_DIR}/libosgdb_dds.a
${OSG_PLUGINS_DIR}/libosgdb_bmp.a
${OSG_PLUGINS_DIR}/libosgdb_tga.a
${OSG_PLUGINS_DIR}/libosgdb_gif.a
${OSG_PLUGINS_DIR}/libosgdb_jpeg.a
${OSG_PLUGINS_DIR}/libosgdb_png.a
-Wl,--no-whole-archive
)
target_link_libraries(openmw
EGL
android
log
dl
MyGUIEngineStatic
cpufeatures
BulletCollision
LinearMath
z
osg
osgDB
osgAnimation
osgText
osgUtil
osgShadow
${OPENSCENEGRAPH_LIBRARIES}
${OSG_PLUGINS}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
jpeg
gif
png
)
endif (ANDROID)

if (OPENGLES)
target_link_libraries(openmw
${OPENGLES_gl_LIBRARY}
${OPENGLES2_gl_LIBRARY}
)
endif (OPENGLES)

if (USE_SYSTEM_TINYXML)
target_link_libraries(openmw ${TINYXML_LIBRARIES})
endif()
Expand Down
1 change: 0 additions & 1 deletion apps/openmw/android_main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "../../SDL_internal.h"

#ifdef __ANDROID__
#include "SDL_main.h"
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#endif


#if (defined(__APPLE__) || defined(__linux) || defined(__unix) || defined(__posix))
#if (defined(__APPLE__) || (defined(__linux) && !defined(ANDROID)) || (defined(__unix) && !defined(ANDROID)) || defined(__posix))
#define USE_CRASH_CATCHER 1
#else
#define USE_CRASH_CATCHER 0
Expand Down
5 changes: 5 additions & 0 deletions apps/openmw/mwrender/localmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@

#include "vismask.hpp"

#ifdef OPENGLES
#include <GLES/gl.h>
#endif


namespace
{

Expand Down
5 changes: 5 additions & 0 deletions apps/openmw/mwrender/sky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
#include "vismask.hpp"
#include "renderbin.hpp"

#ifdef OPENGLES
#include <GLES/gl.h>
#endif


namespace
{

Expand Down
11 changes: 9 additions & 2 deletions apps/openmw/mwrender/water.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
#include "ripplesimulation.hpp"
#include "renderbin.hpp"

#ifdef OPENGLES
#include <GLES/gl.h>
#endif

namespace
{

Expand Down Expand Up @@ -575,10 +579,13 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
// use a define map to conditionally compile the shader
std::map<std::string, std::string> defineMap;
defineMap.insert(std::make_pair(std::string("@refraction_enabled"), std::string(refraction ? "1" : "0")));

#ifdef OPENGLES
osg::ref_ptr<osg::Shader> vertexShader (readShader(osg::Shader::VERTEX, mResourcePath + "/shaders/watergles_vertex.glsl", defineMap));
osg::ref_ptr<osg::Shader> fragmentShader (readShader(osg::Shader::FRAGMENT, mResourcePath + "/shaders/watergles_fragment.glsl", defineMap));
#else
osg::ref_ptr<osg::Shader> vertexShader (readShader(osg::Shader::VERTEX, mResourcePath + "/shaders/water_vertex.glsl", defineMap));
osg::ref_ptr<osg::Shader> fragmentShader (readShader(osg::Shader::FRAGMENT, mResourcePath + "/shaders/water_fragment.glsl", defineMap));

#endif
osg::ref_ptr<osg::Texture2D> normalMap (new osg::Texture2D(readPngImage(mResourcePath + "/shaders/water_nm.png")));
normalMap->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
normalMap->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
Expand Down
94 changes: 94 additions & 0 deletions cmake/FindOpenGLES.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#-------------------------------------------------------------------
# This file is part of the CMake build system for OGRE
# (Object-oriented Graphics Rendering Engine)
# For the latest info, see http://www.ogre3d.org/
#
# The contents of this file are placed in the public domain. Feel
# free to make use of it in any way you like.
#-------------------------------------------------------------------

# - Try to find OpenGLES
# Once done this will define
#
# OPENGLES_FOUND - system has OpenGLES
# OPENGLES_INCLUDE_DIR - the GL include directory
# OPENGLES_LIBRARIES - Link these to use OpenGLES

IF (WIN32)
IF (CYGWIN)

FIND_PATH(OPENGLES_INCLUDE_DIR GLES/gl.h )

FIND_LIBRARY(OPENGLES_gl_LIBRARY libgles_cm )

ELSE (CYGWIN)

IF(BORLAND)
SET (OPENGLES_gl_LIBRARY import32 CACHE STRING "OpenGL ES 1.x library for win32")
ELSE(BORLAND)
#MS compiler - todo - fix the following line:
SET (OPENGLES_gl_LIBRARY ${OGRE_SOURCE_DIR}/Dependencies/lib/release/libgles_cm.lib CACHE STRING "OpenGL ES 1.x library for win32")
ENDIF(BORLAND)

ENDIF (CYGWIN)

ELSE (WIN32)

IF (APPLE)

#create_search_paths(/Developer/Platforms)
#findpkg_framework(OpenGLES)
#set(OPENGLES_gl_LIBRARY "-framework OpenGLES")

ELSE(APPLE)

FIND_PATH(OPENGLES_INCLUDE_DIR GLES/gl.h
/opt/vc/include
/opt/graphics/OpenGL/include
/usr/openwin/share/include
/usr/X11R6/include
/usr/include
)

FIND_LIBRARY(OPENGLES_gl_LIBRARY
NAMES GLES_CM GLESv1_CM
PATHS /opt/vc/lib
/opt/graphics/OpenGL/lib
/usr/openwin/lib
/usr/shlib /usr/X11R6/lib
/usr/lib
)

# On Unix OpenGL most certainly always requires X11.
# Feel free to tighten up these conditions if you don't
# think this is always true.

#IF (OPENGLES_gl_LIBRARY)
# IF(NOT X11_FOUND)
# INCLUDE(FindX11)
# ENDIF(NOT X11_FOUND)
# IF (X11_FOUND)
# SET (OPENGLES_LIBRARIES ${X11_LIBRARIES})
# ENDIF (X11_FOUND)
#ENDIF (OPENGLES_gl_LIBRARY)

ENDIF(APPLE)
ENDIF (WIN32)

SET( OPENGLES_FOUND "NO" )
IF(OPENGLES_gl_LIBRARY)

SET( OPENGLES_LIBRARIES ${OPENGLES_gl_LIBRARY} ${OPENGLES_LIBRARIES})

SET( OPENGLES_FOUND "YES" )

ENDIF(OPENGLES_gl_LIBRARY)

MARK_AS_ADVANCED(
OPENGLES_INCLUDE_DIR
OPENGLES_gl_LIBRARY
)

INCLUDE(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENGLES REQUIRED_VARS OPENGLES_LIBRARIES OPENGLES_INCLUDE_DIR)
Loading

0 comments on commit 69acace

Please sign in to comment.