Merge pull request #254 from tomhog/topic-gles3-ios

Topic gles3 ios
This commit is contained in:
OpenSceneGraph git repository
2017-05-10 11:13:11 +01:00
committed by GitHub
7 changed files with 120 additions and 16 deletions

View File

@@ -7,7 +7,22 @@ SET(TARGET_SRC
osgIPhoneViewer-Info.plist
)
SET(TARGET_ADDED_LIBRARIES osgdb_osg osgdb_imageio osgdb_avfoundation)
SET(TARGET_ADDED_LIBRARIES osgdb_osg osgdb_rgb osgdb_imageio osgdb_avfoundation)
SET(TARGET_ADDED_LIBRARIES ${TARGET_ADDED_LIBRARIES}
osgdb_deprecated_osg osgdb_deprecated_osgparticle osgdb_deprecated_osganimation
osgdb_deprecated_osgfx osgdb_deprecated_osgsim osgdb_deprecated_osgtext
osgdb_deprecated_osgviewer osgdb_deprecated_osgshadow osgdb_deprecated_osgterrain
osgdb_deprecated_osgvolume
)
SET(TARGET_ADDED_LIBRARIES ${TARGET_ADDED_LIBRARIES}
osgdb_serializers_osg osgdb_serializers_osgparticle osgdb_serializers_osgtext
osgdb_serializers_osgterrain osgdb_serializers_osganimation osgdb_serializers_osgfx
osgdb_serializers_osgshadow osgdb_serializers_osgmanipulator osgdb_serializers_osgsim
osgdb_serializers_osgvolume
)
#backup setting
SET(TMP_OSG_BUILD_APPLICATION_BUNDLES {$OSG_BUILD_APPLICATION_BUNDLES})

View File

@@ -7,9 +7,11 @@
// multi-touch gestures.
#import "iphoneViewerAppDelegate.h"
#include <osgGA/MultiTouchTrackballManipulator>
#include <osg/ShapeDrawable>
#include <osgDB/FileUtils>
#include <osgUtil/Optimizer>
#include <osgGA/MultiTouchTrackballManipulator>
//include the iphone specific windowing stuff
#include <osgViewer/api/IOS/GraphicsWindowIOS>
@@ -18,6 +20,7 @@
// global programs
osg::ref_ptr<osg::Program> _vertColorProgram;
osg::ref_ptr<osg::Program> _textureProgram;
@interface MyViewController : UIViewController
@@ -323,6 +326,10 @@ private:
_vertColorProgram = new osg::Program();
_vertColorProgram->addShader( new osg::Shader(osg::Shader::VERTEX, ColorShaderVert));
_vertColorProgram->addShader( new osg::Shader(osg::Shader::FRAGMENT, ColorShaderFrag));
_textureProgram = new osg::Program();
_textureProgram->addShader( new osg::Shader(osg::Shader::VERTEX, TextureShaderVert));
_textureProgram->addShader( new osg::Shader(osg::Shader::FRAGMENT, TextureShaderFrag));
#endif
//create root
@@ -330,7 +337,7 @@ private:
_root->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
//load and attach scene model
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("hog.osg");
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile(osgDB::findDataFile("lz.osg"));
if (!model) {
osg::Geode* geode = new osg::Geode();
osg::ShapeDrawable* drawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 1));
@@ -341,7 +348,8 @@ private:
// attach shader program if needed
#if defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
model->getOrCreateStateSet()->setAttributeAndModes(_vertColorProgram, osg::StateAttribute::ON);
//model->getOrCreateStateSet()->setAttributeAndModes(_vertColorProgram, osg::StateAttribute::ON);
model->getOrCreateStateSet()->setAttributeAndModes(_textureProgram, osg::StateAttribute::ON);
optimizeNode(model);
#endif

View File

@@ -9,11 +9,35 @@ USE_GRAPICSWINDOW_IMPLEMENTATION(IOS)
//plugins
USE_OSGPLUGIN(osg)
USE_DOTOSGWRAPPER_LIBRARY(osg)
USE_DOTOSGWRAPPER_LIBRARY(osgFX)
USE_DOTOSGWRAPPER_LIBRARY(osgParticle)
USE_DOTOSGWRAPPER_LIBRARY(osgShadow)
USE_DOTOSGWRAPPER_LIBRARY(osgSim)
USE_DOTOSGWRAPPER_LIBRARY(osgTerrain)
USE_DOTOSGWRAPPER_LIBRARY(osgText)
USE_DOTOSGWRAPPER_LIBRARY(osgViewer)
USE_DOTOSGWRAPPER_LIBRARY(osgVolume)
USE_OSGPLUGIN(osg2)
USE_SERIALIZER_WRAPPER_LIBRARY(osg)
USE_SERIALIZER_WRAPPER_LIBRARY(osgAnimation)
USE_SERIALIZER_WRAPPER_LIBRARY(osgFX)
USE_SERIALIZER_WRAPPER_LIBRARY(osgManipulator)
USE_SERIALIZER_WRAPPER_LIBRARY(osgParticle)
USE_SERIALIZER_WRAPPER_LIBRARY(osgShadow)
USE_SERIALIZER_WRAPPER_LIBRARY(osgSim)
USE_SERIALIZER_WRAPPER_LIBRARY(osgTerrain)
USE_SERIALIZER_WRAPPER_LIBRARY(osgText)
USE_SERIALIZER_WRAPPER_LIBRARY(osgVolume)
//USE_OSGPLUGIN(obj)
//USE_OSGPLUGIN(ive)
USE_OSGPLUGIN(osg)
USE_OSGPLUGIN(imageio)
USE_OSGPLUGIN(rgb)
//USE_OSGPLUGIN(pvr)
//USE_OSGPLUGIN(avfoundation)
//USE_OSGPLUGIN(freetype)

View File

@@ -57,3 +57,60 @@ const char* ColorShaderFrag = NULL;
#endif
//
// texture shader
//
#if OSG_GLES3_FEATURES
const char* TextureShaderVert =
"#version 300 es\n"
"in vec4 osg_Vertex;\n"
"in vec4 osg_MultiTexCoord0;\n"
"out vec4 texcoord0;\n"
"uniform mat4 osg_ModelViewProjectionMatrix;\n"
"void main()\n"
"{\n"
" gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;\n"
" texcoord0 = osg_MultiTexCoord0;\n"
"}\n";
const char* TextureShaderFrag =
"#version 300 es\n"
"in lowp vec4 texcoord0;\n"
"uniform sampler2D texture0;\n"
"out lowp vec4 fragColor;\n"
"void main()\n"
"{\n"
" fragColor = texture(texture0, texcoord0.xy);\n"
"}\n";
#elif OSG_GLES2_FEATURES
const char* TextureShaderVert =
"#version 100\n"
"attribute vec4 osg_Vertex;\n"
"attribute vec4 osg_MultiTexCoord0;\n"
"uniform mat4 osg_ModelViewProjectionMatrix;\n"
"varying vec4 texcoord0;\n"
"void main()\n"
"{\n"
" gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;\n"
" texcoord0 = osg_MultiTexCoord0;\n"
"}\n";
const char* TextureShaderFrag =
"#version 100\n"
"varying lowp vec4 texcoord0;\n"
"uniform sampler2D texture0;\n"
"void main()\n"
"{\n"
" gl_FragColor = texture2D(texture0, texcoord0.xy);\n"
"}\n";
#else
const char* TextureShaderVert = NULL;
const char* TextureShaderFrag = NULL;
#endif