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
00027
#ifndef SHUBERSTORAGE_HPP
00028
#define SHUBERSTORAGE_HPP
00029
00030
#include "GlBackend.hpp"
00031
#include "ShRefCount.hpp"
00032
#include "ShMemory.hpp"
00033
#include "GlTextureName.hpp"
00034
00035
namespace shgl {
00036
00037
class HostUberTransfer;
00038
class UberStorage :
public SH::ShStorage {
00039
public:
00040 UberStorage(
int context,
00041
SH::ShMemory* memory,
const GlTextureNamePtr& name,
00042
int width,
int height,
int pitch);
00043 ~UberStorage();
00044
00045
void bindAsTexture();
00046
void bindAsAux(
unsigned int n);
00047
void unbind();
00048
00049
enum Binding {
00050 SH_UBER_UNBOUND,
00051 SH_UBER_TEXTURE,
00052 SH_UBER_AUX
00053 };
00054
00055 Binding binding() const;
00056 GlTextureNamePtr textureName() const;
00057
int auxTarget() const;
00058
00059
int width()
const {
return m_width; }
00060
int height()
const {
return m_height; }
00061
int pitch()
const {
return m_pitch; }
00062
int context()
const {
return m_context; }
00063
unsigned int mem()
const {
return m_mem; }
00064
00065 std::string id()
const {
return "uberbuffer"; }
00066
00067
00068
static int temp_fb[4];
00069
static int allocfb(
int,
bool bForce =
false);
00070
00071
void clearBuffer(
float* col);
00072
00073
private:
00074
00075
static bool m_firstTime;
00076
00078
unsigned int alloc(
int bForce=0);
00079
unsigned int remove();
00080
00081
int m_context;
00082
00083
int m_width, m_height, m_pitch;
00084
00085
00086
unsigned int m_mem;
00087
00088 Binding m_binding;
00089
00090 GlTextureNamePtr m_textureName;
00091
int m_auxTarget;
00092
00093
friend class HostUberTransfer;
00094
friend class UberUberTransfer;
00095 };
00096
00097
typedef SH::ShPointer<UberStorage> UberStoragePtr;
00098
00099
class UberUberTransfer :
public SH::ShTransfer {
00100
public:
00101
bool transfer(
const SH::ShStorage* from,
SH::ShStorage* to);
00102
00103
int cost()
00104 {
00105
return 10;
00106 }
00107
00108
private:
00109 UberUberTransfer()
00110 : ShTransfer("uberbuffer", "uberbuffer")
00111 {
00112 }
00113
00114
static UberUberTransfer* instance;
00115 };
00116
00117
00118
class UberHostTransfer :
public SH::ShTransfer {
00119
public:
00120
bool transfer(
const SH::ShStorage* from,
SH::ShStorage* to);
00121
int cost()
00122 {
00123
return 100;
00124 }
00125
00126
private:
00127 UberHostTransfer()
00128 : ShTransfer("uberbuffer", "host")
00129 {
00130 }
00131
00132
static UberHostTransfer* instance;
00133 };
00134
00135
00136
class HostUberTransfer :
public SH::ShTransfer {
00137
public:
00138
bool transfer(
const SH::ShStorage* from,
SH::ShStorage* to);
00139
int cost()
00140 {
00141
return 100;
00142 }
00143
00144
private:
00145 HostUberTransfer()
00146 : ShTransfer("host", "uberbuffer")
00147 {
00148 }
00149
00150
static HostUberTransfer* instance;
00151 };
00152
00153 }
00154
00155
#endif