Esempio n. 1
0
void RenderMaterial::BindTexture( Program& program, ResourceId id, Texture* texture, unsigned int textureUnit, Program::UniformType samplerIndex ) const
{
  DALI_ASSERT_DEBUG( NULL != mTextureCache );

  if( texture != NULL )
  {
    mTextureCache->BindTexture( texture, id, GL_TEXTURE_2D, GL_TEXTURE0 + textureUnit );
    // Set sampler uniforms for textures
    GLint samplerLoc = program.GetUniformLocation( samplerIndex );
    if( -1 != samplerLoc )
    {
      program.SetUniform1i( samplerLoc, textureUnit );
    }

    GLint location = program.GetUniformLocation(Program::UNIFORM_CUSTOM_TEXTURE_COORDS);
    if( Program::UNIFORM_UNKNOWN != location )
    {
      UvRect uvs;
      texture->GetTextureCoordinates(uvs);

      // Account for UV mapping on non power of 2 textures
      program.SetUniform4f(location, uvs.u0, uvs.v0, uvs.u2-uvs.u0, uvs.v2-uvs.v0);
    }
  }
}
Esempio n. 2
0
const int CustomUniform::GetUniformLocation( Program& program, const char* name )
{
  if( 0 == mCacheIndex )
  {
    Initialize( program, name );
  }

  return program.GetUniformLocation( mCacheIndex );
}
Esempio n. 3
0
void Renderer::Render( Context& context,
                       SceneGraph::TextureCache& textureCache,
                       BufferIndex bufferIndex,
                       const SceneGraph::NodeDataProvider& node,
                       SceneGraph::Shader& defaultShader,
                       const Matrix& modelViewMatrix,
                       const Matrix& viewMatrix,
                       const Matrix& projectionMatrix,
                       bool cull,
                       bool blend )
{
  NewRenderer* renderer = GetNewRenderer(); // avoid a dynamic cast per item per frame

  if( renderer )
  {
    // Get the shader from the material:
    mShader = &renderer->mRenderDataProvider->GetShader();
  }

  // if mShader is NULL it means we're set to default
  if( !mShader )
  {
    mShader = &defaultShader;
  }

  if( !CheckResources() )
  {
    // CheckResources() is overriden in derived classes.
    // Prevents modify the GL state if resources are not ready and nothing is to be rendered.
    return;
  }

  // Get the program to use:
  Program* program = mShader->GetProgram();
  if( !program )
  {
    // if program is NULL it means this is a custom shader with non matching geometry type so we need to use default shaders program
    program = defaultShader.GetProgram();
    DALI_ASSERT_DEBUG( program && "Default shader should always have a program available." );
    if( !program )
    {
      DALI_LOG_ERROR( "Failed to get program for shader at address %p.", (void*) &*mShader );
      return;
    }
  }

  // Take the program into use so we can send uniforms to it
  program->Use();

  DoSetCullFaceMode( context, bufferIndex );

  DoSetBlending( context, bufferIndex, blend );

  // Ignore missing uniforms - custom shaders and flat color shaders don't have SAMPLER
  // set projection and view matrix if program has not yet received them yet this frame
  const Matrix& modelMatrix = node.GetModelMatrix( bufferIndex );
  SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix );

  // set color uniform
  GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR );
  if( Program::UNIFORM_UNKNOWN != loc )
  {
    const Vector4& color = node.GetRenderColor( bufferIndex );
    program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
  }

  //@todo MESH_REWORK Remove after removing ImageRenderer
  DoSetUniforms(context, bufferIndex, mShader, program );

  // subclass rendering and actual draw call
  DoRender( context, textureCache, node, bufferIndex, *program, modelViewMatrix, viewMatrix );
}