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

View File

@@ -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

View File

@@ -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;

View File

@@ -1616,7 +1616,7 @@ void Texture::computeInternalFormatWithImage(const osg::Image& image) const
}
}
#if defined (OSG_GLES1_AVAILABLE) || defined (OSG_GLES2_AVAILABLE)
#if defined (OSG_GLES1_AVAILABLE) || defined (OSG_GLES2_AVAILABLE) || defined (OSG_GLES3_AVAILABLE)
// GLES doesn't cope with internal formats of 1,2,3 and 4 and glTexImage doesn't
// handle the _OES pixel formats so map them to the appropriate equivilants.
switch(internalFormat)
@@ -1905,7 +1905,7 @@ void Texture::applyTexParameters(GLenum target, State& state) const
wr = CLAMP;
}
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GL3_AVAILABLE)
#if defined(OSG_GLES1_AVAILABLE) || defined(OSG_GLES2_AVAILABLE) || defined(OSG_GLES3_AVAILABLE) || defined(OSG_GL3_AVAILABLE)
if (ws == CLAMP) ws = CLAMP_TO_EDGE;
if (wt == CLAMP) wt = CLAMP_TO_EDGE;
if (wr == CLAMP) wr = CLAMP_TO_EDGE;
@@ -2206,7 +2206,7 @@ void Texture::applyTexImage2D_load(State& state, GLenum target, const Image* ima
{
pbo = 0;
}
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE)
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE)
glPixelStorei(GL_UNPACK_ROW_LENGTH,rowLength);
#endif
if( !mipmappingRequired || useHardwareMipMapGeneration)
@@ -2552,7 +2552,7 @@ void Texture::applyTexImage2D_subload(State& state, GLenum target, const Image*
{
pbo = 0;
}
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE)
#if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE)
glPixelStorei(GL_UNPACK_ROW_LENGTH,rowLength);
#endif
if( !mipmappingRequired || useHardwareMipMapGeneration)
@@ -2689,7 +2689,7 @@ Texture::GenerateMipmapMode Texture::mipmapBeforeTexImage(const State& state, bo
{
if (hardwareMipmapOn)
{
#if defined( OSG_GLES2_AVAILABLE ) || defined( OSG_GL3_AVAILABLE )
#if defined( OSG_GLES2_AVAILABLE ) || defined( OSG_GLES3_AVAILABLE ) || defined( OSG_GL3_AVAILABLE )
return GENERATE_MIPMAP;
#else