gl-render: still knocking on

git-svn-id: svn://kolibrios.org@4473 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2014-01-18 07:41:36 +00:00
parent cfb22e3303
commit cf77f6abc4

View File

@ -14,8 +14,8 @@
#include <kos32sys.h> #include <kos32sys.h>
#include <pixlib2.h> #include <pixlib2.h>
static EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, EGLImageKHR px_create_image(EGLDisplay display, EGLContext context,
int width, int height, int stride, int name, int depth); int width, int height, int stride, int name);
int main() int main()
{ {
@ -33,7 +33,8 @@ int main()
EGLint config_attribs[32]; EGLint config_attribs[32];
EGLint num_configs, i; EGLint num_configs, i;
GLint list; GLint list;
GLuint *texture; GLuint texture, buffer;
int fd; int fd;
@ -81,7 +82,7 @@ int main()
if (!context) if (!context)
printf("failed to create context"); printf("failed to create context");
gs = gbm_surface_create(gbm, 400, 300, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING); gs = gbm_surface_create(gbm, 1024, 768, GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING);
BeginDraw(); BeginDraw();
@ -101,34 +102,74 @@ int main()
if(fd) if(fd)
{ {
int ret; int ret;
GLenum status;
struct drm_i915_fb_info fb; struct drm_i915_fb_info fb;
struct drm_gem_open open_arg;
memset(&fb, 0, sizeof(fb)); memset(&fb, 0, sizeof(fb));
ret = drmIoctl(fd, SRV_FBINFO, &fb); ret = drmIoctl(fd, SRV_FBINFO, &fb);
if( ret != 0 ) if( ret != 0 )
printf("failed to get framebuffer info\n"); printf("failed to get framebuffer info\n");
memset(&open_arg,0,sizeof(open_arg)); fb_image = px_create_image(dpy,context,fb.width,fb.height,
open_arg.name = fb.name; fb.pitch,fb.name);
ret = drmIoctl(fd,DRM_IOCTL_GEM_OPEN,&open_arg);
if (ret != 0) { printf("fb_image %p\n", fb_image);
printf("Couldn't reference framebuffer handle 0x%08x\n", fb.name);
}
asm volatile ("int3"); asm volatile ("int3");
fb_image = px_create_image(dpy,context,fb.width,fb.height, glGenTextures(1, &texture);
fb.pitch,open_arg.handle,32); glBindTexture(GL_TEXTURE_2D, texture);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,fb_image); glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,fb_image);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glGenFramebuffers(1, &buffer);
glBindFramebuffer(GL_FRAMEBUFFER, buffer);
glFramebufferTexture2D(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, texture,0);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE)
{
const char *str;
switch (status)
{
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
str = "incomplete attachment";
break;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
str = "incomplete/missing attachment";
break;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
str = "incomplete draw buffer";
break;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
str = "incomplete read buffer";
break;
case GL_FRAMEBUFFER_UNSUPPORTED:
str = "unsupported";
break;
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
str = "incomplete multiple";
break;
default:
str = "unknown error";
break;
}
printf("destination is framebuffer incomplete: %s [%#x]\n",
str, status);
}
glViewport(0, 0,fb.width, fb.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
} }
glClearColor( 0, 0, 0, 1); glClearColor( 0, 0, 0, 1);
@ -167,13 +208,6 @@ int main()
glDrawBuffer(GL_BACK); glDrawBuffer(GL_BACK);
glViewport(0, 0, (GLint)400, (GLint)300);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 100.0);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glShadeModel( GL_SMOOTH ); glShadeModel( GL_SMOOTH );
@ -187,12 +221,12 @@ int main()
glFlush(); glFlush();
eglSwapBuffers(dpy, surface); // eglSwapBuffers(dpy, surface);
glFinish(); glFinish();
eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroySurface(dpy, surface); // eglDestroySurface(dpy, surface);
gbm_surface_destroy(gs); // gbm_surface_destroy(gs);
eglDestroyContext(dpy, context); eglDestroyContext(dpy, context);
eglTerminate(dpy); eglTerminate(dpy);
@ -218,8 +252,8 @@ int drmIoctl(int fd, unsigned long request, void *arg)
return call_service(&io); return call_service(&io);
} }
static EGLImageKHR px_create_image(EGLDisplay display, EGLContext context, EGLImageKHR px_create_image(EGLDisplay display, EGLContext context,
int width, int height, int stride, int name, int depth) int width, int height, int stride, int name)
{ {
EGLImageKHR image; EGLImageKHR image;
EGLint attribs[] = { EGLint attribs[] = {
@ -236,12 +270,12 @@ static EGLImageKHR px_create_image(EGLDisplay display, EGLContext context,
attribs[1] = width; attribs[1] = width;
attribs[3] = height; attribs[3] = height;
attribs[5] = stride; attribs[5] = stride;
if (depth != 32 && depth != 24)
return EGL_NO_IMAGE_KHR; printf("%s w:%d :%d pitch:%d handle %d\n", __FUNCTION__,
width, height, stride, name);
image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA, image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA,
(void *) (uintptr_t)name, attribs); (void *) (uintptr_t)name, attribs);
if (image == EGL_NO_IMAGE_KHR)
return EGL_NO_IMAGE_KHR;
return image; return image;
} }