tl;dr: For many types of GL object, we can *NEVER* use the Gen function.
In OpenGL ES (all versions!) and OpenGL compatibility profile,
applications don't have to call Gen functions. The GL spec is very
clear about how you can mix-and-match generated names and non-generated
names: you can use any name you want for a particular object type until
you call the Gen function for that object type.
Here's the problem scenario:
- Application calls a meta function that generates a name. The first
Gen will probably return 1.
- Application decides to use the same name for an object of the same
type without calling Gen. Many demo programs use names 1, 2, 3,
etc. without calling Gen.
- Application calls the meta function again, and the meta function
replaces the data. The application's data is lost, and the app
fails. Have fun debugging that.
Fixes piglit tests:
- object-namespace-pollution glGetTexImage-compressed framebuffer
- object-namespace-pollution glGenerateMipmap framebuffer
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=92363
Reviewed-by: Topi Pohjolainen <topi.pohjolainen@intel.com>
GLint x, GLint y,
GLsizei width, GLsizei height)
{
- GLuint fbo;
struct gl_framebuffer *drawFb;
bool success = false;
GLbitfield mask;
if (!ctx->Extensions.ARB_framebuffer_object)
return false;
- _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_DRAW_BUFFERS);
-
- _mesa_CreateFramebuffers(1, &fbo);
- drawFb = _mesa_lookup_framebuffer(ctx, fbo);
- assert(drawFb != NULL && drawFb->Name == fbo);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ return false;
+ _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_DRAW_BUFFERS);
_mesa_bind_framebuffers(ctx, drawFb, ctx->ReadBuffer);
if (rb->_BaseFormat == GL_DEPTH_STENCIL ||
success = mask == 0x0;
out:
- _mesa_DeleteFramebuffers(1, &fbo);
+ _mesa_reference_framebuffer(&drawFb, NULL);
_mesa_meta_end(ctx);
return success;
}
meta_decompress_fbo_cleanup(struct decompress_fbo_state *decompress_fbo)
{
if (decompress_fbo->fb != NULL) {
- _mesa_DeleteFramebuffers(1, &decompress_fbo->fb->Name);
+ _mesa_reference_framebuffer(&decompress_fbo->fb, NULL);
_mesa_reference_renderbuffer(&decompress_fbo->rb, NULL);
}
/* Create/bind FBO/renderbuffer */
if (decompress_fbo->fb == NULL) {
- GLuint FBO;
-
decompress_fbo->rb = ctx->Driver.NewRenderbuffer(ctx, 0xDEADBEEF);
if (decompress_fbo->rb == NULL) {
_mesa_meta_end(ctx);
decompress_fbo->rb->RefCount = 1;
- _mesa_CreateFramebuffers(1, &FBO);
- decompress_fbo->fb = _mesa_lookup_framebuffer(ctx, FBO);
- assert(decompress_fbo->fb != NULL && decompress_fbo->fb->Name == FBO);
+ decompress_fbo->fb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (decompress_fbo->fb == NULL) {
+ _mesa_meta_end(ctx);
+ return false;
+ }
_mesa_bind_framebuffers(ctx, decompress_fbo->fb, decompress_fbo->fb);
_mesa_framebuffer_renderbuffer(ctx, ctx->DrawBuffer, GL_COLOR_ATTACHMENT0,
GLint zoffset,
const GLvoid *clearValue)
{
- GLuint fbo;
struct gl_framebuffer *drawFb;
bool success;
- _mesa_CreateFramebuffers(1, &fbo);
-
- drawFb = _mesa_lookup_framebuffer(ctx, fbo);
- assert(drawFb != NULL && drawFb->Name == fbo);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ return false;
_mesa_bind_framebuffers(ctx, drawFb, ctx->ReadBuffer);
break;
}
- _mesa_DeleteFramebuffers(1, &fbo);
+ _mesa_reference_framebuffer(&drawFb, NULL);
return success;
}
#include "teximage.h"
#include "texobj.h"
#include "fbobject.h"
+#include "framebuffer.h"
#include "buffers.h"
#include "state.h"
#include "mtypes.h"
GLint src_internal_format, dst_internal_format;
GLuint src_view_texture = 0;
struct gl_texture_image *src_view_tex_image;
- GLuint fbos[2];
struct gl_framebuffer *readFb;
struct gl_framebuffer *drawFb;
bool success = false;
/* We really only need to stash the bound framebuffers and scissor. */
_mesa_meta_begin(ctx, MESA_META_SCISSOR);
- _mesa_CreateFramebuffers(2, fbos);
- readFb = _mesa_lookup_framebuffer(ctx, fbos[0]);
- assert(readFb != NULL && readFb->Name == fbos[0]);
+ readFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (readFb == NULL)
+ goto meta_end;
- drawFb = _mesa_lookup_framebuffer(ctx, fbos[1]);
- assert(drawFb != NULL && drawFb->Name == fbos[1]);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ goto meta_end;
_mesa_bind_framebuffers(ctx, drawFb, readFb);
success = true;
meta_end:
- _mesa_DeleteFramebuffers(2, fbos);
+ _mesa_reference_framebuffer(&readFb, NULL);
+ _mesa_reference_framebuffer(&drawFb, NULL);
_mesa_meta_end(ctx);
cleanup:
* Test that we can actually render in the texture's format.
*/
if (mipmap->fb == NULL) {
- GLuint FBO;
-
- _mesa_CreateFramebuffers(1, &FBO);
- mipmap->fb = _mesa_lookup_framebuffer(ctx, FBO);
- assert(mipmap->fb != NULL && mipmap->fb->Name == FBO);
+ mipmap->fb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (mipmap->fb == NULL) {
+ _mesa_perf_debug(ctx, MESA_DEBUG_SEVERITY_HIGH,
+ "glGenerateMipmap() ran out of memory\n");
+ return true;
+ }
}
_mesa_meta_framebuffer_texture_image(ctx, mipmap->fb,
mipmap->VAO = 0;
_mesa_reference_buffer_object(ctx, &mipmap->buf_obj, NULL);
_mesa_reference_sampler_object(ctx, &mipmap->samp_obj, NULL);
-
- if (mipmap->fb != NULL) {
- _mesa_DeleteFramebuffers(1, &mipmap->fb->Name);
- mipmap->fb = NULL;
- }
+ _mesa_reference_framebuffer(&mipmap->fb, NULL);
_mesa_meta_blit_shader_table_cleanup(&mipmap->shaders);
}
const struct gl_pixelstore_attrib *packing)
{
struct gl_buffer_object *pbo = NULL;
- GLuint pbo_tex = 0, fbos[2] = { 0, 0 };
- struct gl_framebuffer *readFb;
- struct gl_framebuffer *drawFb;
+ GLuint pbo_tex = 0;
+ struct gl_framebuffer *readFb = NULL;
+ struct gl_framebuffer *drawFb = NULL;
int image_height;
struct gl_texture_image *pbo_tex_image;
GLenum status;
_mesa_meta_begin(ctx, ~(MESA_META_PIXEL_TRANSFER |
MESA_META_PIXEL_STORE));
- _mesa_CreateFramebuffers(2, fbos);
-
- readFb = _mesa_lookup_framebuffer(ctx, fbos[0]);
- assert(readFb != NULL && readFb->Name == fbos[0]);
+ readFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (readFb == NULL)
+ goto fail;
- drawFb = _mesa_lookup_framebuffer(ctx, fbos[1]);
- assert(drawFb != NULL && drawFb->Name == fbos[1]);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ goto fail;
_mesa_bind_framebuffers(ctx, drawFb, tex_image ? readFb : ctx->ReadBuffer);
success = true;
fail:
- _mesa_DeleteFramebuffers(2, fbos);
+ _mesa_reference_framebuffer(&readFb, NULL);
+ _mesa_reference_framebuffer(&drawFb, NULL);
_mesa_DeleteTextures(1, &pbo_tex);
_mesa_reference_buffer_object(ctx, &pbo, NULL);
const struct gl_pixelstore_attrib *packing)
{
struct gl_buffer_object *pbo = NULL;
- GLuint pbo_tex = 0, fbos[2] = { 0, 0 };
+ GLuint pbo_tex = 0;
struct gl_framebuffer *readFb;
struct gl_framebuffer *drawFb;
int image_height;
if (ctx->Extensions.ARB_color_buffer_float)
_mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE);
- _mesa_CreateFramebuffers(2, fbos);
-
- readFb = _mesa_lookup_framebuffer(ctx, fbos[0]);
- assert(readFb != NULL && readFb->Name == fbos[0]);
+ readFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (readFb == NULL)
+ goto fail;
- drawFb = _mesa_lookup_framebuffer(ctx, fbos[1]);
- assert(drawFb != NULL && drawFb->Name == fbos[1]);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ goto fail;
if (tex_image && tex_image->TexObject->Target == GL_TEXTURE_1D_ARRAY) {
assert(depth == 1);
success = true;
fail:
- _mesa_DeleteFramebuffers(2, fbos);
+ _mesa_reference_framebuffer(&drawFb, NULL);
+ _mesa_reference_framebuffer(&readFb, NULL);
_mesa_DeleteTextures(1, &pbo_tex);
_mesa_reference_buffer_object(ctx, &pbo, NULL);