static void Init(void) { CheckExtensions(); SetupRenderbuffers(); SetupShaders(); SetupLighting(); glEnable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnableIndexedEXT(GL_BLEND, 1); }
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 texture::bind(int texunit) const { gl_assert_error("entering texture::bind()"); assert(_texture_id); #ifdef SCM_GL_USE_DIRECT_STATE_ACCESS _occupied_texture_unit = texunit > 0 ? texunit : 0; glBindMultiTextureEXT(GL_TEXTURE0 + _occupied_texture_unit, target(), id()); glEnableIndexedEXT(target(), _occupied_texture_unit); #else // SCM_GL_USE_DIRECT_STATE_ACCESS if (texunit >= 0) { _occupied_texture_unit = texunit; glActiveTexture(GL_TEXTURE0 + _occupied_texture_unit); gl_assert_error("texture::bind() after glActiveTexture"); } glEnable(target()); gl_assert_error("texture::bind() after glEnable(glEnable)"); glBindTexture(target(), id()); #endif // SCM_GL_USE_DIRECT_STATE_ACCESS gl_assert_error("exiting texture::bind()"); }
enum piglit_result piglit_display(void) { GLboolean pass = GL_TRUE; GLuint tex0, tex1, fb; GLenum status; float green[] = {0, 1, 0, 0}; float blue[] = {0, 0, 1, 0}; const GLenum attachments[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, }; piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); glGenFramebuffersEXT(1, &fb); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); tex0 = attach_texture(0); tex1 = attach_texture(1); glDrawBuffersARB(2, attachments); status = glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT); if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { fprintf(stderr, "fbo incomplete (status = 0x%04x)\n", status); piglit_report_result(PIGLIT_SKIP); } /* Clear to blue. The first buffer will have no blending and * get overwritten green, and the second will be blended ZERO, * ONE leaving the blue in place. */ glClearColor(0.0, 0.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glBlendFunc(GL_ZERO, GL_ONE); glDisableIndexedEXT(GL_BLEND, 0); glEnableIndexedEXT(GL_BLEND, 1); glColor4fv(green); piglit_draw_rect(0, 0, piglit_width, piglit_height); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, piglit_winsys_fbo); glDisable(GL_BLEND); /* Draw the two textures to halves of the window. */ glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, tex0); piglit_draw_rect_tex(0, 0, piglit_width / 2, piglit_height, 0, 0, 1, 1); glBindTexture(GL_TEXTURE_2D, tex1); piglit_draw_rect_tex(piglit_width / 2, 0, piglit_width, piglit_height, 0, 0, 1, 1); glDisable(GL_TEXTURE_2D); glDeleteTextures(1, &tex0); glDeleteTextures(1, &tex1); glDeleteFramebuffersEXT(1, &fb); pass = pass && piglit_probe_rect_rgb(0, 0, piglit_width/2, piglit_height, green); pass = pass && piglit_probe_rect_rgb(piglit_width/2, 0, piglit_width/2, piglit_height, blue); piglit_present_results(); return pass ? PIGLIT_PASS : PIGLIT_FAIL; }
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; }