mirror of
https://github.com/H-uru/korman.git
synced 2025-07-14 02:27:36 -04:00
Fix issues resulting from incorrect korlib merge
I merged the version with access violations related to textures not actually being set in OpenGL. Dang! Here is the correct version.
This commit is contained in:
@ -27,9 +27,14 @@ class PyObjectRef {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
PyObjectRef(PyObject* o) : m_object(o) { }
|
PyObjectRef(PyObject* o) : m_object(o) { }
|
||||||
~PyObjectRef() { if (m_object) Py_DECREF(m_object); }
|
~PyObjectRef() { Py_XDECREF(m_object); }
|
||||||
|
|
||||||
operator PyObject*() const { return m_object; }
|
operator PyObject*() const { return m_object; }
|
||||||
|
PyObjectRef& operator =(PyObject* rhs) {
|
||||||
|
Py_XDECREF(m_object);
|
||||||
|
m_object = rhs;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _KORLIB_H
|
#endif // _KORLIB_H
|
||||||
|
@ -86,17 +86,18 @@ static PyObject* pyGLTexture__enter__(pyGLTexture* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &self->m_prevImage);
|
glGetIntegerv(GL_TEXTURE_BINDING_2D, &self->m_prevImage);
|
||||||
GLuint image_bindcode = PyLong_AsLong(bindcode);
|
GLuint image_bindcode = PyLong_AsUnsignedLong(bindcode);
|
||||||
self->m_ownIt = image_bindcode == 0;
|
self->m_ownIt = image_bindcode == 0;
|
||||||
|
|
||||||
// Load image into GL
|
// Load image into GL
|
||||||
if (self->m_ownIt) {
|
if (self->m_ownIt) {
|
||||||
PyObjectRef new_bind = PyObject_CallMethod(self->m_blenderImage, "gl_load", NULL);
|
PyObjectRef new_bind = PyObject_CallMethod(self->m_blenderImage, "gl_load", NULL);
|
||||||
if (!(PyObject*)new_bind) {
|
if (PyLong_AsSize_t(new_bind) != 0) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "failed to load image into GL");
|
PyErr_SetString(PyExc_RuntimeError, "failed to load image into GL");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
image_bindcode = PyLong_AsLong(new_bind);
|
bindcode = PyObject_GetAttrString(self->m_blenderImage, "bindcode");
|
||||||
|
image_bindcode = PyLong_AsUnsignedLong(bindcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set image as current in GL
|
// Set image as current in GL
|
||||||
@ -125,14 +126,19 @@ static PyObject* pyGLTexture_generate_mipmap(pyGLTexture* self) {
|
|||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t* _get_level_data(pyGLTexture* self, GLint level, bool bgra, size_t* size) {
|
static uint8_t* _get_level_data(pyGLTexture* self, GLint level, bool bgra, bool quiet, size_t* size) {
|
||||||
GLint width, height;
|
GLint width, height;
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_WIDTH, &width);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_WIDTH, &width);
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_HEIGHT, &height);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_HEIGHT, &height);
|
||||||
GLenum fmt = bgra ? GL_BGRA_EXT : GL_RGBA;
|
GLenum fmt = bgra ? GL_BGRA_EXT : GL_RGBA;
|
||||||
|
|
||||||
*size = (width * height * 4);
|
if (!quiet)
|
||||||
uint8_t* buf = new uint8_t[*size];
|
PySys_WriteStdout(" Level #%i: %ix%i\n", level, width, height);
|
||||||
|
|
||||||
|
size_t bufsz;
|
||||||
|
bufsz = (width * height * 4);
|
||||||
|
if (size) *size = bufsz;
|
||||||
|
uint8_t* buf = new uint8_t[bufsz];
|
||||||
glGetTexImage(GL_TEXTURE_2D, level, fmt, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(buf));
|
glGetTexImage(GL_TEXTURE_2D, level, fmt, GL_UNSIGNED_BYTE, reinterpret_cast<GLvoid*>(buf));
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -150,7 +156,7 @@ static PyObject* pyGLTexture_get_level_data(pyGLTexture* self, PyObject* args, P
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t bufsz;
|
size_t bufsz;
|
||||||
uint8_t* buf = _get_level_data(self, level, bgra, &bufsz);
|
uint8_t* buf = _get_level_data(self, level, bgra, quiet, &bufsz);
|
||||||
if (calc_alpha) {
|
if (calc_alpha) {
|
||||||
for (size_t i = 0; i < bufsz; i += 4)
|
for (size_t i = 0; i < bufsz; i += 4)
|
||||||
buf[i + 3] = (buf[i + 0] + buf[i + 1] + buf[i + 2]) / 3;
|
buf[i + 3] = (buf[i + 0] + buf[i + 1] + buf[i + 2]) / 3;
|
||||||
@ -203,7 +209,7 @@ static PyMethodDef pyGLTexture_Methods[] = {
|
|||||||
|
|
||||||
static PyObject* pyGLTexture_get_has_alpha(pyGLTexture* self, void*) {
|
static PyObject* pyGLTexture_get_has_alpha(pyGLTexture* self, void*) {
|
||||||
size_t bufsz;
|
size_t bufsz;
|
||||||
uint8_t* buf = _get_level_data(self, 0, false, &bufsz);
|
uint8_t* buf = _get_level_data(self, 0, false, true, &bufsz);
|
||||||
for (size_t i = 3; i < bufsz; i += 4) {
|
for (size_t i = 3; i < bufsz; i += 4) {
|
||||||
if (buf[i] != 255) {
|
if (buf[i] != 255) {
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
|
Reference in New Issue
Block a user