mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 14:03:17 +02:00
working version with the gpu::SAmpler and the gpu::Framebuffer
This commit is contained in:
parent
c34c5f6075
commit
87030236cb
11 changed files with 292 additions and 122 deletions
|
@ -179,6 +179,20 @@ public:
|
|||
uint8 _type : 4;
|
||||
};
|
||||
|
||||
|
||||
enum ComparisonFunction {
|
||||
NEVER = 0,
|
||||
LESS,
|
||||
EQUAL,
|
||||
LESS_EQUAL,
|
||||
GREATER,
|
||||
NOT_EQUAL,
|
||||
GREATER_EQUAL,
|
||||
ALWAYS,
|
||||
|
||||
NUM_COMPARISON_FUNCS,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ Framebuffer* Framebuffer::create() {
|
|||
Framebuffer* Framebuffer::create( const Format& colorBufferFormat, const Format& depthStencilBufferFormat, uint16 width, uint16 height, uint16 numSamples) {
|
||||
auto framebuffer = Framebuffer::create();
|
||||
|
||||
auto colorTexture = TexturePointer(Texture::create2D(colorBufferFormat, width, height));
|
||||
auto depthTexture = TexturePointer(Texture::create2D(depthStencilBufferFormat, width, height));
|
||||
auto colorTexture = TexturePointer(Texture::create2D(colorBufferFormat, width, height, Sampler(Sampler::FILTER_MIN_MAG_POINT)));
|
||||
auto depthTexture = TexturePointer(Texture::create2D(depthStencilBufferFormat, width, height, Sampler(Sampler::FILTER_MIN_MAG_POINT)));
|
||||
|
||||
framebuffer->setRenderBuffer(0, colorTexture);
|
||||
framebuffer->setDepthStencilBuffer(depthTexture, depthStencilBufferFormat);
|
||||
|
@ -44,6 +44,15 @@ Framebuffer* Framebuffer::create( const Format& colorBufferFormat, const Format&
|
|||
Framebuffer* Framebuffer::createShadowmap(uint16 width) {
|
||||
auto framebuffer = Framebuffer::create();
|
||||
auto depthTexture = TexturePointer(Texture::create2D(Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH), width, width));
|
||||
|
||||
Sampler::Desc samplerDesc;
|
||||
samplerDesc._borderColor = glm::vec4(1.0f);
|
||||
samplerDesc._wrapModeU = Sampler::WRAP_BORDER;
|
||||
samplerDesc._wrapModeV = Sampler::WRAP_BORDER;
|
||||
samplerDesc._filter = Sampler::FILTER_MIN_MAG_LINEAR;
|
||||
samplerDesc._comparisonFunc = LESS_EQUAL;
|
||||
|
||||
depthTexture->setSampler(Sampler(samplerDesc));
|
||||
|
||||
framebuffer->setDepthStencilBuffer(depthTexture, Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH));
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
Stamp _storageStamp;
|
||||
Stamp _contentStamp;
|
||||
GLuint _texture;
|
||||
GLenum _target;
|
||||
GLuint _size;
|
||||
|
||||
GLTexture();
|
||||
|
@ -61,6 +62,9 @@ public:
|
|||
static GLTexture* syncGPUObject(const Texture& texture);
|
||||
static GLuint getTextureID(const TexturePointer& texture);
|
||||
|
||||
// very specific for now
|
||||
static void syncSampler(const Sampler& sampler, Texture::Type type, GLTexture* object);
|
||||
|
||||
class GLShader : public GPUObject {
|
||||
public:
|
||||
GLuint _shader;
|
||||
|
|
|
@ -237,26 +237,26 @@ void GLBackend::resetPipelineState(State::Signature nextSignature) {
|
|||
}
|
||||
}
|
||||
|
||||
State::ComparisonFunction comparisonFuncFromGL(GLenum func) {
|
||||
ComparisonFunction comparisonFuncFromGL(GLenum func) {
|
||||
if (func == GL_NEVER) {
|
||||
return State::NEVER;
|
||||
return NEVER;
|
||||
} else if (func == GL_LESS) {
|
||||
return State::LESS;
|
||||
return LESS;
|
||||
} else if (func == GL_EQUAL) {
|
||||
return State::EQUAL;
|
||||
return EQUAL;
|
||||
} else if (func == GL_LEQUAL) {
|
||||
return State::LESS_EQUAL;
|
||||
return LESS_EQUAL;
|
||||
} else if (func == GL_GREATER) {
|
||||
return State::GREATER;
|
||||
return GREATER;
|
||||
} else if (func == GL_NOTEQUAL) {
|
||||
return State::NOT_EQUAL;
|
||||
return NOT_EQUAL;
|
||||
} else if (func == GL_GEQUAL) {
|
||||
return State::GREATER_EQUAL;
|
||||
return GREATER_EQUAL;
|
||||
} else if (func == GL_ALWAYS) {
|
||||
return State::ALWAYS;
|
||||
return ALWAYS;
|
||||
}
|
||||
|
||||
return State::ALWAYS;
|
||||
return ALWAYS;
|
||||
}
|
||||
|
||||
State::StencilOp stencilOpFromGL(GLenum stencilOp) {
|
||||
|
|
|
@ -16,7 +16,8 @@ GLBackend::GLTexture::GLTexture() :
|
|||
_storageStamp(0),
|
||||
_contentStamp(0),
|
||||
_texture(0),
|
||||
_size(0)
|
||||
_size(0),
|
||||
_target(GL_TEXTURE_2D)
|
||||
{}
|
||||
|
||||
GLBackend::GLTexture::~GLTexture() {
|
||||
|
@ -285,69 +286,77 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) {
|
|||
// GO through the process of allocating the correct storage and/or update the content
|
||||
switch (texture.getType()) {
|
||||
case Texture::TEX_2D: {
|
||||
if (needUpdate) {
|
||||
if (texture.isStoredMipAvailable(0)) {
|
||||
GLint boundTex = -1;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTex);
|
||||
|
||||
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
||||
const GLvoid* bytes = mip->_sysmem.read<Resource::Byte>();
|
||||
Element srcFormat = mip->_format;
|
||||
|
||||
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, object->_texture);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0,
|
||||
texelFormat.internalFormat, texture.getWidth(), texture.getHeight(), 0,
|
||||
texelFormat.format, texelFormat.type, bytes);
|
||||
|
||||
if (texture.isAutogenerateMips()) {
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
// At this point the mip piels have been loaded, we can notify
|
||||
texture.notifyGPULoaded(0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, boundTex);
|
||||
object->_contentStamp = texture.getDataStamp();
|
||||
}
|
||||
} else {
|
||||
const GLvoid* bytes = 0;
|
||||
Element srcFormat = texture.getTexelFormat();
|
||||
if (texture.isStoredMipAvailable(0)) {
|
||||
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
||||
|
||||
bytes = mip->_sysmem.read<Resource::Byte>();
|
||||
srcFormat = mip->_format;
|
||||
|
||||
object->_contentStamp = texture.getDataStamp();
|
||||
}
|
||||
|
||||
if (texture.getNumSlices() == 1) {
|
||||
GLint boundTex = -1;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTex);
|
||||
glBindTexture(GL_TEXTURE_2D, object->_texture);
|
||||
|
||||
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,
|
||||
texelFormat.internalFormat, texture.getWidth(), texture.getHeight(), 0,
|
||||
texelFormat.format, texelFormat.type, bytes);
|
||||
if (needUpdate) {
|
||||
if (texture.isStoredMipAvailable(0)) {
|
||||
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
||||
const GLvoid* bytes = mip->_sysmem.read<Resource::Byte>();
|
||||
Element srcFormat = mip->_format;
|
||||
|
||||
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat);
|
||||
|
||||
if (bytes && texture.isAutogenerateMips()) {
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glBindTexture(GL_TEXTURE_2D, object->_texture);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0,
|
||||
texelFormat.internalFormat, texture.getWidth(), texture.getHeight(), 0,
|
||||
texelFormat.format, texelFormat.type, bytes);
|
||||
|
||||
if (texture.isAutogenerateMips()) {
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
object->_target = GL_TEXTURE_2D;
|
||||
|
||||
syncSampler(texture.getSampler(), texture.getType(), object);
|
||||
|
||||
|
||||
// At this point the mip piels have been loaded, we can notify
|
||||
texture.notifyGPULoaded(0);
|
||||
|
||||
object->_contentStamp = texture.getDataStamp();
|
||||
}
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
const GLvoid* bytes = 0;
|
||||
Element srcFormat = texture.getTexelFormat();
|
||||
if (texture.isStoredMipAvailable(0)) {
|
||||
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
||||
|
||||
bytes = mip->_sysmem.read<Resource::Byte>();
|
||||
srcFormat = mip->_format;
|
||||
|
||||
object->_contentStamp = texture.getDataStamp();
|
||||
}
|
||||
|
||||
GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0,
|
||||
texelFormat.internalFormat, texture.getWidth(), texture.getHeight(), 0,
|
||||
texelFormat.format, texelFormat.type, bytes);
|
||||
|
||||
if (bytes && texture.isAutogenerateMips()) {
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
object->_target = GL_TEXTURE_2D;
|
||||
|
||||
syncSampler(texture.getSampler(), texture.getType(), object);
|
||||
|
||||
// At this point the mip piels have been loaded, we can notify
|
||||
texture.notifyGPULoaded(0);
|
||||
|
||||
object->_storageStamp = texture.getStamp();
|
||||
object->_size = texture.getSize();
|
||||
}
|
||||
|
||||
// At this point the mip piels have been loaded, we can notify
|
||||
texture.notifyGPULoaded(0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, boundTex);
|
||||
object->_storageStamp = texture.getStamp();
|
||||
object->_size = texture.getSize();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -373,3 +382,70 @@ GLuint GLBackend::getTextureID(const TexturePointer& texture) {
|
|||
}
|
||||
}
|
||||
|
||||
void GLBackend::syncSampler(const Sampler& sampler, Texture::Type type, GLTexture* object) {
|
||||
if (!object) return;
|
||||
if (!object->_texture) return;
|
||||
|
||||
class GLFilterMode {
|
||||
public:
|
||||
GLint minFilter;
|
||||
GLint magFilter;
|
||||
};
|
||||
static const GLFilterMode filterModes[] = {
|
||||
{GL_NEAREST, GL_NEAREST}, //FILTER_MIN_MAG_POINT,
|
||||
{GL_NEAREST, GL_LINEAR}, //FILTER_MIN_POINT_MAG_LINEAR,
|
||||
{GL_LINEAR, GL_NEAREST}, //FILTER_MIN_LINEAR_MAG_POINT,
|
||||
{GL_LINEAR, GL_LINEAR}, //FILTER_MIN_MAG_LINEAR,
|
||||
|
||||
{GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST}, //FILTER_MIN_MAG_MIP_POINT,
|
||||
{GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST}, //FILTER_MIN_MAG_MIP_POINT,
|
||||
{GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST}, //FILTER_MIN_MAG_POINT_MIP_LINEAR,
|
||||
{GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR}, //FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT,
|
||||
{GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR}, //FILTER_MIN_POINT_MAG_MIP_LINEAR,
|
||||
{GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST}, //FILTER_MIN_LINEAR_MAG_MIP_POINT,
|
||||
{GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST}, //FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
|
||||
{GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR}, //FILTER_MIN_MAG_LINEAR_MIP_POINT,
|
||||
{GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}, //FILTER_MIN_MAG_MIP_LINEAR,
|
||||
{GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR} //FILTER_ANISOTROPIC,
|
||||
};
|
||||
|
||||
auto fm = filterModes[sampler.getFilter()];
|
||||
glTexParameteri(object->_target, GL_TEXTURE_MIN_FILTER, fm.minFilter);
|
||||
glTexParameteri(object->_target, GL_TEXTURE_MAG_FILTER, fm.magFilter);
|
||||
|
||||
static const GLenum comparisonFuncs[] = {
|
||||
GL_NEVER,
|
||||
GL_LESS,
|
||||
GL_EQUAL,
|
||||
GL_LEQUAL,
|
||||
GL_GREATER,
|
||||
GL_NOTEQUAL,
|
||||
GL_GEQUAL,
|
||||
GL_ALWAYS };
|
||||
|
||||
if (sampler.doComparison()) {
|
||||
glTexParameteri(object->_target, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||
glTexParameteri(object->_target, GL_TEXTURE_COMPARE_FUNC, comparisonFuncs[sampler.getComparisonFunction()]);
|
||||
} else {
|
||||
glTexParameteri(object->_target, GL_TEXTURE_COMPARE_MODE, GL_NONE);
|
||||
}
|
||||
|
||||
static const GLenum wrapModes[] = {
|
||||
GL_REPEAT, // WRAP_REPEAT,
|
||||
GL_MIRRORED_REPEAT, // WRAP_MIRROR,
|
||||
GL_CLAMP_TO_EDGE, // WRAP_CLAMP,
|
||||
GL_CLAMP_TO_BORDER, // WRAP_BORDER,
|
||||
GL_MIRROR_CLAMP_TO_EDGE_EXT }; // WRAP_MIRROR_ONCE,
|
||||
|
||||
glTexParameteri(object->_target, GL_TEXTURE_WRAP_S, wrapModes[sampler.getWrapModeU()]);
|
||||
glTexParameteri(object->_target, GL_TEXTURE_WRAP_T, wrapModes[sampler.getWrapModeV()]);
|
||||
glTexParameteri(object->_target, GL_TEXTURE_WRAP_R, wrapModes[sampler.getWrapModeW()]);
|
||||
|
||||
glTexParameterfv(object->_target, GL_TEXTURE_BORDER_COLOR, (const float*) &sampler.getBorderColor());
|
||||
glTexParameteri(object->_target, GL_TEXTURE_BASE_LEVEL, sampler.getMipOffset());
|
||||
glTexParameterf(object->_target, GL_TEXTURE_MIN_LOD, (float) sampler.getMinMip());
|
||||
glTexParameterf(object->_target, GL_TEXTURE_MAX_LOD, (sampler.getMaxMip() == Sampler::MAX_MIP_LEVEL ? 1000.f : sampler.getMaxMip()));
|
||||
glTexParameterf(object->_target, GL_TEXTURE_MAX_ANISOTROPY_EXT, sampler.getMaxAnisotropy());
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
}
|
||||
|
|
|
@ -42,19 +42,8 @@ public:
|
|||
virtual ~State();
|
||||
|
||||
const Stamp getStamp() const { return _stamp; }
|
||||
|
||||
enum ComparisonFunction {
|
||||
NEVER = 0,
|
||||
LESS,
|
||||
EQUAL,
|
||||
LESS_EQUAL,
|
||||
GREATER,
|
||||
NOT_EQUAL,
|
||||
GREATER_EQUAL,
|
||||
ALWAYS,
|
||||
|
||||
NUM_COMPARISON_FUNCS,
|
||||
};
|
||||
|
||||
typedef ::gpu::ComparisonFunction ComparisonFunction;
|
||||
|
||||
enum FillMode {
|
||||
FILL_POINT = 0,
|
||||
|
@ -415,5 +404,4 @@ typedef std::vector< StatePointer > States;
|
|||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -93,23 +93,23 @@ bool Texture::Storage::assignMipData(uint16 level, const Element& format, Size s
|
|||
return allocated == size;
|
||||
}
|
||||
|
||||
Texture* Texture::create1D(const Element& texelFormat, uint16 width) {
|
||||
return create(TEX_1D, texelFormat, width, 1, 1, 1, 1);
|
||||
Texture* Texture::create1D(const Element& texelFormat, uint16 width, const Sampler& sampler) {
|
||||
return create(TEX_1D, texelFormat, width, 1, 1, 1, 1, sampler);
|
||||
}
|
||||
|
||||
Texture* Texture::create2D(const Element& texelFormat, uint16 width, uint16 height) {
|
||||
return create(TEX_2D, texelFormat, width, height, 1, 1, 1);
|
||||
Texture* Texture::create2D(const Element& texelFormat, uint16 width, uint16 height, const Sampler& sampler) {
|
||||
return create(TEX_2D, texelFormat, width, height, 1, 1, 1, sampler);
|
||||
}
|
||||
|
||||
Texture* Texture::create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth) {
|
||||
return create(TEX_3D, texelFormat, width, height, depth, 1, 1);
|
||||
Texture* Texture::create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth, const Sampler& sampler) {
|
||||
return create(TEX_3D, texelFormat, width, height, depth, 1, 1, sampler);
|
||||
}
|
||||
|
||||
Texture* Texture::createCube(const Element& texelFormat, uint16 width) {
|
||||
return create(TEX_CUBE, texelFormat, width, width, 1, 1, 1);
|
||||
Texture* Texture::createCube(const Element& texelFormat, uint16 width, const Sampler& sampler) {
|
||||
return create(TEX_CUBE, texelFormat, width, width, 1, 1, 1, sampler);
|
||||
}
|
||||
|
||||
Texture* Texture::create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices)
|
||||
Texture* Texture::create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices, const Sampler& sampler)
|
||||
{
|
||||
Texture* tex = new Texture();
|
||||
tex->_storage.reset(new Storage());
|
||||
|
@ -118,6 +118,8 @@ Texture* Texture::create(Type type, const Element& texelFormat, uint16 width, ui
|
|||
tex->_maxMip = 0;
|
||||
tex->resize(type, texelFormat, width, height, depth, numSamples, numSlices);
|
||||
|
||||
tex->_sampler = sampler;
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
@ -346,3 +348,8 @@ uint16 Texture::evalNumSamplesUsed(uint16 numSamplesTried) {
|
|||
|
||||
return sample;
|
||||
}
|
||||
|
||||
void Texture::setSampler(const Sampler& sampler) {
|
||||
_sampler = sampler;
|
||||
_samplerStamp++;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,85 @@
|
|||
|
||||
namespace gpu {
|
||||
|
||||
class Sampler {
|
||||
public:
|
||||
|
||||
enum Filter {
|
||||
FILTER_MIN_MAG_POINT, // top mip only
|
||||
FILTER_MIN_POINT_MAG_LINEAR, // top mip only
|
||||
FILTER_MIN_LINEAR_MAG_POINT, // top mip only
|
||||
FILTER_MIN_MAG_LINEAR, // top mip only
|
||||
|
||||
FILTER_MIN_MAG_MIP_POINT,
|
||||
FILTER_MIN_MAG_POINT_MIP_LINEAR,
|
||||
FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT,
|
||||
FILTER_MIN_POINT_MAG_MIP_LINEAR,
|
||||
FILTER_MIN_LINEAR_MAG_MIP_POINT,
|
||||
FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
|
||||
FILTER_MIN_MAG_LINEAR_MIP_POINT,
|
||||
FILTER_MIN_MAG_MIP_LINEAR,
|
||||
FILTER_ANISOTROPIC,
|
||||
|
||||
NUM_FILTERS,
|
||||
};
|
||||
|
||||
enum WrapMode {
|
||||
WRAP_REPEAT = 0,
|
||||
WRAP_MIRROR,
|
||||
WRAP_CLAMP,
|
||||
WRAP_BORDER,
|
||||
WRAP_MIRROR_ONCE,
|
||||
|
||||
NUM_WRAP_MODES
|
||||
};
|
||||
|
||||
static const uint8 MAX_MIP_LEVEL = 0xFF;
|
||||
|
||||
class Desc {
|
||||
public:
|
||||
glm::vec4 _borderColor{ 1.0f };
|
||||
uint32 _maxAnisotropy = 16;
|
||||
|
||||
uint8 _wrapModeU = WRAP_REPEAT;
|
||||
uint8 _wrapModeV = WRAP_REPEAT;
|
||||
uint8 _wrapModeW = WRAP_REPEAT;
|
||||
|
||||
uint8 _filter = FILTER_MIN_MAG_POINT;
|
||||
uint8 _comparisonFunc = ALWAYS;
|
||||
|
||||
uint8 _mipOffset = 0;
|
||||
uint8 _minMip = 0;
|
||||
uint8 _maxMip = MAX_MIP_LEVEL;
|
||||
|
||||
Desc() {}
|
||||
Desc(const Filter filter) : _filter(filter) {}
|
||||
};
|
||||
|
||||
Sampler() {}
|
||||
Sampler(const Filter filter) : _desc(filter) {}
|
||||
Sampler(const Desc& desc) : _desc(desc) {}
|
||||
~Sampler() {}
|
||||
|
||||
const glm::vec4& getBorderColor() const { return _desc._borderColor; }
|
||||
|
||||
uint32 getMaxAnisotropy() const { return _desc._maxAnisotropy; }
|
||||
|
||||
WrapMode getWrapModeU() const { return WrapMode(_desc._wrapModeU); }
|
||||
WrapMode getWrapModeV() const { return WrapMode(_desc._wrapModeV); }
|
||||
WrapMode getWrapModeW() const { return WrapMode(_desc._wrapModeW); }
|
||||
|
||||
Filter getFilter() const { return Filter(_desc._filter); }
|
||||
ComparisonFunction getComparisonFunction() const { return ComparisonFunction(_desc._comparisonFunc); }
|
||||
bool doComparison() const { return getComparisonFunction() != ALWAYS; }
|
||||
|
||||
uint8 getMipOffset() const { return _desc._mipOffset; }
|
||||
uint8 getMinMip() const { return _desc._minMip; }
|
||||
uint8 getMaxMip() const { return _desc._maxMip; }
|
||||
|
||||
protected:
|
||||
Desc _desc;
|
||||
};
|
||||
|
||||
class Texture : public Resource {
|
||||
public:
|
||||
|
||||
|
@ -61,10 +140,10 @@ public:
|
|||
TEX_CUBE,
|
||||
};
|
||||
|
||||
static Texture* create1D(const Element& texelFormat, uint16 width);
|
||||
static Texture* create2D(const Element& texelFormat, uint16 width, uint16 height);
|
||||
static Texture* create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth);
|
||||
static Texture* createCube(const Element& texelFormat, uint16 width);
|
||||
static Texture* create1D(const Element& texelFormat, uint16 width, const Sampler& sampler = Sampler());
|
||||
static Texture* create2D(const Element& texelFormat, uint16 width, uint16 height, const Sampler& sampler = Sampler());
|
||||
static Texture* create3D(const Element& texelFormat, uint16 width, uint16 height, uint16 depth, const Sampler& sampler = Sampler());
|
||||
static Texture* createCube(const Element& texelFormat, uint16 width, const Sampler& sampler = Sampler());
|
||||
|
||||
static Texture* createFromStorage(Storage* storage);
|
||||
|
||||
|
@ -181,11 +260,21 @@ public:
|
|||
|
||||
bool isDefined() const { return _defined; }
|
||||
|
||||
|
||||
// Own sampler
|
||||
void setSampler(const Sampler& sampler);
|
||||
const Sampler& getSampler() const { return _sampler; }
|
||||
const Stamp getSamplerStamp() const { return _samplerStamp; }
|
||||
|
||||
protected:
|
||||
std::unique_ptr< Storage > _storage;
|
||||
|
||||
Stamp _stamp;
|
||||
|
||||
Sampler _sampler;
|
||||
Stamp _samplerStamp;
|
||||
|
||||
|
||||
uint32 _size;
|
||||
Element _texelFormat;
|
||||
|
||||
|
@ -202,7 +291,7 @@ protected:
|
|||
bool _autoGenerateMips;
|
||||
bool _defined;
|
||||
|
||||
static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices);
|
||||
static Texture* create(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices, const Sampler& sampler);
|
||||
Texture();
|
||||
|
||||
Size resize(Type type, const Element& texelFormat, uint16 width, uint16 height, uint16 depth, uint16 numSamples, uint16 numSlices);
|
||||
|
|
|
@ -253,7 +253,7 @@ void DeferredLightingEffect::render() {
|
|||
program->bind();
|
||||
}
|
||||
program->setUniformValue(locations->shadowScale,
|
||||
1.0f / textureCache->getShadowFramebufferObject()->width());
|
||||
1.0f / textureCache->getShadowFramebuffer()->getWidth());
|
||||
|
||||
} else {
|
||||
if (_ambientLightMode > -1) {
|
||||
|
|
|
@ -130,7 +130,7 @@ void Model::RenderPipelineLib::addRenderPipeline(Model::RenderKey key,
|
|||
}
|
||||
|
||||
// Z test depends if transparent or not
|
||||
state->setDepthTest(true, !key.isTranslucent(), gpu::State::LESS_EQUAL);
|
||||
state->setDepthTest(true, !key.isTranslucent(), gpu::LESS_EQUAL);
|
||||
|
||||
// Blend on transparent
|
||||
state->setBlendFunction(key.isTranslucent(),
|
||||
|
|
|
@ -259,9 +259,11 @@ void TextureCache::createPrimaryFramebuffer() {
|
|||
auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA);
|
||||
auto width = _frameBufferSize.width();
|
||||
auto height = _frameBufferSize.height();
|
||||
_primaryColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height));
|
||||
_primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height));
|
||||
_primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height));
|
||||
|
||||
auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT);
|
||||
_primaryColorTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
|
||||
_primaryNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
|
||||
_primarySpecularTexture = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width, height, defaultSampler));
|
||||
|
||||
_primaryOpaqueFramebuffer->setRenderBuffer(0, _primaryColorTexture);
|
||||
_primaryOpaqueFramebuffer->setRenderBuffer(1, _primaryNormalTexture);
|
||||
|
@ -270,7 +272,7 @@ void TextureCache::createPrimaryFramebuffer() {
|
|||
_primaryTransparentFramebuffer->setRenderBuffer(0, _primaryColorTexture);
|
||||
|
||||
auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH);
|
||||
_primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height));
|
||||
_primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler));
|
||||
|
||||
_primaryOpaqueFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
|
||||
|
||||
|
@ -380,25 +382,6 @@ gpu::FramebufferPointer TextureCache::getShadowFramebuffer() {
|
|||
_shadowFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::createShadowmap(SHADOW_MAP_SIZE));
|
||||
|
||||
_shadowTexture = _shadowFramebuffer->getDepthStencilBuffer();
|
||||
/*
|
||||
glGenTextures(1, &_shadowDepthTextureID);
|
||||
glBindTexture(GL_TEXTURE_2D, _shadowDepthTextureID);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, SHADOW_MAP_SIZE, SHADOW_MAP_SIZE,
|
||||
0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
const float DISTANT_BORDER[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, DISTANT_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
_shadowFramebufferObject->bind();
|
||||
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _shadowDepthTextureID, 0);
|
||||
_shadowFramebufferObject->release();
|
||||
*/
|
||||
}
|
||||
return _shadowFramebuffer;
|
||||
}
|
||||
|
@ -675,7 +658,7 @@ void NetworkTexture::setImage(const QImage& image, bool translucent, const QColo
|
|||
formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA));
|
||||
formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA));
|
||||
}
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, image.width(), image.height()));
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||
_gpuTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||
_gpuTexture->autoGenerateMips(-1);
|
||||
}
|
||||
|
@ -714,7 +697,7 @@ QSharedPointer<Texture> DilatableNetworkTexture::getDilatedTexture(float dilatio
|
|||
formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA));
|
||||
formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::BGRA));
|
||||
}
|
||||
texture->_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, dilatedImage.width(), dilatedImage.height()));
|
||||
texture->_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, dilatedImage.width(), dilatedImage.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||
texture->_gpuTexture->assignStoredMip(0, formatMip, dilatedImage.byteCount(), dilatedImage.constBits());
|
||||
texture->_gpuTexture->autoGenerateMips(-1);
|
||||
|
||||
|
|
Loading…
Reference in a new issue