gl-render: knocking on frame buffer object
git-svn-id: svn://kolibrios.org@4472 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
c5b31b6cb2
commit
cfb22e3303
@ -3,12 +3,14 @@
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#define EGL_EGLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
#ifndef GLAPIENTRY
|
||||
#define GLAPIENTRY
|
||||
#endif
|
||||
|
||||
#include "EGL/egl.h"
|
||||
#include "EGL/eglext.h"
|
||||
#include "GL/gl.h"
|
||||
#include "gbm.h"
|
||||
#include <kos32sys.h>
|
||||
|
||||
#include "eglut.h"
|
||||
|
||||
@ -48,7 +50,7 @@ idle(void)
|
||||
|
||||
static void reshape(int width, int height)
|
||||
{
|
||||
asm volatile ("int3");
|
||||
|
||||
/*
|
||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||
|
||||
@ -58,10 +60,11 @@ static void reshape(int width, int height)
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
*/
|
||||
glViewport(0, 0, (GLint) width, (GLint) height);
|
||||
|
||||
GLfloat h = (GLfloat) height / (GLfloat) width;
|
||||
|
||||
glViewport(0, 0, (GLint) width, (GLint) height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
|
||||
@ -102,12 +105,13 @@ main(int argc, char *argv[])
|
||||
eglutReshapeFunc(reshape);
|
||||
eglutDisplayFunc(draw);
|
||||
|
||||
glClearColor( 0, 0, 0, 1.0);
|
||||
glClearColor( 0, 0, 0, 1);
|
||||
|
||||
init();
|
||||
// init();
|
||||
glDrawBuffer(GL_BACK);
|
||||
|
||||
eglutMainLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4,13 +4,19 @@
|
||||
#include <sys/time.h>
|
||||
|
||||
#define EGL_EGLEXT_PROTOTYPES
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include "EGL/egl.h"
|
||||
#include "EGL/eglext.h"
|
||||
#include "GL/gl.h"
|
||||
#include "gbm.h"
|
||||
#include <i915_drm.h>
|
||||
#include <kos32sys.h>
|
||||
#include <pixlib2.h>
|
||||
|
||||
static EGLImageKHR px_create_image(EGLDisplay display, EGLContext context,
|
||||
int width, int height, int stride, int name, int depth);
|
||||
|
||||
int main()
|
||||
{
|
||||
struct gbm_device *gbm;
|
||||
@ -21,11 +27,13 @@ int main()
|
||||
|
||||
EGLContext context;
|
||||
EGLSurface surface;
|
||||
EGLImageKHR fb_image;
|
||||
EGLConfig config;
|
||||
|
||||
EGLint config_attribs[32];
|
||||
EGLint num_configs, i;
|
||||
GLint list;
|
||||
GLuint *texture;
|
||||
|
||||
int fd;
|
||||
|
||||
@ -36,6 +44,8 @@ int main()
|
||||
return 1;
|
||||
};
|
||||
|
||||
init_pixlib(HW_BIT_BLIT);
|
||||
|
||||
dpy = eglGetDisplay((EGLNativeDisplayType)gbm);
|
||||
|
||||
if (!eglInitialize(dpy, &major, &minor))
|
||||
@ -78,6 +88,8 @@ int main()
|
||||
DrawWindow(20, 20, 400+9, 300+24, "gl-render", 0x000000, 0x74);
|
||||
EndDraw();
|
||||
|
||||
sna_create_mask();
|
||||
|
||||
surface = eglCreateWindowSurface(dpy,config, (EGLNativeWindowType)gs, NULL);
|
||||
if (surface == EGL_NO_SURFACE)
|
||||
printf("failed to create surface");
|
||||
@ -85,6 +97,40 @@ int main()
|
||||
if (!eglMakeCurrent(dpy, surface, surface, context))
|
||||
printf("failed to make window current");
|
||||
|
||||
|
||||
if(fd)
|
||||
{
|
||||
int ret;
|
||||
struct drm_i915_fb_info fb;
|
||||
struct drm_gem_open open_arg;
|
||||
|
||||
memset(&fb, 0, sizeof(fb));
|
||||
ret = drmIoctl(fd, SRV_FBINFO, &fb);
|
||||
if( ret != 0 )
|
||||
printf("failed to get framebuffer info\n");
|
||||
|
||||
memset(&open_arg,0,sizeof(open_arg));
|
||||
open_arg.name = fb.name;
|
||||
ret = drmIoctl(fd,DRM_IOCTL_GEM_OPEN,&open_arg);
|
||||
if (ret != 0) {
|
||||
printf("Couldn't reference framebuffer handle 0x%08x\n", fb.name);
|
||||
}
|
||||
|
||||
asm volatile ("int3");
|
||||
|
||||
fb_image = px_create_image(dpy,context,fb.width,fb.height,
|
||||
fb.pitch,open_arg.handle,32);
|
||||
|
||||
glGenTextures(1, texture);
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,fb_image);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
}
|
||||
|
||||
glClearColor( 0, 0, 0, 1);
|
||||
|
||||
list = glGenLists(1);
|
||||
@ -117,19 +163,18 @@ int main()
|
||||
|
||||
glEndList();
|
||||
|
||||
asm volatile ("int3");
|
||||
|
||||
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, 1000.0);
|
||||
glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 100.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
asm volatile ("int3");
|
||||
|
||||
|
||||
// glClear(GL_COLOR_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glShadeModel( GL_SMOOTH );
|
||||
|
||||
@ -141,7 +186,6 @@ int main()
|
||||
glCallList(list);
|
||||
glFlush();
|
||||
|
||||
asm volatile ("int3");
|
||||
|
||||
eglSwapBuffers(dpy, surface);
|
||||
|
||||
@ -156,5 +200,48 @@ int main()
|
||||
{
|
||||
delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int drmIoctl(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
ioctl_t io;
|
||||
|
||||
io.handle = fd;
|
||||
io.io_code = request;
|
||||
io.input = arg;
|
||||
io.inp_size = 64;
|
||||
io.output = NULL;
|
||||
io.out_size = 0;
|
||||
|
||||
return call_service(&io);
|
||||
}
|
||||
|
||||
static EGLImageKHR px_create_image(EGLDisplay display, EGLContext context,
|
||||
int width, int height, int stride, int name, int depth)
|
||||
{
|
||||
EGLImageKHR image;
|
||||
EGLint attribs[] = {
|
||||
EGL_WIDTH, 0,
|
||||
EGL_HEIGHT, 0,
|
||||
EGL_DRM_BUFFER_STRIDE_MESA, 0,
|
||||
EGL_DRM_BUFFER_FORMAT_MESA,
|
||||
EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
|
||||
EGL_DRM_BUFFER_USE_MESA,
|
||||
EGL_DRM_BUFFER_USE_SHARE_MESA |
|
||||
EGL_DRM_BUFFER_USE_SCANOUT_MESA,
|
||||
EGL_NONE
|
||||
};
|
||||
attribs[1] = width;
|
||||
attribs[3] = height;
|
||||
attribs[5] = stride;
|
||||
if (depth != 32 && depth != 24)
|
||||
return EGL_NO_IMAGE_KHR;
|
||||
image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA,
|
||||
(void *) (uintptr_t)name, attribs);
|
||||
if (image == EGL_NO_IMAGE_KHR)
|
||||
return EGL_NO_IMAGE_KHR;
|
||||
|
||||
return image;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user