mirror of
https://github.com/MobileGL-Dev/MobileGlues.git
synced 2025-09-28 21:52:40 -04:00
misc(debug): some debug shiz about texture and buffer
This commit is contained in:
parent
e7287e81c3
commit
9187e51ad5
@ -19,6 +19,14 @@ static GLenum get_binding_query(GLenum target) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage) {
|
||||||
|
LOG()
|
||||||
|
LOG_D("glBufferData, target = %s, size = %d, data = 0x%x, usage = %s",
|
||||||
|
glEnumToString(target), size, data, glEnumToString(usage))
|
||||||
|
LOAD_GLES_FUNC(glBufferData)
|
||||||
|
gles_glBufferData(target, size, data, usage);
|
||||||
|
}
|
||||||
|
|
||||||
void* glMapBuffer(GLenum target, GLenum access) {
|
void* glMapBuffer(GLenum target, GLenum access) {
|
||||||
LOG()
|
LOG()
|
||||||
LOG_D("glMapBuffer, target = %s, access = %s", glEnumToString(target), glEnumToString(access))
|
LOG_D("glMapBuffer, target = %s, access = %s", glEnumToString(target), glEnumToString(access))
|
||||||
@ -30,7 +38,7 @@ void* glMapBuffer(GLenum target, GLenum access) {
|
|||||||
if (current_buffer == 0) {
|
if (current_buffer == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (g_active_mapping.mapped_ptr != NULL) {
|
if (g_active_mappings[current_buffer].mapped_ptr != NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
GLint buffer_size;
|
GLint buffer_size;
|
||||||
@ -52,12 +60,23 @@ void* glMapBuffer(GLenum target, GLenum access) {
|
|||||||
mapping.target = target;
|
mapping.target = target;
|
||||||
mapping.buffer_id = (GLuint)current_buffer;
|
mapping.buffer_id = (GLuint)current_buffer;
|
||||||
mapping.mapped_ptr = ptr;
|
mapping.mapped_ptr = ptr;
|
||||||
|
//#if GLOBAL_DEBUG || DEBUG
|
||||||
|
// if (target == GL_PIXEL_UNPACK_BUFFER)
|
||||||
|
// mapping.client_buf.resize(buffer_size, 0xFF);
|
||||||
|
//#endif
|
||||||
mapping.size = buffer_size;
|
mapping.size = buffer_size;
|
||||||
mapping.flags = flags;
|
mapping.flags = flags;
|
||||||
mapping.is_dirty = (flags & GL_MAP_WRITE_BIT) ? GL_TRUE : GL_FALSE;
|
mapping.is_dirty = (flags & GL_MAP_WRITE_BIT) ? GL_TRUE : GL_FALSE;
|
||||||
g_active_mappings[current_buffer] = mapping;
|
g_active_mappings[current_buffer] = mapping;
|
||||||
CHECK_GL_ERROR
|
CHECK_GL_ERROR
|
||||||
|
//#if GLOBAL_DEBUG || DEBUG
|
||||||
|
// if (target == GL_PIXEL_UNPACK_BUFFER)
|
||||||
|
// return mapping.client_buf.data();
|
||||||
|
// else
|
||||||
|
// return ptr;
|
||||||
|
//#else
|
||||||
return ptr;
|
return ptr;
|
||||||
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GLboolean force_unmap() {
|
GLboolean force_unmap() {
|
||||||
@ -82,6 +101,11 @@ GLboolean force_unmap() {
|
|||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GLOBAL_DEBUG || DEBUG
|
||||||
|
#include <fstream>
|
||||||
|
#define BIN_FILE_PREFIX "/sdcard/MG/buf/"
|
||||||
|
#endif
|
||||||
|
|
||||||
GLboolean glUnmapBuffer(GLenum target) {
|
GLboolean glUnmapBuffer(GLenum target) {
|
||||||
LOG()
|
LOG()
|
||||||
|
|
||||||
@ -92,6 +116,20 @@ GLboolean glUnmapBuffer(GLenum target) {
|
|||||||
if (buffer == 0)
|
if (buffer == 0)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
|
#if GLOBAL_DEBUG || DEBUG
|
||||||
|
// Blit data from client side to OpenGL here
|
||||||
|
// if (target == GL_PIXEL_UNPACK_BUFFER) {
|
||||||
|
// auto &mapping = g_active_mappings[buffer];
|
||||||
|
//
|
||||||
|
// std::fstream fs(std::string(BIN_FILE_PREFIX) + "buf" + std::to_string(buffer) + ".bin", std::ios::out | std::ios::binary | std::ios::trunc);
|
||||||
|
// fs.write((const char*)mapping.client_buf.data(), mapping.size);
|
||||||
|
// fs.close();
|
||||||
|
//
|
||||||
|
//// memset(mapping.mapped_ptr, 0xFF, mapping.size);
|
||||||
|
// memcpy(mapping.mapped_ptr, mapping.client_buf.data(), mapping.size);
|
||||||
|
// }
|
||||||
|
#endif
|
||||||
|
|
||||||
LOAD_GLES(glUnmapBuffer, GLboolean, GLenum target);
|
LOAD_GLES(glUnmapBuffer, GLboolean, GLenum target);
|
||||||
GLboolean result = gles_glUnmapBuffer(target);
|
GLboolean result = gles_glUnmapBuffer(target);
|
||||||
|
|
||||||
|
@ -11,20 +11,23 @@
|
|||||||
#include "../gles/loader.h"
|
#include "../gles/loader.h"
|
||||||
#include "mg.h"
|
#include "mg.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#include <vector>
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GLenum target;
|
GLenum target;
|
||||||
GLuint buffer_id;
|
GLuint buffer_id;
|
||||||
void *mapped_ptr;
|
void *mapped_ptr;
|
||||||
|
#if GLOBAL_DEBUG || DEBUG
|
||||||
|
std::vector<uint8_t> client_buf;
|
||||||
|
#endif
|
||||||
GLsizeiptr size;
|
GLsizeiptr size;
|
||||||
GLbitfield flags;
|
GLbitfield flags;
|
||||||
GLboolean is_dirty;
|
GLboolean is_dirty;
|
||||||
} BufferMapping;
|
} BufferMapping;
|
||||||
|
|
||||||
static BufferMapping g_active_mapping = {0};
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
static GLenum get_binding_query(GLenum target);
|
static GLenum get_binding_query(GLenum target);
|
||||||
|
|
||||||
@ -34,6 +37,8 @@ GLAPI GLAPIENTRY GLboolean glUnmapBuffer(GLenum target);
|
|||||||
|
|
||||||
GLAPI GLAPIENTRY void *glMapBuffer(GLenum target, GLenum access);
|
GLAPI GLAPIENTRY void *glMapBuffer(GLenum target, GLenum access);
|
||||||
|
|
||||||
|
GLAPI GLAPIENTRY void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage);
|
||||||
|
|
||||||
GLAPI GLAPIENTRY void glBufferStorage(GLenum target, GLsizeiptr size, const void* data, GLbitfield flags);
|
GLAPI GLAPIENTRY void glBufferStorage(GLenum target, GLsizeiptr size, const void* data, GLbitfield flags);
|
||||||
|
|
||||||
GLAPI GLAPIENTRY void glBindBuffer(GLenum target, GLuint buffer);
|
GLAPI GLAPIENTRY void glBindBuffer(GLenum target, GLuint buffer);
|
||||||
|
@ -171,6 +171,14 @@ void glDrawBuffers(GLsizei n, const GLenum *bufs) {
|
|||||||
CHECK_GL_ERROR
|
CHECK_GL_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void glReadBuffer(GLenum src) {
|
||||||
|
LOG()
|
||||||
|
LOG_D("glReadBuffer, src = %s", glEnumToString(src))
|
||||||
|
|
||||||
|
LOAD_GLES_FUNC(glReadBuffer)
|
||||||
|
gles_glReadBuffer(src);
|
||||||
|
}
|
||||||
|
|
||||||
GLenum glCheckFramebufferStatus(GLenum target) {
|
GLenum glCheckFramebufferStatus(GLenum target) {
|
||||||
LOG()
|
LOG()
|
||||||
LOAD_GLES_FUNC(glCheckFramebufferStatus)
|
LOAD_GLES_FUNC(glCheckFramebufferStatus)
|
||||||
|
@ -33,6 +33,8 @@ GLAPI GLAPIENTRY void glDrawBuffer(GLenum buf);
|
|||||||
|
|
||||||
GLAPI GLAPIENTRY void glDrawBuffers(GLsizei n, const GLenum *bufs);
|
GLAPI GLAPIENTRY void glDrawBuffers(GLsizei n, const GLenum *bufs);
|
||||||
|
|
||||||
|
GLAPI GLAPIENTRY void glReadBuffer(GLenum src);
|
||||||
|
|
||||||
GLAPI GLAPIENTRY GLenum glCheckFramebufferStatus(GLenum target);
|
GLAPI GLAPIENTRY GLenum glCheckFramebufferStatus(GLenum target);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
void glGetIntegerv(GLenum pname, GLint *params) {
|
void glGetIntegerv(GLenum pname, GLint *params) {
|
||||||
LOG();
|
LOG();
|
||||||
LOG_D("glGetIntegerv, pname: 0x%x",pname);
|
LOG_D("glGetIntegerv, pname: %s", glEnumToString(pname));
|
||||||
if (pname == GL_CONTEXT_PROFILE_MASK) {
|
if (pname == GL_CONTEXT_PROFILE_MASK) {
|
||||||
(*params) = GL_CONTEXT_CORE_PROFILE_BIT;
|
(*params) = GL_CONTEXT_CORE_PROFILE_BIT;
|
||||||
return;
|
return;
|
||||||
|
@ -24,7 +24,7 @@ NATIVE_FUNCTION_HEAD(void, glBlendEquation, GLenum mode) NATIVE_FUNCTION_END_NO_
|
|||||||
NATIVE_FUNCTION_HEAD(void, glBlendEquationSeparate, GLenum modeRGB, GLenum modeAlpha) NATIVE_FUNCTION_END_NO_RETURN(void, glBlendEquationSeparate, modeRGB,modeAlpha)
|
NATIVE_FUNCTION_HEAD(void, glBlendEquationSeparate, GLenum modeRGB, GLenum modeAlpha) NATIVE_FUNCTION_END_NO_RETURN(void, glBlendEquationSeparate, modeRGB,modeAlpha)
|
||||||
NATIVE_FUNCTION_HEAD(void, glBlendFunc, GLenum sfactor, GLenum dfactor) NATIVE_FUNCTION_END_NO_RETURN(void, glBlendFunc, sfactor,dfactor)
|
NATIVE_FUNCTION_HEAD(void, glBlendFunc, GLenum sfactor, GLenum dfactor) NATIVE_FUNCTION_END_NO_RETURN(void, glBlendFunc, sfactor,dfactor)
|
||||||
NATIVE_FUNCTION_HEAD(void, glBlendFuncSeparate, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) NATIVE_FUNCTION_END_NO_RETURN(void, glBlendFuncSeparate, sfactorRGB,dfactorRGB,sfactorAlpha,dfactorAlpha)
|
NATIVE_FUNCTION_HEAD(void, glBlendFuncSeparate, GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) NATIVE_FUNCTION_END_NO_RETURN(void, glBlendFuncSeparate, sfactorRGB,dfactorRGB,sfactorAlpha,dfactorAlpha)
|
||||||
NATIVE_FUNCTION_HEAD(void, glBufferData, GLenum target, GLsizeiptr size, const void *data, GLenum usage) NATIVE_FUNCTION_END_NO_RETURN(void, glBufferData, target,size,data,usage)
|
//NATIVE_FUNCTION_HEAD(void, glBufferData, GLenum target, GLsizeiptr size, const void *data, GLenum usage) NATIVE_FUNCTION_END_NO_RETURN(void, glBufferData, target,size,data,usage)
|
||||||
NATIVE_FUNCTION_HEAD(void, glBufferSubData, GLenum target, GLintptr offset, GLsizeiptr size, const void *data) NATIVE_FUNCTION_END_NO_RETURN(void, glBufferSubData, target,offset,size,data)
|
NATIVE_FUNCTION_HEAD(void, glBufferSubData, GLenum target, GLintptr offset, GLsizeiptr size, const void *data) NATIVE_FUNCTION_END_NO_RETURN(void, glBufferSubData, target,offset,size,data)
|
||||||
//NATIVE_FUNCTION_HEAD(GLenum, glCheckFramebufferStatus, GLenum target) NATIVE_FUNCTION_END(GLenum, glCheckFramebufferStatus, target)
|
//NATIVE_FUNCTION_HEAD(GLenum, glCheckFramebufferStatus, GLenum target) NATIVE_FUNCTION_END(GLenum, glCheckFramebufferStatus, target)
|
||||||
NATIVE_FUNCTION_HEAD(void, glClear, GLbitfield mask) NATIVE_FUNCTION_END_NO_RETURN(void, glClear, mask)
|
NATIVE_FUNCTION_HEAD(void, glClear, GLbitfield mask) NATIVE_FUNCTION_END_NO_RETURN(void, glClear, mask)
|
||||||
@ -153,7 +153,7 @@ NATIVE_FUNCTION_HEAD(void, glVertexAttrib4f, GLuint index, GLfloat x, GLfloat y,
|
|||||||
NATIVE_FUNCTION_HEAD(void, glVertexAttrib4fv, GLuint index, const GLfloat *v) NATIVE_FUNCTION_END_NO_RETURN(void, glVertexAttrib4fv, index,v)
|
NATIVE_FUNCTION_HEAD(void, glVertexAttrib4fv, GLuint index, const GLfloat *v) NATIVE_FUNCTION_END_NO_RETURN(void, glVertexAttrib4fv, index,v)
|
||||||
NATIVE_FUNCTION_HEAD(void, glVertexAttribPointer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) NATIVE_FUNCTION_END_NO_RETURN(void, glVertexAttribPointer, index,size,type,normalized,stride,pointer)
|
NATIVE_FUNCTION_HEAD(void, glVertexAttribPointer, GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer) NATIVE_FUNCTION_END_NO_RETURN(void, glVertexAttribPointer, index,size,type,normalized,stride,pointer)
|
||||||
NATIVE_FUNCTION_HEAD(void, glViewport, GLint x, GLint y, GLsizei width, GLsizei height) NATIVE_FUNCTION_END_NO_RETURN(void, glViewport, x,y,width,height)
|
NATIVE_FUNCTION_HEAD(void, glViewport, GLint x, GLint y, GLsizei width, GLsizei height) NATIVE_FUNCTION_END_NO_RETURN(void, glViewport, x,y,width,height)
|
||||||
NATIVE_FUNCTION_HEAD(void, glReadBuffer, GLenum src) NATIVE_FUNCTION_END_NO_RETURN(void, glReadBuffer, src)
|
//NATIVE_FUNCTION_HEAD(void, glReadBuffer, GLenum src) NATIVE_FUNCTION_END_NO_RETURN(void, glReadBuffer, src)
|
||||||
NATIVE_FUNCTION_HEAD(void, glDrawRangeElements, GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices) NATIVE_FUNCTION_END_NO_RETURN(void, glDrawRangeElements, mode,start,end,count,type,indices)
|
NATIVE_FUNCTION_HEAD(void, glDrawRangeElements, GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices) NATIVE_FUNCTION_END_NO_RETURN(void, glDrawRangeElements, mode,start,end,count,type,indices)
|
||||||
//NATIVE_FUNCTION_HEAD(void, glTexImage3D, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels) NATIVE_FUNCTION_END_NO_RETURN(void, glTexImage3D, target,level,internalformat,width,height,depth,border,format,type,pixels)
|
//NATIVE_FUNCTION_HEAD(void, glTexImage3D, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const void *pixels) NATIVE_FUNCTION_END_NO_RETURN(void, glTexImage3D, target,level,internalformat,width,height,depth,border,format,type,pixels)
|
||||||
NATIVE_FUNCTION_HEAD(void, glTexSubImage3D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels) NATIVE_FUNCTION_END_NO_RETURN(void, glTexSubImage3D, target,level,xoffset,yoffset,zoffset,width,height,depth,format,type,pixels)
|
NATIVE_FUNCTION_HEAD(void, glTexSubImage3D, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const void *pixels) NATIVE_FUNCTION_END_NO_RETURN(void, glTexSubImage3D, target,level,xoffset,yoffset,zoffset,width,height,depth,format,type,pixels)
|
||||||
|
@ -26,6 +26,18 @@ const char* glEnumToString(GLenum e) {
|
|||||||
CASE(GL_4_BYTES)
|
CASE(GL_4_BYTES)
|
||||||
CASE(GL_DOUBLE)
|
CASE(GL_DOUBLE)
|
||||||
|
|
||||||
|
CASE(GL_UNSIGNED_BYTE_3_3_2)
|
||||||
|
CASE(GL_UNSIGNED_BYTE_2_3_3_REV)
|
||||||
|
CASE(GL_UNSIGNED_SHORT_5_6_5)
|
||||||
|
CASE(GL_UNSIGNED_SHORT_5_6_5_REV)
|
||||||
|
CASE(GL_UNSIGNED_SHORT_4_4_4_4)
|
||||||
|
CASE(GL_UNSIGNED_SHORT_4_4_4_4_REV)
|
||||||
|
CASE(GL_UNSIGNED_SHORT_5_5_5_1)
|
||||||
|
CASE(GL_UNSIGNED_SHORT_1_5_5_5_REV)
|
||||||
|
CASE(GL_UNSIGNED_INT_8_8_8_8)
|
||||||
|
CASE(GL_UNSIGNED_INT_8_8_8_8_REV)
|
||||||
|
CASE(GL_UNSIGNED_INT_10_10_10_2)
|
||||||
|
|
||||||
/* Primitives */
|
/* Primitives */
|
||||||
CASE(GL_LINE_LOOP)
|
CASE(GL_LINE_LOOP)
|
||||||
CASE(GL_LINE_STRIP)
|
CASE(GL_LINE_STRIP)
|
||||||
@ -949,6 +961,21 @@ const char* glEnumToString(GLenum e) {
|
|||||||
CASE(GL_NUM_SAMPLE_COUNTS)
|
CASE(GL_NUM_SAMPLE_COUNTS)
|
||||||
CASE(GL_TEXTURE_IMMUTABLE_LEVELS)
|
CASE(GL_TEXTURE_IMMUTABLE_LEVELS)
|
||||||
|
|
||||||
|
CASE(GL_TEXTURE_RECTANGLE)
|
||||||
|
CASE(GL_TEXTURE_CUBE_MAP_POSITIVE_X)
|
||||||
|
CASE(GL_TEXTURE_CUBE_MAP_NEGATIVE_X)
|
||||||
|
CASE(GL_TEXTURE_CUBE_MAP_POSITIVE_Y)
|
||||||
|
CASE(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y)
|
||||||
|
CASE(GL_TEXTURE_CUBE_MAP_POSITIVE_Z)
|
||||||
|
CASE(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)
|
||||||
|
CASE(GL_TEXTURE_CUBE_MAP_ARRAY)
|
||||||
|
|
||||||
|
CASE(GL_BGR)
|
||||||
|
CASE(GL_BGRA)
|
||||||
|
CASE(GL_GREEN_INTEGER)
|
||||||
|
CASE(GL_BLUE_INTEGER)
|
||||||
|
CASE(GL_BGR_INTEGER)
|
||||||
|
CASE(GL_BGRA_INTEGER)
|
||||||
/*
|
/*
|
||||||
* Miscellaneous
|
* Miscellaneous
|
||||||
*/
|
*/
|
||||||
|
@ -725,6 +725,7 @@ void glDeleteTextures(GLsizei n, const GLuint *textures) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void glGenerateTextureMipmap(GLuint texture) {
|
void glGenerateTextureMipmap(GLuint texture) {
|
||||||
|
LOG()
|
||||||
GLint currentTexture;
|
GLint currentTexture;
|
||||||
auto& tex = g_textures[bound_texture];
|
auto& tex = g_textures[bound_texture];
|
||||||
GLenum target = tex.target;
|
GLenum target = tex.target;
|
||||||
@ -737,55 +738,71 @@ void glGenerateTextureMipmap(GLuint texture) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, void* pixels) {
|
void glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, void* pixels) {
|
||||||
GLint prevFBO;
|
LOG()
|
||||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFBO);
|
LOG_D("glGetTexImage, target = %s, level = %d, format = %s, type = %s, pixel = 0x%x",
|
||||||
GLenum bindingTarget = get_binding_for_target(target);
|
glEnumToString(target), level, glEnumToString(format), glEnumToString(type), pixels)
|
||||||
if (bindingTarget == 0) return;
|
|
||||||
GLint oldTexBinding;
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glGetIntegerv(bindingTarget, &oldTexBinding);
|
|
||||||
GLuint texture = static_cast<GLuint>(oldTexBinding);
|
|
||||||
if (texture == 0) return;
|
|
||||||
GLint width, height;
|
|
||||||
glBindTexture(target, texture);
|
|
||||||
glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
|
|
||||||
glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
|
|
||||||
glBindTexture(target, oldTexBinding);
|
|
||||||
if (width <= 0 || height <= 0) return;
|
|
||||||
GLuint fbo;
|
|
||||||
glGenFramebuffers(1, &fbo);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
|
||||||
if (target == GL_TEXTURE_2D || (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)) {
|
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, texture, level);
|
|
||||||
} else {
|
|
||||||
glDeleteFramebuffers(1, &fbo);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, prevFBO);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// GLint prevFBO;
|
||||||
|
// glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFBO);
|
||||||
|
// GLenum bindingTarget = get_binding_for_target(target);
|
||||||
|
// if (bindingTarget == 0) return;
|
||||||
|
// GLint oldTexBinding;
|
||||||
|
// glActiveTexture(GL_TEXTURE0);
|
||||||
|
// glGetIntegerv(bindingTarget, &oldTexBinding);
|
||||||
|
// GLuint texture = static_cast<GLuint>(oldTexBinding);
|
||||||
|
// if (texture == 0) return;
|
||||||
|
// GLint width, height;
|
||||||
|
// glBindTexture(target, texture);
|
||||||
|
// glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
|
||||||
|
// glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
|
||||||
|
// glBindTexture(target, oldTexBinding);
|
||||||
|
// if (width <= 0 || height <= 0) return;
|
||||||
|
// GLuint fbo;
|
||||||
|
// glGenFramebuffers(1, &fbo);
|
||||||
|
// glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
// if (target == GL_TEXTURE_2D || (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z)) {
|
||||||
|
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target, texture, level);
|
||||||
|
// } else {
|
||||||
|
// glDeleteFramebuffers(1, &fbo);
|
||||||
|
// glBindFramebuffer(GL_FRAMEBUFFER, prevFBO);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
|
// glDeleteFramebuffers(1, &fbo);
|
||||||
|
// glBindFramebuffer(GL_FRAMEBUFFER, prevFBO);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// GLint oldViewport[4];
|
||||||
|
// glGetIntegerv(GL_VIEWPORT, oldViewport);
|
||||||
|
// glViewport(0, 0, width, height);
|
||||||
|
// GLint oldPackAlignment;
|
||||||
|
// glGetIntegerv(GL_PACK_ALIGNMENT, &oldPackAlignment);
|
||||||
|
// glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
|
// glReadBuffer(GL_COLOR_ATTACHMENT0);
|
||||||
|
// glReadPixels(0, 0, width, height, format, type, pixels);
|
||||||
|
// glPixelStorei(GL_PACK_ALIGNMENT, oldPackAlignment);
|
||||||
|
// glViewport(oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
|
||||||
|
// glDeleteFramebuffers(1, &fbo);
|
||||||
|
// glBindFramebuffer(GL_FRAMEBUFFER, prevFBO);
|
||||||
}
|
}
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
|
||||||
glDeleteFramebuffers(1, &fbo);
|
#if GLOBAL_DEBUG || DEBUG
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, prevFBO);
|
#include <fstream>
|
||||||
return;
|
#define PX_FILE_PREFIX "/sdcard/MG/readpixels/"
|
||||||
}
|
#endif
|
||||||
GLint oldViewport[4];
|
|
||||||
glGetIntegerv(GL_VIEWPORT, oldViewport);
|
|
||||||
glViewport(0, 0, width, height);
|
|
||||||
GLint oldPackAlignment;
|
|
||||||
glGetIntegerv(GL_PACK_ALIGNMENT, &oldPackAlignment);
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
|
||||||
glReadBuffer(GL_COLOR_ATTACHMENT0);
|
|
||||||
glReadPixels(0, 0, width, height, format, type, pixels);
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, oldPackAlignment);
|
|
||||||
glViewport(oldViewport[0], oldViewport[1], oldViewport[2], oldViewport[3]);
|
|
||||||
glDeleteFramebuffers(1, &fbo);
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, prevFBO);
|
|
||||||
}
|
|
||||||
|
|
||||||
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) {
|
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels) {
|
||||||
LOG()
|
LOG()
|
||||||
LOAD_GLES_FUNC(glReadPixels)
|
LOAD_GLES_FUNC(glReadPixels)
|
||||||
LOG_D("glReadPixels, x=%d, y=%d, width=%d, height=%d, format=0x%x, type=0x%x, pixels=0x%x",
|
LOG_D("glReadPixels, x=%d, y=%d, width=%d, height=%d, format=0x%x, type=0x%x, pixels=0x%x",
|
||||||
x, y, width, height, format, type, pixels)
|
x, y, width, height, format, type, pixels)
|
||||||
|
|
||||||
|
static int count = 0;
|
||||||
|
|
||||||
|
GLenum prevFormat = format;
|
||||||
|
|
||||||
if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) {
|
if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8) {
|
||||||
format = GL_RGBA;
|
format = GL_RGBA;
|
||||||
type = GL_UNSIGNED_BYTE;
|
type = GL_UNSIGNED_BYTE;
|
||||||
@ -793,6 +810,19 @@ void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format
|
|||||||
LOG_D("glReadPixels converted, x=%d, y=%d, width=%d, height=%d, format=0x%x, type=0x%x, pixels=0x%x",
|
LOG_D("glReadPixels converted, x=%d, y=%d, width=%d, height=%d, format=0x%x, type=0x%x, pixels=0x%x",
|
||||||
x, y, width, height, format, type, pixels)
|
x, y, width, height, format, type, pixels)
|
||||||
gles_glReadPixels(x, y, width, height, format, type, pixels);
|
gles_glReadPixels(x, y, width, height, format, type, pixels);
|
||||||
|
|
||||||
|
#if GLOBAL_DEBUG || DEBUG
|
||||||
|
if (prevFormat == GL_BGRA && type == GL_UNSIGNED_BYTE) {
|
||||||
|
std::vector<uint8_t> px(width * height * sizeof(uint8_t) * 4, 0);
|
||||||
|
LOAD_GLES_FUNC(glBindBuffer)
|
||||||
|
gles_glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||||
|
gles_glReadPixels(x, y, width, height, format, type, px.data());
|
||||||
|
|
||||||
|
std::fstream fs(std::string(PX_FILE_PREFIX) + std::to_string(count++) + ".bin", std::ios::out | std::ios::binary | std::ios::trunc);
|
||||||
|
fs.write((const char*)px.data(), px.size());
|
||||||
|
fs.close();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
CHECK_GL_ERROR
|
CHECK_GL_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user