PCMBuffer.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "../include/PCMBuffer.h"
00030
00031 #include "../include/PCMStringConverter.h"
00032
00033 #include "../include/PCMNode.h"
00034
00035
00036
00037
00038
00039 #include <IL/il.h>
00040 #include <IL/ilu.h>
00041
00042 namespace ParCompMark
00043 {
00044
00045
00046
00047
00048
00049 Buffer::Buffer()
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 {
00063 Except(INVALID_OPERATION_ERROR, "Buffer::Buffer()",
00064 "Default constructor for Squirrel compatibility. Calling this constructor always raises an exception.");
00065 }
00066
00067
00068
00069 Buffer::Buffer(const PCuint & left, const PCuint & top, const PCuint & width,
00070 const PCuint & height, const PCuint & depthFormat, Node * parent):
00071
00072 mParent(parent
00073 )
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 {
00087 mLeft = left;
00088 mTop = top;
00089 mWidth = width;
00090 mHeight = height;
00091 mOwnPointers = true;
00092 mColour = 0;
00093 mDepth = 0;
00094 mDepthFormat = depthFormat;
00095 mOutputRowPixel = 0;
00096 mInitialized = false;
00097
00098 Logger::getInstance()->log(Logger::NOTICE, "Buffer on node `" + mParent->getName() + "\' has been created.");
00099 }
00100
00101
00102
00103 Buffer::~Buffer()
00104 {
00105 if(mInitialized)
00106 finalize();
00107
00108 Logger::getInstance()->log(Logger::NOTICE, "Buffer on node `" + mParent->getName() + "\' has been destroyed.");
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 void Buffer::initialize()
00118 {
00119 mColour = new PCuint[mWidth * mHeight];
00120
00121 switch (mDepthFormat)
00122 {
00123 case PC_PF_Z32I:
00124 mDepth = new PCuint[mWidth * mHeight];
00125 break;
00126 case PC_PF_Z32F:
00127 mDepth = new float[mWidth * mHeight];
00128
00129 break;
00130 default:
00131 Except(INVALID_ENUM_ERROR, "Buffer::initialize()",
00132 "Depth format `" + StringConverter::toString(mDepthFormat) + "\' on node `" +
00133 mParent->getName() + "\' is invalid.");
00134 }
00135
00136 mInitialized = true;
00137
00138 Logger::getInstance()->log(Logger::DEBUG, "Buffer on node `" + mParent->getName() + "\' has been initialized.");
00139 }
00140
00141
00142
00143 void Buffer::finalize()
00144 {
00145 Assert(mInitialized, INVALID_OPERATION_ERROR, "Buffer::finalize()");
00146
00147 freeBuffers();
00148
00149 mInitialized = false;
00150
00151 Logger::getInstance()->log(Logger::DEBUG, "Buffer on node `" + mParent->getName() + "\' has been finalized.");
00152 }
00153
00154
00155
00156 void Buffer::saveToFile(const std::string & filename)
00157 {
00158 ilInit();
00159 iluInit();
00160 ilEnable(IL_FILE_OVERWRITE);
00161
00162
00163 ILuint img;
00164
00165 ilGenImages(1, &img);
00166 ilBindImage(img);
00167
00168
00169 ilTexImage(mWidth,
00170 mHeight,
00171 1,
00172 4,
00173 IL_BGRA,
00174 IL_UNSIGNED_BYTE,
00175 (ILvoid *) mColour
00176 );
00177
00178
00179 ilSaveImage((char *) filename.c_str());
00180
00181
00182 ilDeleteImages(1, &img);
00183 }
00184
00185
00186
00187 void Buffer::freeBuffers()
00188 {
00189 if(mOwnPointers && mColour)
00190 {
00191 delete[]mColour;
00192
00193 mColour = 0;
00194 }
00195
00196 if(mOwnPointers && mDepth)
00197 {
00198 switch (mDepthFormat)
00199 {
00200 case PC_PF_Z32I:
00201 delete[](PCuint *) mDepth;
00202 break;
00203 case PC_PF_Z32F:
00204 delete[](float *) mDepth;
00205
00206 break;
00207 default:
00208 Except(INTERNAL_ERROR, "Buffer::finalize()",
00209 "Something has changed depth format on node `" + mParent->getName() +
00210 "\' to invalid value: `" + StringConverter::toString(mDepthFormat) + "\' .");
00211 }
00212 mDepth = 0;
00213 }
00214 }
00215
00216
00217
00218 }