Added osg::Image::AllocationMode enum and associated set/get methods.

osg::Image::setImage has also been modified to require the AllocationMode
mode to be passed to it so that it knows how to delete the data once the
image goes out of scope.

Port the image plugins across to specify the new AllocationMode, and converted
them across to using new/delete in place of malloc/free.
This commit is contained in:
Robert Osfield 2003-02-25 11:56:18 +00:00
parent 7877c55770
commit b32c8c65f3
13 changed files with 162 additions and 101 deletions

View File

@ -0,0 +1,15 @@
TOPDIR = ../..
include $(TOPDIR)/Make/makedefs
CXXFILES =\
osgstereoimage.cpp\
LIBS += -losgProducer -lProducer $(OSG_LIBS) -L/usr/local/lib $(FREETYPE_LIB) $(GLUT_LIB) $(GL_LIBS) $(X_LIBS) $(OTHER_LIBS)
INSTFILES = \
$(CXXFILES)\
Makefile.inst=Makefile
EXEC = osgstereoimage
include $(TOPDIR)/Make/makerules

View File

@ -64,6 +64,19 @@ class SG_EXPORT Image : public Object
inline const std::string& getFileName() const { return _fileName; }
enum AllocationMode {
NO_DELETE,
USE_NEW_DELETE,
USE_MALLOC_FREE
};
/** Set the method used for deleting data once it goes out of scope.*/
void setAllocationMode(AllocationMode mode) { _allocationMode = mode; }
/** Get the method used for deleting data once it goes out of scope.*/
AllocationMode setAllocationMode() const { return _allocationMode; }
/* allocated a pixel block of specified size and type.*/
void allocateImage(int s,int t,int r,
GLenum format,GLenum type,
@ -80,6 +93,7 @@ class SG_EXPORT Image : public Object
GLint internalTextureformat,
GLenum format,GLenum type,
unsigned char *data,
AllocationMode mode,
int packing=1);
/** readPixels from screen at specified position and size, using glReadPixels.
@ -220,12 +234,19 @@ class SG_EXPORT Image : public Object
Image& operator = (const Image&) { return *this; }
std::string _fileName;
int _s, _t, _r;
GLint _internalTextureFormat;
GLenum _pixelFormat;
GLenum _dataType;
unsigned int _packing;
AllocationMode _allocationMode;
unsigned char *_data;
void deallocateData();
void setData(unsigned char *data,AllocationMode allocationMode);
unsigned int _modifiedTag;

View File

@ -34,7 +34,8 @@ Image::Image()
_dataType = (unsigned int)0;
_packing = 4;
_data = (unsigned char *)0L;
_allocationMode = USE_NEW_DELETE;
_data = (unsigned char *)0L;
_modifiedTag = 0;
}
@ -60,7 +61,7 @@ Image::Image(const Image& image,const CopyOp& copyop):
_pixelFormat == GL_RGBA ? 4 : 4;
int size = _s*_t*_r*num_components;
_data = (unsigned char*) malloc(size);
setData(new unsigned char [size],USE_NEW_DELETE);
memcpy(_data,image._data,size);
}
@ -68,15 +69,30 @@ Image::Image(const Image& image,const CopyOp& copyop):
Image::~Image()
{
if (_data) ::free(_data);
deallocateData();
}
void Image::deallocateData()
{
if (_data) {
if (_allocationMode==USE_NEW_DELETE) delete [] _data;
else if (_allocationMode==USE_MALLOC_FREE) ::free(_data);
_data = 0;
}
}
void Image::setFileName(const std::string& fileName)
{
_fileName = fileName;
}
void Image::setData(unsigned char* data, AllocationMode mode)
{
deallocateData();
_data = data;
_allocationMode = mode;
}
bool Image::isPackedType(GLenum type)
{
@ -214,12 +230,10 @@ void Image::allocateImage(int s,int t,int r,
if (newTotalSize!=previousTotalSize)
{
if (_data) ::free(_data);
if (newTotalSize)
_data = (unsigned char *)malloc (newTotalSize);
setData(new unsigned char [newTotalSize],USE_NEW_DELETE);
else
_data = 0L;
deallocateData(); // and sets it to NULL.
}
if (_data)
@ -251,9 +265,9 @@ void Image::setImage(int s,int t,int r,
GLint internalTextureFormat,
GLenum format,GLenum type,
unsigned char *data,
AllocationMode mode,
int packing)
{
if (_data) ::free(_data);
_mipmapData.clear();
_s = s;
@ -264,12 +278,10 @@ void Image::setImage(int s,int t,int r,
_pixelFormat = format;
_dataType = type;
_data = data;
setData(data,mode);
_packing = packing;
// test scaling...
// scaleImageTo(16,16,_r);
++_modifiedTag;
}
@ -306,7 +318,7 @@ void Image::scaleImage(int s,int t,int r)
unsigned int newTotalSize = computeRowWidthInBytes(s,_pixelFormat,_dataType,_packing)*t;
// need to sort out what size to really use...
unsigned char* newData = (unsigned char *)malloc(newTotalSize);
unsigned char* newData = new unsigned char [newTotalSize];
if (!newData)
{
// should we throw an exception??? Just return for time being.
@ -331,15 +343,13 @@ void Image::scaleImage(int s,int t,int r)
{
// free old image.
::free(_data);
_s = s;
_t = t;
_data = newData;
setData(newData,USE_NEW_DELETE);
}
else
{
::free(newData);
delete [] newData;
notify(WARN) << "Error Image::scaleImage() do not succeed : errorString = "<<gluErrorString((GLenum)status)<<std::endl;
}
@ -448,7 +458,7 @@ void Image::flipVertical(int image)
unsigned char* imageData = _data+image*imageSizeInBytes;
// make temp. buffer for one image
unsigned char *tmpData = (unsigned char*) malloc(imageSizeInBytes);
unsigned char *tmpData = new unsigned char [imageSizeInBytes];
for (int t=0; t<_t; ++t)
{
@ -460,7 +470,8 @@ void Image::flipVertical(int image)
// insert fliped image
memcpy(imageData, tmpData, imageSizeInBytes);
free(tmpData);
delete [] tmpData;
++_modifiedTag;
}

View File

@ -210,7 +210,7 @@ int *numComponents_ret)
int ncpal=4; // default number of colours per palette entry
size -= sizeof(bmpheader)+infsize;
if (inf.ImageSize<size) inf.ImageSize=size;
imbuff = (unsigned char *)malloc( inf.ImageSize); // read from disk
imbuff = new unsigned char [ inf.ImageSize]; // read from disk
fread((char *)imbuff, sizeof(unsigned char),inf.ImageSize, fp);
ncolours=inf.Colorbits/8;
switch (ncolours) {
@ -234,8 +234,9 @@ int *numComponents_ret)
if (infsize==12 || infsize==64) ncpal=3; // OS2 - uses 3 colours per palette entry
else ncpal=4; // Windoze uses 4!
}
if (ncomp>0) buffer = (unsigned char *)malloc( (ncomp==BW?3:ncomp)*inf.width*inf.height*sizeof(unsigned char)); // to be returned
else buffer = (unsigned char *)malloc( 3*inf.width*inf.height*sizeof(unsigned char)); // default full colour to be returned
if (ncomp>0) buffer = new unsigned char [(ncomp==BW?3:ncomp)*inf.width*inf.height]; // to be returned
else buffer = new unsigned char [ 3*inf.width*inf.height]; // default full colour to be returned
unsigned long off=0;
unsigned long rowbytes=ncomp*sizeof(unsigned char)*inf.width;
@ -271,7 +272,7 @@ int *numComponents_ret)
}
}
}
free(imbuff); // free the on-disk storage
delete [] imbuff; // free the on-disk storage
fclose(fp);
@ -342,7 +343,8 @@ class ReaderWriterBMP : public osgDB::ReaderWriter
internalFormat,
pixelFormat,
dataType,
imageData);
imageData,
osg::Image::USE_NEW_DELETE);
return pOsgImage;

View File

@ -163,17 +163,17 @@ int *numComponents_ret)
transparent = -1; /* no transparent color by default */
n = giffile->SHeight * giffile->SWidth;
buffer = (unsigned char *)malloc(n * 4);
buffer = new unsigned char [n * 4];
if (!buffer)
{
giferror = ERR_MEM;
return NULL;
}
rowdata = (unsigned char *)malloc(giffile->SWidth);
rowdata = new unsigned char [giffile->SWidth];
if (!rowdata)
{
giferror = ERR_MEM;
free(buffer);
delete [] buffer;
return NULL;
}
@ -208,8 +208,8 @@ int *numComponents_ret)
if (DGifGetRecordType(giffile, &recordtype) == GIF_ERROR)
{
giferror = ERR_READ;
free(buffer);
free(rowdata);
delete [] buffer;
delete [] rowdata;
return NULL;
}
switch (recordtype)
@ -218,8 +218,8 @@ int *numComponents_ret)
if (DGifGetImageDesc(giffile) == GIF_ERROR)
{
giferror = ERR_READ;
free(buffer);
free(rowdata);
delete [] buffer;
delete [] rowdata;
return NULL;
}
/* subimage position in composite image */
@ -232,8 +232,8 @@ int *numComponents_ret)
{
/* image is not confined to screen dimension */
giferror = ERR_READ;
free(buffer);
free(rowdata);
delete [] buffer;
delete [] rowdata;
return NULL;
}
if (giffile->Image.Interlace)
@ -248,8 +248,8 @@ int *numComponents_ret)
if (DGifGetLine(giffile, rowdata, width) == GIF_ERROR)
{
giferror = ERR_READ;
free(buffer);
free(rowdata);
delete [] buffer;
delete [] rowdata;
return NULL;
}
else decode_row(giffile, buffer, rowdata, col, j, width, transparent);
@ -263,8 +263,8 @@ int *numComponents_ret)
if (DGifGetLine(giffile, rowdata, width) == GIF_ERROR)
{
giferror = ERR_READ;
free(buffer);
free(rowdata);
delete [] buffer;
delete [] rowdata;
return NULL;
}
else decode_row(giffile, buffer, rowdata, col, row, width, transparent);
@ -276,8 +276,8 @@ int *numComponents_ret)
if (DGifGetExtension(giffile, &extcode, &extension) == GIF_ERROR)
{
giferror = ERR_READ;
free(buffer);
free(rowdata);
delete [] buffer;
delete [] rowdata;
return NULL;
}
/* transparent test from the gimp gif-plugin. Open Source rulez! */
@ -291,8 +291,8 @@ int *numComponents_ret)
if (DGifGetExtensionNext(giffile, &extension) == GIF_ERROR)
{
giferror = ERR_READ;
free(buffer);
free(rowdata);
delete [] buffer;
delete [] rowdata;
return NULL;
}
}
@ -305,7 +305,7 @@ int *numComponents_ret)
}
while (recordtype != TERMINATE_RECORD_TYPE);
free(rowdata);
delete [] rowdata;
*width_ret = giffile->SWidth;
*height_ret = giffile->SHeight;
*numComponents_ret = 4;
@ -368,7 +368,8 @@ class ReaderWriterGIF : public osgDB::ReaderWriter
internalFormat,
pixelFormat,
dataType,
imageData);
imageData,
osg::Image::USE_NEW_DELETE);
return pOsgImage;

View File

@ -181,7 +181,7 @@ int *numComponents_ret)
jpegerror = ERR_JPEGLIB;
jpeg_destroy_decompress(&cinfo);
fclose(infile);
if (buffer) free(buffer);
if (buffer) delete [] buffer;
return NULL;
}
/* Now we can initialize the JPEG decompression object. */
@ -235,8 +235,7 @@ int *numComponents_ret)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
width = cinfo.output_width;
height = cinfo.output_height;
buffer = currPtr = (unsigned char*)
malloc(width*height*cinfo.output_components);
buffer = currPtr = new unsigned char [width*height*cinfo.output_components];
/* Step 6: while (scan lines remain to be read) */
/* jpeg_read_scanlines(...); */
@ -340,7 +339,8 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter
internalFormat,
pixelFormat,
dataType,
imageData);
imageData,
osg::Image::USE_NEW_DELETE);
return pOsgImage;

View File

@ -143,8 +143,8 @@ int *numComponents_ret)
picerror = ERROR_READING_PALETTE;
}
tmpbuf = (unsigned char *)malloc(width);
buffer = (unsigned char*) malloc(3*width*height);
tmpbuf = new unsigned char [width];
buffer = new unsigned char [3*width*height];
if (tmpbuf == NULL || buffer == NULL)
{
picerror = ERROR_MEMORY;
@ -160,8 +160,8 @@ int *numComponents_ret)
{
picerror = ERROR_READ_ERROR;
fclose(fp);
if (tmpbuf) free(tmpbuf);
if (buffer) free(buffer);
if (tmpbuf) delete [] tmpbuf;
if (buffer) delete [] buffer;
buffer = NULL;
width = height = 0;
return NULL;
@ -180,6 +180,9 @@ int *numComponents_ret)
*width_ret = width;
*height_ret = height;
*numComponents_ret = format;
if (tmpbuf) delete [] tmpbuf;
return buffer;
}
@ -222,7 +225,8 @@ class ReaderWriterPIC : public osgDB::ReaderWriter
internalFormat,
pixelFormat,
dataType,
imageData);
imageData,
osg::Image::USE_NEW_DELETE);
return pOsgImage;

View File

@ -103,8 +103,8 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
png_read_update_info(png, info);
data = (png_bytep) malloc(png_get_rowbytes(png, info)*height);
row_p = (png_bytep *) malloc(sizeof(png_bytep)*height);
data = (png_bytep) new unsigned char [png_get_rowbytes(png, info)*height];
row_p = new png_bytep [height];
bool StandardOrientation = true;
for (i = 0; i < height; i++)
@ -116,7 +116,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
}
png_read_image(png, row_p);
free(row_p);
delete [] row_p;
int iBitCount=0;
@ -147,7 +147,7 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
png_read_end(png, endinfo);
png_destroy_read_struct(&png, &info, &endinfo);
// free(data);
// delete [] data;
if (fp)
fclose(fp);
@ -163,13 +163,15 @@ class ReaderWriterPNG : public osgDB::ReaderWriter
iBitCount / 8,// int internalFormat,
GL_RGB, // unsigned int pixelFormat
GL_UNSIGNED_BYTE,// unsigned int dataType
data);
data,
osg::Image::USE_NEW_DELETE);
else
pOsgImage->setImage(width, height, 1,
iBitCount / 8,// int internalFormat,
GL_RGBA, // unsigned int pixelFormat
GL_UNSIGNED_BYTE,// unsigned int dataType
data);
data,
osg::Image::USE_NEW_DELETE);
return pOsgImage;
}
};

View File

@ -87,16 +87,16 @@ static void RawImageClose(rawImageRec *raw)
{
fclose(raw->file);
if (raw->tmp) free(raw->tmp);
if (raw->tmpR) free(raw->tmpR);
if (raw->tmpG) free(raw->tmpG);
if (raw->tmpB) free(raw->tmpB);
if (raw->tmpA) free(raw->tmpA);
if (raw->tmp) delete [] raw->tmp;
if (raw->tmpR) delete [] raw->tmpR;
if (raw->tmpG) delete [] raw->tmpG;
if (raw->tmpB) delete [] raw->tmpB;
if (raw->tmpA) delete [] raw->tmpA;
if (raw->rowStart) free(raw->rowStart);
if (raw->rowSize) free(raw->rowSize);
if (raw->rowStart) delete [] raw->rowStart;
if (raw->rowSize) delete [] raw->rowSize;
free(raw);
delete raw;
}
}
@ -122,7 +122,7 @@ static rawImageRec *RawImageOpen(const char *fileName)
swapFlag = GL_FALSE;
}
raw = (rawImageRec *)malloc(sizeof(rawImageRec));
raw = new rawImageRec;
if (raw == NULL)
{
notify(WARN)<< "Out of memory!"<< std::endl;
@ -130,7 +130,7 @@ static rawImageRec *RawImageOpen(const char *fileName)
}
if ((raw->file = fopen(fileName, "rb")) == NULL)
{
free(raw);
delete raw;
perror(fileName);
return NULL;
}
@ -146,7 +146,7 @@ static rawImageRec *RawImageOpen(const char *fileName)
raw->rowStart = 0;
raw->rowSize = 0;
raw->tmp = (unsigned char *)malloc(raw->sizeX*256);
raw->tmp = new unsigned char [raw->sizeX*256];
if (raw->tmp == NULL )
{
notify(FATAL)<< "Out of memory!"<< std::endl;
@ -156,7 +156,7 @@ static rawImageRec *RawImageOpen(const char *fileName)
if( raw->sizeZ >= 1 )
{
if( (raw->tmpR = (unsigned char *)malloc(raw->sizeX)) == NULL )
if( (raw->tmpR = new unsigned char [raw->sizeX]) == NULL )
{
notify(FATAL)<< "Out of memory!"<< std::endl;
RawImageClose(raw);
@ -165,7 +165,7 @@ static rawImageRec *RawImageOpen(const char *fileName)
}
if( raw->sizeZ >= 2 )
{
if( (raw->tmpG = (unsigned char *)malloc(raw->sizeX)) == NULL )
if( (raw->tmpG = new unsigned char [raw->sizeX]) == NULL )
{
notify(FATAL)<< "Out of memory!"<< std::endl;
RawImageClose(raw);
@ -174,7 +174,7 @@ static rawImageRec *RawImageOpen(const char *fileName)
}
if( raw->sizeZ >= 3 )
{
if( (raw->tmpB = (unsigned char *)malloc(raw->sizeX)) == NULL )
if( (raw->tmpB = new unsigned char [raw->sizeX]) == NULL )
{
notify(FATAL)<< "Out of memory!"<< std::endl;
RawImageClose(raw);
@ -183,7 +183,7 @@ static rawImageRec *RawImageOpen(const char *fileName)
}
if (raw->sizeZ >= 4)
{
if( (raw->tmpA = (unsigned char *)malloc(raw->sizeX)) == NULL )
if( (raw->tmpA = new unsigned char [raw->sizeX]) == NULL )
{
notify(FATAL)<< "Out of memory!"<< std::endl;
RawImageClose(raw);
@ -193,20 +193,21 @@ static rawImageRec *RawImageOpen(const char *fileName)
if ((raw->type & 0xFF00) == 0x0100)
{
x = raw->sizeY * raw->sizeZ * sizeof(GLuint);
if ( (raw->rowStart = (GLuint *)malloc(x)) == NULL )
unsigned int ybyz = raw->sizeY * raw->sizeZ;
if ( (raw->rowStart = new GLuint [ybyz]) == NULL )
{
notify(FATAL)<< "Out of memory!"<< std::endl;
RawImageClose(raw);
return NULL;
}
if ( (raw->rowSize = (GLint *)malloc(x)) == NULL )
if ( (raw->rowSize = new GLint [ybyz]) == NULL )
{
notify(FATAL)<< "Out of memory!"<< std::endl;
RawImageClose(raw);
return NULL;
}
x = ybyz * sizeof(GLuint);
raw->rleEnd = 512 + (2 * x);
fseek(raw->file, 512, SEEK_SET);
fread(raw->rowStart, 1, x, raw->file);
@ -278,8 +279,8 @@ static void RawImageGetData(rawImageRec *raw, unsigned char **data )
// int width = (int)(floorf((float)raw->sizeX/4.0f)*4.0f);
// if (width!=raw->sizeX) width += 4;
*data = (unsigned char *)malloc(2 * (raw->sizeX+1)*(raw->sizeY+1)*4);
// *data = (unsigned char *)malloc(2 * (width+1)*(raw->sizeY+1)*4);
// byte aligned.
*data = new unsigned char [(raw->sizeX)*(raw->sizeY)*(raw->sizeZ)];
ptr = *data;
for (i = 0; i < (int)(raw->sizeY); i++)
@ -364,7 +365,8 @@ class ReaderWriterRGB : public osgDB::ReaderWriter
internalFormat,
pixelFormat,
dataType,
data);
data,
osg::Image::USE_NEW_DELETE);
notify(INFO) << "image read ok "<<s<<" "<<t<< std::endl;
return image;

View File

@ -307,7 +307,7 @@ int *numComponents_ret)
{
int len = getInt16(&header[5]);
indexsize = header[7]>>3;
colormap = (unsigned char *)malloc(len*indexsize);
colormap = new unsigned char [len*indexsize];
fread(colormap, 1, len*indexsize, fp);
}
@ -324,10 +324,10 @@ int *numComponents_ret)
rleIsCompressed = 0;
rleRemaining = 0;
rleEntrySize = depth;
buffer = (unsigned char*)malloc(width*height*format);
buffer = new unsigned char [width*height*format];
dest = buffer;
bpr = format * width;
linebuf = (unsigned char *)malloc(width*depth);
linebuf = new unsigned char [width*depth];
//check the intended image orientation
bool bLeftToRight = (flags&0x10)==0;
@ -383,7 +383,7 @@ int *numComponents_ret)
fseek(fp, 0, SEEK_END);
size = ftell(fp) - pos;
fseek(fp, pos, SEEK_SET);
buf = (unsigned char *)malloc(size);
buf = new unsigned char [size];
if (buf == NULL)
{
tgaerror = ERR_MEM;
@ -406,19 +406,19 @@ int *numComponents_ret)
}
dest += lineoffset;
}
if (buf) free(buf);
if (buf) delete [] buf;
}
break;
default:
tgaerror = ERR_UNSUPPORTED;
}
if (linebuf) free(linebuf);
if (linebuf) delete [] linebuf;
fclose(fp);
if (tgaerror)
{
if (buffer) free(buffer);
if (buffer) delete [] buffer;
return NULL;
}
@ -509,7 +509,8 @@ class ReaderWriterTGA : public osgDB::ReaderWriter
internalFormat,
pixelFormat,
dataType,
imageData);
imageData,
osg::Image::USE_NEW_DELETE);
return pOsgImage;

View File

@ -275,7 +275,7 @@ int *numComponents_ret)
else
format = 3;
buffer = (unsigned char*)malloc(w*h*format);
buffer = new unsigned char [w*h*format];
if (!buffer)
{
@ -298,7 +298,7 @@ int *numComponents_ret)
case pack(PHOTOMETRIC_MINISWHITE, PLANARCONFIG_SEPARATE):
case pack(PHOTOMETRIC_MINISBLACK, PLANARCONFIG_SEPARATE):
inbuf = (unsigned char *)malloc(TIFFScanlineSize(in));
inbuf = new unsigned char [TIFFScanlineSize(in)];
for (row = 0; row < h; row++)
{
if (TIFFReadScanline(in, inbuf, row, 0) < 0)
@ -330,7 +330,7 @@ int *numComponents_ret)
}
}
inbuf = (unsigned char *)malloc(TIFFScanlineSize(in));
inbuf = new unsigned char [TIFFScanlineSize(in)];
for (row = 0; row < h; row++)
{
if (TIFFReadScanline(in, inbuf, row, 0) < 0)
@ -344,7 +344,7 @@ int *numComponents_ret)
break;
case pack(PHOTOMETRIC_RGB, PLANARCONFIG_CONTIG):
inbuf = (unsigned char *)malloc(TIFFScanlineSize(in));
inbuf = new unsigned char [TIFFScanlineSize(in)];
for (row = 0; row < h; row++)
{
if (TIFFReadScanline(in, inbuf, row, 0) < 0)
@ -359,7 +359,7 @@ int *numComponents_ret)
case pack(PHOTOMETRIC_RGB, PLANARCONFIG_SEPARATE):
rowsize = TIFFScanlineSize(in);
inbuf = (unsigned char *)malloc(3*rowsize);
inbuf = new unsigned char [3*rowsize];
for (row = 0; !tifferror && row < h; row++)
{
int s;
@ -382,12 +382,12 @@ int *numComponents_ret)
break;
}
if (inbuf) free(inbuf);
if (inbuf) delete [] inbuf;
TIFFClose(in);
if (tifferror)
{
if (buffer) free(buffer);
if (buffer) delete [] buffer;
return NULL;
}
*width_ret = width;
@ -448,7 +448,8 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter
internalFormat,
pixelFormat,
dataType,
imageData);
imageData,
osg::Image::USE_NEW_DELETE);
return pOsgImage;

View File

@ -138,7 +138,7 @@ Texture2D* txp::GetLocalTexture(trpgrImageHelper& image_helper, trpgLocalMateria
{
int32 size = s.x*s.y*depth;
// int32 size = const_cast<trpgTexture*>(tex)->MipLevelSize(1) ;
data = (char *)::malloc(size);
data = new char [size];
if(locmat)
image_helper.GetImageForLocalMat(locmat,data,size);
@ -147,14 +147,14 @@ Texture2D* txp::GetLocalTexture(trpgrImageHelper& image_helper, trpgLocalMateria
image->setImage(s.x,s.y,1,depth,
gltype,GL_UNSIGNED_BYTE,
(unsigned char*)data);
(unsigned char*)data,osg::Image::USE_NEW_DELETE);
}
else
{
int32 size = tex->CalcTotalSize();
trpgTexture* tmp_tex = const_cast<trpgTexture*>(tex);
data = (char *)::malloc(size);
data = new char [size];
if(locmat)
image_helper.GetImageForLocalMat(locmat,data,size);
@ -164,7 +164,8 @@ Texture2D* txp::GetLocalTexture(trpgrImageHelper& image_helper, trpgLocalMateria
// Load entire texture including mipmaps
image->setImage(s.x,s.y,1,depth,
gltype,GL_UNSIGNED_BYTE,
(unsigned char*)data);
(unsigned char*)data,
osg::Image::USE_NEW_DELETE);
// now set mipmap data (offsets into image raw data)
Image::MipmapDataType mipmaps;

View File

@ -22,8 +22,8 @@ CubeMapGenerator::CubeMapGenerator(int texture_size)
for (int i=0; i<6; ++i)
{
osg::ref_ptr<osg::Image> image = new osg::Image;
unsigned char* data = (static_cast<unsigned char *>(malloc(texture_size*texture_size*4)));
image->setImage(texture_size, texture_size, 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, data);
unsigned char* data = new unsigned char [texture_size*texture_size*4];
image->setImage(texture_size, texture_size, 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE);
images_.push_back(image);
}
}