Ejemplo 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);
    }
  }
}
Ejemplo n.º 2
0
void RenderMaterialUniforms::SetUniforms( const RenderMaterial& material, Program& program, ShaderSubTypes shaderType )
{
  GLint location = Program::UNIFORM_UNKNOWN;

  location = mCustomUniform[ shaderType ][ 0 ].GetUniformLocation( program, "uMaterial.mOpacity" );
  if( Program::UNIFORM_UNKNOWN != location )
  {
    program.SetUniform1f( location, material.mOpacity );
  }

  location = mCustomUniform[ shaderType ][ 1 ].GetUniformLocation( program, "uMaterial.mShininess" );
  if( Program::UNIFORM_UNKNOWN != location )
  {
    program.SetUniform1f( location, material.mShininess );
  }

  location = mCustomUniform[ shaderType ][ 2 ].GetUniformLocation( program, "uMaterial.mAmbient" );
  if( Program::UNIFORM_UNKNOWN != location )
  {
    const Vector4& color = material.mAmbientColor;
    program.SetUniform4f( location,  color.r, color.g, color.b, color.a );
  }

  location = mCustomUniform[ shaderType ][ 3 ].GetUniformLocation( program, "uMaterial.mDiffuse" );
  if( Program::UNIFORM_UNKNOWN != location )
  {
    const Vector4& color = material.mDiffuseColor;
    program.SetUniform4f( location,  color.r, color.g, color.b, color.a );
  }

  location = mCustomUniform[ shaderType ][ 4 ].GetUniformLocation( program, "uMaterial.mSpecular" );
  if( Program::UNIFORM_UNKNOWN != location )
  {
    const Vector4& color = material.mSpecularColor;
    program.SetUniform4f( location, color.r, color.g, color.b, color.a );
  }

  location = mCustomUniform[ shaderType ][ 5 ].GetUniformLocation( program, "uMaterial.mEmissive" );
  if( Program::UNIFORM_UNKNOWN != location )
  {
    const Vector4& color = material.mEmissiveColor;
    program.SetUniform4f( location, color.r, color.g, color.b, color.a );
  }
}
Ejemplo 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 );
}