www.pudn.com > GPUVision_5-13-05-2.zip > IndexMtxPos.cpp
#include "IndexMtxPos.h"
using namespace std;
IndexMtxPos::IndexMtxPos(CGcontext context) : MtxOps(context){
_texWidth=1000;//2048;
_texHeight=1000;//1950;
_width=10;//160000;
_height=10;//160000;
_cgFileName="mtx_index_pos.cg";
this->_LoadCgPrograms();
this->_initParameters();
}
IndexMtxPos::~IndexMtxPos(){
}
void IndexMtxPos::_initParameters(){
cgGLEnableProfile(_fragmentProfile);
_textureAParam = cgGetNamedParameter (_fragmentProgram, "texture");
if (_textureAParam == 0) {
printf("Texture param aquisition failed!");
exit (1);
}
cgGLDisableProfile(_fragmentProfile);
}
void IndexMtxPos::execute(GPUVision *outImg, int arg1){
bool res = outImg->IsReset();
bool unBind = false;
if(!outImg->IsBound()) {
outImg->Begin();
unBind = true;
}
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
cgGLBindProgram(_fragmentProgram);
cgGLSetTextureParameter(_textureAParam, arg1);
cgGLEnableTextureParameter(_textureAParam);
cgGLEnableProfile(_fragmentProfile);
_DrawFull(outImg->GetWidth(), outImg->GetHeight());
cgGLDisableTextureParameter(_textureAParam);
cgGLDisableProfile(_fragmentProfile);
outImg->Flip();
if(unBind) {
outImg->End();
}
}
GLfloat* IndexMtxPos::interpreteResult (float *colBuffer) {
GLfloat* ret = (GLfloat*)malloc(_height*_width*3*sizeof(GLfloat));
int i;
for (i=0; i<(_height*_width); i++) {
// red channel is r-Vector
ret[i*3+0] = colBuffer[i*4+0];
ret[i*3+1] = colBuffer[i*4+1];
ret[i*3+2] = colBuffer[i*4+2];
}
delete colBuffer;
return ret;
}
void IndexMtxPos::showResultMtx(GPUVision* gpuVis, int m, int n){
GLfloat* result;
_height=m;
_width=n;
result=interpreteResult(gpuVis->DownloadTexture());
_printOutMtx(result, m, n);
}