当前位置: 首页>>代码示例>>C++>>正文


C++ ShaderSource::str方法代码示例

本文整理汇总了C++中ShaderSource::str方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderSource::str方法的具体用法?C++ ShaderSource::str怎么用?C++ ShaderSource::str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShaderSource的用法示例。


在下文中一共展示了ShaderSource::str方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: defined

std::string	EnvironmentEs::generateFragmentShader( const ShaderDef &shader )
{
	ShaderSource ss;	

#if ( CINDER_GL_ES_VERSION >= CINDER_GL_ES_VERSION_3 )
  #if ( CINDER_GL_ES_VERSION == CINDER_GL_ES_VERSION_3 )
	ss << "#version 300 es";
  #elif	( CINDER_GL_ES_VERSION == CINDER_GL_ES_VERSION_3_1 )
	ss << "#version 310 es";
  #elif ( CINDER_GL_ES_VERSION == CINDER_GL_ES_VERSION_3_2 )
	ss << "#version 320 es";
  #endif

  #if defined( CINDER_ANDROID )
	if( shader.mTextureMappingExternalOes) {
		ss << "#extension GL_OES_EGL_image_external : require";
	}
  #endif

	ss << "precision highp float;";

  #if defined( CINDER_ANDROID )
	if( shader.mTextureMapping ) {	
		if( shader.mTextureMappingExternalOes ) {
			ss << "uniform samplerExternalOES uTex0;";
			ss << "in highp vec2              TexCoord;";
		}
		else {
			ss << "uniform sampler2D uTex0;";
			ss << "in highp vec2     TexCoord;";
		}
	}
  #else	
	if( shader.mTextureMapping ) {
		ss << "uniform sampler2D uTex0;";
		ss << "in highp vec2     TexCoord;";
	}
  #endif
	if( shader.mColor ) {
		ss << "in lowp vec4 Color;";
	}

	if( shader.mLambert ) { 
		ss << "in highp vec3 Normal;";
	}

	ss << "out lowp vec4 outColor;";
	ss << "void main( void )";
	ss << "{\n";

	if( shader.mLambert ) {
		ss << "    const vec3 L = vec3( 0, 0, 1 );";
		ss << "    vec3 N = normalize( Normal );";
		ss << "    float lambert = max( 0.0, dot( N, L ) );";
	}
	
	std::string s = "outColor = vec4( 1 )";
	
	if( shader.mTextureMapping ) {
		s += " * texture( uTex0, TexCoord.st )";
	}
	
	if( shader.mColor ) {
		s += " * Color";
	}

	if( shader.mLambert ) {
		s += " * vec4( vec3( lambert ), 1.0 )";
	}

	s += ";";
	
	ss << "    " + s;
	
	ss << "}";

#else // OpenGL ES 2.0

	ss << "#version 100";

  #if defined( CINDER_ANDROID )
	if( shader.mTextureMappingExternalOes) {
		ss << "#extension GL_OES_EGL_image_external : require";
	}
  #endif

	ss << "precision highp float;";

  #if defined( CINDER_ANDROID )
	if( shader.mTextureMapping ) {	
		if( shader.mTextureMappingExternalOes ) {
			ss << "uniform samplerExternalOES uTex0;";
			ss << "varying highp vec2         TexCoord;";
		}
		else {
			ss << "uniform sampler2D  uTex0;";
			ss << "varying highp vec2 TexCoord;";
		}
	}
  #else	
//.........这里部分代码省略.........
开发者ID:sortofsleepy,项目名称:Cinder,代码行数:101,代码来源:EnvironmentEs.cpp

示例2: main

std::string	EnvironmentEs::generateVertexShader( const ShaderDef &shader )
{
	ShaderSource ss;

#if ( CINDER_GL_ES_VERSION >= CINDER_GL_ES_VERSION_3 )
  #if ( CINDER_GL_ES_VERSION == CINDER_GL_ES_VERSION_3 )
	ss << "#version 300 es";
  #elif	( CINDER_GL_ES_VERSION == CINDER_GL_ES_VERSION_3_1 )
	ss << "#version 310 es";
  #elif ( CINDER_GL_ES_VERSION == CINDER_GL_ES_VERSION_3_2 )
	ss << "#version 320 es";
  #endif

	ss << "uniform mat4 ciModelViewProjection;";

	if( shader.mLambert ) {
		ss <<  "uniform mat3	ciNormalMatrix;";
	}
	
	ss << "in vec4      ciPosition;";

	if( shader.mUniformBasedPosAndTexCoord ) {
		ss << "uniform vec2 uPositionOffset, uPositionScale;";
		if( shader.mTextureMapping ) {
			ss << "uniform vec2 uTexCoordOffset, uTexCoordScale;";
		}
	}

	if( shader.mTextureMapping ) {
		ss << "in vec2        ciTexCoord0;";
		ss << "out highp vec2 TexCoord;";
	}

	if( shader.mColor ) {
		ss << "in vec4        ciColor;";
		ss << "out lowp vec4  Color;";
	}

	if( shader.mLambert ) {
		ss << "in vec3        ciNormal;";
		ss << "out highp vec3 Normal;";
	}


	ss << "void main( void )";
	ss << "{";

	if( shader.mUniformBasedPosAndTexCoord ) {
		ss << "    gl_Position = ciModelViewProjection * ( vec4( uPositionOffset, 0, 0 ) + vec4( uPositionScale, 1, 1 ) * ciPosition );";
	}
	else {
		ss << "    gl_Position = ciModelViewProjection * ciPosition;";
	}

	if( shader.mTextureMapping ) {	
		if( shader.mUniformBasedPosAndTexCoord ) {
			ss << "    TexCoord = uTexCoordOffset + uTexCoordScale * ciTexCoord0;";
		}
		else {
			ss << "    TexCoord = ciTexCoord0;";
		}
	}

	if( shader.mColor ) {
		ss << "    Color = ciColor;";
	}

	if( shader.mLambert ) {
		ss << "    Normal = ciNormalMatrix * ciNormal;";
	}

	ss << "}";	

#else // OpenGL ES 2.0

	ss << "#version 100";

	ss << "uniform mat4   ciModelViewProjection;";

	if( shader.mLambert ) {
		ss <<  "uniform mat3	ciNormalMatrix;";
	}

	ss << "attribute vec4 ciPosition;";

	if( shader.mUniformBasedPosAndTexCoord ) {
		ss << "uniform vec2 uPositionOffset, uPositionScale;";
		if( shader.mTextureMapping ) {
			ss << "uniform vec2 uTexCoordOffset, uTexCoordScale;";
		}
	}

	if( shader.mTextureMapping ) {
		ss << "attribute vec2 ciTexCoord0;";
		ss << "varying highp vec2 TexCoord;";
	}

	if( shader.mColor ) {
		ss << "attribute vec4    ciColor;";
		ss << "varying lowp vec4 Color;";
//.........这里部分代码省略.........
开发者ID:sortofsleepy,项目名称:Cinder,代码行数:101,代码来源:EnvironmentEs.cpp


注:本文中的ShaderSource::str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。