Skip to content

Commit

Permalink
thin3d: Add support for texture subimage to GLRender.
Browse files Browse the repository at this point in the history
  • Loading branch information
xebra committed Oct 7, 2018
1 parent 0cb6331 commit 3add123
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
24 changes: 22 additions & 2 deletions ext/native/thin3d/GLQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,14 @@ void GLQueueRunner::RunInitSteps(const std::vector<GLRInitStep> &steps, bool ski
glBindTexture(tex->target, tex->texture);
boundTexture = tex->texture;
}
if (!step.texture_image.data)
if (!step.texture_image.data && step.texture_image.allocType != GLRAllocType::NONE)
Crash();
// For things to show in RenderDoc, need to split into glTexImage2D(..., nullptr) and glTexSubImage.
glTexImage2D(tex->target, step.texture_image.level, step.texture_image.internalFormat, step.texture_image.width, step.texture_image.height, 0, step.texture_image.format, step.texture_image.type, step.texture_image.data);
allocatedTextures = true;
if (step.texture_image.allocType == GLRAllocType::ALIGNED) {
FreeAlignedMemory(step.texture_image.data);
} else {
} else if (step.texture_image.allocType == GLRAllocType::NEW) {
delete[] step.texture_image.data;
}
CHECK_GL_ERROR_IF_DEBUG();
Expand All @@ -328,6 +328,26 @@ void GLQueueRunner::RunInitSteps(const std::vector<GLRInitStep> &steps, bool ski
CHECK_GL_ERROR_IF_DEBUG();
break;
}
case GLRInitStepType::TEXTURE_SUBIMAGE:
{
GLRTexture *tex = step.texture_subimage.texture;
CHECK_GL_ERROR_IF_DEBUG();
if (boundTexture != tex->texture) {
glBindTexture(tex->target, tex->texture);
boundTexture = tex->texture;
}
if (!step.texture_subimage.data)
Crash();
// For things to show in RenderDoc, need to split into glTexImage2D(..., nullptr) and glTexSubImage.
glTexSubImage2D(tex->target, step.texture_subimage.level, step.texture_subimage.x, step.texture_subimage.y, step.texture_subimage.width, step.texture_subimage.height, step.texture_subimage.format, step.texture_subimage.type, step.texture_subimage.data);
if (step.texture_subimage.allocType == GLRAllocType::ALIGNED) {
FreeAlignedMemory(step.texture_subimage.data);
} else if (step.texture_subimage.allocType == GLRAllocType::NEW) {
delete[] step.texture_subimage.data;
}
CHECK_GL_ERROR_IF_DEBUG();
break;
}
case GLRInitStepType::TEXTURE_FINALIZE:
{
CHECK_GL_ERROR_IF_DEBUG();
Expand Down
14 changes: 14 additions & 0 deletions ext/native/thin3d/GLQueueRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct GLOffset2D {
};

enum class GLRAllocType {
NONE,
NEW,
ALIGNED,
};
Expand Down Expand Up @@ -196,6 +197,7 @@ enum class GLRInitStepType : uint8_t {
CREATE_FRAMEBUFFER,

TEXTURE_IMAGE,
TEXTURE_SUBIMAGE,
TEXTURE_FINALIZE,
BUFFER_SUBDATA,
};
Expand Down Expand Up @@ -250,6 +252,18 @@ struct GLRInitStep {
bool linearFilter;
uint8_t *data; // owned, delete[]-d
} texture_image;
struct {
GLRTexture *texture;
GLenum format;
GLenum type;
int level;
int x;
int y;
int width;
int height;
GLRAllocType allocType;
uint8_t *data; // owned, delete[]-d
} texture_subimage;
struct {
GLRTexture *texture;
int maxLevel;
Expand Down
15 changes: 15 additions & 0 deletions ext/native/thin3d/GLRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,21 @@ class GLRenderManager {
initSteps_.push_back(step);
}

void TextureSubImage(GLRTexture *texture, int level, int x, int y, int width, int height, GLenum format, GLenum type, uint8_t *data, GLRAllocType allocType = GLRAllocType::NEW) {
GLRInitStep step{ GLRInitStepType::TEXTURE_SUBIMAGE };
step.texture_subimage.texture = texture;
step.texture_subimage.data = data;
step.texture_subimage.format = format;
step.texture_subimage.type = type;
step.texture_subimage.level = level;
step.texture_subimage.x = x;
step.texture_subimage.y = y;
step.texture_subimage.width = width;
step.texture_subimage.height = height;
step.texture_subimage.allocType = allocType;
initSteps_.push_back(step);
}

void FinalizeTexture(GLRTexture *texture, int maxLevels, bool genMips) {
GLRInitStep step{ GLRInitStepType::TEXTURE_FINALIZE };
step.texture_finalize.texture = texture;
Expand Down

0 comments on commit 3add123

Please sign in to comment.