Example #1
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;
    }
Example #2
0
void RadixSort::SortBits (int bits)
{
	// pass current bit shift to the shader programs
	glProgramUniform1i (counting.get (), counting_bitshift, bits);
	glProgramUniform1i (globalsort.get (), globalsort_bitshift, bits);

	// set buffer bindings
	{
		GLuint bufs[4] = { buffer, prefixsums, blocksums.front (), result };
		glBindBuffersBase (GL_SHADER_STORAGE_BUFFER, 0, 4, bufs);
	}

	// counting
	counting.Use ();
	glDispatchCompute (numblocks, 1, 1);
	glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT);

	// create block sums level by level
	blockscan.Use ();
	uint32_t numblocksums = (4 * numblocks) / blocksize;
	for (int i = 0; i < blocksums.size () - 1; i++)
	{
		glBindBuffersBase (GL_SHADER_STORAGE_BUFFER, 0, 2, &blocksums[i]);
		glDispatchCompute (numblocksums > 0 ? numblocksums : 1, 1, 1);
		numblocksums /= blocksize;
		glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT);
	}

	// add block sums level by level (in reversed order)
	addblocksum.Use ();
	for (int i = blocksums.size () - 3; i >= 0; i--)
	{
		uint32_t numblocksums = (4 * numblocks) / intpow (blocksize, i + 1);
		glBindBuffersBase (GL_SHADER_STORAGE_BUFFER, 0, 2, &blocksums[i]);
		glDispatchCompute (numblocksums > 0 ? numblocksums : 1, 1, 1);
		glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT);
	}

	// map values to their global position in the output buffer
	{
		GLuint bufs[2] = { buffer, prefixsums };
		glBindBuffersBase (GL_SHADER_STORAGE_BUFFER, 0, 2, bufs);
	}
	globalsort.Use ();
	glDispatchCompute (numblocks, 1, 1);
	glMemoryBarrier (GL_SHADER_STORAGE_BARRIER_BIT);
}
Example #3
0
void display()
{
	{
		// Compute the MVP (Model View Projection matrix)
		float Aspect = (Window.Size.x * 0.33f) / (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));

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

	glBindProgramPipeline(PipelineName);
	glBindBuffersBase(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, 1, &BufferName[buffer::TRANSFORM]);
	glBindTextures(glf::semantic::sampler::DIFFUSE, 1, &TextureName);
	glBindVertexArray(VertexArrayName);
	glBindVertexBuffer(glf::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);
	}

	glf::checkError("display");
	glf::swapBuffers();
}
Example #4
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL44_nglBindBuffersBase(JNIEnv *env, jclass clazz, jint target, jint first, jint count, jlong buffers, jlong function_pointer) {
	const GLuint *buffers_address = (const GLuint *)(intptr_t)buffers;
	glBindBuffersBasePROC glBindBuffersBase = (glBindBuffersBasePROC)((intptr_t)function_pointer);
	glBindBuffersBase(target, first, count, buffers_address);
}