Commit 7aecfa24 authored by Zhigang Gong's avatar Zhigang Gong Committed by Zhigang Gong

glamor-es2: Add --enable-glamor-gles2 to build system.

Now, to build a gles2 version of glamor server, we could
use ./autogen.sh --enable-glamor-ddx --enable-glamor-gles2
Signed-off-by: Zhigang Gong's avatarZhigang Gong <zhigang.gong@gmail.com>
parent 36a93f62
......@@ -1772,6 +1772,8 @@ AM_CONDITIONAL([XF86VIDMODE], [test "x$XF86VIDMODE" = xyes])
dnl glamor
AM_CONDITIONAL([GLAMOR], [test "x$XEPHYR" = xyes || test "x$GLAMOR_DDX" = xyes])
AM_CONDITIONAL([GLAMOR_GLES2], [test "x$GLAMOR_GLES2" = xyes])
AM_CONDITIONAL([GLAMOR_DDX], [test "x$GLAMOR_DDX" = xyes])
GLAMOR=yes
......
......@@ -10,10 +10,14 @@ if XORG
sdk_HEADERS = glamor.h
endif
if GLAMOR_GLES2
GLAMOR_GLES2_CFLAGS = -DGLAMOR_GLES2
endif
INCLUDES = \
$(XORG_INCS)
AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS)
AM_CFLAGS = $(XORG_CFLAGS) $(DIX_CFLAGS) $(GLAMOR_GLES2_CFLAGS)
libglamor_la_SOURCES = \
glamor.c \
......
......@@ -141,6 +141,7 @@ void
glamor_init_finish_access_shaders(ScreenPtr screen)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
#ifndef GLAMOR_GLES2
const char *vs_source =
"void main()\n"
"{\n"
......@@ -162,6 +163,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
"{\n"
" gl_FragColor = vec4(texture2D(sampler, gl_TexCoord[0].xy).rgb, 1);\n"
"}\n";
#endif
const char *es_vs_source =
"attribute vec4 v_position;\n"
"attribute vec4 v_texcoord0;\n"
......@@ -200,6 +202,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glamor_priv->finish_access_prog[3] = glCreateProgram();
if (GLEW_ARB_fragment_shader) {
#ifndef GLAMOR_GLES2
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, fs_source);
glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
......@@ -209,7 +212,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
aswizzle_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, aswizzle_source);
glAttachShader(glamor_priv->finish_access_prog[1], avs_prog);
glAttachShader(glamor_priv->finish_access_prog[1], aswizzle_prog);
#endif
es_vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, es_vs_source);
es_fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, es_fs_source);
glAttachShader(glamor_priv->finish_access_prog[2], es_vs_prog);
......@@ -221,16 +224,18 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glAttachShader(glamor_priv->finish_access_prog[3], es_aswizzle_prog);
} else {
#ifndef GLAMOR_GLES2
vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source);
glAttachShader(glamor_priv->finish_access_prog[0], vs_prog);
ErrorF("Lack of framgment shader support.\n");
#endif
}
#ifndef GLAMOR_GLES2
glamor_link_glsl_prog(glamor_priv->finish_access_prog[0]);
glamor_link_glsl_prog(glamor_priv->finish_access_prog[1]);
#endif
glBindAttribLocation(glamor_priv->finish_access_prog[2], GLAMOR_VERTEX_POS, "v_position");
glBindAttribLocation(glamor_priv->finish_access_prog[2], GLAMOR_VERTEX_SOURCE, "v_texcoord0");
glamor_link_glsl_prog(glamor_priv->finish_access_prog[2]);
......@@ -241,7 +246,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
if (GLEW_ARB_fragment_shader) {
GLint sampler_uniform_location;
#ifndef GLAMOR_GLES2
sampler_uniform_location =
glGetUniformLocation(glamor_priv->finish_access_prog[0], "sampler");
glUseProgram(glamor_priv->finish_access_prog[0]);
......@@ -253,7 +258,7 @@ glamor_init_finish_access_shaders(ScreenPtr screen)
glUseProgram(glamor_priv->finish_access_prog[1]);
glUniform1i(sampler_uniform_location, 0);
glUseProgram(0);
#endif
sampler_uniform_location =
glGetUniformLocation(glamor_priv->finish_access_prog[2], "sampler");
glUseProgram(glamor_priv->finish_access_prog[2]);
......
......@@ -60,10 +60,16 @@
#define GL_STREAM_DRAW 0x88E0
#define GL_STREAM_READ 0x88E1
#define GL_PACK_ROW_LENGTH 0x0D02
#define GL_UNPACK_ROW_LENGTH 0x0CF2
#define GLEW_MESA_pack_invert 0
#define GL_PACK_INVERT_MESA 0x8758
#define glMapBuffer(x, y) NULL
#define glUnmapBuffer(x)
#define glRasterPos2i(x,y)
#define glDrawPixels(x,y,z,a,b)
#endif
#ifdef GLAMOR_GLES2
......
......@@ -36,6 +36,7 @@ void
glamor_init_putimage_shaders(ScreenPtr screen)
{
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
#if 0
const char *xybitmap_vs =
"uniform float x_bias;\n"
"uniform float x_scale;\n"
......@@ -85,6 +86,7 @@ glamor_init_putimage_shaders(ScreenPtr screen)
&glamor_priv->put_image_xybitmap_transform);
glamor_priv->put_image_xybitmap_prog = prog;
glUseProgram(0);
#endif
}
......@@ -254,7 +256,7 @@ glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
glamor_get_screen_private(drawable->pScreen);
PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
GLenum type, format;
GLenum type, format, iformat;
RegionPtr clip;
BoxPtr pbox;
int nbox;
......@@ -317,17 +319,27 @@ glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
#endif
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
#ifndef GLAMOR_GLES2
glPixelStorei(GL_UNPACK_ROW_LENGTH, src_stride * 8 /
pixmap->drawable.bitsPerPixel);
#endif
}
else {
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
// glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
}
glGenTextures(1, &tex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
if (glamor_priv->gl_flavor == GLAMOR_GL_ES2) {
type = GL_UNSIGNED_BYTE;
iformat = format;
}
else {
iformat = GL_RGBA;
}
glTexImage2D(GL_TEXTURE_2D, 0, iformat,
w, h, 0,
format, type, bits);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
......@@ -396,9 +408,8 @@ glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y,
glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
#endif
glDeleteTextures(1, &tex);
#ifndef GLAMOR_GLES2
if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
#endif
glamor_set_alu(GXcopy);
glamor_set_planemask(pixmap, ~0);
return;
......
......@@ -377,7 +377,7 @@ glamor_set_composite_texture(ScreenPtr screen, int unit, PicturePtr picture,
switch (picture->repeatType) {
case RepeatNone:
#ifdef GLAMOR_GLES2
assert(0);
assert(1);
#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);
......
......@@ -43,6 +43,8 @@ glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
BoxRec *pbox;
int x_off, y_off;
goto fail;
if (glamor_get_tex_format_type_from_pixmap(dest_pixmap,
&format,
&type,
......
......@@ -89,4 +89,10 @@ if LNXACPI
XORG_CFLAGS += -DHAVE_ACPI
endif
AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
if GLAMOR_DDX
GLAMOR_DDX_CFLAGS = -DGLAMOR_DDX
endif
AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) $(GLAMOR_DDX_CFLAGS)
......@@ -1118,7 +1118,7 @@ videoPtrToDriverList(struct pci_device *dev,
} else if (dev->device_id == 0x8108) {
break; /* "hooray" for poulsbo */
} else {
#if GLAMOR_DDX
#ifdef GLAMOR_DDX
driverList[0] = "glamor";
#else
driverList[0] = "intel";
......
......@@ -12,10 +12,17 @@ glamor_la_CFLAGS = \
-I$(top_srcdir)/glamor \
-I/usr/include/drm
if GLAMOR_GLES2
glamor_la_CFLAGS+=-DGLAMOR_GLES2
GLAMOR_GL_LIB = -lGLESv2
else
GLAMOR_GL_LIB = -L$(libdir)/../lib64 -lGLEW
endif
glamor_la_LDFLAGS = \
-module -avoid-version -L$(libdir) -lEGL \
$(top_builddir)/glamor/libglamor.la \
-L$(libdir)/../lib64 -lGLEW
-L$(libdir)/../lib64 $(GLAMOR_GL_LIB)
glamor_ladir = $(moduledir)/drivers
glamor_la_SOURCES = \
......
......@@ -306,6 +306,13 @@ glamor_screen_init_ddx(int scrnIndex, ScreenPtr screen, int argc, char **argv)
struct glamor_screen_private *glamor = glamor_get_screen_private(scrn);
const char *version;
VisualPtr visual;
EGLint config_attribs[] = {
#ifdef GLAMOR_GLES2
EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
EGL_NONE
};
/* If serverGeneration != 1 then fd was closed during the last
time closing screen, actually in eglTerminate(). */
......@@ -327,7 +334,11 @@ glamor_screen_init_ddx(int scrnIndex, ScreenPtr screen, int argc, char **argv)
glamor->display = eglGetDRMDisplayMESA(glamor->fd);
#ifndef GLAMOR_GLES2
eglBindAPI(EGL_OPENGL_API);
#else
eglBindAPI(EGL_OPENGL_ES_API);
#endif
if (!eglInitialize(glamor->display, &glamor->major, &glamor->minor)) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"eglInitialize() failed\n");
......@@ -338,7 +349,7 @@ glamor_screen_init_ddx(int scrnIndex, ScreenPtr screen, int argc, char **argv)
xf86Msg(X_INFO, "%s: EGL version %s:", glamor_name, version);
glamor->context = eglCreateContext(glamor->display,
NULL, EGL_NO_CONTEXT, NULL);
NULL, EGL_NO_CONTEXT, config_attribs);
if (glamor->context == EGL_NO_CONTEXT) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"Failed to create EGL context\n");
......
......@@ -493,7 +493,8 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, drmmode_crtc->cursor);
}
glBindTexture(GL_TEXTURE_2D, drmmode_crtc->cursor_tex);
#if GLAMOR_GLES2
#ifdef GLAMOR_GLES2
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, 64, 64, 0,
GL_BGRA, GL_UNSIGNED_BYTE, image);
#else
......
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