Added more plugins and texture shader to iOS example, fixed a couple of missed if defines for GLES3
This commit is contained in:
@@ -9,6 +9,21 @@ SET(TARGET_SRC
|
||||
|
||||
SET(TARGET_ADDED_LIBRARIES osgdb_osg 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})
|
||||
SET(OSG_BUILD_APPLICATION_BUNDLES TRUE)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -11,9 +11,15 @@ USE_GRAPICSWINDOW_IMPLEMENTATION(IOS)
|
||||
|
||||
//USE_OSGPLUGIN(obj)
|
||||
//USE_OSGPLUGIN(ive)
|
||||
|
||||
USE_OSGPLUGIN(osg)
|
||||
USE_DOTOSGWRAPPER_LIBRARY(osg)
|
||||
|
||||
USE_OSGPLUGIN(osg2)
|
||||
USE_SERIALIZER_WRAPPER_LIBRARY(osg)
|
||||
|
||||
USE_OSGPLUGIN(imageio)
|
||||
USE_OSGPLUGIN(rgb)
|
||||
//USE_OSGPLUGIN(avfoundation)
|
||||
//USE_OSGPLUGIN(freetype)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -49,7 +49,7 @@ unsigned int PrimitiveSet::getNumPrimitives() const
|
||||
//
|
||||
void DrawArrays::draw(State& state, bool) const
|
||||
{
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
|
||||
GLenum mode = _mode;
|
||||
if (_mode==GL_QUADS)
|
||||
{
|
||||
@@ -109,7 +109,7 @@ unsigned int DrawArrayLengths::getNumPrimitives() const
|
||||
void DrawArrayLengths::draw(State& state, bool) const
|
||||
{
|
||||
GLenum mode = _mode;
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
|
||||
if (_mode==GL_QUADS)
|
||||
{
|
||||
GLint first = _first;
|
||||
@@ -188,7 +188,7 @@ DrawElementsUByte::~DrawElementsUByte()
|
||||
void DrawElementsUByte::draw(State& state, bool useVertexBufferObjects) const
|
||||
{
|
||||
GLenum mode = _mode;
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
|
||||
if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN;
|
||||
if (mode==GL_QUAD_STRIP) mode = GL_TRIANGLE_STRIP;
|
||||
#endif
|
||||
@@ -250,7 +250,7 @@ DrawElementsUShort::~DrawElementsUShort()
|
||||
void DrawElementsUShort::draw(State& state, bool useVertexBufferObjects) const
|
||||
{
|
||||
GLenum mode = _mode;
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
|
||||
if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN;
|
||||
if (mode==GL_QUAD_STRIP) mode = GL_TRIANGLE_STRIP;
|
||||
#endif
|
||||
@@ -311,7 +311,7 @@ DrawElementsUInt::~DrawElementsUInt()
|
||||
void DrawElementsUInt::draw(State& state, bool useVertexBufferObjects) const
|
||||
{
|
||||
GLenum mode = _mode;
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE)
|
||||
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
|
||||
if (mode==GL_POLYGON) mode = GL_TRIANGLE_FAN;
|
||||
if (mode==GL_QUAD_STRIP) mode = GL_TRIANGLE_STRIP;
|
||||
#endif
|
||||
|
||||
@@ -567,7 +567,7 @@ void Shader::PerContextShader::compileShader(osg::State& state)
|
||||
if( ! _needsCompile ) return;
|
||||
_needsCompile = false;
|
||||
|
||||
#if defined(OSG_GLES2_AVAILABLE)
|
||||
#if defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE)
|
||||
if (_shader->getShaderBinary())
|
||||
{
|
||||
GLint numFormats = 0;
|
||||
|
||||
Reference in New Issue
Block a user