Commit e08b8265 authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Add ability to retreive an image from a state variable

Although you could easily create a new image using a state buffer, you
could not retreive that image without storing the pointer into another
state buffer. This adds a function named icetRetrieveStateImage to get a
previously allocated image. This simplfies the code some.
parent e82c62d5
......@@ -318,6 +318,12 @@ IceTImage icetGetStateBufferImage(IceTEnum pname,
return icetImageAssignBuffer(buffer, width, height);
}
IceTImage icetRetrieveStateImage(IceTEnum pname)
{
return icetImageUnpackageFromReceive(
(IceTVoid *)icetUnsafeStateGetBuffer(pname));
}
IceTImage icetGetStatePointerImage(IceTEnum pname,
IceTSizeType width,
IceTSizeType height,
......@@ -1245,13 +1251,15 @@ void icetImagePackageForSend(IceTImage image,
IceTImage icetImageUnpackageFromReceive(IceTVoid *buffer)
{
IceTImage image;
IceTEnum magic_number;
IceTEnum color_format, depth_format;
image.opaque_internals = buffer;
/* Check the image for validity. */
if ( ICET_IMAGE_HEADER(image)[ICET_IMAGE_MAGIC_NUM_INDEX]
!= ICET_IMAGE_MAGIC_NUM ) {
magic_number = ICET_IMAGE_HEADER(image)[ICET_IMAGE_MAGIC_NUM_INDEX];
if ( (magic_number != ICET_IMAGE_MAGIC_NUM)
&& (magic_number != ICET_IMAGE_POINTERS_MAGIC_NUM) ) {
icetRaiseError("Invalid image buffer: no magic number.",
ICET_INVALID_VALUE);
image.opaque_internals = NULL;
......@@ -2664,42 +2672,21 @@ static IceTImage renderTile(int tile,
return render_buffer;
}
/* This function is full of hackery. */
static IceTImage getRenderBuffer(void)
{
/* Check to see if we are in the same frame as the last time we returned
this buffer. In that case, just restore the buffer because it still has
the image we need. */
if ( icetStateGetTime(ICET_RENDER_BUFFER_HOLD)
if ( icetStateGetTime(ICET_RENDER_BUFFER)
> icetStateGetTime(ICET_IS_DRAWING_FRAME) ) {
/* A little bit of hackery: this assumes that a buffer initialized is the
same one returned from icetImagePackageForSend. It (currently)
does. */
IceTVoid *buffer;
icetRaiseDebug("Last render should still be good.");
icetGetPointerv(ICET_RENDER_BUFFER_HOLD, &buffer);
return icetImageUnpackageFromReceive(buffer);
return icetRetrieveStateImage(ICET_RENDER_BUFFER);
} else {
IceTInt dim[2];
IceTImage image;
IceTVoid *buffer;
IceTSizeType dummy_size;
icetGetIntegerv(ICET_PHYSICAL_RENDER_WIDTH, &dim[0]);
icetGetIntegerv(ICET_PHYSICAL_RENDER_HEIGHT, &dim[1]);
/* Create a new image object. */
image = icetGetStateBufferImage(ICET_RENDER_BUFFER, dim[0], dim[1]);
/* Record image size and pointer to memory. It is important to "touch"
ICET_RENDER_BUFFER_HOLD to signify the time we created the image so
that the above check works on the next call. */
icetStateSetIntegerv(ICET_RENDER_BUFFER_SIZE, 2, dim);
icetImagePackageForSend(image, &buffer, &dummy_size);
icetStateSetPointer(ICET_RENDER_BUFFER_HOLD, buffer);
return image;
return icetGetStateBufferImage(ICET_RENDER_BUFFER, dim[0], dim[1]);
}
}
......@@ -197,7 +197,6 @@ void icetStateSetDefaults(void)
icetDisable(ICET_RENDER_EMPTY_IMAGES);
icetStateSetBoolean(ICET_IS_DRAWING_FRAME, 0);
icetStateSetBoolean(ICET_RENDER_BUFFER_SIZE, 0);
icetStateSetInteger(ICET_VALID_PIXELS_TILE, -1);
icetStateSetInteger(ICET_VALID_PIXELS_OFFSET, 0);
......@@ -640,6 +639,10 @@ const IceTVoid **icetUnsafeStateGetPointer(IceTEnum pname)
{
return icetUnsafeStateGet(pname, ICET_POINTER);
}
const IceTVoid *icetUnsafeStateGetBuffer(IceTEnum pname)
{
return icetUnsafeStateGet(pname, ICET_VOID);
}
IceTDouble *icetStateAllocateDouble(IceTEnum pname, IceTSizeType num_entries)
{
......@@ -664,16 +667,6 @@ IceTVoid **icetStateAllocatePointer(IceTEnum pname, IceTSizeType num_entries)
IceTVoid *icetGetStateBuffer(IceTEnum pname, IceTSizeType num_bytes)
{
if ( (icetStateGetType(pname) == ICET_VOID)
&& (icetStateGetNumEntries(pname) >= num_bytes) ) {
/* A big enough buffer is already allocated. */
IceTVoid *buffer = icetUnsafeStateGet(pname, ICET_VOID);
#ifdef ICET_STATE_CHECK_MEM
memset(buffer, 0xDC, num_bytes);
#endif
return buffer;
}
/* Check to make sure this state variable has not been used for anything
* besides a buffer. */
if ( (icetStateGetType(pname) != ICET_VOID)
......
......@@ -315,8 +315,6 @@ ICET_EXPORT void icetDiagnostics(IceTBitField mask);
#define ICET_RENDERED_VIEWPORT (ICET_STATE_FRAME_START | (IceTEnum)0x0020)
#define ICET_RENDER_BUFFER (ICET_STATE_FRAME_START | (IceTEnum)0x0021)
#define ICET_RENDER_BUFFER_SIZE (ICET_STATE_FRAME_START | (IceTEnum)0x0022)
#define ICET_RENDER_BUFFER_HOLD (ICET_STATE_FRAME_START | (IceTEnum)0x0023)
#define ICET_TILE_PROJECTIONS (ICET_STATE_FRAME_START | (IceTEnum)0x0024)
#define ICET_STATE_TIMING_START (IceTEnum)0x000000C0
......
......@@ -26,6 +26,7 @@ extern "C" {
ICET_EXPORT IceTImage icetGetStateBufferImage(IceTEnum pname,
IceTSizeType width,
IceTSizeType height);
ICET_EXPORT IceTImage icetRetrieveStateImage(IceTEnum pname);
ICET_EXPORT IceTSizeType icetImageBufferSize(IceTSizeType width,
IceTSizeType height);
ICET_EXPORT IceTSizeType icetImageBufferSizeType(IceTEnum color_format,
......
......@@ -62,6 +62,7 @@ ICET_EXPORT const IceTFloat *icetUnsafeStateGetFloat(IceTEnum pname);
ICET_EXPORT const IceTInt *icetUnsafeStateGetInteger(IceTEnum pname);
ICET_EXPORT const IceTBoolean *icetUnsafeStateGetBoolean(IceTEnum pname);
ICET_EXPORT const IceTVoid **icetUnsafeStateGetPointer(IceTEnum pname);
ICET_EXPORT const IceTVoid *icetUnsafeStateGetBuffer(IceTEnum pname);
ICET_EXPORT IceTDouble *icetStateAllocateDouble(IceTEnum pname,
IceTSizeType num_entries);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment