www.pudn.com > GPUVision_5-13-05-2.zip > GPUVision.h


 
 
#ifndef _GPUVISION_H 
#define _GPUVISION_H 
 
#include "stdafx.h" 
#include "corona.h" 
#include "RenderTexture.h" 
 
#include  
 
#include  
#include  
 
#include  
#include  
#include  
#include  
#include  
#include  
 
using namespace std; 
using namespace corona; 
 
#define PI      3.141592653589793238462643  
#define E       2.718281828459045534884808 
 
const GLenum glsurf[2] = {GL_FRONT_LEFT, GL_BACK_LEFT}; 
const GLenum wglsurf[2] = {WGL_FRONT_LEFT_ARB, WGL_BACK_LEFT_ARB};  
 
//static CGcontext _CGcontext; 
class GPUVision { 
//public: // enums 
public: // interface 
	GPUVision(const char *strFileName=NULL, bool mipmap = false); 
	GPUVision(unsigned int textureID, int width, int height); 
	GPUVision(float* data, int width, int height, bool mipmap = false); 
    ~GPUVision(); 
 
	void LoadBase(); 
 
	void Begin(); 
	void Begin(GPUVision *currentlyBound); 
	void End(); 
	void Clear(); 
 	void Reset() {  
		_isReset = true;  
//		_packedInto = 1; 
		 
	} 
	void Flip(); 
	void Save(const char *strFileName); 
	void Bind() { _rt->Bind();} 
	void PassThrough(); 
	void PassThrough(unsigned int aTextureID); 
	void RGB2Grey(unsigned int aTextureID); 
	void DisplayCurrent();	// show it in the regular screen 
 
public:  
	bool IsReset() { return _isReset; } 
	bool IsBound() { return _bound; } 
 
	CGcontext GetContext() { return _CGcontext; } 
	int GetWidth() { return _width; } 
	int GetHeight() { return _height; } 
	void CopyRenderedToSource(); 
	void CopyRenderedToTexture(unsigned int textureID); 
	void SetWidth(int value) { _width = value; } 
	void SetHeight(int value) { _height = value; } 
	unsigned int GetRenderedTextureID() {return _rt->GetTextureID();} 
	unsigned int GetTextureID() {return _textureID;} 
	void SetTextureID(int val) {_textureID = val;} 
	float* DownloadTexture(); 
	void ConvertByte2Float(byte* data, int data_pixels, int data_offset, int output_offset, float* output, float fill); 
	RenderTexture* CreateRenderTexture(const char *strMode); 
	void SetData(float* data); 
	void SetData(float* data, int width, int height, unsigned int inputDataFormat, unsigned int textureID); 
	unsigned int UploadToTexture(float *data); 
	unsigned int UploadToTexture(float *data, int width, int height, unsigned int inputDataFormat); 
	unsigned int generateTextureID();//IJ 
	void deleteTextureID(const unsigned int textureID);//IJ 
	void PassThrough(unsigned int aTextureID, bool shouldFlip); //IJ 
	int BackUpToTexture();//IJ 
	GPUVision* Copy(); 
	void DrawIntoCoords(int width, int height){_DrawIntoCoords(width,height); } 
 
//	bool IsNotPacked() { return _packedInto == 4; } 
//	bool Is2Packed() { return _packedInto == 2; } 
//	bool Is4Packed() { return _packedInto == 1; } // not supported now in filters 
//	void SetNotPacked() { _packedInto = 4; } 
//	void Set2Packed() { _packedInto = 2; } 
//	void Set4Packed() { _packedInto = 1; } // not supported now in filters 
 
	// should check some sort of 'dirty' bit to see if  
	// the data in _dataFloats is up to date or is dirty 
	// if dirty, then should automatically download 
	float* GetDataFloats() { return this->_dataFloats; } 
 
protected: 
 
private: // attributes 
 
	CGcontext _CGcontext; 
	CGprofile _fragmentProfile; 
	CGprogram _passThroughTextureProgram; 
	CGparameter _passThroughTextureParam, 
				_passThroughXMultParam; 
 
//	int _packedInto; 
	bool _bound; 
	bool _isReset; 
	bool _mipmapped; 
	unsigned int _width; 
	unsigned int _height; 
	RenderTexture *_rt; 
	float* _dataFloats;  
 
	// index into the glsurf and wglsurf arrays for the front and back buffers 
	// by flip-flopping the two this will ping pong between the actual front  
	// and back buffers 
	int _frontBufferIndex;  
	unsigned int _textureID; 
 
	 
 
private: // methods 
 
	void _ExecutePassThrough(unsigned int aTextureID, bool flip); 
	void _Init(); 
 
	void _DrawFull(); 
	void _DrawIntoCoords(int width, int height); 
 
	// for display purposes we need to flip the image around for 
	// some reason 
	void _DrawFullFlip(); 
	void _ChooseProfiles(); 
	void _LoadCgPrograms(); 
}; 
 
#endif