void piglit_init(int argc, char **argv) { int i; bool pass = true; GLenum fbStatus; GLuint fbo, texture; GLint attachmentLayeredStatus; for(i = 0; i < ARRAY_SIZE(textureType); i++) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); texture = create_bind_texture(textureType[i]); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0); if(!piglit_check_gl_error(GL_NO_ERROR)) { printf("Error creating texture and framebuffer setup\n" "texture type: %s\n", piglit_get_gl_enum_name(textureType[i])); glDeleteFramebuffers(1, &fbo); glDeleteTextures(1, &texture); piglit_report_result(PIGLIT_FAIL); } fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); if(fbStatus != GL_FRAMEBUFFER_COMPLETE) { printf("Framebuffer Status: %s\n", piglit_get_gl_enum_name(fbStatus)); glDeleteFramebuffers(1, &fbo); glDeleteTextures(1, &texture); piglit_report_result(PIGLIT_FAIL); } /* Check if the attachment is layered */ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_LAYERED, &attachmentLayeredStatus); pass = piglit_check_gl_error(GL_NO_ERROR) && pass; if(attachmentLayeredStatus != GL_TRUE) { pass = false; } glDeleteFramebuffers(1, &fbo); glDeleteTextures(1, &texture); } piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); }
PIGLIT_GL_TEST_CONFIG_END bool check_attachment(GLenum attach, GLint expect_name) { GLint actual_type; GLint actual_name; glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, attach, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &actual_type); if (actual_type != GL_RENDERBUFFER) { fprintf(stderr, "error: expected GL_RENDERBUFFER for %s attachment type, but found %s\n", piglit_get_gl_enum_name(attach), piglit_get_gl_enum_name(actual_type)); /* Return now and don't query the attachment name, because * that would generate a GL error. */ return false; } glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, attach, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &actual_name); if (actual_name != expect_name) { fprintf(stderr, "error: expected %d for %s attachment name, but found %d\n", expect_name, piglit_get_gl_enum_name(attach), actual_name); return false; } return true; }
void FGoogleVRHMDCustomPresent::BeginRendering(FRHICommandListImmediate& RHICmdList, FSceneViewFamily& InViewFamily) { #if GOOGLEVRHMD_SUPPORTED_PLATFORMS if(TextureSet.IsValid()) { // Binds a framebuffer to the pipeline. When scanline racing, this resource changes every frame. We need to grab the texture // attachment id to apply to the texture set below. gvr_set_active_offscreen_framebuffer(GVRAPI, TextureSet->GetResourceId()); // API returns framebuffer resource, but we need the texture resource for the pipeline check(PLATFORM_USES_ES2); // Some craziness will only work on OpenGL platforms. GLint TextureId = 0; glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &TextureId); TextureSet->Resource = TextureId; } #endif }
static void dumpFramebufferAttachments(JSONWriter &json, Context &context, GLenum target) { GLint read_framebuffer = 0; glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_framebuffer); GLint read_buffer = GL_NONE; glGetIntegerv(GL_READ_BUFFER, &read_buffer); GLint max_draw_buffers = 1; glGetIntegerv(GL_MAX_DRAW_BUFFERS, &max_draw_buffers); GLint max_color_attachments = 0; glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &max_color_attachments); for (GLint i = 0; i < max_draw_buffers; ++i) { GLint draw_buffer = GL_NONE; glGetIntegerv(GL_DRAW_BUFFER0 + i, &draw_buffer); if (draw_buffer != GL_NONE) { glReadBuffer(draw_buffer); GLint attachment; if (draw_buffer >= GL_COLOR_ATTACHMENT0 && draw_buffer < GL_COLOR_ATTACHMENT0 + max_color_attachments) { attachment = draw_buffer; } else { std::cerr << "warning: unexpected GL_DRAW_BUFFER" << i << " = " << draw_buffer << "\n"; attachment = GL_COLOR_ATTACHMENT0; } GLint alpha_size = 0; glGetFramebufferAttachmentParameteriv(target, attachment, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &alpha_size); GLenum format = alpha_size ? GL_RGBA : GL_RGB; dumpFramebufferAttachment(json, context, target, attachment, format); } } glReadBuffer(read_buffer); if (!context.ES) { dumpFramebufferAttachment(json, context, target, GL_DEPTH_ATTACHMENT, GL_DEPTH_COMPONENT); dumpFramebufferAttachment(json, context, target, GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX); } glBindFramebuffer(GL_READ_FRAMEBUFFER, read_framebuffer); }
TEST_F(SRGBTextureTest, srgba_renderbuffer) { bool supported = extensionEnabled("GL_EXT_sRGB") || getClientVersion() == 3; GLuint rbo = 0; glGenRenderbuffers(1, &rbo); glBindRenderbuffer(GL_RENDERBUFFER, rbo); glRenderbufferStorage(GL_RENDERBUFFER, GL_SRGB8_ALPHA8_EXT, 1, 1); if (supported) { EXPECT_GL_NO_ERROR(); } else { EXPECT_GL_ERROR(GL_INVALID_ENUM); // Make sure the rbo has a size for future tests glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, 1, 1); EXPECT_GL_NO_ERROR(); } GLuint fbo = 0; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo); EXPECT_GL_NO_ERROR(); GLint colorEncoding = 0; glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT, &colorEncoding); if (supported) { EXPECT_GL_NO_ERROR(); EXPECT_EQ(GL_SRGB_EXT, colorEncoding); } else { EXPECT_GL_ERROR(GL_INVALID_ENUM); } glDeleteFramebuffers(1, &fbo); glDeleteRenderbuffers(1, &rbo); }
/** * @brief Fog::render * @param commandBuffer * @return */ bool Fog::render(RenderGraph::Parameters & parameters, RHI::CommandBuffer & commandBuffer) { rmt_ScopedOpenGLSample(Fog); if (parameters.size() < 1) { glClearColor(0.0f, 1.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); return false; } const GLuint inputTexture = parameters.pop().asUInt; commandBuffer.BeginRenderPass(m_renderPass, m_framebuffer, ivec2(0, 0), ivec2(m_rendering.GetWidth(), m_rendering.GetHeight())); { commandBuffer.Bind(m_pipeline); SetTexture<GL_TEXTURE_2D>(m_pipeline.m_uShaderObject, "depthMapSampler", 0, inputTexture, m_samplerDepthMap); SetUniform(m_pipeline.m_uShaderObject, "FogScattering", m_rendering.GetScene().fog.Scattering); SetUniform(m_pipeline.m_uShaderObject, "FogExtinction", m_rendering.GetScene().fog.Extinction); SetUniform(m_pipeline.m_uShaderObject, "FogColor", m_rendering.GetScene().fog.Color); SetUniform(m_pipeline.m_uShaderObject, "camera_near", 1.0f); SetUniform(m_pipeline.m_uShaderObject, "camera_far", 1000.0f); SetUniform(m_pipeline.m_uShaderObject, "near_plane_half_size", vec2(m_rendering.GetHeight() * float(m_rendering.GetWidth()/(float)m_rendering.GetHeight()), tanf(75.0f/2.0))); m_rendering.m_pQuadMesh->draw(commandBuffer); } commandBuffer.EndRenderPass(); { GLint texture = 0; glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &texture); RenderGraph::Value v; v.asUInt = texture; parameters.push(v); } return(true); }
bool initFramebuffer() { glGenFramebuffers(1, &FramebufferName); glBindFramebuffer(GL_FRAMEBUFFER, FramebufferName); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, TextureName[texture::COLORBUFFER], 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, TextureName[texture::RENDERBUFFER], 0); if(!this->checkFramebuffer(FramebufferName)) return false; glBindFramebuffer(GL_FRAMEBUFFER, 0); GLint const EncodingLinear = GL_LINEAR; GLint const EncodingSRGB = GL_SRGB; GLint Encoding = 0; glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &Encoding); return true; }
void dumpFramebuffer(JSONWriter &json, Context &context) { json.beginMember("framebuffer"); json.beginObject(); GLint boundDrawFbo = 0, boundReadFbo = 0; glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &boundDrawFbo); glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &boundReadFbo); if (!boundDrawFbo) { dumpDrawableImages(json, context); } else if (context.ES) { dumpFramebufferAttachments(json, context, GL_FRAMEBUFFER); } else { GLint colorRb = 0, stencilRb = 0, depthRb = 0; GLint draw_buffer0 = GL_NONE; glGetIntegerv(GL_DRAW_BUFFER0, &draw_buffer0); bool multisample = false; GLint boundRb = 0; glGetIntegerv(GL_RENDERBUFFER_BINDING, &boundRb); GLint object_type; glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, draw_buffer0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &object_type); if (object_type == GL_RENDERBUFFER) { glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, draw_buffer0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &colorRb); glBindRenderbuffer(GL_RENDERBUFFER, colorRb); GLint samples = 0; glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples); if (samples) { multisample = true; } } glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &object_type); if (object_type == GL_RENDERBUFFER) { glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &depthRb); glBindRenderbuffer(GL_RENDERBUFFER, depthRb); GLint samples = 0; glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples); if (samples) { multisample = true; } } glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &object_type); if (object_type == GL_RENDERBUFFER) { glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &stencilRb); glBindRenderbuffer(GL_RENDERBUFFER, stencilRb); GLint samples = 0; glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_SAMPLES, &samples); if (samples) { multisample = true; } } glBindRenderbuffer(GL_RENDERBUFFER, boundRb); GLuint rbs[3]; GLint numRbs = 0; GLuint fboCopy = 0; if (multisample) { // glReadPixels doesnt support multisampled buffers so we need // to blit the fbo to a temporary one fboCopy = downsampledFramebuffer(context, boundDrawFbo, draw_buffer0, colorRb, depthRb, stencilRb, rbs, &numRbs); } dumpFramebufferAttachments(json, context, GL_DRAW_FRAMEBUFFER); if (multisample) { glBindRenderbuffer(GL_RENDERBUFFER_BINDING, boundRb); glDeleteRenderbuffers(numRbs, rbs); glDeleteFramebuffers(1, &fboCopy); } glBindFramebuffer(GL_READ_FRAMEBUFFER, boundReadFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, boundDrawFbo); } json.endObject(); json.endMember(); // framebuffer }
void GraphicsContext3D::getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum paramName, GC3Dint* value) { makeContextCurrent(); glGetFramebufferAttachmentParameteriv(target, attachment, paramName, value); }
void CentralVideoSettings::init() { m_gl_major_version = 2; m_gl_minor_version = 1; // Parse extensions hasVSLayer = false; hasBaseInstance = false; hasBuffserStorage = false; hasDrawIndirect = false; hasComputeShaders = false; hasArraysOfArrays = false; hasTextureStorage = false; hasTextureView = false; hasBindlessTexture = false; hasAtomics = false; hasSSBO = false; hasImageLoadStore = false; hasMultiDrawIndirect = false; hasTextureCompression = false; hasUBO = false; hasExplicitAttribLocation = false; hasGS = false; m_GI_has_artifact = false; m_need_rh_workaround = false; m_need_srgb_workaround = false; m_need_srgb_visual_workaround = false; // Call to glGetIntegerv should not be made if --no-graphics is used if (!ProfileWorld::isNoGraphics()) { } if (!ProfileWorld::isNoGraphics()) { glGetIntegerv(GL_MAJOR_VERSION, &m_gl_major_version); glGetIntegerv(GL_MINOR_VERSION, &m_gl_minor_version); Log::info("IrrDriver", "OpenGL version: %d.%d", m_gl_major_version, m_gl_minor_version); Log::info("IrrDriver", "OpenGL vendor: %s", glGetString(GL_VENDOR)); Log::info("IrrDriver", "OpenGL renderer: %s", glGetString(GL_RENDERER)); Log::info("IrrDriver", "OpenGL version string: %s", glGetString(GL_VERSION)); } #if !defined(USE_GLES2) m_glsl = (m_gl_major_version > 3 || (m_gl_major_version == 3 && m_gl_minor_version >= 1)) && !UserConfigParams::m_force_legacy_device; #else m_glsl = m_gl_major_version >= 3 && !UserConfigParams::m_force_legacy_device; #endif if (!ProfileWorld::isNoGraphics()) initGL(); if (!ProfileWorld::isNoGraphics()) { std::string driver((char*)(glGetString(GL_VERSION))); std::string card((char*)(glGetString(GL_RENDERER))); GraphicsRestrictions::init(driver, card); #if !defined(USE_GLES2) if (hasGLExtension("GL_AMD_vertex_shader_layer")) { hasVSLayer = true; Log::info("GLDriver", "AMD Vertex Shader Layer Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_BUFFER_STORAGE) && hasGLExtension("GL_ARB_buffer_storage") ) { hasBuffserStorage = true; Log::info("GLDriver", "ARB Buffer Storage Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_BASE_INSTANCE) && hasGLExtension("GL_ARB_base_instance")) { hasBaseInstance = true; Log::info("GLDriver", "ARB Base Instance Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_DRAW_INDIRECT) && hasGLExtension("GL_ARB_draw_indirect")) { hasDrawIndirect = true; Log::info("GLDriver", "ARB Draw Indirect Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_COMPUTE_SHADER) && hasGLExtension("GL_ARB_compute_shader")) { hasComputeShaders = true; Log::info("GLDriver", "ARB Compute Shader Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_ARRAYS_OF_ARRAYS) && hasGLExtension("GL_ARB_arrays_of_arrays")) { hasArraysOfArrays = true; Log::info("GLDriver", "ARB Arrays of Arrays Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_TEXTURE_STORAGE) && hasGLExtension("GL_ARB_texture_storage")) { hasTextureStorage = true; Log::info("GLDriver", "ARB Texture Storage Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_TEXTURE_VIEW) && hasGLExtension("GL_ARB_texture_view")) { hasTextureView = true; Log::info("GLDriver", "ARB Texture View Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_BINDLESS_TEXTURE) && hasGLExtension("GL_ARB_bindless_texture")) { hasBindlessTexture = true; Log::info("GLDriver", "ARB Bindless Texture Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_IMAGE_LOAD_STORE) && hasGLExtension("GL_ARB_shader_image_load_store")) { hasImageLoadStore = true; Log::info("GLDriver", "ARB Image Load Store Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_SHADER_ATOMIC_COUNTERS) && hasGLExtension("GL_ARB_shader_atomic_counters")) { hasAtomics = true; Log::info("GLDriver", "ARB Shader Atomic Counters Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_SHADER_STORAGE_BUFFER_OBJECT) && hasGLExtension("GL_ARB_shader_storage_buffer_object")) { hasSSBO = true; Log::info("GLDriver", "ARB Shader Storage Buffer Object Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_MULTI_DRAW_INDIRECT) && hasGLExtension("GL_ARB_multi_draw_indirect")) { hasMultiDrawIndirect = true; Log::info("GLDriver", "ARB Multi Draw Indirect Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_EXT_TEXTURE_COMPRESSION_S3TC) && hasGLExtension("GL_EXT_texture_compression_s3tc")) { hasTextureCompression = true; Log::info("GLDriver", "EXT Texture Compression S3TC Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_UNIFORM_BUFFER_OBJECT) && hasGLExtension("GL_ARB_uniform_buffer_object")) { hasUBO = true; Log::info("GLDriver", "ARB Uniform Buffer Object Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_EXPLICIT_ATTRIB_LOCATION) && hasGLExtension("GL_ARB_explicit_attrib_location")) { hasExplicitAttribLocation = true; Log::info("GLDriver", "ARB Explicit Attrib Location Present"); } if (!GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_GEOMETRY_SHADER) && (m_gl_major_version > 3 || (m_gl_major_version == 3 && m_gl_minor_version >= 2))) { hasGS = true; Log::info("GLDriver", "Geometry Shaders Present"); } // Only unset the high def textures if they are set as default. If the // user has enabled them (bit 1 set), then leave them enabled. if (GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_HIGHDEFINITION_TEXTURES) && (UserConfigParams::m_high_definition_textures & 0x02) == 0) { UserConfigParams::m_high_definition_textures = 0x00; } if (GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_GI)) { m_GI_has_artifact = true; } // Specific disablement if (strstr((const char *)glGetString(GL_VENDOR), "NVIDIA") != NULL) { // Fix for Nvidia and instanced RH // Compiler crashes with a big loop in RH or GI shaders m_need_rh_workaround = true; } if (strstr((const char *)glGetString(GL_VENDOR), "ATI") != NULL) { // Bindless textures are all treated RGB even sRGB one m_need_srgb_workaround = true; } // Check if visual is sRGB-capable if (GraphicsRestrictions::isDisabled(GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_CAPABLE) && m_glsl == true) { GLint param = GL_SRGB; glGetFramebufferAttachmentParameteriv(GL_DRAW_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, ¶m); m_need_srgb_visual_workaround = (param != GL_SRGB); } #else if (m_glsl == true) { hasArraysOfArrays = true; hasTextureStorage = true; hasTextureView = true; hasBindlessTexture = true; hasImageLoadStore = true; hasAtomics = true; hasSSBO = true; } #endif } }
int main(int argc, char *argv[]) { SDL_Surface *screen; // Slightly different SDL initialization if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return 1; } SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new* screen = SDL_SetVideoMode( 600, 600, 16, SDL_OPENGL ); // *changed* if ( !screen ) { printf("Unable to set video mode: %s\n", SDL_GetError()); return 1; } // Check extensions const char *exts = (const char *)glGetString(GL_EXTENSIONS); assert(hasext(exts, "GL_EXT_texture_filter_anisotropic")); const char *vendor = (const char *)glGetString(GL_VENDOR); printf("vendor: %s\n", vendor); GLint aniso; glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &aniso); printf("Max anisotropy: %d (using that)\n", aniso); assert(aniso >= 4); // Set the OpenGL state after creating the context with SDL_SetVideoMode glClearColor( 0, 0, 0, 0 ); glEnable( GL_TEXTURE_2D ); // Needed when we're using the fixed-function pipeline. glViewport( 0, 0, 600, 600 ); glMatrixMode( GL_PROJECTION ); GLfloat matrixData[] = { 2.0/600, 0, 0, 0, 0, -2.0/600, 0, 0, 0, 0, -2.0/600, 0, -1, 1, 0, 1 }; glLoadMatrixf(matrixData); // test loadmatrix glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Load the OpenGL texture GLuint texture, texture2; const int DDS_SIZE = 43920; FILE *dds = fopen("water.dds", "rb"); assert(dds); char *ddsdata = (char*)malloc(DDS_SIZE); assert(fread(ddsdata, 1, DDS_SIZE, dds) == DDS_SIZE); fclose(dds); { glGenTextures( 1, &texture ); glBindTexture( GL_TEXTURE_2D, texture ); char *curr = ddsdata + 128; int level = 0; int w = 512; int h = 64; while (level < 5) { printf("uploading level %d: %d, %d\n", level, w, h); assert(!glGetError()); glCompressedTexImage2D(GL_TEXTURE_2D, level, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, w, h, 0, w*h, curr); assert(!glGetError()); curr += MAX(w, 4)*MAX(h, 4); w /= 2; h /= 2; level++; } glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); } { glGenTextures( 1, &texture2 ); glBindTexture( GL_TEXTURE_2D, texture2 ); char *curr = ddsdata + 128; int level = 0; int w = 512; int h = 64; while (level < 5) { printf("uploading level %d: %d, %d\n", level, w, h); assert(!glGetError()); glCompressedTexImage2D(GL_TEXTURE_2D, level, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, w, h, 0, w*h, curr); assert(!glGetError()); curr += MAX(w, 4)*MAX(h, 4); w /= 2; h /= 2; level++; } glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso); } { assert(!glGetError()); glBindFramebuffer(GL_RENDERBUFFER, 0); assert(glGetError()); GLint out = 321; assert(!glGetError()); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &out); // invalid, just test output assert(out == 0); } // Prepare and Render // Clear the screen before drawing glClear( GL_COLOR_BUFFER_BIT ); // Bind the texture to which subsequent calls refer to int w = 10; int n = 15; glBindTexture( GL_TEXTURE_2D, texture ); for (int x = 0; x < n; x++) { int start = x*w*2; glBegin( GL_TRIANGLES ); glTexCoord2i( 1, 0 ); glVertex2i( start , 0 ); glTexCoord2i( 0, 0 ); glVertex3f( start+w, 300, 0 ); glTexCoord2i( 1, 1 ); glVertex3f( start-w, 300, 0 ); glEnd(); } glBindTexture( GL_TEXTURE_2D, texture2 ); for (int x = 0; x < n; x++) { int start = n*w*2 + x*w*2; glBegin( GL_TRIANGLES ); glTexCoord2i( 1, 0 ); glVertex3f( start , 0, 0 ); glTexCoord2i( 0, 0 ); glVertex3f( start+w, 300, 0 ); glTexCoord2i( 1, 1 ); glVertex3f( start-w, 300, 0 ); glEnd(); } /* int w = 8; int n = 20; for (int x = 0; x < n; x++) { for (int y = 0; y < n*2; y++) { glBindTexture( GL_TEXTURE_2D, texture ); glBegin( GL_TRIANGLE_STRIP ); glTexCoord2i( 0, 0 ); glVertex3f( x*w, y*(w), 0 ); glTexCoord2i( 1, 0 ); glVertex3f( (x+1)*(w-2*y/n), y*(w), 0 ); glTexCoord2i( 1, 1 ); glVertex3f( (x+1)*(w-2*y/n), (y+1)*(w), 0 ); glTexCoord2i( 0, 1 ); glVertex3f( x*w, (y+1)*(w), 0 ); glEnd(); glBindTexture( GL_TEXTURE_2D, texture2 ); glBegin( GL_TRIANGLE_STRIP ); glTexCoord2i( 0, 0 ); glVertex3f( n*w + x*w, y*(w), 0 ); glTexCoord2i( 1, 0 ); glVertex3f( n*w + (x+1)*(w-2*y/n), y*(w), 0 ); glTexCoord2i( 1, 1 ); glVertex3f( n*w + (x+1)*(w-2*y/n), (y+1)*(w), 0 ); glTexCoord2i( 0, 1 ); glVertex3f( n*w + x*w, (y+1)*(w), 0 ); glEnd(); } } */ SDL_GL_SwapBuffers(); #ifndef __EMSCRIPTEN__ // Wait for 3 seconds to give us a chance to see the image SDL_Delay(2000); #endif // Now we can delete the OpenGL texture and close down SDL glDeleteTextures( 1, &texture ); SDL_Quit(); // check for asm compilation bug with aliased functions with different sigs glBegin( GL_TRIANGLE_STRIP ); void (*f)(int, int) = glVertex2i; if ((int)f % 16 == 4) f(5, 7); void (*g)(int, int) = glVertex3f; if ((int)g % 16 == 4) g(5, 7); return (int)f + (int)g; }
void GLWindow::queryDrawableConfig( DrawableConfig& drawableConfig ) { // GL version const char* glVersion = (const char*)glGetString( GL_VERSION ); if( !glVersion ) // most likely no context - fail { LBWARN << "glGetString(GL_VERSION) returned 0, assuming GL version 1.1" << std::endl; drawableConfig.glVersion = 1.1f; } else drawableConfig.glVersion = static_cast<float>( atof( glVersion )); if( drawableConfig.glVersion >= 3.2f ) { GLint mask; EQ_GL_CALL( glGetIntegerv( GL_CONTEXT_PROFILE_MASK, &mask )); drawableConfig.coreProfile = mask & GL_CONTEXT_CORE_PROFILE_BIT; } // Framebuffer capabilities GLboolean result; EQ_GL_CALL( glGetBooleanv( GL_STEREO, &result )); drawableConfig.stereo = result; EQ_GL_CALL( glGetBooleanv( GL_DOUBLEBUFFER, &result )); drawableConfig.doublebuffered = result; GLint stencilBits, colorBits, alphaBits, accumBits; stencilBits = colorBits = alphaBits = accumBits = 0; if( drawableConfig.coreProfile ) { if( getFrameBufferObject( )) { glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &stencilBits ); // eat GL error if no stencil attachment; should return '0' bits // according to spec, but gives GL_INVALID_OPERATION glGetError(); EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &colorBits )); EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &alphaBits )); } else { EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &stencilBits )); EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &colorBits )); EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &alphaBits )); } } else { EQ_GL_CALL( glGetIntegerv( GL_STENCIL_BITS, &stencilBits )); EQ_GL_CALL( glGetIntegerv( GL_RED_BITS, &colorBits )); EQ_GL_CALL( glGetIntegerv( GL_ALPHA_BITS, &alphaBits )); EQ_GL_CALL( glGetIntegerv( GL_ACCUM_RED_BITS, &accumBits )); } drawableConfig.stencilBits = stencilBits; drawableConfig.colorBits = colorBits; drawableConfig.alphaBits = alphaBits; drawableConfig.accumBits = accumBits * 4; LBDEBUG << "Window drawable config: " << drawableConfig << std::endl; }
uintptr_t processFn(struct fnargs* args, char* parg) { uintptr_t ret = 0; switch (args->fn) { case glfnUNDEFINED: abort(); // bad glfn break; case glfnActiveTexture: glActiveTexture((GLenum)args->a0); break; case glfnAttachShader: glAttachShader((GLint)args->a0, (GLint)args->a1); break; case glfnBindAttribLocation: glBindAttribLocation((GLint)args->a0, (GLint)args->a1, (GLchar*)args->a2); break; case glfnBindBuffer: glBindBuffer((GLenum)args->a0, (GLuint)args->a1); break; case glfnBindFramebuffer: glBindFramebuffer((GLenum)args->a0, (GLint)args->a1); break; case glfnBindRenderbuffer: glBindRenderbuffer((GLenum)args->a0, (GLint)args->a1); break; case glfnBindTexture: glBindTexture((GLenum)args->a0, (GLint)args->a1); break; case glfnBlendColor: glBlendColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnBlendEquation: glBlendEquation((GLenum)args->a0); break; case glfnBlendEquationSeparate: glBlendEquationSeparate((GLenum)args->a0, (GLenum)args->a1); break; case glfnBlendFunc: glBlendFunc((GLenum)args->a0, (GLenum)args->a1); break; case glfnBlendFuncSeparate: glBlendFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3); break; case glfnBufferData: glBufferData((GLenum)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg, (GLenum)args->a2); break; case glfnBufferSubData: glBufferSubData((GLenum)args->a0, (GLint)args->a1, (GLsizeiptr)args->a2, (GLvoid*)parg); break; case glfnCheckFramebufferStatus: ret = glCheckFramebufferStatus((GLenum)args->a0); break; case glfnClear: glClear((GLenum)args->a0); break; case glfnClearColor: glClearColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnClearDepthf: glClearDepthf(*(GLfloat*)&args->a0); break; case glfnClearStencil: glClearStencil((GLint)args->a0); break; case glfnColorMask: glColorMask((GLboolean)args->a0, (GLboolean)args->a1, (GLboolean)args->a2, (GLboolean)args->a3); break; case glfnCompileShader: glCompileShader((GLint)args->a0); break; case glfnCompressedTexImage2D: glCompressedTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLsizeiptr)args->a6, (GLvoid*)parg); break; case glfnCompressedTexSubImage2D: glCompressedTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLenum)args->a6, (GLsizeiptr)args->a7, (GLvoid*)parg); break; case glfnCopyTexImage2D: glCopyTexImage2D((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7); break; case glfnCopyTexSubImage2D: glCopyTexSubImage2D((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4, (GLint)args->a5, (GLint)args->a6, (GLint)args->a7); break; case glfnCreateProgram: ret = glCreateProgram(); break; case glfnCreateShader: ret = glCreateShader((GLenum)args->a0); break; case glfnCullFace: glCullFace((GLenum)args->a0); break; case glfnDeleteBuffer: glDeleteBuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteFramebuffer: glDeleteFramebuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteProgram: glDeleteProgram((GLint)args->a0); break; case glfnDeleteRenderbuffer: glDeleteRenderbuffers(1, (const GLuint*)(&args->a0)); break; case glfnDeleteShader: glDeleteShader((GLint)args->a0); break; case glfnDeleteTexture: glDeleteTextures(1, (const GLuint*)(&args->a0)); break; case glfnDepthFunc: glDepthFunc((GLenum)args->a0); break; case glfnDepthMask: glDepthMask((GLboolean)args->a0); break; case glfnDepthRangef: glDepthRangef(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1); break; case glfnDetachShader: glDetachShader((GLint)args->a0, (GLint)args->a1); break; case glfnDisable: glDisable((GLenum)args->a0); break; case glfnDisableVertexAttribArray: glDisableVertexAttribArray((GLint)args->a0); break; case glfnDrawArrays: glDrawArrays((GLenum)args->a0, (GLint)args->a1, (GLint)args->a2); break; case glfnDrawElements: glDrawElements((GLenum)args->a0, (GLint)args->a1, (GLenum)args->a2, (void*)args->a3); break; case glfnEnable: glEnable((GLenum)args->a0); break; case glfnEnableVertexAttribArray: glEnableVertexAttribArray((GLint)args->a0); break; case glfnFinish: glFinish(); break; case glfnFlush: glFlush(); break; case glfnFramebufferRenderbuffer: glFramebufferRenderbuffer((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3); break; case glfnFramebufferTexture2D: glFramebufferTexture2D((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint)args->a3, (GLint)args->a4); break; case glfnFrontFace: glFrontFace((GLenum)args->a0); break; case glfnGenBuffer: glGenBuffers(1, (GLuint*)&ret); break; case glfnGenFramebuffer: glGenFramebuffers(1, (GLuint*)&ret); break; case glfnGenRenderbuffer: glGenRenderbuffers(1, (GLuint*)&ret); break; case glfnGenTexture: glGenTextures(1, (GLuint*)&ret); break; case glfnGenerateMipmap: glGenerateMipmap((GLenum)args->a0); break; case glfnGetActiveAttrib: glGetActiveAttrib( (GLuint)args->a0, (GLuint)args->a1, (GLsizei)args->a2, NULL, (GLint*)&ret, (GLenum*)args->a3, (GLchar*)parg); break; case glfnGetActiveUniform: glGetActiveUniform( (GLuint)args->a0, (GLuint)args->a1, (GLsizei)args->a2, NULL, (GLint*)&ret, (GLenum*)args->a3, (GLchar*)parg); break; case glfnGetAttachedShaders: glGetAttachedShaders((GLuint)args->a0, (GLsizei)args->a1, (GLsizei*)&ret, (GLuint*)parg); break; case glfnGetAttribLocation: ret = glGetAttribLocation((GLint)args->a0, (GLchar*)args->a1); break; case glfnGetBooleanv: glGetBooleanv((GLenum)args->a0, (GLboolean*)parg); break; case glfnGetBufferParameteri: glGetBufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetFloatv: glGetFloatv((GLenum)args->a0, (GLfloat*)parg); break; case glfnGetIntegerv: glGetIntegerv((GLenum)args->a0, (GLint*)parg); break; case glfnGetError: ret = glGetError(); break; case glfnGetFramebufferAttachmentParameteriv: glGetFramebufferAttachmentParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLint*)&ret); break; case glfnGetProgramiv: glGetProgramiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetProgramInfoLog: glGetProgramInfoLog((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetRenderbufferParameteriv: glGetRenderbufferParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetShaderiv: glGetShaderiv((GLint)args->a0, (GLenum)args->a1, (GLint*)&ret); break; case glfnGetShaderInfoLog: glGetShaderInfoLog((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetShaderPrecisionFormat: glGetShaderPrecisionFormat((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg, &((GLint*)parg)[2]); break; case glfnGetShaderSource: glGetShaderSource((GLuint)args->a0, (GLsizei)args->a1, 0, (GLchar*)parg); break; case glfnGetString: ret = (uintptr_t)glGetString((GLenum)args->a0); break; case glfnGetTexParameterfv: glGetTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnGetTexParameteriv: glGetTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnGetUniformfv: glGetUniformfv((GLuint)args->a0, (GLint)args->a1, (GLfloat*)parg); break; case glfnGetUniformiv: glGetUniformiv((GLuint)args->a0, (GLint)args->a1, (GLint*)parg); break; case glfnGetUniformLocation: ret = glGetUniformLocation((GLint)args->a0, (GLchar*)args->a1); break; case glfnGetVertexAttribfv: glGetVertexAttribfv((GLuint)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnGetVertexAttribiv: glGetVertexAttribiv((GLuint)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnHint: glHint((GLenum)args->a0, (GLenum)args->a1); break; case glfnIsBuffer: ret = glIsBuffer((GLint)args->a0); break; case glfnIsEnabled: ret = glIsEnabled((GLenum)args->a0); break; case glfnIsFramebuffer: ret = glIsFramebuffer((GLint)args->a0); break; case glfnIsProgram: ret = glIsProgram((GLint)args->a0); break; case glfnIsRenderbuffer: ret = glIsRenderbuffer((GLint)args->a0); break; case glfnIsShader: ret = glIsShader((GLint)args->a0); break; case glfnIsTexture: ret = glIsTexture((GLint)args->a0); break; case glfnLineWidth: glLineWidth(*(GLfloat*)&args->a0); break; case glfnLinkProgram: glLinkProgram((GLint)args->a0); break; case glfnPixelStorei: glPixelStorei((GLenum)args->a0, (GLint)args->a1); break; case glfnPolygonOffset: glPolygonOffset(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1); break; case glfnReadPixels: glReadPixels((GLint)args->a0, (GLint)args->a1, (GLsizei)args->a2, (GLsizei)args->a3, (GLenum)args->a4, (GLenum)args->a5, (void*)parg); break; case glfnReleaseShaderCompiler: glReleaseShaderCompiler(); break; case glfnRenderbufferStorage: glRenderbufferStorage((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnSampleCoverage: glSampleCoverage(*(GLfloat*)&args->a0, (GLboolean)args->a1); break; case glfnScissor: glScissor((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnShaderSource: #if defined(os_ios) || defined(os_osx) glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar *const *)args->a2, NULL); #else glShaderSource((GLuint)args->a0, (GLsizei)args->a1, (const GLchar **)args->a2, NULL); #endif break; case glfnStencilFunc: glStencilFunc((GLenum)args->a0, (GLint)args->a1, (GLuint)args->a2); break; case glfnStencilFuncSeparate: glStencilFuncSeparate((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2, (GLuint)args->a3); break; case glfnStencilMask: glStencilMask((GLuint)args->a0); break; case glfnStencilMaskSeparate: glStencilMaskSeparate((GLenum)args->a0, (GLuint)args->a1); break; case glfnStencilOp: glStencilOp((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2); break; case glfnStencilOpSeparate: glStencilOpSeparate((GLenum)args->a0, (GLenum)args->a1, (GLenum)args->a2, (GLenum)args->a3); break; case glfnTexImage2D: glTexImage2D( (GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLsizei)args->a3, (GLsizei)args->a4, 0, // border (GLenum)args->a5, (GLenum)args->a6, (const GLvoid*)parg); break; case glfnTexSubImage2D: glTexSubImage2D( (GLenum)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLsizei)args->a4, (GLsizei)args->a5, (GLenum)args->a6, (GLenum)args->a7, (const GLvoid*)parg); break; case glfnTexParameterf: glTexParameterf((GLenum)args->a0, (GLenum)args->a1, *(GLfloat*)&args->a2); break; case glfnTexParameterfv: glTexParameterfv((GLenum)args->a0, (GLenum)args->a1, (GLfloat*)parg); break; case glfnTexParameteri: glTexParameteri((GLenum)args->a0, (GLenum)args->a1, (GLint)args->a2); break; case glfnTexParameteriv: glTexParameteriv((GLenum)args->a0, (GLenum)args->a1, (GLint*)parg); break; case glfnUniform1f: glUniform1f((GLint)args->a0, *(GLfloat*)&args->a1); break; case glfnUniform1fv: glUniform1fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform1i: glUniform1i((GLint)args->a0, (GLint)args->a1); break; case glfnUniform1iv: glUniform1iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform2f: glUniform2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2); break; case glfnUniform2fv: glUniform2fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform2i: glUniform2i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2); break; case glfnUniform2iv: glUniform2iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform3f: glUniform3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnUniform3fv: glUniform3fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform3i: glUniform3i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; case glfnUniform3iv: glUniform3iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform4f: glUniform4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4); break; case glfnUniform4fv: glUniform4fv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniform4i: glUniform4i((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3, (GLint)args->a4); break; case glfnUniform4iv: glUniform4iv((GLint)args->a0, (GLsizeiptr)args->a1, (GLvoid*)parg); break; case glfnUniformMatrix2fv: glUniformMatrix2fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix3fv: glUniformMatrix3fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUniformMatrix4fv: glUniformMatrix4fv((GLint)args->a0, (GLsizeiptr)args->a1, 0, (GLvoid*)parg); break; case glfnUseProgram: glUseProgram((GLint)args->a0); break; case glfnValidateProgram: glValidateProgram((GLint)args->a0); break; case glfnVertexAttrib1f: glVertexAttrib1f((GLint)args->a0, *(GLfloat*)&args->a1); break; case glfnVertexAttrib1fv: glVertexAttrib1fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib2f: glVertexAttrib2f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2); break; case glfnVertexAttrib2fv: glVertexAttrib2fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib3f: glVertexAttrib3f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; case glfnVertexAttrib3fv: glVertexAttrib3fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttrib4f: glVertexAttrib4f((GLint)args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3, *(GLfloat*)&args->a4); break; case glfnVertexAttrib4fv: glVertexAttrib4fv((GLint)args->a0, (GLfloat*)parg); break; case glfnVertexAttribPointer: glVertexAttribPointer((GLuint)args->a0, (GLint)args->a1, (GLenum)args->a2, (GLboolean)args->a3, (GLsizei)args->a4, (const GLvoid*)args->a5); break; case glfnViewport: glViewport((GLint)args->a0, (GLint)args->a1, (GLint)args->a2, (GLint)args->a3); break; } return ret; }
PIGLIT_GL_TEST_CONFIG_END bool check_texture_parameters(GLenum objType, int objName, int level, int layer, int layered) { int objectType = -1; int objectName = -1; int textureLevel = -1; int textureLayer = -1; int textureLayered = -1; bool pass = true; /* Object Type */ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &objectType); if(objectType != objType) { printf("Object Type\nExpected: %s\nObserved: %s\n", piglit_get_gl_enum_name(objType), piglit_get_gl_enum_name(objectType)); return false; } /* Object Name */ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &objectName); if(objectName != objName) { printf("Object Name\nExpected: %i\nObserved: %i\n", objName, objectName); return false; } if(!piglit_check_gl_error(GL_NO_ERROR)) { printf("Error has occured in check_texture_parameters()\n"); return false; } /* * If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is NONE, no * framebuffer is bound to target. In this case querying pname * FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero, and all * other queries will generate an INVALID_OPERATION error. */ if( objectType != GL_NONE ) { /* Texture Level */ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL, &textureLevel); if(textureLevel != level) { printf("Texture Level\nExpected: %2i\nObserved: %2i\n", level, textureLevel); return false; } /* Texture Layer */ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER, &textureLayer); if(textureLayer != layer) { printf("Texture Layer\nExpected: %2i\nObserved: %2i\n", layer, textureLayer); return false; } /* Texture Layered */ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_LAYERED, &textureLayered); if(textureLayered != layered) { printf("Texture Layered\nExpected: %2i\nObserved: %2i\n", layered, textureLayered); return false; } if(!piglit_check_gl_error(GL_NO_ERROR)) { printf("Error has occured in check_texture_parameters()\n"); return false; } } return pass; }
void get_framebuffer_attachment_parameteriv(framebuffer_target_t target, framebuffer_attachment_t attachment, gl::enum_t pname, gl::int_t * params) { glGetFramebufferAttachmentParameteriv(static_cast<GLenum>(target), static_cast<GLenum>(attachment), pname, params); }
int main(int argc, char** argv) { int ch, client, major, minor, revision, profile; GLint redbits, greenbits, bluebits, alphabits, depthbits, stencilbits; int list_extensions = GLFW_FALSE, list_layers = GLFW_FALSE; GLenum error; GLFWwindow* window; enum { CLIENT, CONTEXT, BEHAVIOR, DEBUG, FORWARD, HELP, EXTENSIONS, LAYERS, MAJOR, MINOR, PROFILE, ROBUSTNESS, VERSION, REDBITS, GREENBITS, BLUEBITS, ALPHABITS, DEPTHBITS, STENCILBITS, ACCUMREDBITS, ACCUMGREENBITS, ACCUMBLUEBITS, ACCUMALPHABITS, AUXBUFFERS, SAMPLES, STEREO, SRGB, SINGLEBUFFER, NOERROR_SRSLY }; const struct option options[] = { { "behavior", 1, NULL, BEHAVIOR }, { "client-api", 1, NULL, CLIENT }, { "context-api", 1, NULL, CONTEXT }, { "debug", 0, NULL, DEBUG }, { "forward", 0, NULL, FORWARD }, { "help", 0, NULL, HELP }, { "list-extensions", 0, NULL, EXTENSIONS }, { "list-layers", 0, NULL, LAYERS }, { "major", 1, NULL, MAJOR }, { "minor", 1, NULL, MINOR }, { "profile", 1, NULL, PROFILE }, { "robustness", 1, NULL, ROBUSTNESS }, { "version", 0, NULL, VERSION }, { "red-bits", 1, NULL, REDBITS }, { "green-bits", 1, NULL, GREENBITS }, { "blue-bits", 1, NULL, BLUEBITS }, { "alpha-bits", 1, NULL, ALPHABITS }, { "depth-bits", 1, NULL, DEPTHBITS }, { "stencil-bits", 1, NULL, STENCILBITS }, { "accum-red-bits", 1, NULL, ACCUMREDBITS }, { "accum-green-bits", 1, NULL, ACCUMGREENBITS }, { "accum-blue-bits", 1, NULL, ACCUMBLUEBITS }, { "accum-alpha-bits", 1, NULL, ACCUMALPHABITS }, { "aux-buffers", 1, NULL, AUXBUFFERS }, { "samples", 1, NULL, SAMPLES }, { "stereo", 0, NULL, STEREO }, { "srgb", 0, NULL, SRGB }, { "singlebuffer", 0, NULL, SINGLEBUFFER }, { "no-error", 0, NULL, NOERROR_SRSLY }, { NULL, 0, NULL, 0 } }; // Initialize GLFW and create window if (!valid_version()) exit(EXIT_FAILURE); glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); while ((ch = getopt_long(argc, argv, "a:b:c:dfhlm:n:p:s:v", options, NULL)) != -1) { switch (ch) { case 'a': case CLIENT: if (strcasecmp(optarg, API_NAME_OPENGL) == 0) glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); else if (strcasecmp(optarg, API_NAME_OPENGL_ES) == 0) glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); else { usage(); exit(EXIT_FAILURE); } break; case 'b': case BEHAVIOR: if (strcasecmp(optarg, BEHAVIOR_NAME_NONE) == 0) { glfwWindowHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, GLFW_RELEASE_BEHAVIOR_NONE); } else if (strcasecmp(optarg, BEHAVIOR_NAME_FLUSH) == 0) { glfwWindowHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, GLFW_RELEASE_BEHAVIOR_FLUSH); } else { usage(); exit(EXIT_FAILURE); } break; case 'c': case CONTEXT: if (strcasecmp(optarg, API_NAME_NATIVE) == 0) glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API); else if (strcasecmp(optarg, API_NAME_EGL) == 0) glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); else { usage(); exit(EXIT_FAILURE); } break; case 'd': case DEBUG: glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); break; case 'f': case FORWARD: glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); break; case 'h': case HELP: usage(); exit(EXIT_SUCCESS); case 'l': case EXTENSIONS: list_extensions = GLFW_TRUE; break; case LAYERS: list_layers = GLFW_TRUE; break; case 'm': case MAJOR: glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, atoi(optarg)); break; case 'n': case MINOR: glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, atoi(optarg)); break; case 'p': case PROFILE: if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); } else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0) { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE); } else { usage(); exit(EXIT_FAILURE); } break; case 's': case ROBUSTNESS: if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0) { glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, GLFW_NO_RESET_NOTIFICATION); } else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0) { glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, GLFW_LOSE_CONTEXT_ON_RESET); } else { usage(); exit(EXIT_FAILURE); } break; case 'v': case VERSION: print_version(); exit(EXIT_SUCCESS); case REDBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_RED_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_RED_BITS, atoi(optarg)); break; case GREENBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_GREEN_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_GREEN_BITS, atoi(optarg)); break; case BLUEBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_BLUE_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_BLUE_BITS, atoi(optarg)); break; case ALPHABITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ALPHA_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ALPHA_BITS, atoi(optarg)); break; case DEPTHBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_DEPTH_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_DEPTH_BITS, atoi(optarg)); break; case STENCILBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_STENCIL_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_STENCIL_BITS, atoi(optarg)); break; case ACCUMREDBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ACCUM_RED_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ACCUM_RED_BITS, atoi(optarg)); break; case ACCUMGREENBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ACCUM_GREEN_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ACCUM_GREEN_BITS, atoi(optarg)); break; case ACCUMBLUEBITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ACCUM_BLUE_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ACCUM_BLUE_BITS, atoi(optarg)); break; case ACCUMALPHABITS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_ACCUM_ALPHA_BITS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_ACCUM_ALPHA_BITS, atoi(optarg)); break; case AUXBUFFERS: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_AUX_BUFFERS, GLFW_DONT_CARE); else glfwWindowHint(GLFW_AUX_BUFFERS, atoi(optarg)); break; case SAMPLES: if (strcmp(optarg, "-") == 0) glfwWindowHint(GLFW_SAMPLES, GLFW_DONT_CARE); else glfwWindowHint(GLFW_SAMPLES, atoi(optarg)); break; case STEREO: glfwWindowHint(GLFW_STEREO, GLFW_TRUE); break; case SRGB: glfwWindowHint(GLFW_SRGB_CAPABLE, GLFW_TRUE); break; case SINGLEBUFFER: glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_FALSE); break; case NOERROR_SRSLY: glfwWindowHint(GLFW_CONTEXT_NO_ERROR, GLFW_TRUE); break; default: usage(); exit(EXIT_FAILURE); } } print_version(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); window = glfwCreateWindow(200, 200, "Version", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(window); gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); error = glGetError(); if (error != GL_NO_ERROR) printf("*** OpenGL error after make current: 0x%08x ***\n", error); // Report client API version client = glfwGetWindowAttrib(window, GLFW_CLIENT_API); major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR); minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR); revision = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION); profile = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE); printf("%s context version string: \"%s\"\n", get_api_name(client), glGetString(GL_VERSION)); printf("%s context version parsed by GLFW: %u.%u.%u\n", get_api_name(client), major, minor, revision); // Report client API context properties if (client == GLFW_OPENGL_API) { if (major >= 3) { GLint flags; glGetIntegerv(GL_CONTEXT_FLAGS, &flags); printf("%s context flags (0x%08x):", get_api_name(client), flags); if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT) printf(" forward-compatible"); if (flags & 2/*GL_CONTEXT_FLAG_DEBUG_BIT*/) printf(" debug"); if (flags & GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB) printf(" robustness"); if (flags & 8/*GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR*/) printf(" no-error"); putchar('\n'); printf("%s context flags parsed by GLFW:", get_api_name(client)); if (glfwGetWindowAttrib(window, GLFW_OPENGL_FORWARD_COMPAT)) printf(" forward-compatible"); if (glfwGetWindowAttrib(window, GLFW_OPENGL_DEBUG_CONTEXT)) printf(" debug"); if (glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS) == GLFW_LOSE_CONTEXT_ON_RESET) printf(" robustness"); if (glfwGetWindowAttrib(window, GLFW_CONTEXT_NO_ERROR)) printf(" no-error"); putchar('\n'); } if (major >= 4 || (major == 3 && minor >= 2)) { GLint mask; glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); printf("%s profile mask (0x%08x): %s\n", get_api_name(client), mask, get_profile_name_gl(mask)); printf("%s profile mask parsed by GLFW: %s\n", get_api_name(client), get_profile_name_glfw(profile)); } if (GLAD_GL_ARB_robustness) { const int robustness = glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS); GLint strategy; glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy); printf("%s robustness strategy (0x%08x): %s\n", get_api_name(client), strategy, get_strategy_name_gl(strategy)); printf("%s robustness strategy parsed by GLFW: %s\n", get_api_name(client), get_strategy_name_glfw(robustness)); } } printf("%s context renderer string: \"%s\"\n", get_api_name(client), glGetString(GL_RENDERER)); printf("%s context vendor string: \"%s\"\n", get_api_name(client), glGetString(GL_VENDOR)); if (major >= 2) { printf("%s context shading language version: \"%s\"\n", get_api_name(client), glGetString(GL_SHADING_LANGUAGE_VERSION)); } printf("%s framebuffer:\n", get_api_name(client)); if (client == GLFW_OPENGL_API && profile == GLFW_OPENGL_CORE_PROFILE) { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &redbits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &greenbits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &bluebits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &alphabits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH, GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE, &depthbits); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &stencilbits); } else { glGetIntegerv(GL_RED_BITS, &redbits); glGetIntegerv(GL_GREEN_BITS, &greenbits); glGetIntegerv(GL_BLUE_BITS, &bluebits); glGetIntegerv(GL_ALPHA_BITS, &alphabits); glGetIntegerv(GL_DEPTH_BITS, &depthbits); glGetIntegerv(GL_STENCIL_BITS, &stencilbits); } printf(" red: %u green: %u blue: %u alpha: %u depth: %u stencil: %u\n", redbits, greenbits, bluebits, alphabits, depthbits, stencilbits); if (client == GLFW_OPENGL_ES_API || GLAD_GL_ARB_multisample || major > 1 || minor >= 3) { GLint samples, samplebuffers; glGetIntegerv(GL_SAMPLES, &samples); glGetIntegerv(GL_SAMPLE_BUFFERS, &samplebuffers); printf(" samples: %u sample buffers: %u\n", samples, samplebuffers); } if (client == GLFW_OPENGL_API && profile != GLFW_OPENGL_CORE_PROFILE) { GLint accumredbits, accumgreenbits, accumbluebits, accumalphabits; GLint auxbuffers; glGetIntegerv(GL_ACCUM_RED_BITS, &accumredbits); glGetIntegerv(GL_ACCUM_GREEN_BITS, &accumgreenbits); glGetIntegerv(GL_ACCUM_BLUE_BITS, &accumbluebits); glGetIntegerv(GL_ACCUM_ALPHA_BITS, &accumalphabits); glGetIntegerv(GL_AUX_BUFFERS, &auxbuffers); printf(" accum red: %u accum green: %u accum blue: %u accum alpha: %u aux buffers: %u\n", accumredbits, accumgreenbits, accumbluebits, accumalphabits, auxbuffers); } if (list_extensions) list_context_extensions(client, major, minor); printf("Vulkan loader: %s\n", glfwVulkanSupported() ? "available" : "missing"); if (glfwVulkanSupported()) { uint32_t i, re_count, pd_count; const char** re; VkApplicationInfo ai = {0}; VkInstanceCreateInfo ici = {0}; VkInstance instance; VkPhysicalDevice* pd; PFN_vkCreateInstance vkCreateInstance = (PFN_vkCreateInstance) glfwGetInstanceProcAddress(NULL, "vkCreateInstance"); PFN_vkDestroyInstance vkDestroyInstance; PFN_vkEnumeratePhysicalDevices vkEnumeratePhysicalDevices; PFN_vkGetPhysicalDeviceProperties vkGetPhysicalDeviceProperties; re = glfwGetRequiredInstanceExtensions(&re_count); printf("Vulkan required instance extensions:"); for (i = 0; i < re_count; i++) printf(" %s", re[i]); putchar('\n'); if (list_extensions) list_vulkan_instance_extensions(); if (list_layers) list_vulkan_instance_layers(); ai.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; ai.pApplicationName = "glfwinfo"; ai.applicationVersion = GLFW_VERSION_MAJOR; ai.pEngineName = "GLFW"; ai.engineVersion = GLFW_VERSION_MAJOR; ai.apiVersion = VK_API_VERSION_1_0; ici.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; ici.pApplicationInfo = &ai; ici.enabledExtensionCount = re_count; ici.ppEnabledExtensionNames = re; if (vkCreateInstance(&ici, NULL, &instance) != VK_SUCCESS) { glfwTerminate(); exit(EXIT_FAILURE); } vkDestroyInstance = (PFN_vkDestroyInstance) glfwGetInstanceProcAddress(instance, "vkDestroyInstance"); vkEnumeratePhysicalDevices = (PFN_vkEnumeratePhysicalDevices) glfwGetInstanceProcAddress(instance, "vkEnumeratePhysicalDevices"); vkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties) glfwGetInstanceProcAddress(instance, "vkGetPhysicalDeviceProperties"); if (vkEnumeratePhysicalDevices(instance, &pd_count, NULL) != VK_SUCCESS) { vkDestroyInstance(instance, NULL); glfwTerminate(); exit(EXIT_FAILURE); } pd = calloc(pd_count, sizeof(VkPhysicalDevice)); if (vkEnumeratePhysicalDevices(instance, &pd_count, pd) != VK_SUCCESS) { free(pd); vkDestroyInstance(instance, NULL); glfwTerminate(); exit(EXIT_FAILURE); } for (i = 0; i < pd_count; i++) { VkPhysicalDeviceProperties pdp; vkGetPhysicalDeviceProperties(pd[i], &pdp); printf("Vulkan %s device: \"%s\"\n", get_device_type_name(pdp.deviceType), pdp.deviceName); if (list_extensions) list_vulkan_device_extensions(instance, pd[i]); if (list_layers) list_vulkan_device_layers(instance, pd[i]); } free(pd); vkDestroyInstance(instance, NULL); } glfwTerminate(); exit(EXIT_SUCCESS); }
static GLuint create_fbo() { GLuint fbo; GLuint depth; GLuint textures[TEXTURE_AMOUNT]; GLint param; unsigned i; /* Generate fbo with TEXTURE_AMOUNT color attachments. */ glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glGenTextures(TEXTURE_AMOUNT, textures); for (i = 0; i < TEXTURE_AMOUNT; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + i, GL_TEXTURE_2D, textures[i], 0); } /* Test adding invalid attachment. */ glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_FALSE, GL_TEXTURE_2D, textures[0], 0); if (!piglit_check_gl_error(GL_INVALID_ENUM)) return 0; /* Create a depth buffer. */ glGenRenderbuffersEXT(1, &depth); glBindRenderbuffer(GL_RENDERBUFFER_EXT, depth); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, 4, 4); /* Test adding invalid renderbuffer. */ glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_FALSE, GL_RENDERBUFFER_EXT, depth); if (!piglit_check_gl_error(GL_INVALID_ENUM)) return 0; glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { return 0; } /* Test invalid attachment with GetFramebufferAttachmentParameteriv. */ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FALSE, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, ¶m); if (!piglit_check_gl_error(GL_INVALID_ENUM)) return 0; glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); return fbo; }
bool InitScene() { SetWindowText(hwnd, TITLE); Quadron::qGLExtensions::QueryFeatures(); //CalculateSphereTetrahedron(4, 0.5f); // setup opengl glClearColor(0, 0, 0, 1); glClearDepth(1.0); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); // create render targets for reference rendertargets[0] = new OpenGLFramebuffer(screenwidth, screenheight); rendertargets[1] = new OpenGLFramebuffer(screenwidth, screenheight); rendertargets[0]->AttachTexture(GL_COLOR_ATTACHMENT0, GLFMT_A32B32G32R32F, GL_NEAREST); rendertargets[1]->AttachTexture(GL_COLOR_ATTACHMENT0, GLFMT_A32B32G32R32F, GL_NEAREST); GL_ASSERT(rendertargets[0]->Validate()); GL_ASSERT(rendertargets[1]->Validate()); GLint value = 0; float white[] = { 1, 1, 1, 1 }; gbuffer = new OpenGLFramebuffer(screenwidth, screenheight); gbuffer->AttachTexture(GL_COLOR_ATTACHMENT0, GLFMT_A8B8G8R8_sRGB, GL_NEAREST); // color gbuffer->AttachTexture(GL_COLOR_ATTACHMENT1, GLFMT_A16B16G16R16F, GL_NEAREST); // normals gbuffer->AttachTexture(GL_COLOR_ATTACHMENT2, GLFMT_R32F, GL_NEAREST); // depth gbuffer->AttachTexture(GL_COLOR_ATTACHMENT3, GLFMT_G16R16F, GL_NEAREST); // velocity glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, white); gbuffer->AttachRenderbuffer(GL_DEPTH_STENCIL_ATTACHMENT, GLFMT_D24S8); GL_ASSERT(gbuffer->Validate()); glBindFramebuffer(GL_FRAMEBUFFER, gbuffer->GetFramebuffer()); { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &value); GL_ASSERT(value == GL_SRGB); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &value); GL_ASSERT(value == GL_LINEAR); glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &value); GL_ASSERT(value == GL_LINEAR); } glBindFramebuffer(GL_FRAMEBUFFER, 0); // load shaders if( !GLCreateEffectFromFile("../media/shadersGL/AOpathtracer.vert", 0, "../media/shadersGL/AOpathtracer.frag", &pathtracer) ) { MYERROR("Could not load 'path tracer' shader"); return false; } if( !GLCreateEffectFromFile("../media/shadersGL/AOpathtracer.vert", 0, "../media/shadersGL/AOpathtracer.frag", &refgbuffereffect, "#define RENDER_GBUFFER\n") ) { MYERROR("Could not load 'gbuffer' shader"); return false; } if( !GLCreateEffectFromFile("../media/shadersGL/basic2D.vert", 0, "../media/shadersGL/gtao.frag", &refgtaoeffect, "#define NUM_DIRECTIONS 32\n#define NUM_STEPS 16\n") ) { MYERROR("Could not load 'GTAO' shader"); return false; } if( !GLCreateEffectFromFile("../media/shadersGL/basic2D.vert", 0, "../media/shadersGL/gtaocombine.frag", &combineeffect) ) { MYERROR("Could not load 'combine' shader"); return false; } if( !GLCreateEffectFromFile("../media/shadersGL/basic2D.vert", 0, "../media/shadersGL/basic2D.frag", &presenteffect) ) { MYERROR("Could not load 'basic2D' shader"); return false; } float id[16]; GLMatrixIdentity(id); presenteffect->SetMatrix("matTexture", id); refgtaoeffect->SetMatrix("matTexture", id); combineeffect->SetInt("sampler0", 0); combineeffect->SetInt("sampler1", 1); refgtaoeffect->SetInt("gbufferDepth", 0); refgtaoeffect->SetInt("gbufferNormals", 1); refgtaoeffect->SetInt("noise", 2); screenquad = new OpenGLScreenQuad(); // render text GLCreateTexture(512, 512, 1, GLFMT_A8B8G8R8, &text1); GLRenderText( "Use the mouse to rotate camera\n\nP - Toggle path tracer\nH - Toggle help text", text1, 512, 512); // setup camera orbitcamera.SetAspect((float)screenwidth / (float)screenheight); orbitcamera.SetFov(GL_PI / 4.0f); orbitcamera.SetPosition(0, 1.633f, 0); orbitcamera.SetOrientation(GLDegreesToRadians(135), GLDegreesToRadians(30), 0); orbitcamera.SetDistance(6); orbitcamera.SetClipPlanes(0.1f, 20); return true; }
void GLWindow::queryDrawableConfig( DrawableConfig& dc ) { dc = DrawableConfig(); // GL version const char* glVersion = (const char*)glGetString( GL_VERSION ); if( !glVersion ) // most likely no context { LBWARN << "glGetString(GL_VERSION) returned 0, assuming GL version 1.1" << std::endl; dc.glVersion = 1.1f; } else dc.glVersion = static_cast<float>( std::atof( glVersion )); if( dc.glVersion >= 3.2f ) { GLint mask; EQ_GL_CALL( glGetIntegerv( GL_CONTEXT_PROFILE_MASK, &mask )); dc.coreProfile = mask & GL_CONTEXT_CORE_PROFILE_BIT; } TEST_GLEW_VERSION( 1, 1 ); TEST_GLEW_VERSION( 1, 2 ); TEST_GLEW_VERSION( 1, 3 ); TEST_GLEW_VERSION( 1, 4 ); TEST_GLEW_VERSION( 1, 5 ); TEST_GLEW_VERSION( 2, 0 ); TEST_GLEW_VERSION( 2, 1 ); TEST_GLEW_VERSION( 3, 0 ); TEST_GLEW_VERSION( 3, 1 ); TEST_GLEW_VERSION( 3, 2 ); TEST_GLEW_VERSION( 3, 3 ); TEST_GLEW_VERSION( 4, 0 ); TEST_GLEW_VERSION( 4, 1 ); TEST_GLEW_VERSION( 4, 2 ); TEST_GLEW_VERSION( 4, 3 ); #ifdef GLEW_VERSION_4_5 TEST_GLEW_VERSION( 4, 4 ); TEST_GLEW_VERSION( 4, 5 ); #endif // Framebuffer capabilities GLboolean result; EQ_GL_CALL( glGetBooleanv( GL_STEREO, &result )); dc.stereo = result; EQ_GL_CALL( glGetBooleanv( GL_DOUBLEBUFFER, &result )); dc.doublebuffered = result; if( dc.coreProfile ) { if( getFrameBufferObject( )) { glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &dc.stencilBits ); // eat GL error if no stencil attachment; should return '0' bits // according to spec, but gives GL_INVALID_OPERATION glGetError(); EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &dc.colorBits )); EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &dc.alphaBits )); } else { EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &dc.stencilBits )); EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &dc.colorBits )); EQ_GL_CALL( glGetFramebufferAttachmentParameteriv( GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &dc.alphaBits )); } } else { EQ_GL_CALL( glGetIntegerv( GL_STENCIL_BITS, &dc.stencilBits )); EQ_GL_CALL( glGetIntegerv( GL_RED_BITS, &dc.colorBits )); EQ_GL_CALL( glGetIntegerv( GL_ALPHA_BITS, &dc.alphaBits )); EQ_GL_CALL( glGetIntegerv( GL_ACCUM_RED_BITS, &dc.accumBits )); } dc.accumBits *= 4; LBDEBUG << "Window drawable config: " << dc << std::endl; }
/////////////////////////////////////////////////////////////////////////////// // print out the FBO infos /////////////////////////////////////////////////////////////////////////////// void printFramebufferInfo(GLuint fbo) { // bind fbo glBindFramebuffer(GL_FRAMEBUFFER, fbo); std::cout << "\n===== FBO STATUS =====\n"; // print max # of colorbuffers supported by FBO int colorBufferCount = 0; glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &colorBufferCount); std::cout << "Max Number of Color Buffer Attachment Points: " << colorBufferCount << std::endl; // get max # of multi samples int multiSampleCount = 0; glGetIntegerv(GL_MAX_SAMPLES, &multiSampleCount); std::cout << "Max Number of Samples for MSAA: " << multiSampleCount << std::endl; int objectType; int objectId; // print info of the colorbuffer attachable image for(int i = 0; i < colorBufferCount; ++i) { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &objectType); if(objectType != GL_NONE) { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &objectId); std::string formatName; std::cout << "Color Attachment " << i << ": "; if(objectType == GL_TEXTURE) { std::cout << "GL_TEXTURE, " << getTextureParameters(objectId) << std::endl; } else if(objectType == GL_RENDERBUFFER) { std::cout << "GL_RENDERBUFFER, " << getRenderbufferParameters(objectId) << std::endl; } } } // print info of the depthbuffer attachable image glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &objectType); if(objectType != GL_NONE) { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &objectId); std::cout << "Depth Attachment: "; switch(objectType) { case GL_TEXTURE: std::cout << "GL_TEXTURE, " << getTextureParameters(objectId) << std::endl; break; case GL_RENDERBUFFER: std::cout << "GL_RENDERBUFFER, " << getRenderbufferParameters(objectId) << std::endl; break; } } // print info of the stencilbuffer attachable image glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &objectType); if(objectType != GL_NONE) { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &objectId); std::cout << "Stencil Attachment: "; switch(objectType) { case GL_TEXTURE: std::cout << "GL_TEXTURE, " << getTextureParameters(objectId) << std::endl; break; case GL_RENDERBUFFER: std::cout << "GL_RENDERBUFFER, " << getRenderbufferParameters(objectId) << std::endl; break; } } std::cout << std::endl; glBindFramebuffer(GL_FRAMEBUFFER, 0); }