Esempio n. 1
0
void
OsdGLSLComputeKernelBundle::ApplyLoopVertexVerticesKernelA(
    int vertexOffset, int tableOffset, int start, int end, bool pass) {

    glUniformSubroutinesuiv(GL_COMPUTE_SHADER, 1, &_subComputeVertexA);
    glUniform1i(_uniformVertexPass, pass ? 1 : 0);
    dispatchCompute(vertexOffset, tableOffset, start, end);
}
Esempio n. 2
0
void
OsdGLSLComputeKernelBundle::ApplyBilinearFaceVerticesKernel(
    int vertexOffset, int tableOffset, int start, int end) {

    glUniformSubroutinesuiv(GL_COMPUTE_SHADER, 1, &_subComputeFace);
    dispatchCompute(vertexOffset, tableOffset, start, end);

    // glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
}
Esempio n. 3
0
void
OsdGLSLComputeKernelBundle::ApplyEditAdd(
    int primvarOffset, int primvarWidth,
    int vertexOffset, int tableOffset, int start, int end) {

    glUniformSubroutinesuiv(GL_COMPUTE_SHADER, 1, &_subEditAdd);
    glUniform1i(_uniformEditPrimVarOffset, primvarOffset);
    glUniform1i(_uniformEditPrimVarWidth, primvarWidth);
    dispatchCompute(vertexOffset, tableOffset, start, end);
}
void subroutines_app::render(double currentTime)
{
    int i = int(currentTime);

    glUseProgram(render_program);

    glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &subroutines[i & 1]);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
Esempio n. 5
0
void
OsdGLSLComputeKernelBundle::ApplyCatmarkFaceVerticesKernel(
    int vertexOffset, int tableOffset, int start, int end) {

    glUniformSubroutinesuiv(GL_COMPUTE_SHADER, 1, &_subComputeFace);
    dispatchCompute(vertexOffset, tableOffset, start, end);

    // see the comment in dispatchCompute()
    // this workaround causes a performance problem.
    // glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
}
void
OsdGLSLTransformFeedbackKernelBundle::ApplyLoopEdgeVerticesKernel(
    GLuint vertexBuffer, GLuint varyingBuffer,
    int vertexOffset, int varyingOffset,
    int offset, int tableOffset, int start, int end) {

    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &_subComputeEdge);
    transformGpuBufferData(vertexBuffer, varyingBuffer,
                           vertexOffset, varyingOffset,
                           offset, tableOffset, start, end);
}
void
OsdGLSLTransformFeedbackKernelBundle::ApplyLoopVertexVerticesKernelB(
    GLuint vertexBuffer, int numVertexElements,
    GLuint varyingBuffer, int numVaryingElements,
    int vertexOffset, int tableOffset, int start, int end) {

    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &_subComputeLoopVertexB);
    transformGpuBufferData(vertexBuffer, numVertexElements,
                           varyingBuffer, numVaryingElements,
                           vertexOffset, tableOffset, start, end);
}
void
OsdGLSLTransformFeedbackKernelBundle::ApplyBilinearVertexVerticesKernel(
    GLuint vertexBuffer, int numVertexElements,
    GLuint varyingBuffer, int numVaryingElements,
    int V_ITa_ofs, int offset, int start, int end) {

    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &_subComputeVertex);
    glUniform1i(_uniformTableOffsets[Table::V_ITa], V_ITa_ofs);
    transformGpuBufferData(vertexBuffer, numVertexElements,
                           varyingBuffer, numVaryingElements,
                           offset, start, end);
}
void
OsdGLSLTransformFeedbackKernelBundle::ApplyCatmarkVertexVerticesKernelA(
    GLuint vertexBuffer, int numVertexElements,
    GLuint varyingBuffer, int numVaryingElements,
    int vertexOffset, int tableOffset, int start, int end, bool pass) {

    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &_subComputeVertexA);
    glUniform1i(_uniformVertexPass, pass ? 1 : 0);
    transformGpuBufferData(vertexBuffer, numVertexElements,
                           varyingBuffer, numVaryingElements,
                           vertexOffset, tableOffset, start, end);
}
Esempio n. 10
0
GLUSboolean update(GLUSfloat time)
{
    glClear(GL_COLOR_BUFFER_BIT);

    // Setting up functions for the red triangle.
    glActiveShaderProgram(g_programPipeline.pipeline, g_vertexProgram.program);
    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &g_getOffsetRedSubIndex);
    glActiveShaderProgram(g_programPipeline.pipeline, g_fragmentProgram.program);
    glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &g_getColorRedSubIndex);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    //

    // Setting up functions for the green triangle.
    glActiveShaderProgram(g_programPipeline.pipeline, g_vertexProgram.program);
    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &g_getOffsetGreenSubIndex);
    glActiveShaderProgram(g_programPipeline.pipeline, g_fragmentProgram.program);
    glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &g_getColorGreenSubIndex);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    //

    // Setting up functions for the blue triangle.
    glActiveShaderProgram(g_programPipeline.pipeline, g_vertexProgram.program);
    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &g_getOffsetBlueSubIndex);
    glActiveShaderProgram(g_programPipeline.pipeline, g_fragmentProgram.program);
    glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &g_getColorBlueSubIndex);

    glDrawArrays(GL_TRIANGLES, 0, 3);

    return GLUS_TRUE;
}
void display()
{
	glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
	glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
	glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glViewport(0, 0, Window.Size.x, Window.Size.y);

	float Depth(1.0f);
	glClearBufferfv(GL_DEPTH, 0, &Depth);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGB8]);

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, TextureName[texture::DXT1]);

	glUseProgram(ProgramName);
	glUniformMatrix4fv(UniformMVP, 1, GL_FALSE, &MVP[0][0]);
	glUniform1i(UniformRGB8, 0);
	glUniform1i(UniformDXT1, 1);

	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);

	glUniform1f(UniformDisplacement,  0.2f);
	glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &IndexDXT1);
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, NULL, 1, 0);

	glUniform1f(UniformDisplacement, -0.2f);
	glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &IndexRGB8);
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, NULL, 1, 0);

	glf::checkError("display");
	glf::swapBuffers();
}
void
OsdGLSLTransformFeedbackKernelBundle::ApplyCatmarkEdgeVerticesKernel(
    GLuint vertexBuffer, int numVertexElements,
    GLuint varyingBuffer, int numVaryingElements,
    int E_IT_ofs, int E_W_ofs, int offset, int start, int end) {

    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &_subComputeEdge);
    glUniform1i(_uniformTableOffsets[Table::E_IT], E_IT_ofs);
    glUniform1i(_uniformTableOffsets[Table::E_W], E_W_ofs);
    transformGpuBufferData(vertexBuffer, numVertexElements,
                           varyingBuffer, numVaryingElements,
                           offset, start, end);
}
Esempio n. 13
0
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    GLuint programHandle = prog.getHandle();
    GLuint adsIndex = glGetSubroutineIndex( programHandle, GL_VERTEX_SHADER, "phongModel" );
    GLuint diffuseIndex = glGetSubroutineIndex(programHandle, GL_VERTEX_SHADER, "diffuseOnly");

    glUniformSubroutinesuiv( GL_VERTEX_SHADER, 1, &adsIndex);
    model = mat4(1.0f);
    model *= glm::translate(vec3(-3.0f,-1.5f,0.0f));
    model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
    setMatrices();
    teapot->render();

    glUniformSubroutinesuiv( GL_VERTEX_SHADER, 1, &diffuseIndex);
    model = mat4(1.0f);
    model *= glm::translate(vec3(3.0f,-1.5f, 0.0f));
    model *= glm::rotate(-90.0f, vec3(1.0f,0.0f,0.0f));
    setMatrices();
    teapot->render();
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * this->view() * Model;

		glViewport(0, 0, static_cast<GLsizei>(WindowSize.x), static_cast<GLsizei>(WindowSize.y));

		float Depth(1.0f);
		glClearBufferfv(GL_DEPTH, 0, &Depth);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f)[0]);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGB8]);

		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::DXT1]);

		glUseProgram(ProgramName);
		glUniformMatrix4fv(UniformMVP, 1, GL_FALSE, &MVP[0][0]);
		glUniform1i(UniformRGB8, 0);
		glUniform1i(UniformDXT1, 1);

		glBindVertexArray(VertexArrayName);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);

		glUniform1f(UniformDisplacement,  1.1f);
		glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &IndexDXT1);
		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, nullptr, 1, 0);

		glUniform1f(UniformDisplacement, -1.1f);
		glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &IndexRGB8);
		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, nullptr, 1, 0);

		return true;
	}
Esempio n. 15
0
void GLWidget::copyTexToFBO(GLuint input_tex,QGLFramebufferObject* dst){


    dst->bind();
    GLCHK( glViewport(0,0,dst->width(),dst->height()) );
    GLCHK( glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_normal_filter"]) );
    GLCHK( filters_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) );
    GLCHK( filters_program->setUniformValue("quad_pos"  , QVector2D(0.0,0.0)) );
    GLCHK( glActiveTexture(GL_TEXTURE0) );
    GLCHK( glBindTexture(GL_TEXTURE_2D, input_tex) );
    quad_mesh->drawMesh(true);
    dst->bindDefault();

}
Esempio n. 16
0
void GLWidget::applyNormalFilter(GLuint input_tex){


    GLCHK( glViewport(0,0,width(),height()) );
    GLCHK( glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_normal_filter"]) );

    GLCHK( filters_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) );
    GLCHK( filters_program->setUniformValue("quad_pos"  , QVector2D(0.0,0.0)) );
    GLCHK( glActiveTexture(GL_TEXTURE0) );
    GLCHK( glBindTexture(GL_TEXTURE_2D, input_tex) );

    GLCHK( quad_mesh->drawMesh(true) );


}
Esempio n. 17
0
void PartialPatchSharpRenderer::renderLevel(int level, std::function<void(const glm::vec4 &)> setDrawColor)
{
	prerenderSetup(level, setDrawColor);

	for (int i = 0; i < partialCases.size(); ++i)
	{
		std::shared_ptr<PartialPatchSharpCaseX> pc = partialCases[i];

		if (pc->ibos[level] != std::numeric_limits<GLuint>::max())
		{
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pc->ibos[level]);
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 9, pc->sbos[level]);
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 10, pc->uvBuffers[level]);

			//setDrawColor(ppDebugColorTable[i]); // Debug

			std::vector<GLuint> &programs = pc->programs;
			for (int j = 0; j < programs.size(); ++j)
			{
				glUseProgram(programs[j]);
				if (controlMesh->hasTexture)
				{
					glBindTextureUnit(4, controlMesh->diffuseMap);
				}
				if (controlMesh->hasDisplacementMap)
				{
					glBindTextureUnit(5, controlMesh->displacementMap);
				}

				for (unsigned k = 0; k < 4; ++k)
				{
					int ibOffset = pc->indexBufferOffsetSizes[level][2 * k];
					int numIndices = pc->indexBufferOffsetSizes[level][2 * k + 1];
					int sbOffset = pc->sharpnessBufferOffsets[level][k];
					int uvbOffset = pc->uvBufferOffsets[level][k];

					if (numIndices > 0)
					{
						glUniformSubroutinesuiv(GL_TESS_EVALUATION_SHADER, 1, &k);
						glUniform1i(0, sbOffset);
						glUniform1i(1, uvbOffset);
						glDrawElements(GL_PATCHES, numIndices, GL_UNSIGNED_INT, (const void *)(ibOffset * sizeof(unsigned)));
					}
				}
			}
		}
	}
}
void display()
{
	// Update of the uniform buffer
	{
		glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]);
		glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(
			GL_UNIFORM_BUFFER, 0,	sizeof(glm::mat4),
			GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

		glm::mat4 Projection = glm::perspective(45.0f, 2.0f / 3.0f, 0.1f, 100.0f);
		glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
		glm::mat4 ViewRotateX = glm::rotate(ViewTranslate, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
		glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
		glm::mat4 Model = glm::mat4(1.0f);
		
		*Pointer = Projection * View * Model;

		// Make sure the uniform buffer is uploaded
		glUnmapBuffer(GL_UNIFORM_BUFFER);
	}

	float Depth(1.0f);
	glClearBufferfv(GL_DEPTH, 0, &Depth);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

	glActiveTexture(GL_TEXTURE0 + sementics::sampler::RGB8);
	glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGB8]);

	glActiveTexture(GL_TEXTURE0 + sementics::sampler::DXT1);
	glBindTexture(GL_TEXTURE_2D, TextureName[texture::DXT1]);

	glBindProgramPipeline(PipelineName);
	glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
	glBindVertexArray(VertexArrayName);

	glViewportIndexedf(0, 0, 0, GLfloat(Window.Size.x) / 2.0f, GLfloat(Window.Size.y));
	glViewportIndexedf(1, GLfloat(Window.Size.x) / 2.0f, 0, GLfloat(Window.Size.x) / 2.0f, GLfloat(Window.Size.y));

	glUseProgram(ProgramName);
	std::vector<GLuint> Index(2);
	Index[0] = sementics::sampling::RGB8;
	Index[1] = sementics::sampling::DXT1;
	glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, GLsizei(Index.size()), &Index[0]);

	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, NULL, 2, 0);

	glf::swapBuffers();
}
void
OsdGLSLTransformFeedbackKernelBundle::ApplyEditAdd(
    GLuint vertexBuffer, int numVertexElements,
    GLuint varyingBuffer, int numVaryingElements,
    int primvarOffset, int primvarWidth,
    int vertexOffset, int tableOffset, int start, int end) {
    
    if (end - start <= 0) return;
    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &_subEditAdd);
    glUniform1i(_uniformEditPrimVarOffset, primvarOffset);
    glUniform1i(_uniformEditPrimVarWidth, primvarWidth);

    glUniform1i(_uniformIndexStart, start);
    glUniform1i(_uniformVertexOffset, vertexOffset);
    glUniform1i(_uniformTableOffset, tableOffset);
    glDrawArrays(GL_POINTS, 0, end - start);
}
void
OsdGLSLTransformFeedbackKernelBundle::ApplyEditAdd(
    GLuint vertexBuffer, int numVertexElements,
    GLuint varyingBuffer, int numVaryingElements,
    int numEditVertices,
    int editIndices_ofs, int editValues_ofs,
    int primvarOffset, int primvarWidth) {

    glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, &_subEditAdd);
    glUniform1i(_uniformEditIndicesOffset, editIndices_ofs);
    glUniform1i(_uniformEditValuesOffset, editValues_ofs);
    glUniform1i(_uniformEditNumVertices, numEditVertices);
    glUniform1i(_uniformEditPrimVarOffset, primvarOffset);
    glUniform1i(_uniformEditPrimVarWidth, primvarWidth);

    glDrawArrays(GL_POINTS, 0, numVertexElements);
}
Esempio n. 21
0
    /** * @brief Render the mesh given a camera and light, using a Phong shader 
     * @param mesh Given mesh
     * @param camera Given camera 
     * @param lightTrackball Given light camera 
     */
    void render (PointCloud& mesh, const Tucano::Camera& camera, const Tucano::Camera& lightTrackball)
    {
        Eigen::Vector4f viewport = camera.getViewport();
        glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);

        particletf_shader.bind();

        glUniformSubroutinesuiv(GL_VERTEX_SHADER, 1, 0);

        // Transform feedback 0
        glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedback[0]);
        glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,0,mesh.getAttribute("in_Position")->getBufferID());
        glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,1,mesh.getAttribute("in_Velocity")->getBufferID());
        // posBuf[0] -> mesh.getAttribute("in_Position")->getBufferID()

        // Transform feedback 1
        glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedback[1]);
        glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,0,mesh.getAttribute("in_Position")->getBufferID());
        glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,1,mesh.getAttribute("in_Velocity")->getBufferID());
//        glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,1,velBuf[1]);
//        glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER,2,startTime[1]);

        // sets all uniform variables for the phong shader
        particletf_shader.setUniform("projectionMatrix", camera.getProjectionMatrix());
        particletf_shader.setUniform("modelMatrix", mesh.getModelMatrix());
        particletf_shader.setUniform("viewMatrix", camera.getViewMatrix());
        particletf_shader.setUniform("lightViewMatrix", lightTrackball.getViewMatrix());
        particletf_shader.setUniform("has_color", mesh.hasAttribute("in_Color"));
        particletf_shader.setUniform("default_color", default_color);

        // Disable rendering
        glEnable(GL_RASTERIZER_DISCARD);
        int drawBuf = 0;
        // Bind the feedback object for the buffers to be drawn next
        glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, feedback[drawBuf]);

        mesh.setAttributeLocation(particletf_shader);

        glEnable(GL_DEPTH_TEST);
        mesh.render();

        particletf_shader.unbind();
//        glEndTransformFeedback();
    }
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glUseProgram(h_prog);



	GLuint	*indices = new GLuint[n_func];
	indices[loc_func] = idx_shader_func[idx_func-IDX_FUNC_BASE];
	printf("idx_func=%d\n", idx_func);
	printf("idx_shader_func[idx_func-IDX_FUNC_BASE]=%d\n", idx_shader_func[idx_func - IDX_FUNC_BASE]);

	glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, n_func, indices);
	delete [] indices;

	glBindVertexArray(vao);
	glDrawArrays(GL_TRIANGLES, 0, 6);
	glFlush();
}
Esempio n. 23
0
void GLWidget::applyGlowFilter(QGLFramebufferObject* outputFBO){


    applyGaussFilter(colorFBO->getAttachedTexture(1),glowInputColor[0]->fbo,glowOutputColor[0]->fbo);
    applyGaussFilter(glowOutputColor[0]->fbo->texture(),glowInputColor[0]->fbo,glowOutputColor[0]->fbo);


    applyGaussFilter(glowOutputColor[0]->fbo->texture(),glowInputColor[1]->fbo,glowOutputColor[1]->fbo);
    applyGaussFilter(glowOutputColor[1]->fbo->texture(),glowInputColor[1]->fbo,glowOutputColor[1]->fbo);

    applyGaussFilter(glowOutputColor[1]->fbo->texture(),glowInputColor[2]->fbo,glowOutputColor[2]->fbo);
    applyGaussFilter(glowOutputColor[2]->fbo->texture(),glowInputColor[2]->fbo,glowOutputColor[2]->fbo);

    applyGaussFilter(glowOutputColor[2]->fbo->texture(),glowInputColor[3]->fbo,glowOutputColor[3]->fbo);


    outputFBO->bind();
        GLCHK( glViewport(0,0,outputFBO->width(),outputFBO->height()) );
        GLCHK( glUniformSubroutinesuiv( GL_FRAGMENT_SHADER, 1, &subroutines["mode_bloom_filter"]) );
        GLCHK( filters_program->setUniformValue("quad_scale", QVector2D(1.0,1.0)) );
        GLCHK( filters_program->setUniformValue("quad_pos"  , QVector2D(0.0,0.0)) );
        GLCHK( glActiveTexture(GL_TEXTURE0) );
        GLCHK( glBindTexture(GL_TEXTURE_2D, colorFBO->fbo->texture()) );
        GLCHK( glActiveTexture(GL_TEXTURE1) );
        GLCHK( glBindTexture(GL_TEXTURE_2D, glowOutputColor[0]->fbo->texture()) );
        GLCHK( glActiveTexture(GL_TEXTURE2) );
        GLCHK( glBindTexture(GL_TEXTURE_2D, glowOutputColor[1]->fbo->texture()) );
        GLCHK( glActiveTexture(GL_TEXTURE3) );
        GLCHK( glBindTexture(GL_TEXTURE_2D, glowOutputColor[2]->fbo->texture()) );
        GLCHK( glActiveTexture(GL_TEXTURE4) );
        GLCHK( glBindTexture(GL_TEXTURE_2D, glowOutputColor[3]->fbo->texture()) );
        quad_mesh->drawMesh(true);

    GLCHK( glActiveTexture(GL_TEXTURE0) );
    outputFBO->bindDefault();




}
Esempio n. 24
0
void Render()
{
	// enable depth test
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

	shader_program.Use();

	glBindVertexArray(vao_handle);

	muggle::vec4f light_position_in_eye = mat_view.Multiply(muggle::vec4f(-5.0f, 5.0f, -2.0f, 1.0f));

	// set uniform variable in shader
	shader_program.setUniform("Light.Position", light_position_in_eye);
	shader_program.setUniform("Light.La", 0.4f, 0.4f, 0.4f);
	shader_program.setUniform("Light.Ld", 1.0f, 1.0f, 1.0f);
	shader_program.setUniform("Light.Ls", 1.0f, 1.0f, 1.0f);
	shader_program.setUniform("Material.Ka", 0.9f, 0.5f, 0.3f);
	shader_program.setUniform("Material.Kd", 0.9f, 0.5f, 0.3f);
	shader_program.setUniform("Material.Ks", 0.8f, 0.8f, 0.8f);
	shader_program.setUniform("Material.Shininess", 100.0f);

	shader_program.setUniform("ModelViewMatrix", mat_mv);
	shader_program.setUniform("NormalMatrix", mat_normal);
	shader_program.setUniform("MVP", mat_mvp);
	shader_program.setUniform("WorldNormalMatrix", mat_world_normal);

	glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 1, &shade_model_index);
	if (p_mesh->num_index > 0)
	{
		int index_type = (p_mesh->size_index == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT);
		glDrawElements(GL_TRIANGLES, p_mesh->num_index, index_type, (GLvoid*)NULL);
	}
	else
	{
		glDrawArrays(GL_TRIANGLES, 0, p_mesh->num_vertex);
	}
	
}
Esempio n. 25
0
void
UniformGroup::apply_subroutines(ProgramPtr prog, GLenum shadertype,
                                const std::unordered_map<std::string, std::string>& subroutines)
{
  assert_gl("apply_subroutines:enter");
  GLint num_uniform_locations;
  glGetProgramStageiv(prog->get_id(), shadertype, GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS, &num_uniform_locations);

  std::vector<GLuint> subroutine_mappings;
  for(int i = 0; i < num_uniform_locations; ++i)
  {
    char name[256];
    GLsizei length;
    glGetActiveSubroutineUniformName(prog->get_id(), shadertype, i, sizeof(name), &length, name);

    const auto& it = subroutines.find(name);
    if (it == subroutines.end())
    {
      log_error("unmapped subroutine: %s", name);
    }
    else
    {
      GLuint loc = glGetSubroutineIndex(prog->get_id(), shadertype, it->second.c_str());
      if (loc == GL_INVALID_INDEX)
      {
        log_error("unknown subroutine: %s", it->second);
      }
      else
      {
        subroutine_mappings.emplace_back(loc);
      }
    }
  }

  glUniformSubroutinesuiv(shadertype, subroutine_mappings.size(), subroutine_mappings.data());

  assert_gl("apply_subroutines:exit");
}
Esempio n. 26
0
void ShaderEffect::SetSubroutineUniforms(uint_t shaderType, SubroutineLink* link, int numLinks)
{
    int maxUniforms;
    glGetProgramStageiv(mProgram, shaderType, GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS, &maxUniforms);

    ASSERT(maxUniforms < MAX_SHADER_SUBROUTINES);

    for(int uniform = 0; uniform < maxUniforms; ++uniform)
    {
        if(uniform < numLinks)
        {
            SubroutineLink* ci = &link[uniform];

            const int uniformIndex = glGetSubroutineUniformLocation(mProgram, shaderType, ci->UniformName);

            const int functionIndex = glGetSubroutineIndex(mProgram, shaderType, ci->FunctionName);

            mSubroutineMap[uniformIndex] = functionIndex;
        }
    }

    glUniformSubroutinesuiv(shaderType, maxUniforms, mSubroutineMap);
}
void
piglit_init(int argc, char **argv)
{
	bool pass = true;

	/* The first 5 indices should be ignored */
	const unsigned indices[6] = {0, 0, 0, 0, 0, 1};

	piglit_require_extension("GL_ARB_shader_subroutine");
	piglit_require_extension("GL_ARB_explicit_uniform_location");
	piglit_require_extension("GL_ARB_explicit_attrib_location");

	prog = piglit_build_simple_program(NULL, frag_shader_text);

	glUseProgram(prog);
	glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 6, indices);

	if (!piglit_check_gl_error(0)) {
		pass = false;
	}

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Esempio n. 28
0
void Graphic::Renderer::ActivateAppropriteToModelSubroutines(const Model& model) const
{
	constexpr unsigned numOfUsedSubroutines = 4;
	GLuint subroutinesArray[numOfUsedSubroutines];

	const ShaderProgram* const shaderProg = GetShaderProgramWithType(ShaderProgram::Type::Main);
	assert(shaderProg);

	const GLint shadeSubUniformLoc = glGetSubroutineUniformLocation(shaderProg->id, GL_FRAGMENT_SHADER, "shadeModel");
	const GLint toObjectLocalCoordSubUniformLoc = glGetSubroutineUniformLocation(shaderProg->id, GL_FRAGMENT_SHADER, "toObjectLocalCoord");
	const GLint getNormalVecSubUniformLoc = glGetSubroutineUniformLocation(shaderProg->id, GL_FRAGMENT_SHADER, "getNormalVec");
	const GLint drawObjectSubUniformLoc = glGetSubroutineUniformLocation(shaderProg->id, GL_VERTEX_SHADER, "drawObject");

	assert(shadeSubUniformLoc < numOfUsedSubroutines
		&& toObjectLocalCoordSubUniformLoc < numOfUsedSubroutines
		&& getNormalVecSubUniformLoc < numOfUsedSubroutines);

#ifdef _DEBUG
	if (   -1 == shadeSubUniformLoc
		|| -1 == toObjectLocalCoordSubUniformLoc
		|| -1 == getNormalVecSubUniformLoc
		|| -1 == drawObjectSubUniformLoc)
	{
		std::cout << "Failed to get subroutines uniform location. \n";
		return;
	}
#endif // _DEBUG

	if (model.material.HasTextureWithType(Texture::Type::Cube))
		subroutinesArray[drawObjectSubUniformLoc] = drawObjectSubroutines[1];
	else
		subroutinesArray[drawObjectSubUniformLoc] = drawObjectSubroutines[0];

	switch (model.GetType())
	{
	case Model::Type::commonModel:
		subroutinesArray[shadeSubUniformLoc] = shadeModelSubroutine[0];
		//subroutinesArray[shadeSubUniformLoc] = modelSubroutine;
		break;
	case Model::Type::lightModel:
		subroutinesArray[shadeSubUniformLoc] = shadeModelSubroutine[0];
		break;
	case Model::Type::skyBoxModel:
		//subroutinesArray[shadeSubUniformLoc] = shadeModelSubroutine[2];
		break;
	default:
		break;
	}

	if (model.material.HasTextureWithType(Texture::Type::Normal))
	{
		subroutinesArray[toObjectLocalCoordSubUniformLoc] = normalTextureSubroutines[0];
		subroutinesArray[getNormalVecSubUniformLoc] = normalTextureSubroutines[1];
	}
	else
	{
		subroutinesArray[toObjectLocalCoordSubUniformLoc] = noNormalTextureSubroutines[0];
		subroutinesArray[getNormalVecSubUniformLoc] = noNormalTextureSubroutines[1];
	}

	glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, 4, subroutinesArray);
}
Esempio n. 29
0
 void Shader::setSubroutine(Type shader_type, const std::string & subroutine_name)
 {
     glUniformSubroutinesuiv(GLenum(shader_type), m_active_subroutine_uniform_locations[GLenum(shader_type)], &m_subroutine_indices[subroutine_name]);
 }
Esempio n. 30
0
void NGLScene::paintGL()
{
  //----------------------------------------------------------------------------------------------------------------------
  // draw to our FBO first
  //----------------------------------------------------------------------------------------------------------------------
  // grab an instance of the shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  (*shader)["Phong"]->use();
  glEnable(GL_MULTISAMPLE);

  // Rotation based on the mouse position for our global transform
  ngl::Mat4 rotX;
  ngl::Mat4 rotY;
  // create the rotation matrices
  rotX.rotateX(m_win.spinXFace);
  rotY.rotateY(m_win.spinYFace);
  // multiply the rotations
  m_mouseGlobalTX=rotY*rotX;
  // add the translations
  m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x;
  m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y;
  m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z;


  static float rot=0.0;
   // get the VBO instance and draw the built in teapot
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
  // we are now going to draw to our FBO
  // set the rendering destination to FBO
  glBindFramebuffer(GL_FRAMEBUFFER, m_fboID);
  // set the background colour (using blue to show it up)
  glClearColor(0,0.4f,0.5f,1);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // set our viewport to the size of the texture
  // if we want a different camera we wouldset this here
  glViewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT);
  // rotate the teapot
  m_transform.reset();
  m_transform.setScale(1.8f,1.8f,1.8f);
  m_transform.setRotation(rot,rot,rot);
  loadMatricesToShader();
  prim->draw("teapot");
  rot+=0.1;

  //----------------------------------------------------------------------------------------------------------------------
  // now we are going to draw to the normal GL buffer and use the texture created
  // in the previous render to draw to our objects
  //----------------------------------------------------------------------------------------------------------------------
  // first bind the normal render buffer

  glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject());
  // now enable the texture we just rendered to
  glDisable(GL_MULTISAMPLE);

  glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_textureID);
  // set the screen for a different clear colour
  glClearColor(0.4f, 0.4f, 0.4f, 1.0f);			   // Grey Background
  // clear this screen
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // get the new shader and set the new viewport size
  shader->use("TextureShader");
  GLsizei numActiveUniforms;

  glGetProgramStageiv(shader->getProgramID("TextureShader"), GL_FRAGMENT_SHADER,
             GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS, &numActiveUniforms);
  glUniformSubroutinesuiv(GL_FRAGMENT_SHADER,numActiveUniforms,&m_subroutines[m_activeSubroutine]);

  // this takes into account retina displays etc
  glViewport(0, 0, static_cast<GLsizei>(width() * devicePixelRatio()), static_cast<GLsizei>(height() * devicePixelRatio()));
  ngl::Mat4 MVP;
  m_transform.reset();
  MVP= m_project*m_view*m_mouseGlobalTX;
  shader->setUniform("MVP",MVP);
  prim->draw("plane");
  m_transform.setPosition(0,1,0);
  MVP= m_project*m_view*m_mouseGlobalTX*m_transform.getMatrix();
  shader->setUniform("MVP",MVP);
  prim->draw("sphere");
  //----------------------------------------------------------------------------------------------------------------------


//  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, defaultFramebufferObject());   // Make sure no FBO is set as the draw framebuffer
//  glBindFramebuffer(GL_READ_FRAMEBUFFER, m_renderFBO); // Make sure your multisampled FBO is the read framebuffer
//  glDrawBuffer(GL_BACK);                       // Set the back buffer as the draw buffer
//  glBlitFramebuffer(0, 0, m_win.width, m_win.height, 0, 0, m_win.width, m_win.height, GL_COLOR_BUFFER_BIT, GL_NEAREST);


}