Ejemplo n.º 1
0
static bool
test_glBlendFunci(const GLenum drawbufs[4])
{
	static const float color_blended_red[4] = {1, CLEAR_COLOR, CLEAR_COLOR, 1};
	static const float color_blended_green[4] = {0, CLEAR_COLOR, 0, CLEAR_COLOR};
	static const float color_blended_blue[4] = {0, 0, CLEAR_COLOR*2, CLEAR_COLOR*2};
	static const float color_blended_yellow[4] = {1-CLEAR_COLOR, 1-CLEAR_COLOR, 0, 1-CLEAR_COLOR};
	static const float *colors_blended[] = {
		color_blended_red,
		color_blended_green,
		color_blended_blue,
		color_blended_yellow,
	};

	glEnable(GL_BLEND);

	glBlendFunciARB(0, GL_ONE, GL_ONE);
	glBlendFunciARB(1, GL_DST_COLOR, GL_ZERO);
	glBlendFunciARB(2, GL_DST_COLOR, GL_SRC_COLOR);
	glBlendFunciARB(3, GL_ONE_MINUS_DST_COLOR, GL_ZERO);

	glUseProgram(prog_write_all_different);
	piglit_draw_rect(-1, -1, 2, 2);
	glUseProgram(0);

	glDisable(GL_BLEND);

	return probe_buffers(drawbufs, colors_blended);
}
Ejemplo n.º 2
0
void piglit_init(int argc, char **argv)
{
	GLint max_dual_source;
	GLenum buffers[32];
	int i;
	piglit_require_gl_version(30);
	piglit_require_extension("GL_ARB_blend_func_extended");
	piglit_require_extension("GL_ARB_draw_buffers_blend");


	/* This test needs some number of draw buffers, so make sure the
	 * implementation isn't broken. This enables the test to generate a
	 * useful failure message.
	 */
	glGetIntegerv(GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, &max_dual_source);
	if (max_dual_source < 1) {
		fprintf(stderr,
			"ARB_blend_func_extended requires GL_MAX_DUAL_SOURCE_DRAW_BUFFERS >= 1.  "
			"Only got %d!\n",
			max_dual_source);
		piglit_report_result(PIGLIT_FAIL);
	}

	max_buffers = max_dual_source + 1;

	create_fbo();

	for (i = 0; i < max_buffers; i++)
		buffers[i] = GL_COLOR_ATTACHMENT0_EXT + i;

	glDrawBuffersARB(max_buffers, buffers);

	for (i = 0; i < max_buffers; i++) {
		if (i >= max_dual_source)
			glBlendFunciARB(i, GL_SRC1_ALPHA, GL_ONE_MINUS_SRC1_ALPHA);
		else
			glBlendFunciARB(i, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnableIndexedEXT(GL_BLEND, i);
	}

	glBegin(GL_QUADS);

	if (!piglit_check_gl_error(GL_INVALID_OPERATION))
		piglit_report_result(PIGLIT_FAIL);
	else
		piglit_report_result(PIGLIT_PASS);
}
void opengl_state::BlendFunci(int buffer, GLenum s_val, GLenum d_val) {
	Assertion(GLAD_GL_ARB_draw_buffers_blend != 0, "Buffer blend modes are not supported by this OpenGL implementation!");
	Assertion(buffer >= 0 && buffer < (int) buffer_blendfunc_Value.size(), "Unsupported index %d specified for buffer blend mode!", buffer);

	auto& state = buffer_blendfunc_Value[buffer];
	if (state.first == s_val && state.second == d_val) {
		// Already uses the correct blend mode
		return;
	}

	glBlendFunciARB(buffer, s_val, d_val);

	// Update the saved state
	state.first = s_val;
	state.second = d_val;
	// Set the non-buffer values to an invalid value to make sure that the next call to BlendFunc resets the state.
	blendfunc_Value.first = GL_INVALID_ENUM;
	blendfunc_Value.second = GL_INVALID_ENUM;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBDrawBuffersBlend_nglBlendFunciARB(JNIEnv *__env, jclass clazz, jint buf, jint src, jint dst, jlong __functionAddress) {
	glBlendFunciARBPROC glBlendFunciARB = (glBlendFunciARBPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	glBlendFunciARB(buf, src, dst);
}
Ejemplo n.º 5
0
static enum piglit_result
test(void)
{
   GLenum buffers[32];
   static const GLfloat dest_color[4] = { 0.75, 0.25, 0.25, 0.5 };
   static const GLfloat test_color[4] = { 1.0, 0.25, 0.75, 0.25 };
   GLfloat expected[32][4];
   int i;

   create_fbo();

   for (i = 0; i < maxBuffers; i++) {
      buffers[i] = GL_COLOR_ATTACHMENT0_EXT + i;
   }

   glDrawBuffersARB(maxBuffers, buffers);

   /* Setup blend modes and compute expected result color.
    * We only test two simple blending modes.  A more elaborate
    * test would exercise a much wider variety of modes.
    */
   for (i = 0; i < maxBuffers; i++) {
      if (i % 2 == 0) {
         float a;

         glBlendFunciARB(i, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

         a = test_color[3];
         expected[i][0] = test_color[0] * a + dest_color[0] * (1.0 - a);
         expected[i][1] = test_color[1] * a + dest_color[1] * (1.0 - a);
         expected[i][2] = test_color[2] * a + dest_color[2] * (1.0 - a);
         expected[i][3] = test_color[3] * a + dest_color[3] * (1.0 - a);
      }
      else {
         glBlendFunciARB(i, GL_ONE, GL_ONE);
         glBlendEquationiARB(i, GL_FUNC_SUBTRACT);

         expected[i][0] = test_color[0] - dest_color[0];
         expected[i][1] = test_color[1] - dest_color[1];
         expected[i][2] = test_color[2] - dest_color[2];
         expected[i][3] = test_color[3] - dest_color[3];
      }

      expected[i][0] = CLAMP(expected[i][0], 0.0, 1.0);
      expected[i][1] = CLAMP(expected[i][1], 0.0, 1.0);
      expected[i][2] = CLAMP(expected[i][2], 0.0, 1.0);
      expected[i][3] = CLAMP(expected[i][3], 0.0, 1.0);

      glEnableIndexedEXT(GL_BLEND, i);
   }

   /* query blend modes */
   for (i = 0; i < maxBuffers; i++) {
      GLint p0, p1, p2, p3;
      glGetIntegerIndexedvEXT(GL_BLEND_SRC, i, &p0);
      glGetIntegerIndexedvEXT(GL_BLEND_DST, i, &p1);
      glGetIntegerIndexedvEXT(GL_BLEND_EQUATION, i, &p2);
      glGetIntegerIndexedvEXT(GL_BLEND, i, &p3);
      if (i % 2 == 0) {
         MY_ASSERT(p0 == GL_SRC_ALPHA);
         MY_ASSERT(p1 == GL_ONE_MINUS_SRC_ALPHA);
         MY_ASSERT(p2 == GL_FUNC_ADD);
      }
      else {
         MY_ASSERT(p0 == GL_ONE);
         MY_ASSERT(p1 == GL_ONE);
         MY_ASSERT(p2 == GL_FUNC_SUBTRACT);
      }
      MY_ASSERT(p3 == GL_TRUE);
   }

   /* test drawing */
   glClearColor(dest_color[0], dest_color[1], dest_color[2], dest_color[3]);
   glClear(GL_COLOR_BUFFER_BIT);

   glColor4fv(test_color);
   piglit_draw_rect(0, 0, piglit_width, piglit_height);

   for (i = 0; i < maxBuffers; i++) {
      glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + i);
      check_error(__LINE__);

      if (!piglit_probe_pixel_rgba(5, 5, expected[i])) {
         printf("For color buffer %d\n", i);
         return PIGLIT_FAIL;
      }
   }

   return PIGLIT_PASS;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBDrawBuffersBlend_nglBlendFunciARB(JNIEnv *env, jclass clazz, jint buf, jint src, jint dst, jlong function_pointer) {
	glBlendFunciARBPROC glBlendFunciARB = (glBlendFunciARBPROC)((intptr_t)function_pointer);
	glBlendFunciARB(buf, src, dst);
}