Example #1
0
static bool
draw_multi_viewport(void)
{
	bool pass = true;
	int i, j;
	const int divX=4, divY=4;
	GLfloat w = (GLfloat) piglit_width / (GLfloat) divX;
	GLfloat h = (GLfloat) piglit_height / (GLfloat) divY;
        GLfloat data[16 * 4 /* 4x4 * (x + y + w + h) */];
	int idx;
	int p;

	idx = 0;
	for (i = 0; i < divX; i++) {
		for (j = 0; j < divY; j++) {
			data[idx * 4 + 0] = (GLfloat)(i * w);
			data[idx * 4 + 1] = (GLfloat)(j * h);
			data[idx * 4 + 2] = w;
			data[idx * 4 + 3] = h;
			idx++;
		}
	}
	glViewport(0, 0, piglit_width, piglit_height); /* for glClear() */
	glClear(GL_COLOR_BUFFER_BIT);
	glViewportArrayv(0, 16, data);

	glDrawArrays(GL_POINTS, 0, 1);
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	for (i = 0; i < divX; i++) {
		for (j = 0; j < divY; j++) {
			GLfloat expected[4];

			expected[0] = 1.0 / (1 + i*4 + j);
			expected[1] = 0.0;
			expected[2] = 0.0;
			expected[3] = 1.0;
			p = piglit_probe_pixel_rgba(i * w + w/2, j * h + h /2,
						    expected);
			if (!p) {
				printf("Wrong color for viewport i,j %d %d\n",
				       i, j);
				pass = false;
			}
		}
	}

	piglit_present_results();

	return pass;
}
Example #2
0
void WrappedOpenGL::glViewportIndexedfv(GLuint index, const GLfloat *v)
{
  glViewportArrayv(index, 1, v);
}
Example #3
0
void WrappedOpenGL::glViewportIndexedf(GLuint index, GLfloat x, GLfloat y, GLfloat w, GLfloat h)
{
  const float v[4] = {x, y, w, h};
  glViewportArrayv(index, 1, v);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL41_nglViewportArrayv(JNIEnv *env, jclass clazz, jint first, jint count, jlong v, jlong function_pointer) {
	const GLfloat *v_address = (const GLfloat *)(intptr_t)v;
	glViewportArrayvPROC glViewportArrayv = (glViewportArrayvPROC)((intptr_t)function_pointer);
	glViewportArrayv(first, count, v_address);
}
Example #5
0
File: bounds.c Project: RAOF/piglit
PIGLIT_GL_TEST_CONFIG_END

/**
 * Test clamping for viewport x,y, width, height. They should be clamped
 * to VIEWPORT_BOUNDS_RANGE and MAX_VIEWPORT_DIMS.  INVALID_VALUE for
 * negative w,h. Test default values of x,y,w,h.
 * OpenGL 4.3 Core section 13.6.1 ref:
 *    "The location of the viewport’s bottom-left corner, given by (x, y),
 *    are clamped to be within the implementation-dependent viewport bounds
 *    range. The viewport bounds range [min, max] tuple may be determined by
 *    calling GetFloatv with the symbolic constant VIEWPORT_BOUNDS_RANGE (see
 *    section 22)."
 *
 *    "Viewport width and height are clamped to implementation-dependent
 *    maximums when specified. The maximum width and height may be found by
 *    calling GetFloatv with the symbolic constant MAX_VIEWPORT_DIMS."
 *
 *    "An INVALID_VALUE error is generated if either w or h is negative."
 *
 *    "In the initial state, w and h for each viewport are set to the width
 *    and height, respectively, of the window into which the GL is to do its
 *    rendering. If the default framebuffer is bound but no default framebuffer
 *    is associated with the GL context (see chapter 9), then w and h are
 *    initially set to zero. ox, oy , n, and f are set to w/2 , h/2, 0.0, and
 *    1.0, respectively."
 */
static bool
viewport_bounds(GLint maxVP)
{
	GLfloat maxDims[2];
	GLfloat range[2];
	GLfloat vp[4], vpGet[4];
	bool pass = true;
	int i;

	/* intial values for x,y,w,h */
	for (i = 0; i < maxVP; i++) {
		glGetFloati_v(GL_VIEWPORT, i, vp);
		if (vp[0] != 0.0 || vp[1] != 0.0 ||
		    vp[2] != (GLfloat) piglit_width ||
		    vp[3] != (GLfloat) piglit_height) {
			printf("viewport default value wrong for idx %d\n", i);
			pass = false;
		}
	}
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* test clamping of viewport values */
	glGetFloatv(GL_MAX_VIEWPORT_DIMS, maxDims);
	glGetFloatv(GL_VIEWPORT_BOUNDS_RANGE, range);
	vp[0] = range[0] - 2.0;
	vp[1] = range[1] + 2.0;
	vp[2] = maxDims[0] + 1.0;
	vp[3] = maxDims[1] + 1.0;
	glViewportArrayv(0, 1, vp);
	glGetFloati_v(GL_VIEWPORT, 0, vpGet);
	if (vpGet[0] != range[0] || vpGet[1] != range[1] ||
	    vpGet[2] != maxDims[0] || vpGet[3] != maxDims[1]) {
		printf("viewport clamping failed glViewportArrayv\n");
		pass = false;
	}
	glViewportIndexedf(1, vp[0], vp[1], vp[2], vp[3]);
	glGetFloati_v(GL_VIEWPORT, 1, vpGet);
	if (vpGet[0] != range[0] || vpGet[1] != range[1] ||
	    vpGet[2] != maxDims[0] || vpGet[3] != maxDims[1]) {
		printf("viewport clamping failed glViewportIndexedf\n");
		pass = false;
	}
	glViewportIndexedfv(2, vp);
	glGetFloati_v(GL_VIEWPORT, 2, vpGet);
	if (vpGet[0] != range[0] || vpGet[1] != range[1] ||
	    vpGet[2] != maxDims[0] || vpGet[3] != maxDims[1]) {
		printf("viewport clamping failed glViewportIndexedfv\n");
		pass = false;
	}

	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	/* negative width, height gives gl error */
	vp[2] = -10.3;
	vp[3] = 0.0;
	for (i = 0; i < 2; i++) {
		glViewportArrayv(0, 1, vp);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		glViewportIndexedf(1, vp[0], vp[1], vp[2], vp[3]);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		glViewportIndexedfv(2, vp);
		pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
		vp[2] = 5.0;
		vp[3] = -12345.7;
	}

	return pass;
}
Example #6
0
	void HandRenderer::PerformDraw(
		bool bTransformTransfer,
		unsigned int iBaseViewport,
		unsigned int iViewPortCount,
		float *pViewPortData) {


		size_t iSpheresPerViewport   = 22*2;
		size_t iCylindersPerViewport = 16*2;

		size_t iSpheresPerViewportUniform   = iSpheresPerViewport;
		size_t iCylindersPerViewportUniform = iCylindersPerViewport;

		if(pViewPortData != NULL) {
			glViewportArrayv(0, iViewPortCount,
							 &pViewPortData[4*iBaseViewport]);
		}

		if(bTransformTransfer) {
			// bind and fill sphere transform SSBO
			size_t sizeSphereTransforms =
				sizeof(VistaTransformMatrix) *
				iSpheresPerViewport *
				iViewPortCount;
			size_t sizeCylinderTransforms =
				sizeof(VistaTransformMatrix) *
				iCylindersPerViewport *
				iViewPortCount;

			size_t sizeSpheresArray = 22*2*16;
			float *data = new float[sizeSpheresArray];
			for(size_t i = 0; i < sizeSpheresArray; ++i) {
				data[i] = 0;
			}			

			glBindBuffer(GL_SHADER_STORAGE_BUFFER,
						 m_idSSBOTransforms);
			glBufferSubData(GL_SHADER_STORAGE_BUFFER,
							0, sizeSphereTransforms,
							&m_vSphereTransforms[0]);
			glBufferSubData(GL_SHADER_STORAGE_BUFFER,
							sizeof(VistaTransformMatrix) *
							iSpheresPerViewport * 64, sizeCylinderTransforms,
							&m_vCylinderTransforms[0]);
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2,
							 m_idSSBOTransforms);

			m_vSphereTransforms.clear();
			m_vCylinderTransforms.clear();
		}

		// set uniform for transform buffer offset
		glUniform1ui(m_locTransformOffset,
					 iSpheresPerViewport*iBaseViewport);
		
		// set uniform for viewport indexing
		glUniform1i(m_locInstancesPerViewportUniform,
					iSpheresPerViewportUniform);
		
		// draw all shperes
		glDrawArraysInstanced(GL_TRIANGLES,
							  0, m_szSphereData,
							  iSpheresPerViewport * iViewPortCount);


		// set uniform for transform buffer offset
		glUniform1ui(m_locTransformOffset,
					 iSpheresPerViewport * 64 +
					 iCylindersPerViewport*iBaseViewport);

		// set uniform for viewport indexing
		glUniform1i(m_locInstancesPerViewportUniform,
					iCylindersPerViewportUniform);


		// draw all cylinders
		glDrawArraysInstanced(GL_TRIANGLES,
							  m_szSphereData, m_szCylinderData,
							  iCylindersPerViewport * iViewPortCount);

		if(bTransformTransfer) {
			glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, 0);
		}
	}