Example #1
0
    virtual void render(double currentTime)
    {
        int i;
        static const GLfloat black[] = { 0.0f, 0.0f, 0.0f, 1.0f };
        static const GLfloat one = 1.0f;

        glViewport(0, 0, info.windowWidth, info.windowHeight);
        glClearBufferfv(GL_COLOR, 0, black);
        glClearBufferfv(GL_DEPTH, 0, &one);

        // Each rectangle will be 7/16 of the screen
        float viewport_width = (float)(7 * info.windowWidth) / 16.0f;
        float viewport_height = (float)(7 * info.windowHeight) / 16.0f;

        // Four rectangles - lower left first...
        glViewportIndexedf(0, 0, 0, viewport_width, viewport_height);

        // Lower right...
        glViewportIndexedf(1,
                           info.windowWidth - viewport_width, 0,
                           viewport_width, viewport_height);

        // Upper left...
        glViewportIndexedf(2,
                           0, info.windowHeight - viewport_height,
                           viewport_width, viewport_height);

        // Upper right...
        glViewportIndexedf(3,
                           info.windowWidth - viewport_width,
                           info.windowHeight - viewport_height,
                           viewport_width, viewport_height);

        vmath::mat4 proj_matrix = vmath::perspective(50.0f,
                                                     (float)info.windowWidth / (float)info.windowHeight,
                                                     0.1f,
                                                     1000.0f);

        float f = (float)currentTime * 0.3f;

        glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniform_buffer);
        vmath::mat4 * mv_matrix_array = (vmath::mat4 *)glMapBufferRange(GL_UNIFORM_BUFFER,
                                                                        0,
                                                                        4 * sizeof(vmath::mat4),
                                                                        GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

        for (i = 0; i < 4; i++)
        {
            mv_matrix_array[i] = proj_matrix *
                                 vmath::translate(0.0f, 0.0f, -2.0f) *
                                 vmath::rotate((float)currentTime * 45.0f * (float)(i + 1), 0.0f, 1.0f, 0.0f) *
                                 vmath::rotate((float)currentTime * 81.0f * (float)(i + 1), 1.0f, 0.0f, 0.0f);
        }

        glUnmapBuffer(GL_UNIFORM_BUFFER);

        glUseProgram(program);

        glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
    }
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			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::perspectiveFov(glm::pi<float>() * 0.25f, WindowSize.x, WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
			*Pointer = Projection * this->view() * Model;

			glUnmapBuffer(GL_UNIFORM_BUFFER);
		}

		// Clear
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::CLEAR]);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		// Render
		glViewportIndexedf(0, 0, 0, WindowSize.x * this->Supersampling, WindowSize.y * this->Supersampling);
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::BLEND]);
		glBindVertexArray(this->VertexArrayName[pipeline::RENDER]);

		glBindProgramPipeline(PipelineName[pipeline::RENDER]);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
		glBindImageTexture(semantic::image::DIFFUSE, TextureName[texture::COLORBUFFER], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantic::storage::VERTEX, BufferName[buffer::VERTEX]);

		for (std::size_t i = 0; i < this->Viewports.size(); ++i)
		{
			glViewportIndexedfv(0, &this->Viewports[i][0]);
			glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);
		}

		// Splash
		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glBindVertexArray(this->VertexArrayName[pipeline::SPLASH]);

		glBindProgramPipeline(PipelineName[pipeline::SPLASH]);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);

		return true;
	}
Example #3
0
/**
 * Draws a single quad into multiple viewport  each with a different
 * color.  Reads back the expected color  to test if the drawing was correct.
 * @param  changeVPloc;   if true then the geometry shader viewport location
 *         is changed with each loop, otherwise viewport location is fixed.
 */
static bool
draw_multi_viewport(const bool changeVPLoc)
{
    bool pass = true;
    int i, j;
    const int divX=2, divY=4;
    GLfloat w = (GLfloat) piglit_width / (GLfloat) divX;
    GLfloat h = (GLfloat) piglit_height / (GLfloat) divY;
    const GLfloat colors[][3] = {{0.0, 0.0, 1.0},
        {0.0, 1.0, 0.0},
        {1.0, 0.0, 0.0},
        {1.0, 1.0, 0.0},
        {0.0, 1.0, 1.0},
        {1.0, 0.0, 1.0},
        {1.0, 1.0, 1.0},
        {0.0, 0.0, 0.5},
        {0.0, 0.0, 0.0}
    };

    assert(ARRAY_SIZE(colors) == divX*divY + 1);

    glViewport(0, 0, piglit_width, piglit_height); /* for glClear() */
    glClear(GL_COLOR_BUFFER_BIT);
    glUniform1i(vpIndexLoc, divX * divY);
    glViewportIndexedf(divX * divY, -10.0, -30.0, piglit_width, 20.0);
    for (i = 0; i < divX; i++) {
        for (j = 0; j < divY; j++) {
            int p;
            GLfloat *expected;
            glUniform3fv(colorLoc, 1, &colors[j + i*divY][0]);
            if (changeVPLoc) {
                glUniform1i(vpIndexLoc, j + i*divY);
                expected = (GLfloat *) &colors[j + i*divY][0];
            } else  {
                expected = (GLfloat *) &colors[divX * divY][0];
            }
            glViewportIndexedf(j + i*divY, i * w, j * h, w, h);
            piglit_draw_rect(-1, -1, 2, 2);
            pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
            p = piglit_probe_pixel_rgb(i * w + w/2, j * h + h/2,
                                       expected);
            piglit_present_results();
            if (!p) {
                printf("Wrong color for viewport i,j %d %d changeVP=%d\n",
                       i, j, changeVPLoc);
                pass = false;
            }
        }
    }
    return pass;
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			glm::mat4* Pointer = static_cast<glm::mat4*>(glMapNamedBufferRange(BufferName[buffer::TRANSFORM],
				0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));

			//glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f);
			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);
		
			*Pointer = Projection * this->view() * Model;

			// Make sure the uniform buffer is uploaded
			glUnmapNamedBuffer(BufferName[buffer::TRANSFORM]);
		}

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glViewportIndexedf(0, 0, 0, WindowSize.x / 16.0f, WindowSize.y / 16.0f);

		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

		// Bind rendering objects
		glViewportIndexedf(0, 0, 0, WindowSize.x / 16.0f, WindowSize.y / 16.0f);
		glBindProgramPipeline(PipelineName[pipeline::TEXTURE]);
		glBindVertexArray(VertexArrayName[pipeline::TEXTURE]);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);

		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL0]);

		//glSubpixelPrecisionBiasNV(-8, -8);
		glEnable(GL_CONSERVATIVE_RASTERIZATION_NV);
		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL1]);

		glDisable(GL_CONSERVATIVE_RASTERIZATION_NV);
		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);

		glBindProgramPipeline(PipelineName[pipeline::SPLASH]);
		glBindVertexArray(VertexArrayName[pipeline::SPLASH]);
		glBindTextureUnit(0, TextureName[texture::COLORBUFFER]);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);

		return true;
	}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			glm::mat4* Pointer = reinterpret_cast<glm::mat4*>(glMapNamedBufferRange(BufferName[buffer::TRANSFORM],
				0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));

			//glm::mat4 Projection = glm::perspectiveFov(glm::pi<float>() * 0.25f, 640.f, 480.f, 0.1f, 100.0f);
			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);
		
			*Pointer = Projection * this->view() * Model;

			// Make sure the uniform buffer is uploaded
			glUnmapNamedBuffer(BufferName[buffer::TRANSFORM]);
		}

		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LESS);

		glClearTexImage(TextureName[texture::COLORBUFFER], 0, GL_RGBA, GL_UNSIGNED_BYTE, &glm::u8vec4(255, 255, 255, 255)[0]);
		glClearTexImage(TextureName[texture::RENDERBUFFER], 0, GL_DEPTH_COMPONENT, GL_FLOAT, &glm::vec1(1.0)[0]);
		glClearTexImage(TextureName[texture::INVOCATION_COUNT], 0, GL_RED_INTEGER, GL_UNSIGNED_INT, &glm::u32vec1(0)[0]);

		glViewportIndexedf(0, 0, 0, WindowSize.x * FRAMEBUFFER_SCALE, WindowSize.y * FRAMEBUFFER_SCALE);

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glBindProgramPipeline(PipelineName[pipeline::TEXTURE]);
		glBindVertexArray(VertexArrayName[pipeline::TEXTURE]);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindImageTexture(0, TextureName[texture::INVOCATION_COUNT], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32UI);

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 5, 0, 0);

		glDisable(GL_DEPTH_TEST);

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glBindProgramPipeline(PipelineName[pipeline::SPLASH]);
		glBindVertexArray(VertexArrayName[pipeline::SPLASH]);
		glBindImageTexture(0, TextureName[texture::INVOCATION_COUNT], 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);

		return true;
	}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			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(glm::pi<float>() * 0.25f, WindowSize.x * 0.5f / WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
		
			*Pointer = Projection * this->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, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindVertexArray(VertexArrayName);

		glUseProgram(ProgramName);
		std::vector<GLuint> Index(2);
		Index[0] = sementics::sampling::RGB8;
		Index[1] = sementics::sampling::DXT1;
		
		glViewportIndexedf(0, 0, 0, GLfloat(WindowSize.x) / 2.0f, GLfloat(WindowSize.y));
		glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, GLsizei(1), &Index[0]);
		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, nullptr, 1, 0);

		glViewportIndexedf(0, GLfloat(WindowSize.x) / 2.0f, 0, GLfloat(WindowSize.x) / 2.0f, GLfloat(WindowSize.y));
		glUniformSubroutinesuiv(GL_FRAGMENT_SHADER, GLsizei(1), &Index[1]);
		glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, nullptr, 1, 0);
		
		return true;
	}
Example #7
0
void display()
{
	glUseProgram(ProgramName);
	glProgramUniform1i(ProgramName, UniformDiffuse, 0);

	// Pass 1
	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferRenderName);
	glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y));
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]);
	renderFBO(ProgramName);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);

	// Generate FBO mipmaps
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, ColorTextureName);
	glGenerateMipmap(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, 0);

	// Blit framebuffers
	GLint const Border = 2;
	int const Tile = 4;
	glBindFramebuffer(GL_READ_FRAMEBUFFER, FramebufferRenderName);
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, FramebufferResolveName);

	for(int j = 0; j < Tile; ++j)
	for(int i = 0; i < Tile; ++i)
	{
		if((i + j) % 2)
			continue;

		glBlitFramebuffer(0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
			FRAMEBUFFER_SIZE.x / Tile * (i + 0) + Border, 
			FRAMEBUFFER_SIZE.x / Tile * (j + 0) + Border, 
			FRAMEBUFFER_SIZE.y / Tile * (i + 1) - Border, 
			FRAMEBUFFER_SIZE.y / Tile * (j + 1) - Border, 
			GL_COLOR_BUFFER_BIT, GL_LINEAR);
	}

	// Pass 2
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);
	renderFB(ProgramName);

	glf::swapBuffers();
	glf::checkError("Render");
}
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();
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());
		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

		glBindProgramPipeline(PipelineName);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantics::INPUT, BufferName[semantics::INPUT]);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantics::OUTPUT, BufferName[semantics::OUTPUT]);
		glDispatchCompute(1, 1, 1);

		glMemoryBarrier(GL_ALL_BARRIER_BITS);

		std::vector<GLuint> Results(DataSize);
		glBindBuffer(GL_COPY_READ_BUFFER, BufferName[semantics::OUTPUT]);
		glm::uint* Pointer = (glm::uint*)glMapBufferRange(GL_COPY_READ_BUFFER, 0, sizeof(glm::uint) * Results.size(), GL_MAP_READ_BIT);
		memcpy(&Results[0], Pointer, Results.size() * sizeof(glm::uint));
		glUnmapBuffer(GL_COPY_READ_BUFFER);

		std::array<glm::uint, 14> const Expect{0u,  2u,  3u,  4u,  6u,  7u,  8u};

		for(std::size_t i = 0, n = Expect.size(); i < n; ++i)
			if(Expect[i] != Results[i])
				return false;
		return true;
	}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());
		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);

		glBindVertexArray(this->VertexArrayName);
		glBindSampler(0, this->SamplerName);

		// Render
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		glBindProgramPipeline(PipelineName[pipeline::RENDER]);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
		glBindImageTexture(semantic::image::DIFFUSE, TextureName[texture::COLORBUFFER], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);

		// Splash
		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		glBindProgramPipeline(PipelineName[pipeline::SPLASH]);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);

		return true;
	}
Example #11
0
void display()
{
	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));
	glDrawBuffer(GL_BACK);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]);

	// Renderer to image
	{
		glDrawBuffer(GL_NONE);

		glBindProgramPipeline(PipelineName[pipeline::SAVE]);
		glBindImageTexture(glf::semantic::image::DIFFUSE, TextureName, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
		glBindVertexArray(VertexArrayName);
		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);
	}

	// Read from image
	{
		GLint Border(8);
		glEnable(GL_SCISSOR_TEST);
		glScissorIndexed(0, Border, Border, Window.Size.x - 2 * Border, Window.Size.y - 2 * Border);

		glDrawBuffer(GL_BACK);

		glBindProgramPipeline(PipelineName[pipeline::READ]);
		glBindImageTexture(glf::semantic::image::DIFFUSE, TextureName, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
		glBindVertexArray(VertexArrayName);
		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);

		glDisable(GL_SCISSOR_TEST);
	}

	glf::swapBuffers();
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			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::perspectiveFov(glm::pi<float>() * 0.25f, WindowSize.x, WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
		
			*Pointer = Projection * this->view() * Model;

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

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

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

		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 6, 1, 0);

		return true;
	}
    bool render()
    {
        glm::vec2 WindowSize(this->getWindowSize());

        {
            glm::mat4* Pointer = static_cast<glm::mat4*>(glMapNamedBufferRange(BufferName[buffer::TRANSFORM], 0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));

            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;

            *Pointer = MVP;

            glUnmapNamedBuffer(BufferName[buffer::TRANSFORM]);
        }

        glm::uint Data(0);
        glClearNamedBufferSubData(BufferName[buffer::ATOMIC_COUNTER], GL_R8UI, 0, sizeof(glm::uint), GL_RGBA, GL_UNSIGNED_BYTE, &Data);

        glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
        glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

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

        glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

        return true;
    }
Example #14
0
    bool render()
    {
        glm::vec2 WindowSize(this->getWindowSize());

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

            *UniformPointer = MVP;
        }

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

        glBindProgramPipeline(PipelineName);
        glBindBuffersBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, 1, &BufferName[buffer::TRANSFORM]);
        glBindTextures(semantic::sampler::DIFFUSE, 1, &TextureName);
        glBindVertexArray(VertexArrayName);
        glBindVertexBuffer(semantic::buffer::STATIC, BufferName[buffer::VERTEX], 0, GLsizei(sizeof(vertex)));

        for(std::size_t Index = 0; Index < viewport::MAX; ++Index)
        {
            glViewportIndexedf(0,
                               Viewport[Index].x,
                               Viewport[Index].y,
                               Viewport[Index].z,
                               Viewport[Index].w);

            glBindSamplers(0, 1, &SamplerName[Index]);
            glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);
        }

        return true;
    }
void renderFBO(GLuint Framebuffer)
{
	glm::mat4 Perspective = glm::perspective(45.0f, float(FRAMEBUFFER_SIZE.x) / FRAMEBUFFER_SIZE.y, 0.1f, 100.0f);
	glm::mat4 ViewFlip = glm::scale(glm::mat4(1.0f), glm::vec3(1.0f,-1.0f, 1.0f));
	glm::mat4 ViewTranslate = glm::translate(ViewFlip, glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y * 2.0));
	glm::mat4 View = glm::rotate(ViewTranslate,-15.f, glm::vec3(0.f, 0.f, 1.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Perspective * View * Model;

	glProgramUniformMatrix4fv(ProgramName[program::VERTEX], UniformMVP, 1, GL_FALSE, &MVP[0][0]);
	glProgramUniform1i(ProgramName[program::FRAGMENT], UniformDiffuse, 0);

	glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y));
	glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]);

	glBindMultiTextureEXT(GL_TEXTURE0, GL_TEXTURE_2D, TextureName);
	glBindSampler(0, SamplerName);

	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);

	glf::checkError("renderFBO");
}
Example #16
0
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			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(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
		
			*Pointer = Projection * this->view() * Model;

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

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

		glUseProgram(ProgramName);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName);
		glBindSampler(0, SamplerName);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);

		glBindVertexArray(VertexArrayName);
		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 15, 0);

		return true;
	}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		// Update of the uniform buffer
		{
			glm::mat4* Pointer = static_cast<glm::mat4*>(glMapNamedBufferRange(BufferName[buffer::TRANSFORM],
				0, sizeof(glm::mat4), GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT));

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

			// Make sure the uniform buffer is uploaded
			glUnmapNamedBuffer(BufferName[buffer::TRANSFORM]);
		}

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		GLint LocationDiffuse = 0;
		glProgramUniformHandleui64NV(ProgramName, LocationDiffuse, TextureHandle);

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

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

		return true;
	}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			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 | GL_MAP_UNSYNCHRONIZED_BIT);

			glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 1000.0f);
			glm::mat4 Model = glm::mat4(1.0f);
			*Pointer = Projection * this->view() * Model;

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

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		glBindProgramPipeline(PipelineName);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindImageTexture(0, TextureName, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
		glBindImageTexture(1, TextureName, 1, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
		glBindImageTexture(2, TextureName, 2, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);

		glBindVertexArray(VertexArrayName);
		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 3, 0, 0);

		return true;
	}
Example #19
0
void display()
{
    // Update of the array buffer
    glm::mat4 Perspective = glm::perspective(45.0f, float(Window.Size.x) / float(Window.Size.y), 0.1f, 100.0f);
    glm::mat4 ViewTranslate = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y * 2.0 - 0.0));
    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 = Perspective * View * Model;

    for(GLsizei i = (0); i < VertexCount; ++i)
        (Pointer + i)->Position = MVP * VertexData[i].Position;

    glBindBuffer(GL_ARRAY_BUFFER, BufferName[buffer::VERTEX]);
    glFlushMappedBufferRange(GL_ARRAY_BUFFER, 0, sizeof(glf::vertex_v4fv2f) * 4);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

    glViewportIndexedf(0, 0, 0, GLfloat(Window.Size.x), GLfloat(Window.Size.y));
    glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

    // Bind rendering objects
    glBindProgramPipeline(PipelineName);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, TextureName);
    glBindVertexArray(VertexArrayName);

    // Make sure the array buffer is uploaded
    glMemoryBarrier(GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT);

    glDrawElementsInstancedBaseVertexBaseInstance(
        GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

    glf::swapBuffers();
}
void display()
{
	// Compute the MVP (Model View Projection matrix)
	glm::mat4 Projection = glm::perspective(45.0f, float(Window.Size.x) / float(Window.Size.y), 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;

	// Set the value of MVP uniform.
	glProgramUniformMatrix4fv(ProgramName, UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	// Clear color buffer with black
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

	// Bind program
	glUseProgram(ProgramName);

	// Bind vertex array & draw 
	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBufferName);

	// Set the display viewport
	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));
	glProvokingVertex(GL_LAST_VERTEX_CONVENTION);
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, NULL, 1, 0);

	glf::checkError("display");
	glf::swapBuffers();
}
Example #21
0
	bool render()
	{
		glm::uvec2 WindowSize = this->getWindowSize();

		{
			// Compute the MVP (Model View Projection matrix)
			float Aspect = (WindowSize.x * 0.33f) / (WindowSize.y * 0.50f);
			glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, Aspect, 0.1f, 100.0f);
			glm::mat4 MVP = Projection * this->test::view() * glm::mat4(1.0f);

			*UniformPointer = MVP;
		}

		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

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

		for(std::size_t Index = 0; Index < viewport::MAX; ++Index)
		{
			glViewportIndexedf(0, 
				Viewport[Index].Viewport.x, 
				Viewport[Index].Viewport.y, 
				Viewport[Index].Viewport.z, 
				Viewport[Index].Viewport.w);

			glBindVertexArray(VertexArrayName[Viewport[Index].VertexFormat]);
			glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 1);
		}

		return true;
	}
Example #22
0
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glDrawBuffer(GL_BACK);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]);

		// Renderer to image
		{
			glDrawBuffer(GL_NONE);

			glBindProgramPipeline(PipelineName[pipeline::SAVE]);
			glBindImageTexture(semantic::image::DIFFUSE, TextureName, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
			glBindVertexArray(VertexArrayName);
			glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);
		}

		// Read from image
		{
			glDrawBuffer(GL_BACK);

			glBindProgramPipeline(PipelineName[pipeline::READ]);
			glBindImageTexture(semantic::image::DIFFUSE, TextureName, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
			glBindVertexArray(VertexArrayName);
			glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 3, 1, 0);
		}

		return true;
	}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		static int FrameIndex = 0;

		// Bind shared objects
		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glBindSampler(0, SamplerName);
		glBindVertexArray(VertexArrayName);

		// Update a colorbuffer bound as a framebuffer attachement and as a texture
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glBindProgramPipeline(PipelineName[pipeline::UPDATE]);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, FrameIndex ? TextureName[texture::COLORBUFFER] : TextureName[texture::DIFFUSE]);

		glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT | GL_TEXTURE_FETCH_BARRIER_BIT);
		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, 0);

		// Blit to framebuffer
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glBindProgramPipeline(PipelineName[pipeline::BLIT]);
	
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);

		glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 1, 0);

		FrameIndex = (FrameIndex + 1) % 256;

		return 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;

	glProgramUniform4fv(ProgramName, UniformDiffuse, 1, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);
	glProgramUniformMatrix4fv(ProgramName, UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));

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

	glUseProgram(ProgramName);

	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBufferName);
	glDrawElementsInstancedBaseVertex(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, 0, 1, 4);

	glf::swapBuffers();
	glf::checkError("display");
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		{
			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 | GL_MAP_UNSYNCHRONIZED_BIT);

			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);
		
			*Pointer = Projection * this->view() * Model;
		}

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		// Bind rendering objects
		glBindProgramPipeline(PipelineName);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindVertexArray(VertexArrayName);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);

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

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);

		return true;
	}
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::perspectiveFov(45.f, 640.f, 480.f, 0.1f, 100.0f);
		//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);
		
		*Pointer = Projection * View * Model;

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

	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);

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

	glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, 6, 1, 0);

	glf::swapBuffers();
}
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 + 45.0f, glm::vec3(1.f, 0.f, 0.f));
	glm::mat4 View = glm::rotate(ViewRotateX, Window.RotationCurrent.x + 45.0f, glm::vec3(0.f, 1.f, 0.f));
	glm::mat4 Model = glm::mat4(1.0f);
	glm::mat4 MVP = Projection * View * Model;

	glProgramUniformMatrix4fv(ProgramName, UniformMVP, 1, GL_FALSE, &MVP[0][0]);

	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));

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

	glUseProgram(ProgramName);

	glBindVertexArray(VertexArrayName);
	glDrawArraysInstanced(GL_TRIANGLES, 0, VertexCount, 10);

	glf::swapBuffers();
	glf::checkError("display");
}
void CascadedShadowMappingRenderer::updateLightProjAndViewports()
{
    // Find a bounding box of whole camera frustum in light view space.
    nv::vec4f frustumMin(std::numeric_limits<float>::max());
    nv::vec4f frustumMax(std::numeric_limits<float>::lowest());
    frustumBoundingBoxLightViewSpace(m_nearPlane, m_farPlane, frustumMin, frustumMax);

    // Update light projection matrix to only cover the area viewable by the camera
    nv::ortho3D(m_lightProjMatrix, frustumMin.x, frustumMax.x, frustumMin.y, frustumMax.y, 0.0f, frustumMin.z);

    // Find a bounding box of segment in light view space.
    float nearSegmentPlane = 0.0f;
    for (unsigned int i = 0; i < m_frustumSegmentCount; ++i) {
        nv::vec4f segmentMin(std::numeric_limits<float>::max());
        nv::vec4f segmentMax(std::numeric_limits<float>::lowest());
        frustumBoundingBoxLightViewSpace(nearSegmentPlane, m_farPlanes[i], segmentMin, segmentMax);

        // Update viewports.
        nv::vec2f frustumSize(frustumMax.x - frustumMin.x, frustumMax.y - frustumMin.y);
        const float segmentSizeX = segmentMax.x - segmentMin.x;
        const float segmentSizeY = segmentMax.y - segmentMin.y;
        const float segmentSize = segmentSizeX < segmentSizeY ? segmentSizeY : segmentSizeX;
        const nv::vec2f offsetBottomLeft(segmentMin.x - frustumMin.x, segmentMin.y - frustumMin.y);
        const nv::vec2f offsetSegmentSizeRatio(offsetBottomLeft.x / segmentSize, offsetBottomLeft.y / segmentSize);
        const nv::vec2f frustumSegmentSizeRatio(frustumSize.x / segmentSize, frustumSize.y / segmentSize);

        nv::vec2f pixelOffsetTopLeft(offsetSegmentSizeRatio * LIGHT_TEXTURE_SIZE);
        nv::vec2f pixelFrustumSize(frustumSegmentSizeRatio * LIGHT_TEXTURE_SIZE);

        // Scale factor that helps if frustum size is supposed to be bigger
        // than maximum viewport size.
        nv::vec2f scaleFactor(
            m_viewportDims[0] < pixelFrustumSize.x ? m_viewportDims[0] / pixelFrustumSize.x : 1.0f,
            m_viewportDims[1] < pixelFrustumSize.y ? m_viewportDims[1] / pixelFrustumSize.y : 1.0f);

        pixelOffsetTopLeft *= scaleFactor;
        pixelFrustumSize *= scaleFactor;

        m_lightViewports[i] = nv::vec4f(-pixelOffsetTopLeft.x, -pixelOffsetTopLeft.y, pixelFrustumSize.x, pixelFrustumSize.y);
        glViewportIndexedfv(i, m_lightViewports[i]._array);

        // Update light view-projection matrices per segment.
        nv::matrix4f lightProj;
        nv::ortho3D(lightProj, segmentMin.x, segmentMin.x + segmentSize, segmentMin.y, segmentMin.y + segmentSize, 0.0f, frustumMin.z);
        nv::matrix4f lightScale;
        lightScale.set_scale(nv::vec3f(0.5f * scaleFactor.x, 0.5f * scaleFactor.y, 0.5f));
        nv::matrix4f lightBias;
        lightBias.set_translate(nv::vec3f(0.5f * scaleFactor.x, 0.5f * scaleFactor.y, 0.5f));
        m_lightSegmentVPSBMatrices[i] = lightBias * lightScale * lightProj * m_lightViewMatrix;

        nearSegmentPlane = m_normalizedFarPlanes[i];
    }

    // Set remaining viewports to some kind of standard state.
    for (unsigned int i = m_frustumSegmentCount; i < MAX_CAMERA_FRUSTUM_SPLIT_COUNT; ++i) {
        glViewportIndexedf(i, 0, 0, LIGHT_TEXTURE_SIZE, LIGHT_TEXTURE_SIZE);
    }
}
Example #29
0
void Triangle::Render(int w, int h)
{
	float t = float(GetTickCount() & 0x3FFF) / float(0x3FFF);
	static const vmath::vec3 X(1.0f, 0.0f, 0.0f);
	static const vmath::vec3 Y(0.0f, 1.0f, 0.0f);
	static const vmath::vec3 Z(0.0f, 0.0f, 1.0f);

	glClearColor(0.3f, 0.1f, 0.2f, 1.0f);
	glClearDepth(1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glUseProgram(program);

	static const float aspect = static_cast<float>(w) / static_cast<float>(h);
	vmath::mat4 p(vmath::frustum(-1.0f, 1.0f, aspect, -aspect, 1.0f, 5000.0f));
	vmath::mat4 m[4];

	for (int i = 0; i < 4; i++)
	{
		m[i] = vmath::mat4(vmath::translate(0.0f, 0.0f, 100.0f * sinf(6.28318531f * t + i) - 230.0f) *
			vmath::rotate(360.0f * t * float(i + 1), X) *
			vmath::rotate(360.0f * t * float(i + 2), Y) *
			vmath::rotate(360.0f * t * float(5 - i), Z) *
			vmath::translate(0.0f, -80.0f, 0.0f));
	}

	//We send the four model matrix to see the different scene in different viewport
	glUniformMatrix4fv(model_matrix_pos, 4, GL_FALSE, m[0]);
	glUniformMatrix4fv(projection_matrix_pos, 1, GL_FALSE, p);

	const float wot = float(w) * 0.5f;
	const float hot = float(h) * 0.5f;
	glViewportIndexedf(0, 0.0f, 0.0f, wot, hot);
	glViewportIndexedf(1, wot, 0.0f, wot, hot);
	glViewportIndexedf(2, 0.0f, hot, wot, hot);
	glViewportIndexedf(3, wot, hot, wot, hot);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_FRONT);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	object.Render();

	glUseProgram(0);
}
	bool render()
	{
		glm::vec2 WindowSize(this->getWindowSize());

		this->Monitor->begin();

		{
			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(glm::pi<float>() * 0.25f, WindowSize.x / WindowSize.y, 0.1f, 100.0f);
			glm::mat4 Model = glm::mat4(1.0f);
			*Pointer = Projection * this->view() * Model;

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

		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LESS);

		glViewportIndexedf(0, 0, 0, WindowSize.x, WindowSize.y);

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

		// Bind rendering objects
		glBindProgramPipeline(PipelineName[pipeline::TEXTURE]);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
		glBindVertexArray(VertexArrayName[pipeline::TEXTURE]);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 2, 0, 0);

		glDisable(GL_DEPTH_TEST);

		glBindFramebuffer(GL_FRAMEBUFFER, 0);

		glBindProgramPipeline(PipelineName[pipeline::SPLASH]);
		glActiveTexture(GL_TEXTURE0);
		glBindVertexArray(VertexArrayName[pipeline::SPLASH]);
		glBindTexture(GL_TEXTURE_2D, TextureName[texture::COLORBUFFER]);

		glDrawArraysInstanced(GL_TRIANGLES, 0, 3, 1);

		this->Monitor->end();
		this->Monitor->log();

		return true;
	}