Example #1
0
uint32_t BillboardShader::init(){
	cerr<<"INIT Billboard SHADER"<<endl;
	if(ShaderProgram::init())
		return 1;
	
	if(addShader(new Shader("../../../Grafic/Shaders/BillboardVertexShader.glsl", GL_VERTEX_SHADER)))
		return 2;
	
	if(addShader(new Shader("../../../Grafic/Shaders/BillboardGeometryShader.glsl", GL_GEOMETRY_SHADER)))
		return 3;
	
	if(addShader(new Shader("../../../Grafic/Shaders/BillboardFragmentShader.glsl", GL_FRAGMENT_SHADER)))
		return 4;
	
	if(finalize())
		return 5;
	
	_VPLocation = getUniformLocation("gVP");
	_cameraPosLocation = getUniformLocation("gCameraPos");
    _colorMapLocation = getUniformLocation("gColorMap");
    _billboardSizeLocation = getUniformLocation("gBillboardSize");	
	
	cerr<<"DONE INIT Billborad Shader"<<endl;
	return 0;
}
Example #2
0
void ShaderProgram::compileShader (std::string &vs, std::string &fs) {
	m_program = glCreateProgram();

	if (m_program == 0) {
		fprintf(stderr, "Error creating shader program\n");
		exit(EXIT_FAILURE);
	}
	
	addShader(vs, GL_VERTEX_SHADER);
	addShader(fs, GL_FRAGMENT_SHADER);
	
	GLint success = 0;
	GLchar ErrorLog[1024] = { 0 };

	glLinkProgram(m_program);
	glGetProgramiv(m_program, GL_LINK_STATUS, &success);
	if (success == 0) {
		glGetProgramInfoLog(m_program, sizeof(ErrorLog), NULL, ErrorLog);
		fprintf(stderr, "Error linking shader program: '%s'\n", ErrorLog);
		exit(EXIT_FAILURE);
	}
	
	glValidateProgram(m_program);
	glGetProgramiv(m_program, GL_VALIDATE_STATUS, &success);
	if (!success) {
		glGetProgramInfoLog(m_program, sizeof(ErrorLog), NULL, ErrorLog);
		fprintf(stderr, "Invalid shader program: '%s'\n", ErrorLog);
		exit(EXIT_FAILURE);
	}
}
ShaderProgram::ShaderProgram(std::string vertexShader, std::string fragmentShader)
{
	/* Create */
	
	this->shaderProgram = glCreateProgram();
	
	/* Compile Shaders */
	
	//	Add our two shaders - OpenGL 4 support more kinds of shaders.
	bool vertexShaderDidSucceed = addShader((GLchar *)vertexShader.c_str(), GL_VERTEX_SHADER);
	bool fragmentShaderDidSucceed = addShader((GLchar *)fragmentShader.c_str(), GL_FRAGMENT_SHADER);
	
	//	If either failed, throw
	if (!vertexShaderDidSucceed) {
		throw "Vertex shader failed";
	}
	
	if (!fragmentShaderDidSucceed) {
		throw "Fragment shader failed";
	}
	
	/* Link */
	
	if(!link())
	{
		throw "Linker failed";
	}
}
static void compileShader( void )
{
	GLuint shaderProgram = glCreateProgram();

	if( shaderProgram == 0 )
	{
		std::cerr << "Error create shader program" << std::endl;

		exit( 1 );
	}

	addShader( shaderProgram , vertexShader , GL_VERTEX_SHADER );
	addShader( shaderProgram , fragmentShader , GL_FRAGMENT_SHADER );

	GLint success = 0;
	GLchar infoLog[ 1024 ] = { 0 };

	glLinkProgram( shaderProgram );
	glGetProgramiv( shaderProgram , GL_LINK_STATUS , &success );

	if( success == 0 )
	{
		glGetProgramInfoLog( shaderProgram , sizeof( infoLog ) , nullptr , infoLog );

		std::cerr << "Invalid shader program '" << infoLog << "'" << std::endl;

		exit( 1 );
	}

	glUseProgram( shaderProgram );
}
Example #5
0
SSAOPass::SSAOPass(osg::Camera *mainCamera, osg::TextureRectangle *positionTex, osg::TextureRectangle *normalTex, osg::Texture2D *randomJitterTex, osg::Texture2D *sharedDepthTex)
: ScreenPass(mainCamera)
{
    _ssao_shader_id = addShader("ssao.vert", "ssao.frag");
    _in_position_tex = addInTexture(positionTex);
    _in_normal_tex = addInTexture(normalTex);
    //_in_random_tex = addInTexture(randomJitterTex);
    _randomTexture2D = randomJitterTex;
    _blurCamera = new osg::Camera;
    
    _blurX_shader = addShader("gBlur.vert", "gBlurSSAOX.frag");
    _blurY_shader = addShader("gBlur.vert", "gBlurSSAOY.frag");
    
    setSSAOParameters(0.5f, 30.0f, 0.3f, 0.36f);
    
    setupCamera();
    configRTTCamera();
    
    // get matrix and farPlaneDist
    osg::Matrix projMatrix = mainCamera->getProjectionMatrix();
    float dummy;
    // TODO: fix nearPlane
    projMatrix.getFrustum(dummy, dummy, dummy, dummy, dummy, _farPlaneDist);
   
    _sharedDepthTex = sharedDepthTex;
    configureStateSet();
    setupBlurCamera();
}
Example #6
0
 Shader::Shader(const std::string & vertex_shader_filename,
                const std::string & fragment_shader_filename)
     : Shader()
 {
     addShader(vertex_shader_filename, GL_VERTEX_SHADER);
     addShader(fragment_shader_filename, GL_FRAGMENT_SHADER);
 }
Example #7
0
void Renderer::addShaders()
{
    addShader("/terrain/terrain.vs.glsl", QOpenGLShader::Vertex);
    addShader("/terrain/terrain.tcs.glsl", QOpenGLShader::TessellationControl);
    addShader("/terrain/terrain.tes.glsl", QOpenGLShader::TessellationEvaluation);
    addShader("/terrain/terrain.fs.glsl", QOpenGLShader::Fragment);
}
bool PictureShader::init()
{
	if (!Shader::init()) 
	{
		return false;
	}

	if (!addShader(GL_VERTEX_SHADER, "Resources/shaders/picture.vert"))
	{
		return false;
	}
	if (!addShader(GL_FRAGMENT_SHADER, "Resources/shaders/picture.frag"))
	{
		return false;
	}
	if (!finalize()) 
	{
		return false;
	}

	MVPLocation = getUniformLocation("MVP");
	if (MVPLocation == INVALID_UNIFORM_LOCATION) 
	{
		return false;
	}

	LightMVPLocation = getUniformLocation("LightMVP");
	if (LightMVPLocation == INVALID_UNIFORM_LOCATION)
	{
		return false;
	}

	TextureMapLocation = getUniformLocation("TextureMap");
	if (TextureMapLocation == INVALID_UNIFORM_LOCATION)
	{
		return false;
	}

	ShadowMapLocation = getUniformLocation("ShadowMap");
	if (ShadowMapLocation == INVALID_UNIFORM_LOCATION)
	{
		return false;
	}

	IsBlurLocation = getUniformLocation("IsBlur");
	if (IsBlurLocation == INVALID_UNIFORM_LOCATION)
	{
		return false;
	}

	AlphaLocation = getUniformLocation("Alpha");
	if (AlphaLocation == INVALID_UNIFORM_LOCATION)
	{
		return false;
	}

	return true;
}
Example #9
0
void GLProgram::getShaders(void)
{
	Configuration *c = Configuration::getInstance();
	std::string str = c->getConfiguration("VERTEX_SHADER");
	addShader(str, GL_VERTEX_SHADER);
	str = c->getConfiguration("FRAGMENT_SHADER");
	addShader(str, GL_FRAGMENT_SHADER);
	linkShaders();
}
Example #10
0
 Shader::Shader(const std::string & vertex_shader_filename,
                const std::string & fragment_shader_filename,
                const std::string & tessellation_control_shader_filename,
                const std::string & tessellation_evaluation_shader_filename)
     : Shader(vertex_shader_filename, fragment_shader_filename)
 {
     addShader(tessellation_control_shader_filename, GL_TESS_CONTROL_SHADER);
     addShader(tessellation_evaluation_shader_filename, GL_TESS_EVALUATION_SHADER);
 }
bool PhongLightTechnique::init()
{
	// Initialize base
	if (BaseTechnique::init() == false)
	{
		std::cout << "Failed to initialize base technique - PhongLightTechnique. \n";
		return false;
	}

	// Add shaders
	if (addShader(GL_VERTEX_SHADER, ".\\Shaders\\blinnPhongSolid.vert") == false)
	{
		std::cout << "Failed to add vertex shader - PhongLightTechnique. \n";
		return false;
	}
	if (addShader(GL_FRAGMENT_SHADER, ".\\Shaders\\blinnPhongSolid.frag") == false)
	{
		std::cout << "Failed to add fragment shader - PhongLightTechnique. \n";
		return false;
	}

	// Link program
	if (finalize() == false)
	{
		std::cout << "Failed to link the program - PhongLightTechnique. \n";
		return false;
	}

	// Get uniform locations
	m_uiEyePosWVecLoc = getUniformLocation("eyePosW");
	m_uiDirLightCountLoc = getUniformLocation("dirLightCount");
	m_uiPointLightCountLoc = getUniformLocation("pointLightCount");
	m_uiSpotLightCountLoc = getUniformLocation("spotLightCount");

	// Initialize the base class - transform
	if (TransformTechnique::init() == false)
	{
		std::cout << "Failed to initialize transform technique - PhongLightTechnique. \n";
		return false;
	}

	m_pSimpleColorTechnique = new SimpleColorTechnique();
	if (m_pSimpleColorTechnique->init() == false)
	{
		std::cout << "Failed to init SimpleColorTechnique from PhongLightTechnique. \n";
		return false;
	}
	else
	{
		// Add technique to the tech manager
		TechniqueMan::Instance().registerTechnique(m_pSimpleColorTechnique);
	}

	// Success
	return true;
}
Example #12
0
 bool Shader::loadFromFile(const std::string& vertex, const std::string& tessControl, const std::string& tessEvaluation, const std::string& fragment)
 {
     // Create a program
     m_program = render::lib::createProgram();
     
     // Read the files
     std::string vertexShader;
     if (!getFileContents(vertex, vertexShader))
     {
         LOG_ERROR("Failed to open Vertex Shader file: %s", vertex.c_str());
         return false;
     }
     else LOG_INFO("Vertex Shader successfully loaded: %s", vertex.c_str());
     
     std::string tessControlShader;
     if (!getFileContents(tessControl, tessControlShader))
     {
         LOG_ERROR("Failed to open Tesselation Control Shader file: %s", tessControl.c_str());
         return false;
     }
     else LOG_INFO("Tesselation Control Shader successfully loaded: %s", tessControl.c_str());
     
     std::string tessEvaluationShader;
     if (!getFileContents(tessEvaluation, tessEvaluationShader))
     {
         LOG_ERROR("Failed to open Tesselation Evaluation Shader file: %s", tessEvaluation.c_str());
         return false;
     }
     else LOG_INFO("Tesselation Evaluation Shader successfully loaded: %s", tessEvaluation.c_str());
     
     std::string fragmentShader;
     if (!getFileContents(fragment, fragmentShader))
     {
         LOG_ERROR("Failed to open Fragment Shader file: %s", fragment.c_str());
         return false;
     }
     else LOG_INFO("Fragment Shader successfully loaded: %s", fragment.c_str());
     
     bool success = false;
     if(addShader(vertexShader, ODIN_VERTEX_SHADER) &&
        addShader(tessControlShader, ODIN_TESS_CONTROL_SHADER) &&
        addShader(tessEvaluationShader, ODIN_TESS_EVALUATION_SHADER) &&
        addShader(fragmentShader, ODIN_FRAGMENT_SHADER))
     {
         // link program
         render::lib::linkProgram(m_program);
         if (!checkLinkErrors(m_program))
         {
             render::lib::deleteProgram(m_program);
             m_program = 0;
         }
         success = true;
     }
     
     return success;
 }
Example #13
0
FogShaderProgram::FogShaderProgram(bool useAlphaBlend) :
    EffectShaderProgram(AUTO_LOGGER)
{
    addShader("Data/Shaders/PostProcess/fog.vert");
    addShader("Data/Shaders/PostProcess/fog.frag");
    addShader("Data/Shaders/depth.frag");
    if (useAlphaBlend) {
        addDefinition("#define USE_ALPHA_BLEND");
    }
    constructProgram();
}
Example #14
0
//-----------------------------------------------------------------------------
//! Ctor with a vertex and a fragment shader filename
SLGLShaderProg::SLGLShaderProg(SLstring vertShaderFile, 
                           SLstring fragShaderFile) : SLObject("")
{  
   _stateGL = SLGLState::getInstance();
   _isLinked = false;
   _programObjectGL = 0;   

   // optional load vertex and/or fragment shaders
   addShader(new SLGLShader(defaultPath+vertShaderFile, SLVertexShader));
   addShader(new SLGLShader(defaultPath+fragShaderFile, SLFragmentShader));
}
Example #15
0
bool CVBackgroundTechnique::addShaders()
{
	if (!addShader(GL_VERTEX_SHADER, "shaders/ProjectionWithModelViewOffset2D.vert")) {
		return false;
	}

	if (!addShader(GL_FRAGMENT_SHADER, "shaders/TexOnlyNoGamma.frag")) {
		return false;
	}

	return true;
}
Example #16
0
File: gl.c Project: Spekkio/sdltest
int compileShaders()
{
  GLuint shaderProgram;
  GLint success;
  GLchar infolog[1024];

  shaderProgram = glCreateProgram();

  if(shaderProgram == 0)
    {
      printf("Error: glCreateProgram() == 0");
      return -1;
    }

  if(addShader(shaderProgram, pVS, GL_VERTEX_SHADER) < 0)
    {
      printf("Error: addShader(shaderProgram, pVS, GL_VERTEX_SHADER)\n");
      return -1;
    }
  if(addShader(shaderProgram, pFS, GL_FRAGMENT_SHADER) < 0)
    {
      printf("Error: addShader(shaderProgram, pFS, GL_FRAGMENT_SHADER)\n");
      return -1;
    }
  
  success = 0;

  glLinkProgram(shaderProgram);
  glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);

  if(success == 0)
    {
      glGetProgramInfoLog(shaderProgram, sizeof(infolog), NULL, infolog);
      printf("Error glLinkProgram(): %s\n",infolog);
      return -1;
    }

  success = 0;

  glValidateProgram(shaderProgram);
  glGetProgramiv(shaderProgram, GL_VALIDATE_STATUS, &success);
  if(success == 0)
    {
      glGetProgramInfoLog(shaderProgram, sizeof(infolog), NULL, infolog);
      printf("Error glValidateProgram(): %s\n",infolog);
      return -1;
    }

  glUseProgram(shaderProgram);

  return 0;

}
Example #17
0
static void compileShader()
{
	GLuint shaderProgram = glCreateProgram();
	if (shaderProgram == 0)
	{
		fprintf(stderr, "Error: creating program\n");
		exit(1);
	}

	string vs, fs;
	if (!ReadFile(pVSShader, vs))
	{
		exit(1);
	}
	if (!ReadFile(pFSShader, fs))
	{
		exit(1);
	}

	addShader(shaderProgram, vs.c_str(), GL_VERTEX_SHADER);
	addShader(shaderProgram, fs.c_str(), GL_FRAGMENT_SHADER);

	GLint res = 0;
	GLchar errorInfo[1024] = {};

	glLinkProgram(shaderProgram);
	glGetProgramiv(shaderProgram, GL_LINK_STATUS, &res);
	if (res == 0)
	{
		glGetProgramInfoLog(shaderProgram, sizeof(errorInfo), nullptr, errorInfo);
		fprintf(stderr, "Error: Linking program: '%s'\n", errorInfo);
		exit(1);
	}

	glValidateProgram(shaderProgram);
	glGetProgramiv(shaderProgram, GL_VALIDATE_STATUS, &res);
	if (res == 0)
	{
		glGetProgramInfoLog(shaderProgram, sizeof(errorInfo), nullptr, errorInfo);
		fprintf(stderr, "Error: Validating program: '%s'\n", errorInfo);
		exit(1);
	}

	glUseProgram(shaderProgram);

	gWorldLocation = glGetUniformLocation(shaderProgram, "gWorld");
	if (gWorldLocation == 0xFFFFFFFF)
	{
		exit(1);
	}
}
    void canValidateLinkedProgramWhenShadersCompiled()
    {
        ShaderProgram shaderProgram;

        addShader(shaderProgram, Shader::FRAGMENT_SHADER, VALID_FRAGMENT_SHADER_SOURCE);
        QVERIFY(shaderProgram.link());

        addShader(shaderProgram, Shader::VERTEX_SHADER, VALID_VERTEX_SHADER_SOURCE);
        QVERIFY(shaderProgram.link());

        shaderProgram.link();

        QVERIFY(shaderProgram.validate());
    }
Example #19
0
static void CompileShaders()
{
	GLuint shaderProgram = glCreateProgram();

	if (shaderProgram == 0)
	{
		fprintf(stderr, "Error creating shader program\n");
		exit(1);
	}

	string vs, fs;
	if (!ReadFile(pVSFileName, vs))
	{
		exit(1);
	}
	if (!ReadFile(pFSFileName, fs))
	{
		exit(1);
	}

	addShader(shaderProgram, vs.c_str(), GL_VERTEX_SHADER);
	addShader(shaderProgram, fs.c_str(), GL_FRAGMENT_SHADER);

	GLint success;
	GLchar errorLog[1024] = {};

	glLinkProgram(shaderProgram);
	glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
	if (success == 0)
	{
		glGetProgramInfoLog(shaderProgram, sizeof(errorLog), NULL, errorLog);
		fprintf(stderr, "Error linking shader program: '%s'\n", errorLog);
		exit(1);
	}

	glValidateProgram(shaderProgram);
	glGetProgramiv(shaderProgram, GL_VALIDATE_STATUS, &success);
	if (success == 0)
	{
		glGetProgramInfoLog(shaderProgram, sizeof(errorLog), NULL, errorLog);
		fprintf(stderr, "Invalid shader program: '%s' \n", errorLog);
		exit(1);
	}

	glUseProgram(shaderProgram);

	gWVPLocation = glGetUniformLocation(shaderProgram, "gWVP");
	assert(gWVPLocation != 0xFFFFFFFF);
}
Example #20
0
    /*!
    * @brief Initilize everything SDL needs at the start
    */
    void GLGraphics::Init(void) //Initilize SDL
    {
      // Register the components needed for graphics.
      RegisterComponent(MC_Transform);
      RegisterComponent(MC_Sprite);

      CreateMesh();

      // Create the default shader.
      ShaderPtr defaultShader(new GLShader());

      // Load the shader files for the default shader.
      defaultShader->LoadShaderFile("dvert.glsl", "dfrag.glsl", 0);

      // Compile the shaders.
      defaultShader->Compile();

      // Find the variables in the shaders that will be modified by the end-users.
      defaultShader->FindUniforms("model");
      defaultShader->FindUniforms("view");
      defaultShader->FindUniforms("proj");
      defaultShader->FindUniforms("color");
      
      

      // Add the shader to the ShaderMap.
      addShader("Box", defaultShader);

    }
Example #21
0
void GlShaderProgram::addShaderFromSourceFile(const ShaderType shaderType, const std::string &shaderSrcFilename) {
  GlShader *shader = new GlShader(shaderType);
  shader->setAnonymousCreation(true);
  shader->compileFromSourceFile(shaderSrcFilename);
  addShader(shader);

}
Example #22
0
        bool Shader::loadFromFile(const std::string& compute)
        {
#if defined ODIN_COMPUTE_SHADER
            // Create a program
            m_program = render::lib::createProgram();
            
            // Read the files
            std::string computeShader;
            if (!getFileContents(compute, computeShader))
            {
                LOG_ERROR("Failed to open Compute Shader file: %s", compute.c_str());
                return false;
            }
            else LOG_INFO("Compute Shader successfully loaded: %s", compute.c_str());
            
            bool success = false;
            if(addShader(computeShader, ODIN_COMPUTE_SHADER))
            {
                // link program
                render::lib::linkProgram(m_program);
                if (!checkLinkErrors(m_program))
                {
                    render::lib::deleteProgram(m_program);
                    m_program = 0;
                }
                success = true;
            }
            return success;
#else
            LOG_ERROR("This system does not support Compute shaders");
            return false;
#endif
        }
Example #23
0
CrossCompiler::Spirv CrossCompiler::hlslToSpirv(std::string hlslText)
{
    auto program = glslang::TProgram();

    auto entryPoints = getEntryPoints(hlslText);
    for (auto& stageEntries : entryPoints)
    {
        auto stage = toEShLanguage(stageEntries.first);
        for (auto name : stageEntries.second)
        {
            addShader(program, hlslText, stage, name);
        }
    }

    if (!program.link(messagesType))
        throw std::exception(program.getInfoLog());

    Spirv spirv;
    if (entryPoints["vs"].size() > 0)
        spirv.vs = getBinary(program, EShLanguage::EShLangVertex);

    if (entryPoints["ps"].size() > 0)
        spirv.ps = getBinary(program, EShLanguage::EShLangFragment);
    return spirv;
}
Example #24
0
 Shader::Shader(const std::string & vertex_shader_filename,
                const std::string & fragment_shader_filename,
                const std::string & geometry_shader_filename)
     : Shader(vertex_shader_filename, fragment_shader_filename)
 {
     addShader(geometry_shader_filename, GL_GEOMETRY_SHADER);
 }
Example #25
0
void GlShaderProgram::addShaderFromSourceCode(const ShaderType shaderType, const char *shaderSrc) {
  GlShader *shader = new GlShader(shaderType);
  shader->setAnonymousCreation(true);
  shader->compileFromSourceCode(shaderSrc);
  addShader(shader);

}
Example #26
0
void QtSE::projectTreeContextMenu( QPoint point )
{
	CProjectTreeItem *item = (CProjectTreeItem*)projectTree->itemAt( point );

	if( item )
	{
		QMenu *menu = new QMenu();
		menu->setAttribute( Qt::WA_DeleteOnClose , true );

		switch( item->getPartType() )
		{
			case CProjectTreeItem::stage:
				menu->addAction( "Add Stage" , this , SLOT(addStage()) );
				break;
			case CProjectTreeItem::framebuffer:
				menu->addAction( "Add Framebuffer" , this , SLOT(addFramebuffer()) );
				break;
			case CProjectTreeItem::shader:
				menu->addAction( "Add Shader" , this , SLOT(addShader()) );
				break;
			case CProjectTreeItem::texture:
				menu->addAction( "Add Texture" , this , SLOT(addTexture()) );
				break;
			case CProjectTreeItem::model:
				menu->addAction( "Add Model" , this , SLOT(addModel()) );
				break;
			default:
				delete menu;
				return;
		}

		menu->popup( QCursor::pos() , NULL );
	}
}
Example #27
0
 bool Shader::loadFromFile(const std::string& vertex, const std::string& geometry, const std::string& fragment)
 {
     // Create a program
     m_program = render::lib::createProgram();
     
     // Read the files
     std::string vertexShader;
     if (!getFileContents(vertex, vertexShader))
     {
         LOG_ERROR("Failed to open Vertex Shader file: %s", vertex.c_str());
         return false;
     }
     else LOG_INFO("Vertex Shader successfully loaded: %s", vertex.c_str());
     
     std::string geometryShader;
     if (!getFileContents(geometry, geometryShader))
     {
         LOG_ERROR("Failed to open Geometry Shader file: %s", geometry.c_str());
         return false;
     }
     else LOG_INFO("Geometry Shader successfully loaded: %s", geometry.c_str());
     
     std::string fragmentShader;
     if (!getFileContents(fragment, fragmentShader))
     {
         LOG_ERROR("Failed to open Fragment Shader file: %s", fragment.c_str());
         return false;
     }
     else LOG_INFO("Fragment Shader successfully loaded: %s", fragment.c_str());
     
     bool success = false;
     if(addShader(vertexShader, ODIN_VERTEX_SHADER) &&
        addShader(geometryShader, ODIN_GEOMETRY_SHADER) &&
        addShader(fragmentShader, ODIN_FRAGMENT_SHADER))
     {
         // link program
         render::lib::linkProgram(m_program);
         if (!checkLinkErrors(m_program))
         {
             render::lib::deleteProgram(m_program);
             m_program = 0;
         }
         success = true;
     }
     
     return success;
 }
Example #28
0
bool ShaderPartLoader::load()
{



    std::vector<std::string> data = loadAndPreproccess(file);
    if(data.size()<=0)
        return false;


    std::vector<std::string> code;
    int status = STATUS_WAITING;
    GLenum type = GL_INVALID_ENUM;
    int lineCount =0;

    for(std::string line : data) {
        lineCount++;

        bool readLine = true;
        for(int i = 0 ; i < ShaderPart::shaderTypeCount ; ++i) {
            if(line.compare("##"+ShaderPart::shaderTypeStrings[i])==0) {
                if(status==STATUS_READING) {
                    addShader(code,type);
                    code.clear();
                }
                status = STATUS_READING;
                type = ShaderPart::shaderTypes[i];
                readLine = false;
                break;

            }
        }

        if(status == STATUS_READING && readLine) {
            code.push_back(line+'\n');
        }

    }

    if(status==STATUS_READING) {
        addShader(code,type);
        code.clear();
    }


    return true;
}
Example #29
0
bool initializeRenderingResources(Renderer* pRenderer, RenderTarget* pRenderTarget)
{
	// SHADER
	//----------------------------------------------------------------------------------------------------------------
	ShaderLoadDesc paniniPass = {};
	paniniPass.mStages[0] = { "panini_projection.vert", NULL, 0, FSR_SrcShaders_Common };
	paniniPass.mStages[1] = { "panini_projection.frag", NULL, 0, FSR_SrcShaders_Common };
	addShader(pRenderer, &paniniPass, &pShaderPanini);

	// SAMPLERS & STATES
	//----------------------------------------------------------------------------------------------------------------
	addSampler(pRenderer, &pSamplerTrilinearAniso, FILTER_TRILINEAR_ANISO, FILTER_BILINEAR, MIPMAP_MODE_LINEAR, ADDRESS_MODE_REPEAT, ADDRESS_MODE_REPEAT, ADDRESS_MODE_REPEAT, 0.0f, 8.0f);
	addRasterizerState(&pRasterizerStateCullNone, CULL_MODE_NONE);
	addDepthState(pRenderer, &pDepthStateDisable, false, false);


	// ROOT SIGNATURE
	//----------------------------------------------------------------------------------------------------------------
	RootSignatureDesc paninniRootDesc = {};
	paninniRootDesc.mStaticSamplers["uSampler"] = pSamplerTrilinearAniso;
	addRootSignature(pRenderer, 1, &pShaderPanini, &pRootSignaturePaniniPostProcess, &paninniRootDesc);


	// PIPELINE
	//----------------------------------------------------------------------------------------------------------------
	VertexLayout vertexLayoutPanini = {};
	vertexLayoutPanini.mAttribCount = 1;
	vertexLayoutPanini.mAttribs[0].mSemantic = SEMANTIC_POSITION;
	vertexLayoutPanini.mAttribs[0].mFormat = ImageFormat::RGBA32F;
	vertexLayoutPanini.mAttribs[0].mBinding = 0;
	vertexLayoutPanini.mAttribs[0].mLocation = 0;
	vertexLayoutPanini.mAttribs[0].mOffset = 0;

	GraphicsPipelineDesc pipelineSettings = { 0 };
	pipelineSettings.mPrimitiveTopo = PRIMITIVE_TOPO_TRI_LIST;
	pipelineSettings.mRenderTargetCount = 1;
	pipelineSettings.pDepthState = pDepthStateDisable;
	pipelineSettings.pColorFormats = &pRenderTarget->mDesc.mFormat;
	pipelineSettings.pSrgbValues = &pRenderTarget->mDesc.mSrgb;
	pipelineSettings.mSampleCount = pRenderTarget->mDesc.mSampleCount;
	pipelineSettings.mSampleQuality = pRenderTarget->mDesc.mSampleQuality;
	pipelineSettings.pRasterizerState = pRasterizerStateCullNone;
	pipelineSettings.pRootSignature = pRootSignaturePaniniPostProcess;
	pipelineSettings.pShaderProgram = pShaderPanini;
	pipelineSettings.pVertexLayout = &vertexLayoutPanini;
	addPipeline(pRenderer, &pipelineSettings, &pPipielinePaniniPostProcess);

	createTessellatedQuadBuffers(&pVertexBufferTessellatedQuad, &pIndexBufferTessellatedQuad, gPaniniDistortionTessellation[0], gPaniniDistortionTessellation[1]);


#if USE_DEDICATED_COMMAND_LIST
	// COMMAND LIST
	//----------------------------------------------------------------------------------------------------------------
	addCmdPool(pRenderer, pGraphicsQueue, false, &pPaniniCmdPool);
	addCmd_n(pPaniniCmdPool, false, imageCount, &ppPaniniCmds);
#endif

	return true;
}
Example #30
0
bool ShaderProgram::addShaderFromSourceFile(Shader::ShaderType shaderType, const std::string& sourceFile) {
    ShaderPtr shader(new Shader(shaderType));
    if(!shader->compileSourceFile(sourceFile)) {
        g_logger.error(stdext::format("failed to compile shader: %s", shader->log()));
        return false;
    }
    return addShader(shader);
}