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

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

		{
			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::ortho(0.f, 256.f, 0.f, 256.f, 0.f, 16.f);
			glm::mat4 Model = glm::mat4(1.0f);
		
			*Pointer = Projection * this->view() * Model;

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

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

		glBindVertexArray(VertexArrayName);
		glActiveTexture(GL_TEXTURE0);

		glBindProgramPipeline(PipelineName[program::UINT]);
		{
			glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8UI])[0]);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8UI]);

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

		glBindProgramPipeline(PipelineName[program::NORM]);
		{
			glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA32F])[0]);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA32F]);

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

			glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8])[0]);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8]);

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

			glViewportIndexedfv(0, &glm::vec4(Viewport[texture::RGBA8_SNORM])[0]);
			glBindTexture(GL_TEXTURE_2D, TextureName[texture::RGBA8_SNORM]);

			glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 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::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;
	}
示例#3
0
		Error operator()(GlState& state)
		{
			GLenum indicesType = 0;
			switch(state.m_indexSize)
			{
			case 2:
				indicesType = GL_UNSIGNED_SHORT;
				break;
			case 4:
				indicesType = GL_UNSIGNED_INT;
				break;
			default:
				ANKI_ASSERT(0);
				break;
			};

			state.flushVertexState();
			state.flushStencilState();
			glDrawElementsInstancedBaseVertexBaseInstance(state.m_topology,
				m_info.m_count,
				indicesType,
				(const void*)(PtrSize)(m_info.m_firstIndex * state.m_indexSize),
				m_info.m_instanceCount,
				m_info.m_baseVertex,
				m_info.m_baseInstance);

			ANKI_TRACE_INC_COUNTER(GR_DRAWCALLS, 1);
			ANKI_TRACE_INC_COUNTER(GR_VERTICES, m_info.m_instanceCount * m_info.m_count);

			return ErrorCode::NONE;
		}
	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;
	}
示例#6
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();
}
	Error operator()(GlCommandBuffer*)
	{
		ANKI_ASSERT(indexSize != 0);

		GLenum indicesType = 0;
		switch(indexSize)
		{
		case 1:
			indicesType = GL_UNSIGNED_BYTE;
			break;
		case 2:
			indicesType = GL_UNSIGNED_SHORT;
			break;
		case 4:
			indicesType = GL_UNSIGNED_INT;
			break;
		default:
			ANKI_ASSERT(0);
			break;
		};

		glDrawElementsInstancedBaseVertexBaseInstance(
			mode,
			m_info.m_count,
			indicesType,
			(const void*)(PtrSize)(m_info.m_firstIndex * indexSize),
			m_info.m_instanceCount,
			m_info.m_baseVertex,
			m_info.m_baseInstance);

		ANKI_COUNTER_INC(GL_DRAWCALLS_COUNT, (U64)1);

		return ErrorCode::NONE;
	}
	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;
	}
    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;
    }
	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;
	}
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);
	}

	glBindProgramPipeline(PipelineName[program::COMPUTE]);
	glBindImageTexture(image::POSITION_INPUT, TextureName[texture::POSITION_INPUT], 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);
	glBindImageTexture(image::TEXCOORD_INPUT, TextureName[texture::TEXCOORD_INPUT], 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);
	glBindImageTexture(image::COLOR_INPUT, TextureName[texture::COLOR_INPUT], 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);
	glBindImageTexture(image::POSITION_OUTPUT, TextureName[texture::POSITION_OUTPUT], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
	glBindImageTexture(image::TEXCOORD_OUTPUT, TextureName[texture::TEXCOORD_OUTPUT], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);
	glBindImageTexture(image::COLOR_OUTPUT, TextureName[texture::COLOR_OUTPUT], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);

	glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
	glDispatchCompute(GLuint(VertexCount), 1, 1);

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

	glBindProgramPipeline(PipelineName[program::GRAPHICS]);
	glActiveTexture(GL_TEXTURE0 + glf::semantic::sampling::SAMPLER_DIFFUSE);
	glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
	glActiveTexture(GL_TEXTURE0 + sampling::SAMPLER_POSITION);
	glBindTexture(GL_TEXTURE_BUFFER, TextureName[texture::POSITION_OUTPUT]);
	glActiveTexture(GL_TEXTURE0 + sampling::SAMPLER_TEXCOORD);
	glBindTexture(GL_TEXTURE_BUFFER, TextureName[texture::TEXCOORD_OUTPUT]);
	glActiveTexture(GL_TEXTURE0 + sampling::SAMPLER_COLOR);
	glBindTexture(GL_TEXTURE_BUFFER, TextureName[texture::COLOR_OUTPUT]);

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

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

	glf::swapBuffers();
}
void display()
{
	GLsizeiptr BufferSize = sizeof(glm::mat4);

	{
		glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]);

		glm::byte* Pointer = (glm::byte*)glMapBufferRange(
			GL_UNIFORM_BUFFER, 0, BufferSize,
			GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);

		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;

			*(glm::mat4*)Pointer = MVP;
		}
		{
			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 + 90.f + 45.0f, glm::vec3(0.f, 1.f, 0.f));
			glm::mat4 Model = glm::mat4(1.0f);
			glm::mat4 MVP = Projection * View * Model;

			*(glm::mat4*)(Pointer + UniformBufferOffset) = MVP;
		}

		// 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);
	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);
	glBindBufferRange(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], 0, BufferSize);
	glBindBufferRange(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM1, BufferName[buffer::TRANSFORM], UniformBufferOffset, BufferSize);
	glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL]);

	for(GLint i = 0; i < 2; ++i)
	{
		glProgramUniform1i(ProgramName, UniformInstance, i);
		glDrawElementsInstancedBaseVertexBaseInstance(
			GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 1, 0, 0);
	}

	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;

			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;
	}
	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);
		}

		glClearTexImage(TextureName[texture::COLORBUFFER], 0, GL_RGBA, GL_FLOAT, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);

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

		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);
			glTextureBarrier();
		}

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

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

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

		return true;
	}
void display()
{
	// Setup blending
	glEnable(GL_BLEND);
	glBlendEquation(GL_FUNC_ADD);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// Compute the MVP (Model View Projection matrix)
	{
		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(15.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;

		*Pointer = MVP;

		glUnmapBuffer(GL_UNIFORM_BUFFER);
	}

	{
		glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, BufferName[buffer::ATOMIC_COUNTER]);
		glm::uint32* Pointer = (glm::uint32*)glMapBufferRange(
			GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(glm::uint32),
			GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT);

		*Pointer = 0;

		glUnmapBuffer(GL_ATOMIC_COUNTER_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);
	glBindVertexArray(VertexArrayName);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);
	glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, BufferName[buffer::ATOMIC_COUNTER]);
	glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);

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

	glf::swapBuffers();
}
示例#16
0
inline void draw_elements_instanced_bv_bi(Primitive primitive, uint32 count, IndexType index_type,
	uint32 index_byte_offset, uint32 instance_count, uint32 vertex_count_offset, uint32 instance_offset)
{
	ARC_GL_CLEAR_ERRORS();
	glDrawElementsInstancedBaseVertexBaseInstance(
		(GLenum)primitive,
		count,
		(GLenum)index_type,
		(void*)index_byte_offset,
		instance_count,
		vertex_count_offset,
		instance_offset);
	ARC_GL_CHECK_FOR_ERRORS();
}
	void renderFB()
	{
		glm::vec2 WindowSize(this->getWindowSize());

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

		glBindFramebuffer(GL_FRAMEBUFFER, 0);
		glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], this->UniformBlockSize, this->UniformBlockSize);
		glBindTextureUnit(0, TextureName[texture::COLORBUFFER]);
		glBindVertexArray(VertexArrayName);

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, nullptr, 1, 0, 0);
	}
示例#18
0
	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;
	}
示例#19
0
inline void drawElementsInstancedBaseVertexBaseInstance(
	DrawElementsInstancedBaseVertexBaseInstanceMode mode,
	GLsizei count,
	DrawElementsInstancedBaseVertexBaseInstanceType type,
	GLvoid *indices,
	GLsizei primcount,
	GLint basevertex,
	GLuint baseinstance) {
	glDrawElementsInstancedBaseVertexBaseInstance(
		GLenum(mode),
		GLsizei(count),
		GLenum(type),
		(GLvoid*)(indices),
		GLsizei(primcount),
		GLint(basevertex),
		GLuint(baseinstance));
}
示例#20
0
void display()
{
	glPushDebugGroup(
		GL_DEBUG_SOURCE_APPLICATION, 
		1, 
		-1, "Frame");

	// 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, 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);
	glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);

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

	glPopDebugGroup();

	glf::swapBuffers();
}
	void renderFBO()
	{
		glEnable(GL_MULTISAMPLE);
		glEnable(GL_SAMPLE_SHADING);
		glMinSampleShading(4.0f);

		glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE);
		glViewportIndexedf(0, 0, 0, static_cast<float>(FRAMEBUFFER_SIZE.x), static_cast<float>(FRAMEBUFFER_SIZE.y));
		glClearNamedFramebufferfv(FramebufferName[framebuffer::RENDER], GL_COLOR, 0, &glm::vec4(0.0f, 0.5f, 1.0f, 1.0f)[0]);

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]);
		glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], 0, this->UniformBlockSize);
		glBindSamplers(0, 1, &SamplerName);
		glBindTextureUnit(0, TextureName[texture::TEXTURE]);
		glBindVertexArray(VertexArrayName);

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

		glDisable(GL_MULTISAMPLE);
	}
示例#22
0
	void draw()
	{
		VK_CHECK_RESULT(Swapchain.acquire(presentCompleteSemaphore, &currentBuffer));
		VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[currentBuffer], VK_TRUE, UINT64_MAX));
		VK_CHECK_RESULT(vkResetFences(device, 1, &waitFences[currentBuffer]));

		glo::context* Context = (glo::context*)this->Context;
		Context->temp_set_framebuffer(frameBuffers[currentBuffer]);
		Context->temp_set_renderpass(renderPass, 0, 0, width, height);

		wglMakeCurrentGTC(this->DeviceContext, this->Context);

		VkCommandBuffer CommandBuffer = Context->temp_get_command_buffer();

		glViewportIndexedf(0, 0, 0, width, height);
		glScissor(0, 0, width, height);

		vkCmdBindPipeline(CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);

		glBindBufferRange(GL_UNIFORM_BUFFER, 0, uniformDataVS.buffer, 0, sizeof(uboVS));
		glBindVertexBuffer(VERTEX_BUFFER_BIND_ID, vertices.buffer, 0, 0);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indices.buffer);

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, indices.count, GL_UNSIGNED_INT, NULL, 1, 0, 0);

		glFlush();

		VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
		VkSubmitInfo submitInfo = {};
		submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
		submitInfo.pWaitDstStageMask = &waitStageMask;
		submitInfo.pWaitSemaphores = &presentCompleteSemaphore;
		submitInfo.waitSemaphoreCount = 1;
		submitInfo.pSignalSemaphores = &renderCompleteSemaphore;
		submitInfo.signalSemaphoreCount = 1;
		submitInfo.pCommandBuffers = &CommandBuffer;
		submitInfo.commandBufferCount = 1;

		VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
		VK_CHECK_RESULT(Swapchain.present(queue, currentBuffer, renderCompleteSemaphore));
	}
	void renderFBO()
	{
		//glEnable(GL_SAMPLE_MASK);
		//glSampleMaski(0, 0xFF);

		glEnable(GL_MULTISAMPLE);
		glEnable(GL_SAMPLE_SHADING);
		glMinSampleShading(4.0f);

		glViewportIndexedf(0, 0, 0, static_cast<float>(FRAMEBUFFER_SIZE.x), static_cast<float>(FRAMEBUFFER_SIZE.y));
		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName[framebuffer::RENDER]);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f)[0]);

		glBindBufferRange(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM], 0, this->UniformBlockSize);
		glBindSampler(0, SamplerName);
		glBindMultiTextureEXT(GL_TEXTURE0, GL_TEXTURE_2D, TextureName[texture::TEXTURE]);
		glBindVertexArray(VertexArrayName);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);

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

		glDisable(GL_MULTISAMPLE);
	}
void display()
{
    {
        glm::mat4 Projection = glm::perspective(45.0f, float(Window.Size.x) / Window.Size.y, 0.1f, 1000.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;

        glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::TRANSFORM]);
        glm::mat4* Pointer = (glm::mat4*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(MVP), GL_MAP_WRITE_BIT);
        *Pointer = MVP;
        glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    {
        glBindBuffer(GL_UNIFORM_BUFFER, BufferName[buffer::MATERIAL]);
        glm::uvec2* Pointer = (glm::uvec2*)glMapBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(glm::uvec2), GL_MAP_WRITE_BIT);
        *Pointer = ImageSize;
        glUnmapBuffer(GL_UNIFORM_BUFFER);
    }

    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]);

    glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
    glBindBufferBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::MATERIAL, BufferName[buffer::MATERIAL]);
    glBindProgramPipeline(PipelineName);
    glBindImageTexture(glf::semantic::image::DIFFUSE, TextureName, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI);
    glBindVertexArray(VertexArrayName);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferName[buffer::ELEMENT]);

    glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, NULL, 1, 0, 0);

    glf::swapBuffers();
}
	Error operator()(CommandBufferImpl*)
	{
		ANKI_ASSERT(m_indexSize != 0);

		GLenum indicesType = 0;
		switch(m_indexSize)
		{
		case 1:
			indicesType = GL_UNSIGNED_BYTE;
			break;
		case 2:
			indicesType = GL_UNSIGNED_SHORT;
			break;
		case 4:
			indicesType = GL_UNSIGNED_INT;
			break;
		default:
			ANKI_ASSERT(0);
			break;
		};

		if(!m_query.isCreated() || !m_query.get().skipDrawcall())
		{
			glDrawElementsInstancedBaseVertexBaseInstance(
				m_mode,
				m_info.m_count,
				indicesType,
				(const void*)(PtrSize)(m_info.m_firstIndex * m_indexSize),
				m_info.m_instanceCount,
				m_info.m_baseVertex,
				m_info.m_baseInstance);

			ANKI_COUNTER_INC(GL_DRAWCALLS_COUNT, (U64)1);
		}

		return ErrorCode::NONE;
	}
示例#26
0
	bool render()
	{
		glm::ivec2 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, 640.f, 480.f, 0.1f, 100.0f);
			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;

			glUnmapBuffer(GL_UNIFORM_BUFFER);
		}

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

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

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

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName[texture::VIEW_A]);

		glActiveTexture(GL_TEXTURE1);
		glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName[texture::VIEW_B]);

		glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, ElementCount, GL_UNSIGNED_SHORT, 0, 2, 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);

			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);
		}

		glBindProgramPipeline(PipelineName[program::COMPUTE]);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantics::INPUT, BufferName[buffer::INPUT]);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantics::OUTPUT, BufferName[buffer::OUTPUT]);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glDispatchCompute(GLuint(VertexCount), 1, 1);

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

		glBindProgramPipeline(PipelineName[program::GRAPHICS]);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, TextureName);
		glBindVertexArray(VertexArrayName);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantics::INPUT, BufferName[buffer::OUTPUT]);

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

		return true;
	}
	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 MVP = Projection * this->test::view() * glm::mat4(1.0f);

			*UniformPointer = MVP;
		}

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

		glBindProgramPipeline(PipelineName);
		glBindTextureUnit(semantic::sampler::DIFFUSE, TextureName);
		glBindVertexArray(VertexArrayName);
		glBindBufferBase(GL_UNIFORM_BUFFER, semantic::uniform::TRANSFORM0, BufferName[buffer::TRANSFORM]);
		glBindBufferBase(GL_SHADER_STORAGE_BUFFER, semantic::storage::VERTEX, BufferName[buffer::VERTEX]);

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

		return true;
	}
示例#29
0
void display()
{
	{
		// Compute the MVP (Model View Projection matrix)
		float Aspect = (Window.Size.x * 0.50f) / (Window.Size.y * 0.50f);
		glm::mat4 Projection = glm::perspective(45.0f, Aspect, 0.1f, 100.0f);
		glm::mat4 ViewTranslateZ = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Window.TranlationCurrent.y));
		glm::mat4 ViewRotateX = glm::rotate(ViewTranslateZ, Window.RotationCurrent.y, glm::vec3(1.f, 0.f, 0.f));
		glm::mat4 ViewRotateY = glm::rotate(ViewRotateX, Window.RotationCurrent.x, glm::vec3(0.f, 1.f, 0.f));
		glm::mat4 View = ViewRotateY;
		glm::mat4 Model = glm::mat4(1.0f);
		glm::mat4 MVP = Projection * View * Model;

		*UniformPointer = MVP;
	}

	glFlushMappedBufferRange(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4));

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);

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

	glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
	float Depth(1.0f);
    glm::u8vec4 ColorClear(255, 127, 0, 255);
    glm::u8vec4 ColorTex(0, 127, 255, 255);
	glClearBufferfv(GL_DEPTH , 0, &Depth);
	glClearTexImage(TextureName[texture::COLORBUFFER], 0, 
		GL_RGBA, GL_UNSIGNED_BYTE, &ColorClear);
	glClearTexSubImage(TextureName[texture::COLORBUFFER], 0, 
		64, 64, 0,
		64, 64, 1,
		GL_RGBA, GL_UNSIGNED_BYTE, &ColorTex);
	glClearTexSubImage(TextureName[texture::COLORBUFFER], 0, 
		256, 0, 0,
		64, 64, 1,
		GL_RGBA, GL_UNSIGNED_BYTE, &ColorTex);
	glClearTexSubImage(TextureName[texture::COLORBUFFER], 0, 
		128, 384, 0,
		64, 64, 1,
		GL_RGBA, GL_UNSIGNED_BYTE, &ColorTex);
	glClearTexSubImage(TextureName[texture::COLORBUFFER], 0, 
		512, 256, 0,
		64, 64, 1,
		GL_RGBA, GL_UNSIGNED_BYTE, &ColorTex);


	// Bind rendering objects
	glBindProgramPipeline(PipelineName[pipeline::TEXTURE]);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, TextureName[texture::DIFFUSE]);
	glBindVertexArray(VertexArrayName[pipeline::TEXTURE]);
	glBindVertexBuffer(glf::semantic::buffer::STATIC, BufferName[buffer::VERTEX], 0, GLsizei(sizeof(glf::vertex_v2fv2f)));
	glBindBufferBase(GL_UNIFORM_BUFFER, glf::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);

	glf::swapBuffers();
}
示例#30
0
      void RenderEngineGLIndirect::render( RenderGroupGLHandle groupHandle, const dp::rix::core::RenderOptions& /*renderOptions*/ )
      {
        // if dirty, update sorted list
        RenderGroupGL::ProgramPipelineCaches::iterator glIt;
        RenderGroupGL::ProgramPipelineCaches::iterator glIt_end = groupHandle->m_programPipelineCaches.end();
        for ( glIt = groupHandle->m_programPipelineCaches.begin(); glIt != glIt_end; ++glIt )
        {
          ProgramPipelineGLHandle programPipeline = glIt->first;
          RenderGroupGLCache* cache = glIt->second.get<RenderGroupGLCache>();

#if RIX_GL_SEPARATE_SHADER_OBJECTS_SUPPORT == 1
          glBindProgramPipeline( programPipeline->m_pipelineId );
#else
          glUseProgram( programPipeline->m_programs[0]->getProgram()->getGLId() );
#endif

          //if ( giList->m_indirectEntries.size() != giList->m_geometryInstances.size())
          if ( !cache->m_initialized ) // TODO support changes
          {
            cache->m_initialized = true;

            RenderGroupGLCache::DrawArrayListEntry triangles;
            RenderGroupGLCache::DrawArrayListEntry lines;
            RenderGroupGLCache::DrawArrayListEntry linesStrips;

            //cache->m_indirectEntries.clear();
            //cache->m_indirectCommands.clear();
            for (size_t index = 0; index < cache->getGeometryInstances().size(); ++index )
            {
              GeometryInstanceGLHandle gi = cache->getGeometryInstances()[index];

              if ( !gi->getGeometry()->getIndices() )
              {
                switch ( gi->getGeometry()->getGeometryDescription()->getPrimitiveType() )
                {
                case GeometryPrimitiveType::TRIANGLES:
                  //drawEntry = &triangles;
                  addArrayIndirectCommand(gi, triangles);
                  break;
                case GeometryPrimitiveType::LINES:
                  addArrayIndirectCommand(gi, lines);
                  break;
                case GeometryPrimitiveType::LINE_STRIP:
                  addArrayIndirectCommand(gi, linesStrips);
                  break;
                default:
                  assert( 0 && "unsupported primitve types");
                }
              }
              else
              {
                //addElementIndirectCommand(cache, gi );
              }

            }

            addDrawArrayList( cache, triangles, GL_TRIANGLES);
            addDrawArrayList( cache, lines, GL_LINES );
            addDrawArrayList( cache, linesStrips, GL_LINE_STRIP );
            for ( size_t idx = 0;idx < cache->m_drawElementsList.size(); ++idx )
            {
              prepareDrawElementsEntry( &cache->m_drawElementsList[idx] );
            }

          }

          // prepare fixed containers
#if 0
          GeometryInstanceGLHandle gi = cache->getGeometryInstances()[0];
          for ( size_t containerIdx = 0; containerIdx < gi->m_containers.size(); ++containerIdx )
          {
            // debug info
            auto infos = gi->m_containers[containerIdx].container->m_descriptor->m_parameterInfos;
            for ( size_t infoIdx = 0; infoIdx < infos.size(); ++infoIdx )
            {
              std::cout << "c: " << containerIdx << ", infoIdX:" << infoIdx << ", name: " << infos[infoIdx].m_name << std::endl;
            }
          }
#endif
          assert( !"No implementation available atm");
          // TODO update to new interface
          //gi->m_containers[0].parameters[0]->update( gi->m_containers[0].container->m_data ); // sys_View
          //gi->m_containers[1].parameters[0]->update( gi->m_containers[1].container->m_data ); // lights


          for ( size_t idx = 0;idx < cache->m_drawArrayList.size(); ++idx )
          {
            RenderGroupGLCache::DrawArrayListEntry &entry = cache->m_drawArrayList[idx];

            glEnableVertexAttribArray( 12 );
            dp::gl::bind( GL_ARRAY_BUFFER, entry.m_indirectPointersBuffer->getBuffer() );
            glVertexAttribLPointerEXT( 12, 1, GL_UNSIGNED_INT64_NV, 0, 0 );
            glVertexAttribDivisor( 12, 1);
            // TODO update vertex attrib pointer to 64-bit values


            #define USE_DRAW_INDIRECT_BUFFER

#if 0

#if defined(USE_DRAW_INDIRECT_BUFFER) 
            dp::gl::bind( GL_DRAW_INDIRECT_BUFFER, entry.m_indirectCommandsBuffer->getBuffer() );
            size_t offset = 0;
            for (size_t index = 0; index < entry.m_indirectCommands.size(); ++index )
            {
              glDrawArraysIndirect( entry.m_primitiveType, (const void*)(offset) );
              offset += sizeof( RenderGroupGLCache::DrawArraysIndirectCommand );

            }
#else
            RenderGroupGLCache::DrawArraysIndirectCommand *command = &entry.m_indirectCommands[0];
            for (size_t index = 0; index < entry.m_indirectCommands.size(); ++index )
            {
              //glDrawArraysIndirect( entry.m_primitiveType, command );
              glDrawArraysInstancedBaseInstance( entry.m_primitiveType, command->first, command->count, command->primCount, command->baseInstance );
              //glDrawementsBaseVertex( entry.m_primitiveType, command->count, GL_UN)
              ++command;
            }
#endif

#else

#if defined(USE_DRAW_INDIRECT_BUFFER)
            dp::gl::bind( GL_DRAW_INDIRECT_BUFFER, entry.m_indirectCommandsBuffer->getBuffer() );
            glMultiDrawArraysIndirectAMD( entry.m_primitiveType, 0, static_cast<GLsizei>(entry.m_indirectCommands.size()), sizeof( RenderGroupGLCache::DrawArraysIndirectCommand ) );
#else
            RenderGroupGLCache::DrawArraysIndirectCommand *commands = &entry.m_indirectCommands[0];
            glMultiDrawArraysIndirectAMD( entry.m_primitiveType, commands, static_cast<GLuint>(entry.m_indirectCommands.size()), 0 );
#endif

#endif

          }


#if 0
          unsigned int indirectCommands = 0;

          glEnable( GL_PRIMITIVE_RESTART );
          //glDisable( GL_PRIMITIVE_RESTART );
          glPrimitiveRestartIndex( ~0 );

          glEnableClientState(GL_ELEMENT_ARRAY_UNIFIED_NV );
          glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV);
          glEnableVertexAttribArray( 12 );
          glVertexAttribDivisor( 12, 1);
          glVertexAttribLFormatNV( 12, 1, GL_UNSIGNED_INT64_NV, 0 );

          for ( size_t idx = 0;idx < cache->m_drawElementsList.size(); ++idx )
          {
            const RenderGroupGLCache::DrawElementsListEntry& entry = cache->m_drawElementsList[idx];

            //dp::gl::bind( GL_ARRAY_BUFFER, entry.m_indirectPointersBuffer );
            //glVertexAttribLPointerEXT( 12, 1, GL_UNSIGNED_INT64_NV, 0, 0 );
            glBufferAddressRangeNV( GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, 12, entry.m_indirectPointersBufferAddress, entry.m_indirectPointersBufferRange );

            //dp::gl::bind( GL_ELEMENT_ARRAY_BUFFER, entry.m_indexBuffer );
            glBufferAddressRangeNV( GL_ELEMENT_ARRAY_ADDRESS_NV, 0, entry.m_indexBufferAddress, entry.m_indexBufferRange );
            //glMultiDrawElementsIndirectAMD( entry.m_primitiveType, GL_UNSIGNED_INT, &entry.m_indirectCommands[0], static_cast<GLuint>(entry.m_indirectCommands.size()), 0);
            //glDrawElementsIndirect( entry.m_primitiveType, GL_UNSIGNED_INT, &entry.m_indirectCommands[0] );
            glDrawElementsInstancedBaseVertexBaseInstance( entry.m_primitiveType, entry.m_indirectCommands[0].count, GL_UNSIGNED_INT, 0, 1, entry.m_indirectCommands[0].baseVertex, entry.m_indirectCommands[0].baseInstance );

            indirectCommands += static_cast<unsigned int>(entry.m_indirectCommands.size());
          }
          glDisableClientState(GL_ELEMENT_ARRAY_UNIFIED_NV );
          glDisableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV);

#endif

          //std::cout << "indirect commands " << indirectCommands << ", " << cache->m_drawElementsList.size() << std::endl;
        }
      }