Re: eglInitialize
Alberich de megres <[email protected]>
| Newsgroups | gmane.comp.video.mesa3d.user |
|---|---|
| Message-ID | <[email protected]> |
I found my error, I compiled a kernel and forgot some kms options. So now i can get a DRMDisplay But, now I got a different problem: I can set a mode, using drm. And I set up the minimun so i should be able to clean the backgound (or the buffer) to white and see the screen on white. But what i really get is weird things like lots of columns... Is there some place where i can read about drm+egl? My init code is barely copy+paste from wayland.. I attached the code, don't blame me for the code (copy+paste stuff) i'm only trying to understand how drm+egl works so i can create one by my own. thanks! On Mon, Dec 20, 2010 at 1:55 PM, Chia-I Wu <[email protected]> wrote: > On Tue, Dec 14, 2010 at 5:24 PM, Alberich de megres > <[email protected]> wrote: >> Hi !! >> >> I got a problem while initializing egl, using the source on git repo: >> git clone git://anongit.freedesktop.org/mesa/mesa >> >> So what i do is first >> >> display = (EGLDisplay) eglGetDRMDisplayMESA(fd); >> if (display == NULL) return -1; >> >> if (!eglInitialize(display, &major, &minor)) { >> ... error check >> } >> >> When I do that i receive a message: >> libEGL warning: failed to create DRM screen >> >> And sometimes i get this other on the same point: >> libEGL warning: failed to create DRM screen >> libEGL warning: EGL-DRI2: malformed or no PCI ID >> >> I tried with both nourveau modeset=1, and radeon modeset=1 >> >> I compiled libdrm with the following options: >> ./configure --enable-nouveau-experimental-api --enable-vmwgfx-experimental-api >> >> And mesa with the following: >> ./configure --with-dri-drivers=nouveau --enable-glx-tls >> --with-driver=dri --enable-xcb --disable-glut --enable-egl >> --enable-gles2 --with-egl-platforms=drm --disable-gallium >> >> Also i tried those recomended on wayland site: >> ./configure --enable-egl --enable-gles2 >> >> Can any one point me some light? > The configure options look fine. It is not clear what might have gone > wrong. Can you try again with EGL_LOG_LEVEL=debug set? > >> thanks! >> Albert >> _______________________________________________ >> mesa-users mailing list >> [email protected] >> http://lists.freedesktop.org/mailman/listinfo/mesa-users >> > > > > -- > [email protected] > _______________________________________________ mesa-users mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-users
modeset2.c
(text/x-csrc, 4.2 KB)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libdrm/drm.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <GL/gl.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglplatform.h>
#include <linux/input.h>
/////////////////////////////////////////////
// TO REMOVED
#define DEV_PATH "/dev/dri/card0"
#define DEV_MICE "/dev/input/mice"
/////////////////////////////////////////////
struct egl_e{
EGLDisplay e_display;
EGLContext e_context;
};
struct engine{
int fd;
GLint rbo[2];
GLint fbo;
//EGLDisplay display;
//EGLContext context;
struct egl_e egl;
};
// Inits EGL
int engine_init_egl(struct engine *e){
EGLint major, minor;
EGLint context_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION,2,EGL_NONE
};
e->egl.e_display=(EGLDisplay)eglGetDRMDisplayMESA(e->fd);
if (!e->egl.e_display){
printf("Error getting DRM Display\n");
return 0;
}
if (!eglInitialize(e->egl.e_display, &major, &minor)) {
printf("Error initializing display\n");
return 0;
}
eglBindAPI(EGL_OPENGL_ES_API);
//eglBindAPI(EGL_OPENGL_API);
e->egl.e_context = eglCreateContext(e->egl.e_display, NULL,
EGL_NO_CONTEXT, context_attribs);
if (!e->egl.e_context){
printf("Failed initializing EGLConext\n");
return 0;
}
if (!eglMakeCurrent(e->egl.e_display, EGL_NO_SURFACE,
EGL_NO_SURFACE,e->egl.e_context)){
printf("Error on eglMakeCurrent\n");
return 0;
}
return 1;
}
int init_mode(struct engine *e)
{
drmModeRes *resources;
drmModeConnector *connector;
drmModeModeInfo *mode;
int i,res;
unsigned int stride, handle,fb_id[2];
uint32_t buff_size;
EGLImageKHR image[2];
EGLint attribs[] = {
EGL_WIDTH,0,
EGL_HEIGHT,0,
EGL_DRM_BUFFER_FORMAT_MESA,EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
EGL_DRM_BUFFER_USE_MESA,EGL_DRM_BUFFER_USE_SCANOUT_MESA,
EGL_NONE
};
resources = drmModeGetResources(e->fd);
if (!resources) {
printf("Error getting DRM resouces\n");
return 0;
}
for (i=0; i < resources->count_connectors; i++){
connector = drmModeGetConnector(e->fd,resources->connectors[i]);
if (!connector){
printf("Error getting drm connector with i=0\n");
continue;
}
if (!connector->count_modes) {
printf("No modes found!!\n");
continue;
}
if ( (connector!=NULL) && connector->count_modes > 0){
printf("Mode found on connector i=%d, id=%d\n",i, connector->connector_id);
break;
}
}
mode=&(connector->modes[0]);
handle=0;
stride = (mode->hdisplay + 63) & -64;
buff_size = stride * mode->hdisplay;
attribs[1] = mode->hdisplay; // WIDTH
attribs[3] = mode->vdisplay; // HEIGHT
glGenFramebuffers(1,&e->fbo);
glBindFramebuffer(GL_FRAMEBUFFER,e->fbo);
glGenRenderbuffers(2,&e->rbo);
for(i=0;i<2;i++){
glBindRenderbuffer(GL_RENDERBUFFER,e->rbo[i]);
image[i] = (EGLImageKHR) eglCreateDRMImageMESA(e->egl.e_display, &attribs);
glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, image[i]);
eglExportDRMImageMESA(e->egl.e_display, image[i], NULL, &handle, &stride);
res=drmModeAddFB(e->fd,
mode->hdisplay,mode->vdisplay,
32,32,stride, handle, &fb_id[i]);
if (res) {
printf("failed adding FB i=%d\n",i);
exit(-1);
}
}
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, e->rbo[0]);
res=drmModeSetCrtc(e->fd,(int)5,
fb_id[0 ^1] ,0 ,0,
&connector->connector_id, 1, mode);
if (res){
printf("error setting mode\n");
return -1;
}
return 1;
}
void draw_scene(struct engine *c){
glViewport(0, 0, 1024, 758);
glClear(GL_COLOR_BUFFER_BIT);
}
int main(int argc, char **argv)
{
struct engine e;
// TODO
//get udev device..
e.fd = open(DEV_PATH,O_RDWR);
if (!e.fd){
printf("Could not open graphic device %s\n",DEV_PATH);
return -1;
}
if (!engine_init_egl(&e)){
printf("Error on init_egl(c)\n");
return -1;
}
if (!init_mode(&e)){
printf("Error on init_mode\n");
return -1;
}
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
while(1){
draw_scene(&e);
}
return 1;
}