mirror of
https://github.com/H-uru/korman.git
synced 2025-07-14 02:27:36 -04:00
Change to Blender 2.77 style bpy.types.Image.bindcode.
This idiotic change was introduced in stealth mode from 2.76 to 2.77. It has something to do with 3d textures, supposedly. I think the person who made this change is simply an asshat...
This commit is contained in:
@ -30,6 +30,8 @@
|
|||||||
# define GL_GENERATE_MIPMAP 0x8191
|
# define GL_GENERATE_MIPMAP 0x8191
|
||||||
#endif // GL_GENERATE_MIPMAP
|
#endif // GL_GENERATE_MIPMAP
|
||||||
|
|
||||||
|
#define TEXTARGET_TEXTURE_2D 0
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -80,8 +82,16 @@ static int pyGLTexture___init__(pyGLTexture* self, PyObject* args, PyObject* kwd
|
|||||||
static PyObject* pyGLTexture__enter__(pyGLTexture* self) {
|
static PyObject* pyGLTexture__enter__(pyGLTexture* self) {
|
||||||
// Is the image already loaded?
|
// Is the image already loaded?
|
||||||
PyObjectRef bindcode = PyObject_GetAttrString(self->m_blenderImage, "bindcode");
|
PyObjectRef bindcode = PyObject_GetAttrString(self->m_blenderImage, "bindcode");
|
||||||
|
|
||||||
|
// bindcode changed to a sequence in 2.77. We want the first element for a 2D texture.
|
||||||
|
// Why did we make this change, exactly?
|
||||||
|
if (PySequence_Check(bindcode)) {
|
||||||
|
bindcode = PySequence_GetItem(bindcode, TEXTARGET_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now we should have a GLuint...
|
||||||
if (!PyLong_Check(bindcode)) {
|
if (!PyLong_Check(bindcode)) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Image bindcode isn't a long?");
|
PyErr_SetString(PyExc_TypeError, "Image bindcode isn't a long?");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,11 +102,24 @@ static PyObject* pyGLTexture__enter__(pyGLTexture* self) {
|
|||||||
// 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 (PyLong_AsSize_t(new_bind) != 0) {
|
if (!PyLong_Check(new_bind)) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "failed to load image into GL");
|
PyErr_SetString(PyExc_TypeError, "gl_load() did not return a long");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ssize_t result = PyLong_AsSize_t(new_bind);
|
||||||
|
if (result != GL_NO_ERROR) {
|
||||||
|
PyErr_Format(PyExc_RuntimeError, "gl_load() error: %d", result);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bindcode = PyObject_GetAttrString(self->m_blenderImage, "bindcode");
|
bindcode = PyObject_GetAttrString(self->m_blenderImage, "bindcode");
|
||||||
|
if (PySequence_Check(bindcode)) {
|
||||||
|
bindcode = PySequence_GetItem(bindcode, TEXTARGET_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
// Now we should have a GLuint...
|
||||||
|
if (!PyLong_Check(bindcode)) {
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Image bindcode isn't a long?");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
image_bindcode = PyLong_AsUnsignedLong(bindcode);
|
image_bindcode = PyLong_AsUnsignedLong(bindcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +22,10 @@ from . import operators
|
|||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "Korman",
|
"name": "Korman",
|
||||||
"author": "Guild of Writers",
|
"author": "Guild of Writers",
|
||||||
"blender": (2, 74, 0), # I can't be bothered to support old stuff
|
"blender": (2, 77, 0),
|
||||||
"location": "File > Import-Export",
|
"location": "File > Import-Export",
|
||||||
"description": "Exporter for Cyan Worlds' Plasma Engine",
|
"description": "Exporter for Cyan Worlds' Plasma Engine",
|
||||||
"warning": "alpha",
|
"warning": "beta",
|
||||||
"category": "System", # Eventually, we will hide some of the default
|
"category": "System", # Eventually, we will hide some of the default
|
||||||
# Blender panels (think materials)
|
# Blender panels (think materials)
|
||||||
}
|
}
|
||||||
|
@ -572,9 +572,10 @@ class MaterialConverter:
|
|||||||
|
|
||||||
def _resize_image(self, image, width, height):
|
def _resize_image(self, image, width, height):
|
||||||
image.scale(width, height)
|
image.scale(width, height)
|
||||||
|
image.update()
|
||||||
|
|
||||||
# If the image is already loaded into OpenGL, we need to refresh it to get the scaling.
|
# If the image is already loaded into OpenGL, we need to refresh it to get the scaling.
|
||||||
if image.bindcode != 0:
|
if image.bindcode[0] != 0:
|
||||||
image.gl_free()
|
image.gl_free()
|
||||||
image.gl_load()
|
image.gl_load()
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ bgl.GL_BGRA = 0x80E1
|
|||||||
|
|
||||||
class GLTexture:
|
class GLTexture:
|
||||||
def __init__(self, blimg):
|
def __init__(self, blimg):
|
||||||
self._ownit = (blimg.bindcode == 0)
|
self._ownit = (blimg.bindcode[0] == 0)
|
||||||
self._blimg = blimg
|
self._blimg = blimg
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
@ -32,9 +32,9 @@ class GLTexture:
|
|||||||
raise RuntimeError("failed to load image")
|
raise RuntimeError("failed to load image")
|
||||||
|
|
||||||
self._previous_texture = self._get_integer(bgl.GL_TEXTURE_BINDING_2D)
|
self._previous_texture = self._get_integer(bgl.GL_TEXTURE_BINDING_2D)
|
||||||
self._changed_state = (self._previous_texture != self._blimg.bindcode)
|
self._changed_state = (self._previous_texture != self._blimg.bindcode[0])
|
||||||
if self._changed_state:
|
if self._changed_state:
|
||||||
bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._blimg.bindcode)
|
bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._blimg.bindcode[0])
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
|
Reference in New Issue
Block a user