#include "main/feedback.h"
#include "main/formats.h"
#include "main/format_unpack.h"
+#include "main/framebuffer.h"
#include "main/glformats.h"
#include "main/image.h"
#include "main/macros.h"
#include "main/polygon.h"
#include "main/queryobj.h"
#include "main/readpix.h"
+#include "main/renderbuffer.h"
#include "main/scissor.h"
#include "main/shaderapi.h"
#include "main/shaderobj.h"
struct drawpix_state *drawpix);
void
-_mesa_meta_bind_fbo_image(GLenum fboTarget, GLenum attachment,
- struct gl_texture_image *texImage, GLuint layer)
+_mesa_meta_framebuffer_texture_image(struct gl_context *ctx,
+ struct gl_framebuffer *fb,
+ GLenum attachment,
+ struct gl_texture_image *texImage,
+ GLuint layer)
{
struct gl_texture_object *texObj = texImage->TexObject;
int level = texImage->Level;
- GLenum texTarget = texObj->Target;
+ const GLenum texTarget = texObj->Target == GL_TEXTURE_CUBE_MAP
+ ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + texImage->Face
+ : texObj->Target;
- switch (texTarget) {
- case GL_TEXTURE_1D:
- _mesa_FramebufferTexture1D(fboTarget,
- attachment,
- texTarget,
- texObj->Name,
- level);
- break;
- case GL_TEXTURE_1D_ARRAY:
- case GL_TEXTURE_2D_ARRAY:
- case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
- case GL_TEXTURE_CUBE_MAP_ARRAY:
- case GL_TEXTURE_3D:
- _mesa_FramebufferTextureLayer(fboTarget,
- attachment,
- texObj->Name,
- level,
- layer);
- break;
- default: /* 2D / cube */
- if (texTarget == GL_TEXTURE_CUBE_MAP)
- texTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + texImage->Face;
-
- _mesa_FramebufferTexture2D(fboTarget,
- attachment,
- texTarget,
- texObj->Name,
- level);
- }
+ _mesa_framebuffer_texture(ctx, fb, attachment, texObj, texTarget,
+ level, layer, false, __func__);
}
GLuint
_mesa_DeleteShader(fs);
_mesa_AttachShader(*program, vs);
_mesa_DeleteShader(vs);
- _mesa_BindAttribLocation(*program, 0, "position");
- _mesa_BindAttribLocation(*program, 1, "texcoords");
_mesa_meta_link_program_with_debug(ctx, *program);
_mesa_UseProgram(*program);
{
char *vs_source, *fs_source;
struct blit_shader *shader = choose_blit_shader(target, table);
- const char *vs_input, *vs_output, *fs_input, *vs_preprocess, *fs_preprocess;
+ const char *fs_input, *vs_preprocess, *fs_preprocess;
void *mem_ctx;
if (ctx->Const.GLSLVersion < 130) {
vs_preprocess = "";
- vs_input = "attribute";
- vs_output = "varying";
fs_preprocess = "#extension GL_EXT_texture_array : enable";
fs_input = "varying";
} else {
vs_preprocess = "#version 130";
- vs_input = "in";
- vs_output = "out";
fs_preprocess = "#version 130";
fs_input = "in";
shader->func = "texture";
vs_source = ralloc_asprintf(mem_ctx,
"%s\n"
- "%s vec2 position;\n"
- "%s vec4 textureCoords;\n"
- "%s vec4 texCoords;\n"
+ "#extension GL_ARB_explicit_attrib_location: enable\n"
+ "layout(location = 0) in vec2 position;\n"
+ "layout(location = 1) in vec4 textureCoords;\n"
+ "out vec4 texCoords;\n"
"void main()\n"
"{\n"
" texCoords = textureCoords;\n"
" gl_Position = vec4(position, 0.0, 1.0);\n"
"}\n",
- vs_preprocess, vs_input, vs_input, vs_output);
+ vs_preprocess);
fs_source = ralloc_asprintf(mem_ctx,
"%s\n"
if (ctx->RasterDiscard)
_mesa_set_enable(ctx, GL_RASTERIZER_DISCARD, GL_FALSE);
- save->DrawBufferName = ctx->DrawBuffer->Name;
- save->ReadBufferName = ctx->ReadBuffer->Name;
+ _mesa_reference_framebuffer(&save->DrawBuffer, ctx->DrawBuffer);
+ _mesa_reference_framebuffer(&save->ReadBuffer, ctx->ReadBuffer);
}
}
if (save->TransformFeedbackNeedsResume)
_mesa_ResumeTransformFeedback();
- if (ctx->DrawBuffer->Name != save->DrawBufferName)
- _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, save->DrawBufferName);
-
- if (ctx->ReadBuffer->Name != save->ReadBufferName)
- _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, save->ReadBufferName);
+ _mesa_bind_framebuffers(ctx, save->DrawBuffer, save->ReadBuffer);
+ _mesa_reference_framebuffer(&save->DrawBuffer, NULL);
+ _mesa_reference_framebuffer(&save->ReadBuffer, NULL);
if (state & MESA_META_DRAW_BUFFERS) {
_mesa_drawbuffers(ctx, ctx->DrawBuffer, ctx->Const.MaxDrawBuffers,
if (clear->ShaderProg != 0)
return;
- vs = _mesa_CreateShader(GL_VERTEX_SHADER);
- _mesa_ShaderSource(vs, 1, &vs_source, NULL);
- _mesa_CompileShader(vs);
-
- fs = _mesa_CreateShader(GL_FRAGMENT_SHADER);
- _mesa_ShaderSource(fs, 1, &fs_source, NULL);
- _mesa_CompileShader(fs);
-
- clear->ShaderProg = _mesa_CreateProgram();
- _mesa_AttachShader(clear->ShaderProg, fs);
- _mesa_DeleteShader(fs);
- _mesa_AttachShader(clear->ShaderProg, vs);
- _mesa_DeleteShader(vs);
- _mesa_ObjectLabel(GL_PROGRAM, clear->ShaderProg, -1, "meta clear");
- _mesa_LinkProgram(clear->ShaderProg);
+ _mesa_meta_compile_and_link_program(ctx, vs_source, fs_source, "meta clear",
+ &clear->ShaderProg);
has_integer_textures = _mesa_is_gles3(ctx) ||
(_mesa_is_desktop_gl(ctx) && ctx->Const.GLSLVersion >= 130);
" out_color = color;\n"
"}\n");
- vs = _mesa_meta_compile_shader_with_debug(ctx, GL_VERTEX_SHADER,
- vs_int_source);
- fs = _mesa_meta_compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER,
- fs_int_source);
+ _mesa_meta_compile_and_link_program(ctx, vs_int_source, fs_int_source,
+ "integer clear",
+ &clear->IntegerShaderProg);
ralloc_free(shader_source_mem_ctx);
- clear->IntegerShaderProg = _mesa_CreateProgram();
- _mesa_AttachShader(clear->IntegerShaderProg, fs);
- _mesa_DeleteShader(fs);
- _mesa_AttachShader(clear->IntegerShaderProg, vs);
- _mesa_DeleteShader(vs);
-
/* Note that user-defined out attributes get automatically assigned
* locations starting from 0, so we don't need to explicitly
* BindFragDataLocation to 0.
*/
-
- _mesa_ObjectLabel(GL_PROGRAM, clear->IntegerShaderProg, -1,
- "integer clear");
- _mesa_meta_link_program_with_debug(ctx, clear->IntegerShaderProg);
}
}
GLint x, GLint y,
GLsizei width, GLsizei height)
{
- GLuint fbo;
+ struct gl_framebuffer *drawFb;
bool success = false;
GLbitfield mask;
GLenum status;
if (!ctx->Extensions.ARB_framebuffer_object)
return false;
- _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_DRAW_BUFFERS);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ return false;
- _mesa_GenFramebuffers(1, &fbo);
- _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+ _mesa_meta_begin(ctx, MESA_META_ALL & ~MESA_META_DRAW_BUFFERS);
+ _mesa_bind_framebuffers(ctx, drawFb, ctx->ReadBuffer);
if (rb->_BaseFormat == GL_DEPTH_STENCIL ||
rb->_BaseFormat == GL_DEPTH_COMPONENT) {
- _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- texImage, zoffset);
+ _mesa_meta_framebuffer_texture_image(ctx, ctx->DrawBuffer,
+ GL_DEPTH_ATTACHMENT,
+ texImage, zoffset);
mask = GL_DEPTH_BUFFER_BIT;
if (rb->_BaseFormat == GL_DEPTH_STENCIL &&
texImage->_BaseFormat == GL_DEPTH_STENCIL) {
- _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
- texImage, zoffset);
+ _mesa_meta_framebuffer_texture_image(ctx, ctx->DrawBuffer,
+ GL_STENCIL_ATTACHMENT,
+ texImage, zoffset);
mask |= GL_STENCIL_BUFFER_BIT;
}
_mesa_DrawBuffer(GL_NONE);
} else {
- _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- texImage, zoffset);
+ _mesa_meta_framebuffer_texture_image(ctx, ctx->DrawBuffer,
+ GL_COLOR_ATTACHMENT0,
+ texImage, zoffset);
mask = GL_COLOR_BUFFER_BIT;
_mesa_DrawBuffer(GL_COLOR_ATTACHMENT0);
}
- status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
+ status = _mesa_check_framebuffer_status(ctx, ctx->DrawBuffer);
if (status != GL_FRAMEBUFFER_COMPLETE)
goto out;
success = mask == 0x0;
out:
- _mesa_DeleteFramebuffers(1, &fbo);
+ _mesa_reference_framebuffer(&drawFb, NULL);
_mesa_meta_end(ctx);
return success;
}
static void
meta_decompress_fbo_cleanup(struct decompress_fbo_state *decompress_fbo)
{
- if (decompress_fbo->FBO != 0) {
- _mesa_DeleteFramebuffers(1, &decompress_fbo->FBO);
- _mesa_DeleteRenderbuffers(1, &decompress_fbo->RBO);
+ if (decompress_fbo->fb != NULL) {
+ _mesa_reference_framebuffer(&decompress_fbo->fb, NULL);
+ _mesa_reference_renderbuffer(&decompress_fbo->rb, NULL);
}
memset(decompress_fbo, 0, sizeof(*decompress_fbo));
ctx->Texture.Unit[ctx->Texture.CurrentUnit].Sampler);
/* Create/bind FBO/renderbuffer */
- if (decompress_fbo->FBO == 0) {
- _mesa_CreateRenderbuffers(1, &decompress_fbo->RBO);
+ if (decompress_fbo->fb == NULL) {
+ decompress_fbo->rb = ctx->Driver.NewRenderbuffer(ctx, 0xDEADBEEF);
+ if (decompress_fbo->rb == NULL) {
+ _mesa_meta_end(ctx);
+ return false;
+ }
- _mesa_GenFramebuffers(1, &decompress_fbo->FBO);
- _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT, decompress_fbo->FBO);
- _mesa_FramebufferRenderbuffer(GL_FRAMEBUFFER_EXT,
- GL_COLOR_ATTACHMENT0_EXT,
- GL_RENDERBUFFER_EXT,
- decompress_fbo->RBO);
+ decompress_fbo->rb->RefCount = 1;
+
+ 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,
+ decompress_fbo->rb);
}
else {
- _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT, decompress_fbo->FBO);
+ _mesa_bind_framebuffers(ctx, decompress_fbo->fb, decompress_fbo->fb);
}
/* alloc dest surface */
if (width > decompress_fbo->Width || height > decompress_fbo->Height) {
- _mesa_NamedRenderbufferStorage(decompress_fbo->RBO, rbFormat,
- width, height);
- status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
+ _mesa_renderbuffer_storage(ctx, decompress_fbo->rb, rbFormat,
+ width, height, 0);
+ status = _mesa_check_framebuffer_status(ctx, ctx->DrawBuffer);
if (status != GL_FRAMEBUFFER_COMPLETE) {
/* If the framebuffer isn't complete then we'll leave
* decompress_fbo->Width as zero so that it will fail again next time
GLenum datatype;
GLenum status;
- _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- texImage, zoffset);
+ _mesa_meta_framebuffer_texture_image(ctx, ctx->DrawBuffer,
+ GL_COLOR_ATTACHMENT0,
+ texImage, zoffset);
- status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
+ status = _mesa_check_framebuffer_status(ctx, ctx->DrawBuffer);
if (status != GL_FRAMEBUFFER_COMPLETE)
return false;
GLfloat depthValue;
GLenum status;
- _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
- texImage, zoffset);
+ _mesa_meta_framebuffer_texture_image(ctx, ctx->DrawBuffer,
+ GL_DEPTH_ATTACHMENT,
+ texImage, zoffset);
if (texImage->_BaseFormat == GL_DEPTH_STENCIL)
- _mesa_meta_bind_fbo_image(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
- texImage, zoffset);
+ _mesa_meta_framebuffer_texture_image(ctx, ctx->DrawBuffer,
+ GL_STENCIL_ATTACHMENT,
+ texImage, zoffset);
- status = _mesa_CheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
+ status = _mesa_check_framebuffer_status(ctx, ctx->DrawBuffer);
if (status != GL_FRAMEBUFFER_COMPLETE)
return false;
GLint zoffset,
const GLvoid *clearValue)
{
- GLuint fbo;
+ struct gl_framebuffer *drawFb;
bool success;
- _mesa_GenFramebuffers(1, &fbo);
- _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+ drawFb = ctx->Driver.NewFramebuffer(ctx, 0xDEADBEEF);
+ if (drawFb == NULL)
+ return false;
+
+ _mesa_bind_framebuffers(ctx, drawFb, ctx->ReadBuffer);
switch(texImage->_BaseFormat) {
case GL_DEPTH_STENCIL:
break;
}
- _mesa_DeleteFramebuffers(1, &fbo);
+ _mesa_reference_framebuffer(&drawFb, NULL);
return success;
}