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


C++ ShaderSource类代码示例

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


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

示例1: ForwardModule

void DrawWidget::initPipeline()
{
    if(renderer.isModernOpenGLAvailable())
    {
        forward = new ForwardModule();
        QString frag = QtUtils::fileToString(":shaders/shaders/forward.frag.glsl");
        QString vert = QtUtils::fileToString(":shaders/shaders/forward.vert.glsl");
        ShaderSource *source = new ShaderSource();
        source->setSource(frag.toStdString().c_str(), ShaderSource::FRAGMENT);
        source->setSource(vert.toStdString().c_str(), ShaderSource::VERTEX);
        forward->setShaderSource(source);
        forward->compileShaders(sceneManager.getScene());
        renderer.addModule(forward, "forward");
        pick = new PickModule(width(), height());
        forward->setRenderTarget(pick->getFrameBuffer());
        renderer.addModule(pick, "pick");
        forward->setClearBeforeDrawing(true);
#ifdef COMPATIBILITY_DIMITRI
        qtFBO = new FrameBuffer(defaultFramebufferObject());
#endif
        pick->setRenderTarget(qtFBO);
    }
    else
        renderer.addModule(new CrappyModule(), "crappy");
}
开发者ID:ValtielArchangel,项目名称:PhysiK,代码行数:25,代码来源:drawwidget.cpp

示例2: ReadShaderSource

static bool ReadShaderSource(const char* fileName, ShaderSource& source) {
    FILE* in = fopen(fileName, "rb");
    if (!in) {
        printf("Error: unable to open input file: %s\n", fileName);
        return false;
    }

    // Obtain file size.
    fseek(in, 0, SEEK_END);
    int count = ftell(in);
    rewind(in);

    int len = (int)ceil((float)count / (float)NUM_SOURCE_STRINGS);
    source.reserve(NUM_SOURCE_STRINGS);
    // Notice the usage of do-while instead of a while loop here.
    // It is there to handle empty files in which case a single empty
    // string is added to vector.
    do {
        char* data = new char[len + 1];
        int nread = fread(data, 1, len, in);
        data[nread] = '\0';
        source.push_back(data);

        count -= nread;
    } while (count > 0);

    fclose(in);
    return true;
}
开发者ID:hideakihata,项目名称:mozilla-central.fgv,代码行数:29,代码来源:translator.cpp

示例3: create_blur_shaders

static void
create_blur_shaders(ShaderSource& vtx_source, ShaderSource& frg_source,
                    unsigned int radius, float sigma, BlurDirection direction)
{
    vtx_source.append_file(GLMARK_DATA_PATH"/shaders/desktop.vert");
    frg_source.append_file(GLMARK_DATA_PATH"/shaders/desktop-blur.frag");

    /* Don't let the gaussian curve become too narrow */
    if (sigma < 1.0)
        sigma = 1.0;

    unsigned int side = 2 * radius + 1;

    for (unsigned int i = 0; i < radius + 1; i++) {
        float s2 = 2.0 * sigma * sigma;
        float k = 1.0 / std::sqrt(M_PI * s2) * std::exp( - (static_cast<float>(i) * i) / s2);
        std::stringstream ss_tmp;
        ss_tmp << "Kernel" << i;
        frg_source.add_const(ss_tmp.str(), k);
    }

    std::stringstream ss;
    ss << "result = " << std::endl;

    if (direction == BlurDirectionHorizontal) {
        for (unsigned int i = 0; i < side; i++) {
            int offset = static_cast<int>(i - radius);
            ss << "texture2D(Texture0, TextureCoord + vec2(" <<
                  offset << ".0 * TextureStepX, 0.0)) * Kernel" <<
                  std::abs(offset) << " +" << std::endl;
        }
        ss << "0.0 ;" << std::endl;
    }
    else if (direction == BlurDirectionVertical) {
        for (unsigned int i = 0; i < side; i++) {
            int offset = static_cast<int>(i - radius);
            ss << "texture2D(Texture0, TextureCoord + vec2(0.0, " <<
                  offset << ".0 * TextureStepY)) * Kernel" <<
                  std::abs(offset) << " +" << std::endl;
        }
        ss << "0.0 ;" << std::endl;
    }
    else if (direction == BlurDirectionBoth) {
        for (unsigned int i = 0; i < side; i++) {
            int ioffset = static_cast<int>(i - radius);
            for (unsigned int j = 0; j < side; j++) {
                int joffset = static_cast<int>(j - radius);
                ss << "texture2D(Texture0, TextureCoord + vec2(" <<
                      ioffset << ".0 * TextureStepX, " <<
                      joffset << ".0 * TextureStepY))" <<
                      " * Kernel" << std::abs(ioffset) <<
                      " * Kernel" << std::abs(joffset) << " +" << std::endl;
            }
        }
        ss << " 0.0;" << std::endl;
    }

    frg_source.replace("$CONVOLUTION$", ss.str());
}
开发者ID:Gnurou,项目名称:glmark2,代码行数:59,代码来源:scene-desktop.cpp

示例4: FreeShaderSource

static void FreeShaderSource(ShaderSource &source)
{
    for (ShaderSource::size_type i = 0; i < source.size(); ++i)
    {
        delete [] source[i];
    }
    source.clear();
}
开发者ID:eltictacdicta,项目名称:freshplayerplugin,代码行数:8,代码来源:translator.cpp

示例5: CompileFile

//
//   Read a file's data into a string, and compile it using ShCompile
//
bool CompileFile(char* fileName, ShHandle compiler, int compileOptions)
{
    ShaderSource source;
    if (!ReadShaderSource(fileName, source))
        return false;

    int ret = ShCompile(compiler, &source[0], source.size(), compileOptions);

    FreeShaderSource(source);
    return ret ? true : false;
}
开发者ID:hideakihata,项目名称:mozilla-central.fgv,代码行数:14,代码来源:translator.cpp

示例6: stream_source

void
UberShaderStreamer<T>::
stream_source(ShaderSource &dst, const std::string &in_prefix,
              const ShaderSource &shader)
{
  /* This terribly hack is because GLES specfication mandates
   * for GLSL in GLES to not support token pasting (##) in the
   * pre-processor. Many GLES drivers support it anyways, but
   * Mesa does not. Sighs. So we emulate the token pasting
   * for the FASTUIDRAW_LOCAL() macro.
   */
  using namespace fastuidraw;
  std::string src, needle;
  std::string::size_type pos, last_pos;
  std::string prefix(in_prefix + "_local_");

  needle = "FASTUIDRAW_LOCAL";
  src = shader.assembled_code(true);

  /* HUNT for FASTUIDRAW_LOCAL(X) anywhere in the code and expand
   * it. NOTE: this is NOT robust at all as it is not a real
   * pre-processor, just a hack. It will fail if the macro
   * invocation is spread across multiple lines or if the agument
   * was a macro itself that needs to expanded by the pre-processor.
   */
  for (last_pos = 0, pos = src.find(needle); pos != std::string::npos; last_pos = pos + 1, pos = src.find(needle, pos + 1))
    {
      std::string::size_type open_pos, close_pos;

      /* stream up to pos */
      if (pos > last_pos)
        {
          dst << src.substr(last_pos, pos - last_pos);
        }

      /* find the first open and close-parentesis pair after pos. */
      open_pos = src.find('(', pos);
      close_pos = src.find(')', pos);

      if (open_pos != std::string::npos
          && close_pos != std::string::npos
          && open_pos < close_pos)
        {
          std::string tmp;
          tmp = src.substr(open_pos + 1, close_pos - open_pos - 1);
          // trim the string of white spaces.
          tmp.erase(0, tmp.find_first_not_of(" \t"));
          tmp.erase(tmp.find_last_not_of(" \t") + 1);
          dst << prefix << tmp;
          pos = close_pos;
        }
    }

  dst << src.substr(last_pos)
      << "\n";
}
开发者ID:01org,项目名称:fastuidraw,代码行数:56,代码来源:uber_shader_builder.cpp

示例7: LoadShaderSource

    void ShaderSourceLoaderGL::LoadShaderSource(const std::string name, ShaderSource& shaderSource) const {
        std::string vertexSource;
        std::string fragmentSource;

        FileSystem * fileSystem = FileSystem::Instance();
        std::string builtinPath = fileSystem->FixupPathForLocalFilesystem(Constants::BuiltinShaderPathOpenGL);
        vertexSource = std::string(name + std::string(".vertex.shader"));
        fragmentSource = std::string(name + std::string(".fragment.shader"));
        shaderSource.Init(vertexSource, fragmentSource, ShaderSourceType::File, builtinPath, name);
    }
开发者ID:mkkellogg,项目名称:GTE,代码行数:10,代码来源:shadersourceloaderGL.cpp

示例8: createShaderProgram

std::auto_ptr< ShaderProgram >
createShaderProgram(
	const char * vertexFilename,
	const char * fragmentFilename
)
{
	ShaderSource vertexSource;
	vertexSource.loadShaderSource( vertexFilename );
	Shader vertexShader( Shader::VertexShader );
	vertexShader.setSource( vertexSource );
	ShaderSource fragmentSource;
	fragmentSource.loadShaderSource( fragmentFilename );
	Shader fragmentShader( Shader::FragmentShader );
	fragmentShader.setSource( fragmentSource );
	std::auto_ptr< ShaderProgram > program( new ShaderProgram() );
	program->attachShader( vertexShader );
	program->attachShader( fragmentShader );
	program->link();
	return program;
}
开发者ID:devnev,项目名称:skyways,代码行数:20,代码来源:shader.cpp

示例9: stream_shader

void
UberShaderStreamer<T>::
stream_shader(ShaderSource &dst, const std::string &prefix,
              get_src_type get_src, get_main_name_type get_main_name,
              const StreamVaryingsHelper<T> &stream_varyings_helper,
              const StreamSurroundSrcHelper<T> &stream_surround_src,
              const fastuidraw::reference_counted_ptr<const T> &sh,
              int dependency_depth)
{
  using namespace fastuidraw;

  c_array<const reference_counted_ptr<const T> > deps(sh->dependency_list_shaders());
  c_array<const c_string> dep_names(sh->dependency_list_names());

  FASTUIDRAWassert(deps.size() == dep_names.size());
  dst << "// Have " << deps.size() << " dependencies at depth " << dependency_depth << "\n";
  for (unsigned int i = 0; i < deps.size(); ++i)
    {
      std::string realized_name;
      realized_name = stream_dependency(dst, prefix, i, get_src, get_main_name,
                                        stream_varyings_helper, stream_surround_src,
                                        deps[i], dep_names[i], dependency_depth + 1);
      dst.add_macro(dep_names[i], realized_name.c_str());
    }

  dst.add_macro(get_main_name(sh), prefix.c_str());
  stream_surround_src.pre_source(dst, sh);
  stream_source(dst, prefix, (sh.get()->*get_src)());
  stream_surround_src.post_source(dst);
  dst.remove_macro(get_main_name(sh));

  for (unsigned int i = 0; i < deps.size(); ++i)
    {
      dst.remove_macro(dep_names[i]);
    }
}
开发者ID:01org,项目名称:fastuidraw,代码行数:36,代码来源:uber_shader_builder.cpp

示例10: compile

        inline void compile(ShaderSource& mSource)
        {
            glShaderSource(glId, 1, mSource.getSourceData(), nullptr);
            glCompileShader(glId);

            GLint status;
            glGetShaderiv(glId, GL_COMPILE_STATUS, &status);

            char logBuffer[shaderLogBufferSize];
            glGetShaderInfoLog(glId, shaderLogBufferSize, nullptr, logBuffer);

            std::string compilationLog = std::string{logBuffer};
            if(!compilationLog.empty())
                ssvu::lo("Shader compilation log") << compilationLog
                                                   << std::endl;
        }
开发者ID:SuperV1234,项目名称:glTests,代码行数:16,代码来源:Shader.hpp

示例11: glShaderSource

void Shader::setSource(const ShaderSource& source)
{
	std::list< std::string > sources = source.getSources();
	if ( sources.size() == 0 )
	{
		throw std::runtime_error("Attempted to create shader with empty sources");
	}
	if ( sources.size() == 1 )
	{
		const char * cstr = sources.front().c_str();
		glShaderSource(_shaderId, 1, &cstr, 0);
	}
	else
	{
		std::vector< const char* > strArray(sources.size(), 0);
		size_t i = 0;
		std::list< std::string >::iterator sourcestr = sources.begin();
		for ( ; sourcestr != sources.end(); ++sourcestr, ++i )
		{
			strArray[i] = sourcestr->c_str();
		}
		glShaderSource(_shaderId, i, &strArray[0], 0);
	}
}
开发者ID:devnev,项目名称:skyways,代码行数:24,代码来源:shader.cpp

示例12: create_blur_shaders

void
create_blur_shaders(ShaderSource& vtx_source, ShaderSource& frg_source,
                    unsigned int radius, float sigma, BlurRenderer::BlurDirection direction,
                    float tilt_shift)
{
    vtx_source.append_file(GLMARK_DATA_PATH"/shaders/terrain-texture.vert");
    frg_source.append_file(GLMARK_DATA_PATH"/shaders/terrain-blur.frag");

    /* Don't let the gaussian curve become too narrow */
    if (sigma < 1.0)
        sigma = 1.0;

    unsigned int side = 2 * radius + 1;
    float values[radius];
    float sum = 0.0;

    for (unsigned int i = 0; i < radius + 1; i++) {
        float s2 = 2.0 * sigma * sigma;
        float k = 1.0 / std::sqrt(M_PI * s2) * std::exp( - (static_cast<float>(i) * i) / s2);
        values[i] = k;
        sum += k;
    }

    sum += sum - values[0];

    for (unsigned int i = 0; i < radius + 1; i++) {
        std::stringstream ss_tmp;
        ss_tmp << "Kernel" << i;
        frg_source.add_const(ss_tmp.str(), values[i] / sum);
    }

    frg_source.add_const("TiltShift", tilt_shift);

    std::stringstream ss;

    if (direction == BlurRenderer::BlurDirectionHorizontal ||
        direction == BlurRenderer::BlurDirectionBoth)
    {
        if (tilt_shift == 1.0)
            ss << "const float stepX = TextureStepX;" << std::endl;
        else
            ss << "float stepX = TextureStepX * abs(TiltShift - TextureCoord.y) / abs(1.0 - TiltShift);" << std::endl;
    }

    if (direction == BlurRenderer::BlurDirectionVertical ||
        direction == BlurRenderer::BlurDirectionBoth)
    {
        if (tilt_shift == 1.0)
            ss << "const float stepY = TextureStepY;" << std::endl;
        else
            ss << "float stepY = TextureStepY * abs(TiltShift - TextureCoord.y) / abs(1.0 - TiltShift);" << std::endl;
    }

    ss << "result = " << std::endl;

    if (direction == BlurRenderer::BlurDirectionHorizontal) {
        for (unsigned int i = 0; i < side; i++) {
            int offset = static_cast<int>(i - radius);
            ss << "texture2D(Texture0, TextureCoord + vec2(" <<
                  offset << ".0 * stepX, 0.0)) * Kernel" <<
                  std::abs(offset) << " +" << std::endl;
        }
        ss << "0.0 ;" << std::endl;
    }
    else if (direction == BlurRenderer::BlurDirectionVertical) {
        for (unsigned int i = 0; i < side; i++) {
            int offset = static_cast<int>(i - radius);
            ss << "texture2D(Texture0, TextureCoord + vec2(0.0, " <<
                  offset << ".0 * stepY)) * Kernel" <<
                  std::abs(offset) << " +" << std::endl;
        }
        ss << "0.0 ;" << std::endl;
    }
    else if (direction == BlurRenderer::BlurDirectionBoth) {
        for (unsigned int i = 0; i < side; i++) {
            int ioffset = static_cast<int>(i - radius);
            for (unsigned int j = 0; j < side; j++) {
                int joffset = static_cast<int>(j - radius);
                ss << "texture2D(Texture0, TextureCoord + vec2(" <<
                      ioffset << ".0 * stepX, " <<
                      joffset << ".0 * stepY))" <<
                      " * Kernel" << std::abs(ioffset) <<
                      " * Kernel" << std::abs(joffset) << " +" << std::endl;
            }
        }
        ss << " 0.0;" << std::endl;
    }

    frg_source.replace("$CONVOLUTION$", ss.str());
}
开发者ID:Gnurou,项目名称:glmark2,代码行数:90,代码来源:blur-renderer.cpp

示例13: OGLShader

std::unique_ptr<OGL::OGLShader> OGL::OGLShader::Load(const ShaderSource& shaderSource)
{
	GLuint programID = OGL::LoadShaderFromSource(shaderSource.GetParsedSource());
	return std::unique_ptr<OGLShader>(new OGLShader(new Impl(programID)));
}
开发者ID:JaakkoLipsanen,项目名称:Elbaf,代码行数:5,代码来源:OGLShader.cpp

示例14: 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

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