Ejemplo n.º 1
0
void OpenGLShaderQuad::SetParametersFromList(IPluginObjectInstance *pInstance) {
  for(int i=0;i<shaderParams.size();i++) {
    OpenGLShaderParameter *param = shaderParams[i];
    std::string name = param->GetName();

    unsigned int idParam = program->GetUniform(name.c_str());
    if (idParam == -1) {  // missing in shader
      if (!param->WarningIssued()) {
        pInstance->GetLogger()->Error("Parameter '%s' not found in shader!", name.c_str());
        param->SetWarningFlag();
      }
      continue;
    }

    switch(param->GetType()) {
      case kParamType_Float :
        glUniform1f(idParam, param->GetFloat()); 
        break;
      case kParamType_Vec3 :
        {
          float tmp[3];
          param->GetVec3(tmp);
          glUniform3f(idParam, tmp[0], tmp[1], tmp[2]);
        }
        break;
      default :
        // not supported just yet...
        break;
    }


  }
}
Ejemplo n.º 2
0
void OpenGLShaderQuad::SetParametersFromList(IPluginObjectInstance *pInstance) {
  for(int i=0;i<shaderParams.size();i++) {
    OpenGLShaderParameter *param = shaderParams[i];
    std::string name = param->GetName();

    int idParam = program->GetUniform(name.c_str());
    if (idParam == -1) {  // missing in shader
      if (!param->WarningIssued()) {
        pInstance->GetLogger()->Error("Parameter '%s' not found in shader!", name.c_str());
        param->SetWarningFlag();
        exit(1);
      }
      continue;
    }

    // printf("%d:%s\n",i,name.c_str());

    switch(param->GetType()) {
      case kParamType_Float :
        glUniform1f(idParam, param->GetFloat()); 
        break;
      case kParamType_Vec3 :
        {
          float tmp[3];
          param->GetVec3(tmp);
          glUniform3f(idParam, tmp[0], tmp[1], tmp[2]);
        }
        break;
      case kParamType_Texture :
        {
          glActiveTexture(GL_TEXTURE0+texture_count);        
          glBindTexture(GL_TEXTURE_2D,param->GetTexture());
          glUniform1i(idParam, texture_count); // texture_count);  
          int err = glGetError();
          if (err != GL_NO_ERROR) {
            pInstance->GetLogger()->Error("Unable to bind texture for param: %s (error=%d)",name.c_str(),err);
          }
          texture_count++;

        }
      default :
        // not supported just yet...
        break;
    }


  }
}
Ejemplo n.º 3
0
void OpenGLShaderQuad::PostInitialize(ISystem *ySys, IPluginObjectInstance *pInstance) {
  OpenGLShaderBase::Initialize(ySys, 
    std::string(vertexshader_source->v->string),
    std::string(pixelshader_source->v->string));

  OpenGLShaderBase::ReloadIfNeeded(true);
  if (program == NULL) {
    ySys->GetLogger("GLShaderQuad")->Error("Shader program load error");
    exit(1);
  }

  // TODO: Go through children and find any shader parameters
  IDocNode *pNode = pInstance->GetDocumentNode();
  int nChildren = pNode->GetNumChildren(kNodeType_ObjectInstance);
  if (nChildren == 0) return;

  pInstance->GetLogger()->Debug("Checking %d child nodes for shader parameters",nChildren);
  for (int i=0;i<nChildren;i++)
  {
    //    IPluginObjectInstance *pObject = pDoc->GetChildAt(pInstance, i, kNodeType_ObjectInstance);
    IDocNode *pChildNode = pNode->GetChildAt(i, kNodeType_ObjectInstance);
    IPluginObjectInstance *pObject = dynamic_cast<IPluginObjectInstance *>(pChildNode->GetNodeObject());
    OpenGLShaderParameter *shaderParam = dynamic_cast<OpenGLShaderParameter *> (pObject->GetExtObject());
    if (shaderParam != NULL)
    {

      shaderParams.push_back(shaderParam);
    } else
    {
      pInstance->GetLogger()->Error("Unsupported child type, gl.ShaderQuad only supports 'gl.ShaderParam'");
    }
  }

  pInstance->GetLogger()->Debug("Dump params");
  for(int i=0;i<shaderParams.size();i++) {
    OpenGLShaderParameter *param = shaderParams[i];
    std::string name = param->GetName();
    std::string tname = param->GetTypeName();
    ShaderParamType tParam = param->GetType();

    pInstance->GetLogger()->Debug("  name: %s, type=%s (%d)", name.c_str(), tname.c_str(), tParam);
  }

}