blocks animation fix
This commit is contained in:
parent
4fe79458ab
commit
36a5da5bc1
@ -5,13 +5,14 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
TextureAnimator::TextureAnimator() :
|
TextureAnimator::TextureAnimator() {
|
||||||
frameBuffer(new Framebuffer(1u, 1u))
|
glGenFramebuffers(1, &fboR);
|
||||||
{
|
glGenFramebuffers(1, &fboD);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureAnimator::~TextureAnimator() {
|
TextureAnimator::~TextureAnimator() {
|
||||||
delete frameBuffer;
|
glDeleteFramebuffers(1, &fboR);
|
||||||
|
glDeleteFramebuffers(1, &fboD);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureAnimator::addAnimations(const std::vector<TextureAnimation>& animations) {
|
void TextureAnimator::addAnimations(const std::vector<TextureAnimation>& animations) {
|
||||||
@ -23,7 +24,6 @@ void TextureAnimator::addAnimations(const std::vector<TextureAnimation>& animati
|
|||||||
void TextureAnimator::update(float delta) {
|
void TextureAnimator::update(float delta) {
|
||||||
std::unordered_set<uint> changedTextures;
|
std::unordered_set<uint> changedTextures;
|
||||||
|
|
||||||
frameBuffer->bind();
|
|
||||||
for (auto& elem : animations) {
|
for (auto& elem : animations) {
|
||||||
elem.timer += delta;
|
elem.timer += delta;
|
||||||
size_t frameNum = elem.currentFrame;
|
size_t frameNum = elem.currentFrame;
|
||||||
@ -37,18 +37,27 @@ void TextureAnimator::update(float delta) {
|
|||||||
if (frameNum != elem.currentFrame){
|
if (frameNum != elem.currentFrame){
|
||||||
if (changedTextures.find(elem.dstTexture->id) == changedTextures.end()) changedTextures.insert(elem.dstTexture->id);
|
if (changedTextures.find(elem.dstTexture->id) == changedTextures.end()) changedTextures.insert(elem.dstTexture->id);
|
||||||
|
|
||||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, elem.srcTexture->id, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, fboD);
|
||||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, elem.dstTexture->id, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, elem.dstTexture->id, 0);
|
||||||
glDrawBuffer(GL_COLOR_ATTACHMENT1);
|
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, fboR);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, elem.srcTexture->id, 0);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboD);
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboR);
|
||||||
|
|
||||||
float srcPosY = elem.srcTexture->height - frame.size.y - frame.srcPos.y; // vertical flip
|
float srcPosY = elem.srcTexture->height - frame.size.y - frame.srcPos.y; // vertical flip
|
||||||
|
|
||||||
glBlitFramebuffer(frame.srcPos.x, srcPosY, frame.srcPos.x + frame.size.x, srcPosY + frame.size.y,
|
glBlitFramebuffer(frame.srcPos.x, srcPosY, frame.srcPos.x + frame.size.x, srcPosY + frame.size.y,
|
||||||
frame.dstPos.x, frame.dstPos.y, frame.dstPos.x + frame.size.x, frame.dstPos.y + frame.size.y,
|
frame.dstPos.x, frame.dstPos.y, frame.dstPos.x + frame.size.x, frame.dstPos.y + frame.size.y,
|
||||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||||
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
frameBuffer->unbind();
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
for (auto& elem : changedTextures) {
|
for (auto& elem : changedTextures) {
|
||||||
glBindTexture(GL_TEXTURE_2D, elem);
|
glBindTexture(GL_TEXTURE_2D, elem);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|||||||
@ -43,8 +43,8 @@ public:
|
|||||||
|
|
||||||
void update(float delta);
|
void update(float delta);
|
||||||
private:
|
private:
|
||||||
|
uint fboR;
|
||||||
Framebuffer* frameBuffer;
|
uint fboD;
|
||||||
|
|
||||||
std::vector<TextureAnimation> animations;
|
std::vector<TextureAnimation> animations;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user