+static void
+setup_ff_generate_mipmap(struct gl_context *ctx,
+ struct gen_mipmap_state *mipmap)
+{
+ struct vertex {
+ GLfloat x, y, tex[3];
+ };
+
+ if (mipmap->ArrayObj == 0) {
+ /* one-time setup */
+ /* create vertex array object */
+ _mesa_GenVertexArraysAPPLE(1, &mipmap->ArrayObj);
+ _mesa_BindVertexArrayAPPLE(mipmap->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &mipmap->VBO);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, mipmap->VBO);
+ /* setup vertex arrays */
+ _mesa_VertexPointer(2, GL_FLOAT, sizeof(struct vertex), OFFSET(x));
+ _mesa_TexCoordPointer(3, GL_FLOAT, sizeof(struct vertex), OFFSET(tex));
+ _mesa_EnableClientState(GL_VERTEX_ARRAY);
+ _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY);
+ }
+
+ /* setup projection matrix */
+ _mesa_MatrixMode(GL_PROJECTION);
+ _mesa_LoadIdentity();
+ _mesa_Ortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
+}
+
+
+static void
+setup_glsl_generate_mipmap(struct gl_context *ctx,
+ struct gen_mipmap_state *mipmap)
+{
+ struct vertex {
+ GLfloat x, y, tex[3];
+ };
+
+ static const char *vs_source =
+ "attribute vec2 position;\n"
+ "attribute vec3 textureCoords;\n"
+ "varying vec3 texCoords;\n"
+ "void main()\n"
+ "{\n"
+ " texCoords = textureCoords;\n"
+ " gl_Position = vec4(position, 0.0, 1.0);\n"
+ "}\n";
+ static const char *fs_source =
+ "uniform sampler2D tex2d;\n"
+ "varying vec3 texCoords;\n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = texture2D(tex2d, texCoords.xy);\n"
+ "}\n";
+
+ static const char *vs_int_source =
+ "#version 130\n"
+ "in vec2 position;\n"
+ "in vec3 textureCoords;\n"
+ "out vec3 texCoords;\n"
+ "void main()\n"
+ "{\n"
+ " texCoords = textureCoords;\n"
+ " gl_Position = gl_Vertex;\n"
+ "}\n";
+ static const char *fs_int_source =
+ "#version 130\n"
+ "uniform isampler2D tex2d;\n"
+ "in vec3 texCoords;\n"
+ "out ivec4 out_color;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " out_color = texture(tex2d, texCoords.xy);\n"
+ "}\n";
+ GLuint vs, fs;
+
+ /* Check if already initialized */
+ if (mipmap->ArrayObj != 0)
+ return;
+ /* create vertex array object */
+ _mesa_GenVertexArrays(1, &mipmap->ArrayObj);
+ _mesa_BindVertexArray(mipmap->ArrayObj);
+
+ /* create vertex array buffer */
+ _mesa_GenBuffersARB(1, &mipmap->VBO);
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, mipmap->VBO);
+
+ /* setup vertex arrays */
+ _mesa_VertexAttribPointerARB(0, 2, GL_FLOAT, GL_FALSE,
+ sizeof(struct vertex), OFFSET(x));
+ _mesa_VertexAttribPointerARB(1, 3, GL_FLOAT, GL_FALSE,
+ sizeof(struct vertex), OFFSET(tex));
+
+ vs = compile_shader_with_debug(ctx, GL_VERTEX_SHADER, vs_source);
+ fs = compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER, fs_source);
+
+ mipmap->ShaderProg = _mesa_CreateProgramObjectARB();
+ _mesa_AttachShader(mipmap->ShaderProg, fs);
+ _mesa_DeleteObjectARB(fs);
+ _mesa_AttachShader(mipmap->ShaderProg, vs);
+ _mesa_DeleteObjectARB(vs);
+ _mesa_BindAttribLocationARB(mipmap->ShaderProg, 0, "position");
+ _mesa_BindAttribLocationARB(mipmap->ShaderProg, 1, "texcoords");
+ _mesa_EnableVertexAttribArrayARB(0);
+ _mesa_EnableVertexAttribArrayARB(1);
+ link_program_with_debug(ctx, mipmap->ShaderProg);
+
+ if ((_mesa_is_desktop_gl(ctx) && ctx->Const.GLSLVersion >= 130) ||
+ _mesa_is_gles3(ctx)){
+ vs = compile_shader_with_debug(ctx, GL_VERTEX_SHADER, vs_int_source);
+ fs = compile_shader_with_debug(ctx, GL_FRAGMENT_SHADER, fs_int_source);
+
+ mipmap->IntegerShaderProg = _mesa_CreateProgramObjectARB();
+ _mesa_AttachShader(mipmap->IntegerShaderProg, fs);
+ _mesa_DeleteObjectARB(fs);
+ _mesa_AttachShader(mipmap->IntegerShaderProg, vs);
+ _mesa_DeleteObjectARB(vs);
+ _mesa_BindAttribLocationARB(mipmap->IntegerShaderProg, 0, "position");
+ _mesa_BindAttribLocationARB(mipmap->IntegerShaderProg, 1, "texcoords");
+
+ /* Note that user-defined out attributes get automatically assigned
+ * locations starting from 0, so we don't need to explicitly
+ * BindFragDataLocation to 0.
+ */
+ link_program_with_debug(ctx, mipmap->IntegerShaderProg);
+ }
+}
+
+
+static void
+meta_glsl_generate_mipmap_cleanup(struct gl_context *ctx,
+ struct gen_mipmap_state *mipmap)
+{
+ if (mipmap->ArrayObj == 0)
+ return;
+ _mesa_DeleteVertexArraysAPPLE(1, &mipmap->ArrayObj);
+ mipmap->ArrayObj = 0;
+ _mesa_DeleteBuffersARB(1, &mipmap->VBO);
+ mipmap->VBO = 0;
+ _mesa_DeleteObjectARB(mipmap->ShaderProg);
+ mipmap->ShaderProg = 0;
+
+ if (mipmap->IntegerShaderProg) {
+ _mesa_DeleteObjectARB(mipmap->IntegerShaderProg);
+ mipmap->IntegerShaderProg = 0;
+ }
+}
+
+