Ejemplo n.º 1
0
bool
OSGLContext_osmesa::unSetContext(const OSGLContext_osmesa* context)
{
    bool ret = OSMesaMakeCurrent( context ? context->_imp->ctx : NULL, NULL, 0, 0, 0 ); // detach buffer from context
    OSMesaMakeCurrent(NULL, NULL, 0, 0, 0); // deactivate the context (not really recessary)
    assert(OSMesaGetCurrentContext() == 0);
    return ret;

}
Ejemplo n.º 2
0
int init_osmesa_3Demu(void) 
{
    if (!ctx)
    {
        printf("OSMesaCreateContext failed!\n");
        return false;
    }

    buffer = malloc(256 * 192 * 4);
    if (!buffer)
    {
        printf("Could not allocate enough memory!\n");
        return false;
    }

    if (!OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, 256, 192))
    {
        printf("OSMesaMakeCurrent failed!\n");
        free(buffer);
        return false;
    }

    oglrender_init = osmesa_init;
    oglrender_beginOpenGL = osmesa_beginOpenGL;
    oglrender_endOpenGL = osmesa_endOpenGL;

    return true;
}
Ejemplo n.º 3
0
//
// LLWindowMesaHeadless
//
LLWindowMesaHeadless::LLWindowMesaHeadless(LLWindowCallbacks* callbacks,
                                           const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height,
							 U32 flags,  BOOL fullscreen, BOOL clearBg,
							 BOOL disable_vsync, BOOL use_gl, BOOL ignore_pixel_depth)
	: LLWindow(callbacks, fullscreen, flags)
{
	if (use_gl)
	{
		llinfos << "MESA Init" << llendl;
		mMesaContext = OSMesaCreateContextExt( GL_RGBA, 32, 0, 0, NULL );

		/* Allocate the image buffer */
		mMesaBuffer = new unsigned char [width * height * 4 * MESA_CHANNEL_SIZE];
		llassert(mMesaBuffer);

		gMesaBuffer = (U16*)mMesaBuffer;

		/* Bind the buffer to the context and make it current */
		if (!OSMesaMakeCurrent( mMesaContext, mMesaBuffer, MESA_CHANNEL_TYPE, width, height ))
		{
			llerrs << "MESA: OSMesaMakeCurrent failed!" << llendl;
		}

		llverify(gGLManager.initGL());
	}
}
Ejemplo n.º 4
0
static void makeContextCurrentOSMesa(_GLFWwindow* window)
{
    if (window)
    {
        // Check to see if we need to allocate a new buffer
        if ((window->context.osmesa.buffer == NULL) ||
            (window->osmesa.width != window->context.osmesa.width) ||
            (window->osmesa.height != window->context.osmesa.height))
        {
            free(window->context.osmesa.buffer);

            // Allocate the new buffer (width * height * 8-bit RGBA)
            window->context.osmesa.buffer =
                calloc(4, window->osmesa.width * window->osmesa.height);

            window->context.osmesa.width = window->osmesa.width;
            window->context.osmesa.height = window->osmesa.height;
        }

        if (!OSMesaMakeCurrent(window->context.osmesa.handle,
                            window->context.osmesa.buffer,
                            GL_UNSIGNED_BYTE,
                            window->osmesa.width, window->osmesa.height))
        {
            _glfwInputError(GLFW_PLATFORM_ERROR,
                            "OSMesa: Failed to make context current");
            return;
        }
    }

    _glfwPlatformSetCurrentContext(window);
}
Ejemplo n.º 5
0
GLboolean glewCreateContext (struct createParams* params)
{
  GLenum format = OSMESA_RGBA;
  GLsizei height = OSM_HEIGHT;
  GLsizei width = OSM_WIDTH;
  GLenum type = GL_UNSIGNED_BYTE;
  void * buffer_pointer = (void *)(&(pixels[0]));
  /*
  GLint depthBits = 24;
  GLint stencilBits = 8;
  GLint accumBits = 8;
  OSMesaContext sharelist = NULL;
  */
  (void)(params);

  /*ctx = OSMesaCreateContextExt( format, depthBits, stencilBits, accumBits, sharelist );*/
  ctx = OSMesaCreateContext( format, NULL );
  if (!ctx) {
    return GL_TRUE;
  }
  if (!OSMesaMakeCurrent( ctx, buffer_pointer, type, width, height )) {
    return GL_TRUE;
  }
  return GL_FALSE;
}
Ejemplo n.º 6
0
void main()
{
	unsigned char *data;
	allocDoubleBuffer_vbe();
	
	sys_VBEstart();
	SCREEN =sys_giveSCREEN();
	
    allocDoubleBuffer_vbe();
   	memset(SCREEN, 10, 1024*768*4);
   		
    OSMesaContext gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
	if(!OSMesaMakeCurrent(gl_ctx, DOUBLEBUFFER_vbe, GL_UNSIGNED_BYTE, 1024,768))
		sys_reboot();
		
	OSMesaPixelStore(OSMESA_Y_UP, 0);
	reshape(1024,768);
	
	init();
	
	int i;
	for(i = 0; i < 20000; i++)
	{
		angle += 6;
		draw();
		SwapBuffers_vbe();
	}
	fps(); 
}
Ejemplo n.º 7
0
int init_context(int w, int h)
{
    Width = w;
    Height = h;

   ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
   if (!ctx) {
      printf("OSMesaCreateContext failed!\n");
      return -1;
   }

   buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
   if (!buffer) {
      printf("Alloc image buffer failed!\n");
      return -1;
   }

   if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) {
      printf("OSMesaMakeCurrent failed!\n");
      return -1;
   }


   {
      int z, s, a;
      glGetIntegerv(GL_DEPTH_BITS, &z);
      glGetIntegerv(GL_STENCIL_BITS, &s);
      glGetIntegerv(GL_ACCUM_RED_BITS, &a);
      printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
   }
   return 0;
}
Ejemplo n.º 8
0
void SkMesaGLContext::onPlatformMakeCurrent() const {
    if (fContext) {
        if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage,
                               GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
            SkDebugf("Could not make MESA context current.");
        }
    }
}
void
Renderer3dImpl::set_parameters_low_level()
{
  ctx_ = OSMesaCreateContextExt(OSMESA_RGB, 16, 0, 0, NULL);

  ctx_buffer_ = malloc(width_ * height_ * 3 * sizeof(GLubyte));
  OSMesaMakeCurrent(ctx_, ctx_buffer_, GL_UNSIGNED_BYTE, width_, height_);
}
Ejemplo n.º 10
0
static bool osmesa_ctx_set_video_mode(void *data, unsigned width, unsigned height,
      bool fullscreen)
{
   gfx_ctx_osmesa_data_t *osmesa = (gfx_ctx_osmesa_data_t*)data;
   uint8_t *screen = osmesa->screen;

   (void)fullscreen;

   bool size_changed = (width * height) != (osmesa->width * osmesa->height);

   if (!osmesa->screen || size_changed)
      screen = (uint8_t*)calloc(1, (width * height) * osmesa->pixsize);

   if (!screen)
      return false;

   if (!OSMesaMakeCurrent(osmesa->ctx, screen, GL_UNSIGNED_BYTE, width, height))
   {
      if (screen != osmesa->screen)
         free(screen);

      return false;
   }

   osmesa->width  = width;
   osmesa->height = height;

   if (osmesa->screen && osmesa->screen != screen)
      free(osmesa->screen);

   osmesa->screen = screen;

   if (!osmesa->socket)
   {
#if 0
      unlink(g_osmesa_fifo);
      if (mkfifo(g_osmesa_fifo, 0666) == 0)
      {
         RARCH_WARN("[osmesa]: Please connect the sink to the fifo...\n");
         RARCH_WARN("[osmesa]: Picture size is %ux%u\n", width, height);
         osmesa->socket = open(g_osmesa_fifo, O_WRONLY);

         if (osmesa->socket)
            RARCH_WARN("[osmesa]: Initialized fifo at %s\n", g_osmesa_fifo);
      }

      if (!osmesa->socket || osmesa->socket < 0)
      {
         unlink(g_osmesa_fifo);
         RARCH_WARN("[osmesa]: Failed to initialize fifo: %s\n", strerror(errno));
      }
#endif
      osmesa_fifo_open(osmesa);
   }

   return true;
}
Ejemplo n.º 11
0
int resize(gfx_context_t * ctx, OSMesaContext gl_ctx) {

	if (!OSMesaMakeCurrent(gl_ctx, ctx->backbuffer, GL_UNSIGNED_BYTE, ctx->width, ctx->height))
		return 1;

	OSMesaPixelStore(OSMESA_Y_UP, 0);

	reshape(ctx->width, ctx->height);
	return 0;
}
Ejemplo n.º 12
0
OSMesaContext init_osmesa(int width, int height, void *buffer) {
    OSMesaContext ctx = OSMesaCreateContextExt(OSMESA_RGBA, 16, 0, 0, NULL);
    if (!ctx) {
        fprintf(stderr, "ERROR: OSMesaCreateContext failed");
    } else if (!OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, width, height)) {
        fprintf(stderr, "ERROR: OSMesaMakeCurrent failed");
        OSMesaDestroyContext(ctx);
        ctx = NULL;
    }

    return ctx;
}
Ejemplo n.º 13
0
bool
OSGLContext_osmesa::makeContextCurrent(const OSGLContext_osmesa* context,
                                       int type,
                                       int width,
                                       int height,
                                       int rowWidth,
                                       void* buffer)
{
    bool ret = OSMesaMakeCurrent( context ? context->_imp->ctx : 0, buffer, type, width, height );
    OSMesaPixelStore(OSMESA_ROW_LENGTH, rowWidth);
    return ret;
}
Ejemplo n.º 14
0
int get_event() {

    struct ace_event_get_msg        getevent_msg;
    ace_event_t                     ace_event;
    int                             port;
    int                             status;
    int                             charcode;

    /* Send a message to the windows server to get the event */

    while (1) {

        charcode = -1;

        getevent_msg.flags = 0;
        getevent_msg.win_handle = gl_win->handle;
        msg_rpc_port_status(gl_win->connection->port, ACE_EVENT_GET, &getevent_msg, sizeof(getevent_msg), &status, &ace_event, sizeof(ace_event));

        if (status == -1) {
            //anvil_syslog(0, "TERM-SVR: No event\n");
            break;
        }

        switch (ace_event.type) {
            case ACE_EVTYPE_KEY_PRESS:
                //anvil_syslog(0, "TERM-SVR: PRESS\n");
                return ace_event.key.keycode;
                break;
            case ACE_EVTYPE_KEY_RELEASE:
                //anvil_syslog(0, "TERM-SVR: RELEASE\n");
                break;
            case ACE_EVTYPE_SIZE:
                /* Send a size message to the application */
                //anvil_syslog(0, "AwApp: ACE_EVTYPE_SIZE: %d %d\n", ace_event.size.width, ace_event.size.height);
                //doSize(Size(ace_event.size.width, ace_event.size.height));
                width = ace_event.size.width;
                height = ace_event.size.height;
                OSMesaMakeCurrent(gl_ctx, ace_buffer->pixel_buf, GL_UNSIGNED_BYTE, ace_event.size.width, ace_event.size.height);
                reshape(ace_event.size.width, ace_event.size.height);
                memset(ace_buffer->pixel_buf, 0, 700 * 500 * sizeof(uint32_t));
                draw();
                ace_win_update(gl_win, ace_buffer, width, height, width*4);
                break;
        }

        if (status == 0) {
            //anvil_syslog(0, "TERM-SVR: No event %d\n");
            break;
        }
    }

    return 0;
}
Ejemplo n.º 15
0
SkMesaGLContext::SkMesaGLContext()
    : fContext(static_cast<Context>(NULL))
    , fImage(NULL) {
    GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));

    /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
    /* specify Z, stencil, accum sizes */
    fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, NULL);
#else
    fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, NULL);
#endif
    if (!fContext) {
        SkDebugf("OSMesaCreateContext failed!\n");
        this->destroyGLContext();
        return;
    }
    // Allocate the image buffer
    fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
                                           4 * sizeof(GrGLubyte));
    if (!fImage) {
        SkDebugf("Alloc image buffer failed!\n");
        this->destroyGLContext();
        return;
    }

    // Bind the buffer to the context and make it current
    if (!OSMesaMakeCurrent((OSMesaContext)fContext,
                           fImage,
                           GR_GL_UNSIGNED_BYTE,
                           gBOGUS_SIZE,
                           gBOGUS_SIZE)) {
        SkDebugf("OSMesaMakeCurrent failed!\n");
        this->destroyGLContext();
        return;
    }

    SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface());
    if (NULL == gl.get()) {
        SkDebugf("Could not create GL interface!\n");
        this->destroyGLContext();
        return;
    }

    if (!gl->validate()) {
        SkDebugf("Could not validate GL interface!\n");
        this->destroyGLContext();
        return;
    }

    this->init(gl.detach());
}
Ejemplo n.º 16
0
GLboolean glewCreateContext (struct createParams *params)
{
  ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
  if (NULL == ctx) return GL_TRUE;
  if (NULL == osmPixels)
  {
    osmPixels = (GLubyte *) calloc(osmWidth*osmHeight*4, 1);
  }
  if (!OSMesaMakeCurrent(ctx, osmPixels, GL_UNSIGNED_BYTE, osmWidth, osmHeight))
  {
      return GL_TRUE;
  }
  return GL_FALSE;
}
Ejemplo n.º 17
0
GLboolean CreateContext (GLContext* ctx)
{
  GLenum format = OSMESA_RGBA;
  GLsizei height = OSM_HEIGHT;
  GLsizei width = OSM_WIDTH;
  GLenum type = GL_UNSIGNED_BYTE;
  GLubyte pixels[OSM_WIDTH*OSM_HEIGHT*OSM_BYTES_PER_PIXEL];
  void * buffer_pointer = (void *)(&(pixels[0]));
  ctx->ctx = OSMesaCreateContext( format, NULL );
  if (!ctx->ctx) return GL_TRUE;
  if (!OSMesaMakeCurrent( ctx->ctx, buffer_pointer, type, width, height )) {
    return GL_TRUE;
  }
  return GL_FALSE;
}
Ejemplo n.º 18
0
static GLboolean CreateContext(GLContext* ctx)
{
	if (NULL == ctx) return GL_TRUE;
	ctx->ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
	if (NULL == ctx->ctx) return GL_TRUE;
	if (NULL == osmPixels)
	{
		osmPixels = (GLubyte *)calloc(osmWidth*osmHeight * 4, 1);
	}
	if (!OSMesaMakeCurrent(ctx->ctx, osmPixels, GL_UNSIGNED_BYTE, osmWidth, osmHeight))
	{
		return GL_TRUE;
	}
	return GL_FALSE;
}
void vtkOSMesaRenderWindow::MakeCurrent()
{
  TraceBegin("vtkOSMesaRenderWindow::MakeCurrent");

  if (this->Internal->OffScreenContextId) 
    {
    if (OSMesaMakeCurrent(this->Internal->OffScreenContextId, 
                          this->Internal->OffScreenWindow, GL_UNSIGNED_BYTE, 
                          this->Size[0], this->Size[1]) != GL_TRUE) 
      {
      vtkWarningMacro("failed call to OSMesaMakeCurrent");
      }
    }

  TraceEnd("vtkOSMesaRenderWindow::MakeCurrent");
}
Ejemplo n.º 20
0
GLboolean
DMesaMakeCurrent (DMesaContext dmesa, DMesaBuffer buffer)
{
    if (dmesa == NULL || buffer == NULL) {
	ctx = NULL;
	return GL_TRUE;
    }
    if (OSMesaMakeCurrent(dmesa->osmesa, buffer->the_window,
			  buffer->type,
			  buffer->width, buffer->height) &&
	vl_sync_buffer(&buffer->the_window, buffer->xpos, buffer->ypos, buffer->width, buffer->height) == 0) {
	OSMesaPixelStore(OSMESA_Y_UP, GL_FALSE);
	dmesa->buffer = buffer;
	ctx = dmesa;
	return GL_TRUE;
    }
    return GL_FALSE;
}
Ejemplo n.º 21
0
CAMLprim value
ml_osmesamakecurrent( value ctx, value buffer_ba, value _type,
                      value width, value height )
{
    GLenum type;
    GLboolean ret;
    void *buffer;
    buffer = (void *) Data_bigarray_val(buffer_ba);

    if (Int_val(_type) != 0) caml_invalid_argument("OSMesaMakeCurrent");
    type = GL_UNSIGNED_BYTE;

    ret = OSMesaMakeCurrent( (OSMesaContext) ctx, buffer, type,
                             Int_val(width), Int_val(height) );

    if (!ret) caml_failwith("OSMesaMakeCurrent");

    return Val_unit;
}
Ejemplo n.º 22
0
const GrGLInterface* SkMesaGLContext::createGLContext() {
    /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
    /* specify Z, stencil, accum sizes */
    fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, NULL);
#else
    fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, NULL);
#endif
    if (!fContext) {
        SkDebugf("OSMesaCreateContext failed!\n");
        this->destroyGLContext();
        return NULL;
    }
    // Allocate the image buffer
    fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
                                           4 * sizeof(GrGLubyte));
    if (!fImage) {
        SkDebugf("Alloc image buffer failed!\n");
        this->destroyGLContext();
        return NULL;
    }
    
    // Bind the buffer to the context and make it current
    if (!OSMesaMakeCurrent((OSMesaContext)fContext, 
                           fImage, 
                           GR_GL_UNSIGNED_BYTE, 
                           gBOGUS_SIZE, 
                           gBOGUS_SIZE)) {
        SkDebugf("OSMesaMakeCurrent failed!\n");
        this->destroyGLContext();
        return NULL;
    }
    
    const GrGLInterface* interface = GrGLCreateMesaInterface();
    if (!interface) {
        SkDebugf("Could not create GL interface!\n");
        this->destroyGLContext();
        return NULL;
    }
    return interface;
    
}
Ejemplo n.º 23
0
    static sk_sp<GrContext> create_grcontext() {
        // We just leak the OSMesaContext... the process will die soon anyway.
        if (OSMesaContext osMesaContext = OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr)) {
            static uint32_t buffer[16 * 16];
            OSMesaMakeCurrent(osMesaContext, &buffer, GL_UNSIGNED_BYTE, 16, 16);
        }

        auto osmesa_get = [](void* ctx, const char name[]) {
            SkASSERT(nullptr == ctx);
            SkASSERT(OSMesaGetCurrentContext());
            return OSMesaGetProcAddress(name);
        };
        sk_sp<const GrGLInterface> mesa(GrGLAssembleInterface(nullptr, osmesa_get));
        if (!mesa) {
            return nullptr;
        }
        return sk_sp<GrContext>(GrContext::Create(
                                        kOpenGL_GrBackend,
                                        reinterpret_cast<intptr_t>(mesa.get())));
    }
Ejemplo n.º 24
0
int main(int argc, char** argv){

	{
		PreInitEvent evt;
		evt.argc = argc;
		evt.argv = argv;
		AppEventFunction(evt);
	}

	OSMesaContext ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
	
	imgBuffer = (unsigned char*)malloc(width*height*4);
	
	OSMesaMakeCurrent(ctx, imgBuffer, GL_UNSIGNED_BYTE, width, height);
	
	InitGlExts();

	AppEventFunction(PostInitEvent());
	
	bool success = true;
	{
		UpdateEvent evt;
		evt.shouldContinue = &success;
		AppEventFunction(evt);
	}

	if (!success){
		AppEventFunction(ShutDownEvent());
		OSMesaDestroyContext(ctx);
		free(imgBuffer);

		return -1;
	}

	AppEventFunction(ShutDownEvent());
	OSMesaDestroyContext(ctx);
	free(imgBuffer);
	
	return 0;
}
Ejemplo n.º 25
0
int main(int argc, char *argv[])
{
   int Width  = 384;
   int Height = 384;

    OSMesaContext ctx;
    void *buffer;
    char *filename = NULL;
    int ev;
    int repeat=1;

   /* Create an RGBA-mode context */
   /* specify Z, stencil, accum sizes */

    ctx = OSMesaCreateContextExt( OSMESA_BGRA, 16, 0, 0, NULL );
    if (!ctx) {
        printf("OSMesaCreateContext failed!\n");
        return 0;
    }

   /* Allocate the image buffer */
    buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
    if (!buffer) {
        printf("Alloc image buffer failed!\n");
        return 0;
    }

   /* Bind the buffer to the context and make it current */
   if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) {
      printf("OSMesaMakeCurrent failed!\n");
      return 0;
   }

   {
      int z, s, a;
      glGetIntegerv(GL_DEPTH_BITS, &z);
      glGetIntegerv(GL_STENCIL_BITS, &s);
      glGetIntegerv(GL_ACCUM_RED_BITS, &a);
      printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
   }

    reshape(Width, Height);

    glClearColor( 0, 0, 0, 1);

    init();
    draw();

    DrawWindow(10, 10, Width+TYPE_3_BORDER_WIDTH*2, Height+TYPE_3_BORDER_WIDTH+get_skin_height(),
               "OpenGL Engine Demo", 0x000000, 0x74);
    Blit(buffer, TYPE_3_BORDER_WIDTH, get_skin_height(), 0, 0, Width, Height, Width,Height,Width*4);

    int start = time_now();
    int frames = 0;

    while(repeat)
    {
        int now = time_now();
        oskey_t   key;

        ev = check_os_event();
        switch(ev)
        {
            case 1:
                DrawWindow(0,0,0,0, NULL, 0x000000,0x74);
                break;

            case 2:
                key = get_key();
                keyboard(key.code);
                break;

            case 3:
                if(get_os_button()==1)
                    repeat=0;
                    continue;
        };

        if (now - start >= 5000)
        {
            double elapsed = (double) (now - start) / 1000.0;

            printf("%d frames in %3.1f seconds = %6.3f FPS\n",
                    frames, elapsed, frames / elapsed);
            fflush(stdout);

            start = now;
            frames = 0;
        }

        idle();
        draw();
        glFlush();
        Blit(buffer, TYPE_3_BORDER_WIDTH, get_skin_height(), 0, 0, Width, Height, Width,Height,Width*4);
        frames++;
    };

   /* free the image buffer */
   free( buffer );

   /* destroy the context */
   OSMesaDestroyContext( ctx );

   return 0;
}
Ejemplo n.º 26
0
int main(int argc, char *argv[]) {

    int             ret;
    int             cnt;
    struct timespec tsp;
    long            next_frame;


    gl_ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);

    ace_connection = ace_connect("GlxGears");
    width = 400;
    height = 300;
    gl_win = ace_win_create(ace_connection, 1, 0, 0);
    ace_buffer = ace_buffer_create(ace_connection, 1024 * 768 * sizeof(uint32_t));
    //ace_win_clear(gl_win, 0x000000);
    //ace_buffer_damage(gl_win, ace_buffer, -1, -1, -1, -1, -1);

    ace_win_update(gl_win, ace_buffer, width, height, width*4);
    ace_win_show(gl_win);

    ret = OSMesaMakeCurrent(gl_ctx, ace_buffer->pixel_buf, GL_UNSIGNED_BYTE, width, height);
    OSMesaPixelStore( OSMESA_Y_UP , GL_FALSE );
    reshape(width, height);

    init();

    clock_gettime(CLOCK_REALTIME, &tsp);
    next_frame = TIMESPEC_TO_TICK(&tsp);
    while (1) {
        //ace_win_clear(gl_win, 0x80000000);
        memset(ace_buffer->pixel_buf, 0, 1024 * 768 * sizeof(uint32_t));
        draw();
        /* Now wait for the next frame time */
        while (1) {
            long    curr_time;
            clock_gettime(CLOCK_REALTIME, &tsp);
            curr_time = TIMESPEC_TO_TICK(&tsp);
            if (curr_time > next_frame)
                break;
            switch (get_event()) {
                case ACE_KEY_RIGHT:
                    view_roty += 0.5;
                    break;
                case ACE_KEY_LEFT:
                    view_roty -= 0.5;
                    break;
                case ACE_KEY_UP:
                    view_rotx += 0.5;
                    break;
                case ACE_KEY_DOWN:
                    view_rotx -= 0.5;
                    break;
                default:
                    break;
            }
        }
        ace_win_update(gl_win, ace_buffer, width, height, width);
//        ace_win_damage(gl_win, -1, -1, -1, -1);
        next_frame += 40000000;
        angle += 1;
        clock_gettime(CLOCK_REALTIME, &tsp);
        if (++cnt == 1000) {
            anvil_syslog(0, "TIME %ld %ld\n", tsp.tv_sec, tsp.tv_nsec);
            cnt = 0;
        }
//        usleep(40000);
    }
    anvil_syslog(0, "All done\n");

    while (1)
        sleep(1);
}
Ejemplo n.º 27
0
    int
main(int argc, char *argv[])
{
    OSMesaContext ctx;
    void *buffer;

    if (argc < 3) {
        fprintf(stderr, "Usage:\n");
        fprintf(stderr, "  render modelname pngname [width height] [camx camy camz] [centerx centerz centerz] [upx upy upz] [fovy]\n");
        fprintf(stderr, "Default: width=%d height=%d cam=[%0.4f %0.4f %0.4f] center=[%0.4f %0.4f %0.4f] up=[%0.4f %0.4f %0.4f] fovy=%0.4f\n", Width, Height, camx, camy, camz, centerx, centery, centerz, upx, upy, upz, fovy);
        return 0;
    }

    modelname = argv[1];
    pngname = argv[2];

    if (argc >= 5) {
        Width = atoi(argv[3]);
        Height = atoi(argv[4]);
    }

    if (argc >= 8) {
        camx = atoi(argv[5]);
        camy = atoi(argv[6]);
        camz = atoi(argv[7]);
    }

    if (argc >= 11) {
        centerx = atoi(argv[8]);
        centery = atoi(argv[9]);
        centerz = atoi(argv[10]);
    }

    if (argc >= 14) {
        upx = atoi(argv[11]);
        upy = atoi(argv[12]);
        upz = atoi(argv[13]);
    }
        
    if (argc >= 15) {
        fovy = atoi(argv[14]);
    }

    if (!Import3DFromFile(modelname)) {
        fprintf(stderr, "model cannot be loaded!\n");
        return 0;
    }    

    /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
    /* specify Z, stencil, accum sizes */
    ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
#else
    ctx = OSMesaCreateContext( OSMESA_RGBA, NULL );
#endif
    if (!ctx) {
        printf("OSMesaCreateContext failed!\n");
        return 0;
    }

    /* Allocate the image buffer */
    buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
    if (!buffer) {
        printf("Alloc image buffer failed!\n");
        return 0;
    }

    /* Bind the buffer to the context and make it current */
    if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) {
        printf("OSMesaMakeCurrent failed!\n");
        return 0;
    }

    {
        int z, s, a;
        glGetIntegerv(GL_DEPTH_BITS, &z);
        glGetIntegerv(GL_STENCIL_BITS, &s);
        glGetIntegerv(GL_ACCUM_RED_BITS, &a);
        printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
    }

    InitGL(Width, Height);
    render_image();

    if (pngname != NULL) {
        png::image< png::rgba_pixel > image(Width, Height);
        GLubyte * p_buffer = (GLubyte*)buffer;
        for (png::uint_32 y = 0; y < Height; ++y)
        {
            for (png::uint_32 x = 0; x < Width; ++x)
            {
                png::uint_32 r, g, b, a;
                r = *(p_buffer++);
                g = *(p_buffer++);
                b = *(p_buffer++);
                a = *(p_buffer++);
                image[Height-1-y][x] = png::rgba_pixel(r, g, b, a);
            }
        }
        image.write(pngname);
    }
    else {
        printf("Specify a filename if you want to make an image file\n");
    }

    printf("all done\n");

    /* free the image buffer */
    free( buffer );

    // *** cleanup ***
    textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step)
    textureName.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step)

    if (textureIds)
    {
        delete[] textureIds;
        textureIds = NULL;
    }

    /* destroy the context */
    OSMesaDestroyContext( ctx );

    return 0;
}
Ejemplo n.º 28
0
SkMesaGLContext::AutoContextRestore::~AutoContextRestore() {
    if (NULL != (OSMesaContext)fOldContext) {
        OSMesaMakeCurrent((OSMesaContext)fOldContext, fOldImage, 
                          fOldFormat, fOldWidth, fOldHeight);
    }
}
Ejemplo n.º 29
0
static int
setup(int width, int height)
{
#if USE_OSMESA
    const size_t size = width * height * 4;
    pbuffer = malloc(size);
    memset(pbuffer, 0x21, size);
    context = OSMesaCreateContextExt(GL_RGBA, 24, 0, 0, 0);
    OSMesaMakeCurrent(context, (void *)pbuffer, GL_UNSIGNED_BYTE, width, height);
    return 0;
#elif USE_CGL
    /* OpenGL PBuffer initialization: OSX specific */
    CGLPixelFormatAttribute pfattr[] = {
        kCGLPFAPBuffer,
        (CGLPixelFormatAttribute)0
    };
    CGLPixelFormatObj pixformat;
    GLint npixels;
    int e;

    e = CGLChoosePixelFormat(pfattr, &pixformat, &npixels);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLChoosePixelFormat failed, err %d\n", e);
       return e;
    }
    e = CGLCreateContext(pixformat, 0, &context);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLChoosePixelFormat failed, err %d\n", e);
       return e;
    }
    e = CGLDestroyPixelFormat(pixformat);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLDestroyPixelFormat failed, err %d\n", e);
       return e;
    }
    e = CGLSetCurrentContext(context);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLSetCurrentContext failed, err %d\n", e);
       return e;
    }
    e = CGLCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGB, 0, &pbuffer);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLCreatePBuffer failed, err %d\n", e);
       return e;
    }
    e = CGLSetPBuffer(context, pbuffer, 0, 0, 0);
    if (e != kCGLNoError) {
       fprintf(stderr, "CGLSetPBuffer failed, err %d\n", e);
       return e;
    }
    return (int)kCGLNoError;
#elif USE_GLX
    int result = (-1);
    char *glxversion;
    int screen;
    GLXFBConfig *fbConfigs = NULL;
    GLXFBConfig chosenFBConfig;
    GLXFBConfig fbconfig = 0;
    GLXPbuffer pbuffer = None;
    int nConfigs;
    int fbconfigid;
    int fbAttribs[] = {
       GLX_RENDER_TYPE, GLX_RGBA_BIT,
       GLX_DEPTH_SIZE, 1,
       GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT | GLX_PBUFFER_BIT,
       None
    };
    int pbAttribs[] = {
       GLX_PBUFFER_WIDTH, 0,
       GLX_PBUFFER_HEIGHT, 0,
       GLX_LARGEST_PBUFFER, False,
       GLX_PRESERVED_CONTENTS, False,
       None
    };

    /* Open the X display */
    display = XOpenDisplay(NULL);
    if (!display) {
       fprintf(stderr, "Error: couldn't open default X display.\n");
       goto end;
    }

    /* Get default screen */
    screen = DefaultScreen(display);
    glxversion = (char *) glXGetClientString(display, GLX_VERSION);
    if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4"))) {
       goto end;
    }
    glxversion = (char *) glXQueryServerString(display, screen, GLX_VERSION);
    if (!(strstr(glxversion, "1.3") || strstr(glxversion, "1.4"))) {
       goto end;
    }

    /* Create Pbuffer */
    pbAttribs[1] = width;
    pbAttribs[3] = height;

    fbConfigs = glXChooseFBConfig(display, screen, fbAttribs, &nConfigs);
    if (0 == nConfigs || !fbConfigs) {
       fprintf(stderr, "Error: glxChooseFBConfig failed\n");
       XFree(fbConfigs);
       goto end;
    }
    chosenFBConfig = fbConfigs[0];
    glXGetFBConfigAttrib(display, chosenFBConfig, GLX_FBCONFIG_ID, &fbconfigid);

    /* Create the pbuffer using first fbConfig in the list that works. */
    pbuffer = glXCreatePbuffer(display, chosenFBConfig, pbAttribs);
    if (pbuffer) {
       fbconfig = chosenFBConfig;
    }
    XFree(fbConfigs);
    if (pbuffer == None) {
       fprintf(stderr, "Error: couldn't create pbuffer\n");
       goto end;
    }
    /* Create GLX context */
    context = glXCreateNewContext(display, fbconfig, GLX_RGBA_TYPE, NULL, True);
    if (!context) {
       fprintf(stderr, "Error: Couldn't create GLXContext\n");
       goto end;
    }
    /* Bind context to pbuffer */
    if (!glXMakeCurrent(display, pbuffer, context)) {
       fprintf(stderr, "Error: glXMakeCurrent failed\n");
       goto end;
    }
    result = 0;
end:
    if (fbConfigs)
       XFree(fbConfigs);
    if (display)
       XCloseDisplay(display);
    return result;
#else
    /* TODO: pbuffer initialization */
    return 0;
#endif
}
Ejemplo n.º 30
0
int main( int argc, char *argv[] )
{
   void *buffer;
   int i;
   char *filename = NULL;


   /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
   /* specify Z, stencil, accum sizes */
   OSMesaContext ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
#else
   OSMesaContext ctx = OSMesaCreateContext( OSMESA_RGBA, NULL );
#endif
   if (!ctx) {
      printf("OSMesaCreateContext failed!\n");
      return 0;
   }

   for ( i=1; i<argc; i++ ) {
      if (argv[i][0] != '-') filename = argv[i];
   }

   /* Allocate the image buffer */
   buffer = malloc( WIDTH * HEIGHT * 4 * sizeof(GLubyte) );
   if (!buffer) {
      printf("Alloc image buffer failed!\n");
      return 0;
   }

   /* Bind the buffer to the context and make it current */
   if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, WIDTH, HEIGHT )) {
      printf("OSMesaMakeCurrent failed!\n");
      return 0;
   }
     

   {
      int z, s, a;
      glGetIntegerv(GL_DEPTH_BITS, &z);
      glGetIntegerv(GL_STENCIL_BITS, &s);
      glGetIntegerv(GL_ACCUM_RED_BITS, &a);
      printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
   }

  InitGL();
  RenderImage();

   if (filename != NULL) {
      write_ppm(filename, (GLubyte*)buffer, WIDTH, HEIGHT);
   }
   else {
      printf("Specify a filename (with ppm extension) if you want to make an image file\n");
   }

   printf("all done\n");

   /* free the image buffer */
   free( buffer );

   /* destroy the context */
   OSMesaDestroyContext( ctx );

   return 0;
}