Exemplo n.º 1
0
GLuint LoadShaderAMT::attachShader(GLuint programGlid, GLenum type, const std::string &filePath, const std::string &source)
{
    char *log;
    const char *cPtr;
    GLuint glid;
    GLint logLength;
    GLint charsWritten;
    GLint compilationStatus;

    if(source.length() == 0)
    {
        return 0;
    }

    glid = glCreateShader(type);

    cPtr = source.c_str();
    glShaderSource(glid, 1, &cPtr, 0);
    glCompileShader(glid);
    glGetShaderiv(glid, GL_COMPILE_STATUS, (GLint*)&compilationStatus);

    if(compilationStatus == 0)
    {
        glGetShaderiv(glid, GL_INFO_LOG_LENGTH, &logLength);
        log = new char[logLength];
        glGetShaderInfoLog(glid, logLength, &charsWritten, log);
        rLogAssetFail(g_log, filePath, log);
        delete [] log;
        removeShader(glid);
        return 0;
    }

    glAttachShader(programGlid, glid);
    return glid;
}
Exemplo n.º 2
0
void GlShaderProgram::removeAllShaders() {
  for (size_t i = 0 ; i < attachedShaders.size() ; ++i) {
    removeShader(attachedShaders[i]);

    if (attachedShaders[i]->anonymouslyCreated()) {
      delete attachedShaders[i];
    }
  }
}
Exemplo n.º 3
0
void AppPanini::Exit(Renderer* pRenderer)
{
	ASSERT(pRenderer);

	removeShader(pRenderer, pShaderPanini);

	removeSampler(pRenderer, pSamplerTrilinearAniso);
	removeRasterizerState(pRasterizerStateCullNone);
	removeDepthState(pDepthStateDisable);

	removeRootSignature(pRenderer, pRootSignaturePaniniPostProcess);
	removePipeline(pRenderer, pPipielinePaniniPostProcess);

	removeResource(pVertexBufferTessellatedQuad);
	removeResource(pIndexBufferTessellatedQuad);

#if USE_DEDICATED_COMMAND_LIST
	removeCmd_n(pPaniniCmdPool, imageCount, ppPaniniCmds);
	removeCmdPool(pRenderer, pPaniniCmdPool);
#endif
}
Exemplo n.º 4
0
void ShaderProgram::removeAllShaders()
{
    while(!m_shaders.empty())
        removeShader(m_shaders.front());
}
Exemplo n.º 5
0
void Renderer::deleteShader(const int index){
	if (shaders[index].programObj != SHADER_UNDEFINED){
		removeShader(shaders[index]);
		shaders[index].programObj = SHADER_UNDEFINED;
	}
}
Exemplo n.º 6
0
void LoadShaderAMT::processGPU()
{
    rLogInfo(g_log, "LoadShaderAMT GPU processing : " << m_assetFilePath);

    if(!m_proceed)
    {
        return;
    }

    // Assign program handle a "name"
    GLuint programGlid = glCreateProgram();

    GLuint vtxGlid = attachShader(programGlid, GL_VERTEX_SHADER, m_assetFilePath, m_vtxSource);
    GLuint tclGlid = attachShader(programGlid, GL_TESS_CONTROL_SHADER, m_assetFilePath, m_tclSource);
    GLuint telGlid = attachShader(programGlid, GL_TESS_EVALUATION_SHADER, m_assetFilePath, m_telSource);
    GLuint geoGlid = attachShader(programGlid, GL_GEOMETRY_SHADER, m_assetFilePath, m_geoSource);
    GLuint fraGlid = attachShader(programGlid, GL_FRAGMENT_SHADER, m_assetFilePath, m_fraSource);
    GLuint comGlid = attachShader(programGlid, GL_COMPUTE_SHADER, m_assetFilePath, m_comSource);

    // Bind vertex attributes (always before glLinkProgram!)
    glBindAttribLocation(programGlid, OPENGL_VXA_POSITION_ID,    OPENGL_VXA_POSITION_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_NORMAL_ID,      OPENGL_VXA_NORMAL_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_TEXCOORD0_ID,   OPENGL_VXA_TEXCOORD0_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_TANGENT_ID,     OPENGL_VXA_TANGENT_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_BITANGENT_ID,   OPENGL_VXA_BITANGENT_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_BWEIGHTSET0_ID, OPENGL_VXA_BWEIGHTSET0_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_BINDEXSET0_ID,  OPENGL_VXA_BINDEXSET0_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_BINDEXSET1_ID,  OPENGL_VXA_BINDEXSET1_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_BINDEXSET2_ID,  OPENGL_VXA_BINDEXSET2_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_BINDEXSET3_ID,  OPENGL_VXA_BINDEXSET3_NAME);
    glBindAttribLocation(programGlid, OPENGL_VXA_TEXCOORD1_ID,   OPENGL_VXA_TEXCOORD1_NAME);

    // Bind fragment shader outputs (always before glLinkProgram!)
    glBindFragDataLocation(programGlid, OPENGL_FOUT0_ID, OPENGL_FOUT0_NAME);
    glBindFragDataLocation(programGlid, OPENGL_FOUT1_ID, OPENGL_FOUT1_NAME);
    glBindFragDataLocation(programGlid, OPENGL_FOUT2_ID, OPENGL_FOUT2_NAME);
    glBindFragDataLocation(programGlid, OPENGL_FOUT3_ID, OPENGL_FOUT3_NAME);
    glBindFragDataLocation(programGlid, OPENGL_FOUT4_ID, OPENGL_FOUT4_NAME);

    // Link program
    glLinkProgram(programGlid);

    removeShader(vtxGlid);
    removeShader(tclGlid);
    removeShader(telGlid);
    removeShader(geoGlid);
    removeShader(comGlid);
    removeShader(fraGlid);

    // Bind samplers to texture units
    glUseProgram(programGlid);
    glUniform1i(glGetUniformLocation(programGlid, OPENGL_TUNIT0_NAME), 0);
    glUniform1i(glGetUniformLocation(programGlid, OPENGL_TUNIT1_NAME), 1);
    glUniform1i(glGetUniformLocation(programGlid, OPENGL_TUNIT2_NAME), 2);
    glUniform1i(glGetUniformLocation(programGlid, OPENGL_TUNIT3_NAME), 3);
    glUniform1i(glGetUniformLocation(programGlid, OPENGL_TUNIT4_NAME), 4);
    glUniform1i(glGetUniformLocation(programGlid, OPENGL_TUNIT5_NAME), 5);
    glUseProgram(0);

    ShaderAsset::rebindCurrent();

    m_context->m_shaderId = programGlid;
}