Commit 94d884a1 authored by Zhigang Gong's avatar Zhigang Gong

glamor-es2: Fix some non-es2 functions.

ES2.0 doesn't support QUADS and also doesn't support
some EXT APIs. Fix some of them in this commit.
Signed-off-by: default avatarZhigang Gong <zhigang.gong@linux.intel.com>
parent 68c3c6eb
......@@ -291,9 +291,9 @@ glamor_init(ScreenPtr screen, unsigned int flags)
return FALSE;
}
glewInit();
#ifndef GLAMOR_GLES2
glewInit();
if (!GLEW_EXT_framebuffer_object) {
ErrorF("GL_EXT_framebuffer_object required\n");
goto fail;
......@@ -306,17 +306,19 @@ glamor_init(ScreenPtr screen, unsigned int flags)
ErrorF("GL_ARB_vertex_shader required\n");
goto fail;
}
if (!GLEW_EXT_bgra) {
ErrorF("GL_EXT_bgra required\n");
goto fail;
}
#endif
if (!GLEW_ARB_pixel_buffer_object) {
ErrorF("GL_ARB_pixel_buffer_object required\n");
goto fail;
}
if (!GLEW_EXT_bgra) {
ErrorF("GL_EXT_bgra required\n");
goto fail;
}
#endif
if (!RegisterBlockAndWakeupHandlers(glamor_block_handler,
glamor_wakeup_handler,
NULL)) {
......
......@@ -31,6 +31,7 @@
*
* GC CopyArea implementation
*/
#ifndef GLAMOR_GLES2
static Bool
glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
DrawablePtr dst,
......@@ -51,7 +52,6 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
glamor_delayed_fallback(screen,"no EXT_framebuffer_blit\n");
return FALSE;
}
src_pixmap_priv = glamor_get_pixmap_private(src_pixmap);
if (src_pixmap_priv->pending_op.type == GLAMOR_PENDING_FILL)
......@@ -77,8 +77,8 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
return FALSE;
}
glamor_validate_pixmap(dst_pixmap);
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, src_pixmap_priv->fb);
glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, src_pixmap_priv->fb);
glamor_get_drawable_deltas(dst, dst_pixmap, &dst_x_off, &dst_y_off);
glamor_get_drawable_deltas(src, src_pixmap, &src_x_off, &src_y_off);
src_y_off += dy;
......@@ -115,6 +115,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
}
return TRUE;
}
#endif
static Bool
glamor_copy_n_to_n_textured(DrawablePtr src,
......@@ -293,13 +294,14 @@ glamor_copy_n_to_n(DrawablePtr src,
}
/* XXX need revisit to handle overlapped area copying. */
#ifndef GLAMOR_GLES2
if ((overlaped
|| !src_pixmap_priv->gl_tex || !dst_pixmap_priv->gl_tex )
&& glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx, dy)) {
goto done;
return;
}
#endif
glamor_calculate_boxes_bound(&bound, box, nbox);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(src_pixmap_priv)
......
......@@ -88,15 +88,15 @@ glamor_compile_glsl_prog(GLenum type, const char *source)
prog = glCreateShader(type);
glShaderSource(prog, 1, (const GLchar **)&source, NULL);
glCompileShader(prog);
glGetObjectParameterivARB(prog, GL_OBJECT_COMPILE_STATUS_ARB, &ok);
glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
if (!ok) {
GLchar *info;
GLint size;
glGetObjectParameterivARB(prog, GL_OBJECT_INFO_LOG_LENGTH_ARB, &size);
glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
info = malloc(size);
glGetInfoLogARB(prog, size, NULL, info);
glGetShaderInfoLog(prog, size, NULL, info);
ErrorF("Failed to compile %s: %s\n",
type == GL_FRAGMENT_SHADER ? "FS" : "VS",
info);
......@@ -113,15 +113,15 @@ glamor_link_glsl_prog(GLint prog)
GLint ok;
glLinkProgram(prog);
glGetObjectParameterivARB(prog, GL_OBJECT_LINK_STATUS_ARB, &ok);
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
if (!ok) {
GLchar *info;
GLint size;
glGetObjectParameterivARB(prog, GL_OBJECT_INFO_LOG_LENGTH_ARB, &size);
glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
info = malloc(size);
glGetInfoLogARB(prog, size, NULL, info);
glGetProgramInfoLog(prog, size, NULL, info);
ErrorF("Failed to link: %s\n",
info);
FatalError("GLSL link failure\n");
......@@ -209,6 +209,7 @@ glamor_finish_access(DrawablePtr drawable)
{
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
glamor_screen_private *glamor_priv = glamor_get_screen_private(drawable->pScreen);
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv))
return;
......@@ -218,8 +219,9 @@ glamor_finish_access(DrawablePtr drawable)
}
if (pixmap_priv->pbo != 0 && pixmap_priv->pbo_valid) {
glBindBuffer (GL_PIXEL_PACK_BUFFER_EXT, 0);
glBindBuffer (GL_PIXEL_UNPACK_BUFFER_EXT, 0);
assert(glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP);
glBindBuffer (GL_PIXEL_PACK_BUFFER, 0);
glBindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);
pixmap_priv->pbo_valid = FALSE;
glDeleteBuffers(1, &pixmap_priv->pbo);
pixmap_priv->pbo = 0;
......
......@@ -46,7 +46,7 @@ _glamor_pixmap_validate_filling(glamor_screen_private *glamor_priv,
vertices[5] = 1;
vertices[6] = -1;
vertices[7] = 1;
glDrawArrays(GL_QUADS, 0, 4);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glUseProgram(0);
pixmap_priv->pending_op.type = GLAMOR_PENDING_NONE;
......@@ -83,7 +83,7 @@ glamor_validate_pixmap(PixmapPtr pixmap)
void
glamor_set_destination_pixmap_priv_nc(glamor_pixmap_private *pixmap_priv)
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, pixmap_priv->fb);
glBindFramebuffer(GL_FRAMEBUFFER, pixmap_priv->fb);
glMatrixMode(GL_PROJECTION); glLoadIdentity();
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
......@@ -223,7 +223,7 @@ __glamor_upload_pixmap_to_texture(PixmapPtr pixmap, GLenum format, GLenum type,
if (pixmap_priv->pbo && pixmap_priv->pbo_valid) {
texels = NULL;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_EXT, pixmap_priv->pbo);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixmap_priv->pbo);
}
else
texels = pixmap->devPrivate.ptr;
......@@ -288,7 +288,7 @@ _glamor_upload_pixmap_to_texture(PixmapPtr pixmap, GLenum format, GLenum type, i
glClientActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, sizeof(float) * 2, ptexcoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, pixmap_priv->fb);
glBindFramebuffer(GL_FRAMEBUFFER, pixmap_priv->fb);
glViewport(0, 0, pixmap->drawable.width, pixmap->drawable.height);
glGenTextures(1, &tex);
......@@ -309,7 +309,7 @@ _glamor_upload_pixmap_to_texture(PixmapPtr pixmap, GLenum format, GLenum type, i
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDeleteTextures(1, &tex);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
......@@ -347,7 +347,7 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, int ax)
if (need_fbo) {
if (pixmap_priv->fb == 0)
glGenFramebuffersEXT(1, &pixmap_priv->fb);
glGenFramebuffers(1, &pixmap_priv->fb);
glBindTexture(GL_TEXTURE_2D, pixmap_priv->tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
......@@ -355,9 +355,9 @@ glamor_pixmap_upload_prepare(PixmapPtr pixmap, int ax)
pixmap->drawable.height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, pixmap_priv->fb);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT,
glBindFramebuffer(GL_FRAMEBUFFER, pixmap_priv->fb);
glFramebufferTexture2D(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
pixmap_priv->tex,
0);
......@@ -498,45 +498,45 @@ glamor_download_pixmap_to_cpu(PixmapPtr pixmap, glamor_access_t access)
glPixelStorei(GL_PACK_INVERT_MESA, 1);
if (pixmap_priv->pbo == 0)
glGenBuffers (1, &pixmap_priv->pbo);
glBindBuffer (GL_PIXEL_PACK_BUFFER_EXT, pixmap_priv->pbo);
glBufferData (GL_PIXEL_PACK_BUFFER_EXT,
glBindBuffer (GL_PIXEL_PACK_BUFFER, pixmap_priv->pbo);
glBufferData (GL_PIXEL_PACK_BUFFER,
stride * pixmap->drawable.height,
NULL, gl_usage);
glReadPixels (0, 0,
row_length, pixmap->drawable.height,
format, type, 0);
data = glMapBuffer (GL_PIXEL_PACK_BUFFER_EXT, gl_access);
data = glMapBuffer (GL_PIXEL_PACK_BUFFER, gl_access);
pixmap_priv->pbo_valid = TRUE;
if (!glamor_priv->yInverted)
glPixelStorei(GL_PACK_INVERT_MESA, 0);
glBindBuffer (GL_PIXEL_PACK_BUFFER_EXT, 0);
glBindBuffer (GL_PIXEL_PACK_BUFFER, 0);
} else {
data = malloc(stride * pixmap->drawable.height);
assert(data);
if (access != GLAMOR_ACCESS_WO) {
if (pixmap_priv->pbo == 0)
glGenBuffers(1, &pixmap_priv->pbo);
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, pixmap_priv->pbo);
glBufferData(GL_PIXEL_PACK_BUFFER_EXT,
glBindBuffer(GL_PIXEL_PACK_BUFFER, pixmap_priv->pbo);
glBufferData(GL_PIXEL_PACK_BUFFER,
stride * pixmap->drawable.height,
NULL, GL_STREAM_READ);
glReadPixels (0, 0, row_length, pixmap->drawable.height,
format, type, 0);
read = glMapBuffer(GL_PIXEL_PACK_BUFFER_EXT, GL_READ_ONLY);
read = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
for (y = 0; y < pixmap->drawable.height; y++)
memcpy(data + y * stride,
read + (pixmap->drawable.height - y - 1) * stride, stride);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER_EXT);
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, 0);
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
pixmap_priv->pbo_valid = FALSE;
glDeleteBuffers(1, &pixmap_priv->pbo);
pixmap_priv->pbo = 0;
}
}
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
done:
pixmap->devPrivate.ptr = data;
return TRUE;
......
......@@ -49,9 +49,31 @@
#define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
#define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
#define GLEW_ARB_fragment_shader 1
#define GL_PIXEL_PACK_BUFFER 0x88EB
#define GL_PIXEL_UNPACK_BUFFER 0x88EC
#define GL_CLAMP_TO_BORDER 0x812D
#define GL_READ_WRITE 0x88BA
#define GL_READ_ONLY 0x88B8
#define GL_WRITE_ONLY 0x88B9
#define GL_STREAM_DRAW 0x88E0
#define GL_STREAM_READ 0x88E1
#define GL_PACK_ROW_LENGTH 0x0D02
#define GLEW_MESA_pack_invert 0
#define GL_PACK_INVERT_MESA 0x8758
#endif
#ifdef GLAMOR_GLES2
#define GL_GLEXT_PROTOTYPES
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#else
#include <GL/glew.h>
#endif
#ifdef RENDER
#include "glyphstr.h"
......@@ -171,6 +193,12 @@ struct glamor_screen_private;
struct glamor_pixmap_private;
typedef void (*glamor_pixmap_validate_function_t)(struct glamor_screen_private*,
struct glamor_pixmap_private*);
enum glamor_gl_flavor {
GLAMOR_GL_DESKTOP, // OPENGL API
GLAMOR_GL_ES2 // OPENGL ES2.0 API
};
#define GLAMOR_CREATE_PIXMAP_CPU 0x100
typedef struct glamor_screen_private {
CloseScreenProcPtr saved_close_screen;
......@@ -196,6 +224,7 @@ typedef struct glamor_screen_private {
int vbo_size;
char *vb;
int vb_stride;
enum glamor_gl_flavor gl_flavor;
/* glamor_finishaccess */
GLint finish_access_prog[2];
......@@ -287,8 +316,8 @@ typedef struct glamor_pixmap_private {
#define GLAMOR_CHECK_PENDING_FILL(_glamor_priv_, _pixmap_priv_) do \
{ \
if (_pixmap_priv_->pending_op.type == GLAMOR_PENDING_FILL) { \
glUseProgramObjectARB(_glamor_priv_->solid_prog); \
glUniform4fvARB(_glamor_priv_->solid_color_uniform_location, 1, \
glUseProgram(_glamor_priv_->solid_prog); \
glUniform4fv(_glamor_priv_->solid_color_uniform_location, 1, \
_pixmap_priv_->pending_op.fill.color4fv); \
} \
} while(0)
......
......@@ -362,6 +362,9 @@ glamor_set_composite_texture(ScreenPtr screen, int unit, PicturePtr picture,
glBindTexture(GL_TEXTURE_2D, pixmap_priv->tex);
switch (picture->repeatType) {
case RepeatNone:
#ifdef GLAMOR_GLES2
assert(0);
#endif
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
break;
......@@ -562,7 +565,7 @@ glamor_flush_composite_rects(ScreenPtr screen)
glBufferData(GL_ARRAY_BUFFER, glamor_priv->vbo_offset, glamor_priv->vb,
GL_STREAM_DRAW);
glDrawArrays(GL_QUADS, 0, glamor_priv->render_nr_verts);
glDrawArrays(GL_TRIANGLES, 0, glamor_priv->render_nr_verts);
glamor_reset_composite_vbo(screen);
}
......@@ -574,7 +577,7 @@ glamor_emit_composite_rect(ScreenPtr screen,
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
if (glamor_priv->vbo_offset + 4 * glamor_priv->vb_stride >
if (glamor_priv->vbo_offset + 6 * glamor_priv->vb_stride >
glamor_priv->vbo_size)
{
glamor_flush_composite_rects(screen);
......@@ -590,6 +593,8 @@ glamor_emit_composite_rect(ScreenPtr screen,
glamor_emit_composite_vert(screen, src_coords, mask_coords, dst_coords, 0);
glamor_emit_composite_vert(screen, src_coords, mask_coords, dst_coords, 1);
glamor_emit_composite_vert(screen, src_coords, mask_coords, dst_coords, 2);
glamor_emit_composite_vert(screen, src_coords, mask_coords, dst_coords, 0);
glamor_emit_composite_vert(screen, src_coords, mask_coords, dst_coords, 2);
glamor_emit_composite_vert(screen, src_coords, mask_coords, dst_coords, 3);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment