Пример #1
0
	void Cube::init_viewport()
	{
		glUseProgram(m_program);
		glBindVertexArray(m_vao);

		int i;
		auto sw = WindowInfo::getInstance()->getWidth();
		auto sh = WindowInfo::getInstance()->getHeight();



		static const int width = sw;
		static const int height = sh;
		int scissor_width = (7 * width) / 16; // 7/16window
		int scissor_height = (7 * height) / 16;
		// Lower left...
		glScissorIndexed(0,     //index
			0, 0, //left bottom
			scissor_width, scissor_height); // width height
											// Lower right...
		glScissorIndexed(1,
			width - scissor_width, 0,
			width - scissor_width, scissor_height);
		//Upper left...
		glScissorIndexed(2,
			0, height - scissor_height,
			scissor_width, scissor_height);
		// Upper right...
		glScissorIndexed(3,
			width - scissor_width, height - scissor_height,
			scissor_width, scissor_height);
	}
void resolveMultisampling()
{
	{
		glm::mat4* Pointer = (glm::mat4*)glMapNamedBufferRangeGTC(
			BufferName[buffer::BLIT], 0, sizeof(glm::mat4),
			GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT);

		glm::mat4 Perspective = glm::perspective(45.0f, float(Window.Size.x) / Window.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;

		*Pointer = MVP;
		glUnmapNamedBufferGTC(BufferName[buffer::BLIT]);
		//glNamedBufferSubDataEXT(BufferName[buffer::BLIT], 0, sizeof(glm::mat4), &MVP[0][0]);
	}

	glViewportIndexedf(0, 0, 0, float(Window.Size.x), float(Window.Size.y));
	glEnable(GL_SCISSOR_TEST);
	glBindNamedTextureLevelGTC(GL_FRAMEBUFFER, 0, 0, 0);

	glBindNamedBufferGTC(GL_UNIFORM_BUFFER, glf::semantic::uniform::TRANSFORM0, BufferName[buffer::BLIT]);
	glBindNamedTextureGTC(GL_TEXTURE, 0, TextureName[texture::MULTISAMPLE]);
	glBindNamedSamplerGTC(0, SamplerName);
	glBindNamedVertexArrayGTC(VertexArrayName);

	// Box
	{
		glScissorIndexed(0, 1, 1, Window.Size.x  / 2 - 2, Window.Size.y - 2);
		glBindNamedProgramPipelineGTC(PipelineName[program::RESOLVE_BOX]);
		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 5, 0);
	}

	// Near
	{
		glScissorIndexed(0, Window.Size.x / 2 + 1, 1, Window.Size.x / 2 - 2, Window.Size.y - 2);
		glBindNamedProgramPipelineGTC(PipelineName[program::RESOLVE_NEAR]);
		glDrawArraysInstancedBaseInstance(GL_TRIANGLES, 0, VertexCount, 5, 0);
	}

	//glBindImageBaseGTC(GL_READ_FRAMEBUFFER, glf::semantic::renderbuffer::COLOR0, TextureName[texture::MULTISAMPLE], 0);
	//glBindImageBaseGTC(GL_READ_FRAMEBUFFER, glf::semantic::renderbuffer::DEPTH, TextureName[texture::DEPTH], 0);
	//glBindImageBaseGTC(GL_DRAW_FRAMEBUFFER, glf::semantic::renderbuffer::COLOR0, 0, 0);
	//glBlitFramebuffer(
	//	0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
	//	0, 0, FRAMEBUFFER_SIZE.x, FRAMEBUFFER_SIZE.y, 
	//	GL_COLOR_BUFFER_BIT, GL_NEAREST);

	glDisable(GL_SCISSOR_TEST);

	glf::checkError("renderFB");
}
void display()
{
	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);

	glEnable(GL_SCISSOR_TEST);
	glDisable(GL_FRAMEBUFFER_SRGB);
	glScissorIndexed(0, 0, 0, Window.Size.x, Window.Size.y);
	glClearBufferfv(GL_COLOR, 0, &glm::vec4(1.0f, 0.5f, 0.0f, 1.0f)[0]);

	{
		glm::mat4 Projection = glm::perspective(45.0f, float(FRAMEBUFFER_SIZE.x) / float(FRAMEBUFFER_SIZE.y), 0.1f, 100.0f);
		glm::mat4 MVP = Projection * View * Model;

		glViewportIndexedf(0, 0, 0, float(FRAMEBUFFER_SIZE.x), float(FRAMEBUFFER_SIZE.y));
		glDisable(GL_FRAMEBUFFER_SRGB);

		glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName);
		glClearBufferfv(GL_COLOR, 0, &glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)[0]);
		renderScene(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), MVP, Texture2DName);
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}

	{
		glm::mat4 Projection = glm::perspective(45.0f, float(Window.Size.x) / float(Window.Size.y), 0.1f, 100.0f);
		glm::mat4 MVP = Projection * View * Model;

		glViewportIndexedfv(0, &glm::vec4(0, 0, Window.Size.x, Window.Size.y)[0]);

		// Correct display
		glScissorIndexed(0, 0, Window.Size.y / 2 - 1, Window.Size.x, Window.Size.y / 2);
		glEnable(GL_FRAMEBUFFER_SRGB);
		glSamplerParameteri(SamplerName, GL_TEXTURE_SRGB_DECODE_EXT, GL_SKIP_DECODE_EXT); // GL_DECODE_EXT 
		renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName);
		glDisable(GL_FRAMEBUFFER_SRGB);

		// Incorrected display
		glScissorIndexed(0, 0, 0, Window.Size.x, Window.Size.y / 2);
		glEnable(GL_FRAMEBUFFER_SRGB);
		glSamplerParameteri(SamplerName, GL_TEXTURE_SRGB_DECODE_EXT, GL_DECODE_EXT); // GL_DECODE_EXT 
		renderScene(glm::vec4(1.0f, 0.5f, 0.0f, 1.0f), MVP, ColorbufferName);
		glDisable(GL_FRAMEBUFFER_SRGB);
	}

	glf::swapBuffers();
	glf::checkError("display");
}
Пример #4
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();
}
Пример #5
0
/**
 * Test invalid values for scissor left, bottom, width, height
 * INVALID_VALUE for negative w,h.  Test default values for left, bottom,
 * width, height.
 * OpenGL 4.3 Core section 13.6.1 ref:
 *    "In the initial state, left = bottom = 0, and width and
 *    height are determined by the size of the window into which the GL is
 *    to do its rendering for all viewports. If the default framebuffer is
 *    bound but no default framebuffer is associated with the GL context
 *    (see chapter 4), then width and height are initially set to zero."
 *
 *    "If either width or height is less than zero for any scissor rectangle,
 *    then an INVALID_VALUE error is generated."
 */
static bool
scissor_bounds(GLint maxVP)
{
	GLint sc[4];
	bool pass = true;
	int i;

	/* intial values for left, bottom, width, height */
	for (i = 0; i < maxVP; i++) {
		glGetIntegeri_v(GL_SCISSOR_BOX, i, sc);
		if (sc[0] != 0 || sc[1] != 0 || sc[2] != piglit_width ||
		    sc[3] != piglit_height) {
			printf("scissor box default value wrong for idx %d\n",
			       i);
			pass = false;
		}
	}
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* make sure large values don't cause gl errors */
	glScissorIndexed(0, 0x8000, 0x80000000, 0x7ffff, 0x7fffffff);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* negative width, height gives gl error */
	sc[2] = -10;
	sc[3] = 0;
	for (i = 0; i < 2; i++) {
		glScissorArrayv(0, 1, sc);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		glScissorIndexed(1, sc[0], sc[1], sc[2], sc[3]);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		glScissorIndexedv(2, sc);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		sc[2] = 5;
		sc[3] = -12345;
	}

	return pass;
}
Пример #6
0
PIGLIT_GL_TEST_CONFIG_END

/**
 * Test that ScissorArrayv, ScissorIndexed(v), GetIntegeri_v give the
 * "expected_error" gl error.  Given the values for "first" and "count"
 * or "index" in range [first, first+count).
 */
static bool
check_sc_index(GLuint first, GLsizei count, GLenum expected_error)
{
	static const GLint sv[] = {0, 10, 20, 35};
	GLint *mv, svGet[4];
	unsigned int i;
	bool pass = true;
	const unsigned int numIterate = (expected_error == GL_NO_ERROR)
		? count : 1;

	mv = malloc(sizeof(GLint) * 4 * count);
	if (mv == NULL)
		return false;
	for (i = 0; i < count; i++) {
		mv[i * 4] = sv[0];
		mv[i * 4 + 1] = sv[1];
		mv[i * 4 + 2] = sv[2];
		mv[i * 4 + 3] = sv[3];
	}
	glScissorArrayv(first, count, mv);
	free(mv);
	pass = piglit_check_gl_error(expected_error) && pass;

	/* only iterate multiple indices for no error case */
	for (i = count; i > count - numIterate; i--) {
		glScissorIndexed(first + i - 1, sv[0], sv[1], sv[2], sv[3]);
		pass = piglit_check_gl_error(expected_error) && pass;

		glGetIntegeri_v(GL_SCISSOR_BOX, first + i - 1, svGet);
		pass = piglit_check_gl_error(expected_error) && pass;

		glEnablei(GL_SCISSOR_TEST, first + i - 1);
		pass = piglit_check_gl_error(expected_error) && pass;

		glDisablei(GL_SCISSOR_TEST, first + i - 1);
		pass = piglit_check_gl_error(expected_error) && pass;

		glIsEnabledi(GL_SCISSOR_TEST, first + i - 1);
		pass = piglit_check_gl_error(expected_error) && pass;
	}

	return pass;
}
Пример #7
0
enum piglit_result
piglit_display(void)
{
	static const float expected[] = {
		0.0f, 1.0f, 0.0f, 1.0f
	};

	const int slice_height = (piglit_height + num_viewports - 2)
		/ (num_viewports - 1);

	bool pass = false;
	int i;

	glDisable(GL_SCISSOR_TEST);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glClear(GL_COLOR_BUFFER_BIT);

	glScissorIndexed(0, 0, 0, piglit_width, piglit_height);
	glEnablei(GL_SCISSOR_TEST, 0);

	for (i = 1; i < num_viewports; i++) {
		glEnablei(GL_SCISSOR_TEST, i);
		glScissorIndexed(i,
				 0, i * slice_height,
				 piglit_width, slice_height);
	}

	glClearColor(0.0, 1.0, 0.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT);

	pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
				      expected);

	piglit_present_results();
	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}
Пример #8
0
/**
 * Draws a single quad full window size, with different scissor rectangles
 * and different scissor test enables for each viewport index.
 * Scissor rectangles or viewport restrict drawing to sub-area of full
 * window surface.  Geometry shader is responsible for exapnding primitves
 * to cover all divX * divY viewport/scissor indices.  The function reads
 * back the expected color to test if the scissored drawing was correct.
 */
static bool
draw_multi_viewport_scissor(void)
{
	bool pass = true, scEnabled;
	int i, j;
	GLfloat w = (GLfloat) piglit_width / (GLfloat) divX;
	GLfloat h = (GLfloat) piglit_height / (GLfloat) divY;

	/* Setup scissor/viewport rectangles and enables for indices.
	 * Every other index has SCISSOR_TEST enabled with a scissor
	 * rectangle that restricts rendering to the sub-region (wxh).
	 * The other indices  restrict rendering by making the viewport
	 * restricted to the sub-region (wxh sized).  For the indices with
	 * viewport restricted rendering, the SCISSOR_TEST is alternatively
	 * enabled/disabled.
	 */
	glScissor(0, 0, piglit_width, piglit_height);
	glViewport(0, 0, piglit_width, piglit_height);
	glClear(GL_COLOR_BUFFER_BIT);
	glEnable(GL_SCISSOR_TEST);
	scEnabled = false;
	for (i = 0; i < divX; i++) {
		for (j = 0; j < divY; j++) {
			GLuint idx = j + i*divY;
			if (scEnabled) {
				/* use viewport to restrict rendering */
				if (i & 1)
					glDisablei(GL_SCISSOR_TEST, idx);
				glViewportIndexedf(idx, i * w, j * h, w, h);
				scEnabled = false;
			} else {
				/* use scissor to restrict rendering */
				glScissorIndexed(idx, i * w, j * h, w, h);
				scEnabled = true;
			}
		}
	}

	/* draw restricted size quads with scissoring enabled/disabled */
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
	pass = draw_check_pixels() & pass;
	glDisable(GL_SCISSOR_TEST);
	return pass;
}
Пример #9
0
/**
 * Draws a single quad full window size, with different scissor rectangles.
 * Scissor rectangles restrict drawing to sub-area of full window.
 * Geometry shader is responsible for expanding primitives to cover all
 * divX * divY viewport/scissor indices.  The function reads back the expected
 * color to test if the scissored drawing was correct.
 */
static bool
draw_multi_scissor_rect(void)
{
	bool pass = true;
	int i, j;
	GLfloat w = (GLfloat) piglit_width / (GLfloat) divX;
	GLfloat h = (GLfloat) piglit_height / (GLfloat) divY;

	glViewport(0, 0, piglit_width, piglit_height);
	glClear(GL_COLOR_BUFFER_BIT);
	glEnable(GL_SCISSOR_TEST);
	/* setup scissor rectangles for viewport indices */
	for (i = 0; i < divX; i++) {
		for (j = 0; j < divY; j++) {
			glScissorIndexed(j + i*divY, i * w, j * h, w, h);
		}
	}

	/* draw full viewport sized quads scissored down and check results */
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
	pass = draw_check_pixels() & pass;
	glDisable(GL_SCISSOR_TEST);
	return pass;
}
Пример #10
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
		{
			GLint Border(8);
			glEnable(GL_SCISSOR_TEST);
			glScissorIndexed(0, Border, Border, static_cast<GLsizei>(WindowSize.x - 2) * Border, static_cast<GLsizei>(WindowSize.y - 2) * Border);

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

			glDisable(GL_SCISSOR_TEST);
		}

		return true;
	}
Пример #11
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL41_nglScissorIndexed(JNIEnv *env, jclass clazz, jint index, jint left, jint bottom, jint width, jint height, jlong function_pointer) {
	glScissorIndexedPROC glScissorIndexed = (glScissorIndexedPROC)((intptr_t)function_pointer);
	glScissorIndexed(index, left, bottom, width, height);
}
Пример #12
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;

        glDisable(GL_SCISSOR_TEST);

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

        // Turn on scissor testing
        glEnable(GL_SCISSOR_TEST);

        // Each rectangle will be 7/16 of the screen
        int scissor_width = (7 * info.windowWidth) / 16;
        int scissor_height = (7 * info.windowHeight) / 16;

        // Four rectangles - lower left first...
        glScissorIndexed(0,
                         0, 0,
                         scissor_width, scissor_height);

        // Lower right...
        glScissorIndexed(1,
                         info.windowWidth - scissor_width, 0,
                         scissor_width, scissor_height);

        // Upper left...
        glScissorIndexed(2,
                         0, info.windowHeight - scissor_height,
                         scissor_width, scissor_height);

        // Upper right...
        glScissorIndexed(3,
                         info.windowWidth - scissor_width,
                         info.windowHeight - scissor_height,
                         scissor_width, scissor_height);

        glUseProgram(program);

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

        glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, 0);
    }