---
name: "ggiDBGetNumBuffers"
section: "3ggi"
platform: "linux"
package: "libggi2-dev"
version: "1:2.0.1-2"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/ggiDBGetBuffer/3ggi"
---

# ggiDBGetNumBuffers(3ggi)

Get DirectBuffers from a visual

Part of [ggiDBGetBuffer(3ggi)](/ggiDBGetBuffer/3ggi.md).

## NAME

ggiDBGetNumBuffers, ggiDBGetBuffer - Get DirectBuffers from a visual

## SYNOPSIS

**#include \<ggi/ggi.h\>**

**int ggiDBGetNumBuffers(ggi\_visual\_t** *vis***);**

**const ggi\_directbuffer \*ggiDBGetBuffer(ggi\_visual\_t** *vis***, int** *bufnum***);** .SH "DESCRIPTION"

**ggiDBGetNumBuffers** returns the number of DirectBuffers available to the application. **ggiDBGetBuffer** obtains the DirectBuffer at the specified position.

Use **ggiDBGetBuffer** to obtain the DirectBuffers at 0 to n-1, where n is the number returned by **ggiDBGetNumBuffers**.

Pixel-linear buffers have type==GGI\_DB\_SIMPLE\_PLB \| GGI\_DB\_NORMAL. You're on your own now.

DirectBuffers where **ggiResourceMustAcquire** is true need to be 'acquired' (i.e. locked) before using. An acquire is done by using **ggiResourceAcquire** and is released by calling **ggiResourceRelease**.  (See [**ggiResourceAcquire**(3)](/ggiResourceAcquire/3.md).) Beware that the **read**, **write** and **stride** fields of the DirectBuffer may be changed by an acquire, and that they may be **NULL** or invalid when the DirectBuffer is not acquired.

## RETURN VALUE

**ggiDBGetNumBuffers** returns the number of DirectBuffers available. 0 indicates that no DirectBuffers are available.

**ggiDBGetBuffer** returns a pointer to a DirectBuffer structure.

## EXAMPLES

### HOW TO OBTAIN A DIRECTBUFFER

```
ggi_visual_t	vis;
ggi_mode	mode;
int		i;
/* Framebuffer info */
unsigned char *fbptr[2];
int stride[2];
int numbufs;
mode.frames = 2;	/* Double-buffering */
mode.visible.x = 640;	/* Screen res */
mode.visible.y = 480;
mode.virt.x = GGI_AUTO;	/* Any virtual resolution.  Will usually be set
mode.virt.y = GGI_AUTO;	   to be the same as visible but some targets may
			   have restrictions on virtual size. */
mode.graphtype = GT_8BIT;		/* Depend on 8-bit palette. */
mode.dpp.x = mode.dpp.y = GGI_AUTO;	/* Always 1x1 but we don't care. */
if(ggiInit())
{
	/* Failed to initialize library. Bomb out. */
}
vis = ggiOpen(NULL);
if(!vis)
{
	/* Opening default visual failed, quit. */
}
if(ggiSetMode(vis, &mode))
{
	/* Set mode has failed, should check if suggested mode
	   is o.k. for us, and try the call again. */
}
numbufs = ggiDBGetNumBuffers(vis);
for(i = 0; i < numbufs; i++)
{
	ggi_directbuffer *db;
	int frameno;
	db = ggiDBGetBuffer(vis, i);
	if(!(db->type & GGI_DB_SIMPLE_PLB))
	{
		/* We don't handle anything but simple pixel-linear buffers.
		   Fall back to ggiPutBox() or something. */
		continue;
	}
	frameno = db->frame;
	if(readptr[frameno] != NULL &&
		(db->buffer.plb.pixelformat->flags & GGI_PF_REVERSE_ENDIAN))
	{
		continue;
	}
	fbptr[frameno] = db->write;	/* read == write for simple plbs */
	/* Stride of framebuffer (in bytes). */
	stride[frameno] = db->buffer.plb.stride;
	/* Check pixel format, be portable.... */

```
