Browse Source

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...
pull/35/head
Adam Johnson 8 years ago
parent
commit
cb6541675a
  1. 29
      korlib/texture.cpp
  2. 4
      korman/__init__.py
  3. 3
      korman/exporter/material.py
  4. 6
      korman/korlib/texture.py

29
korlib/texture.cpp

@ -30,6 +30,8 @@
# define GL_GENERATE_MIPMAP 0x8191
#endif // GL_GENERATE_MIPMAP
#define TEXTARGET_TEXTURE_2D 0
extern "C" {
typedef struct {
@ -80,8 +82,16 @@ static int pyGLTexture___init__(pyGLTexture* self, PyObject* args, PyObject* kwd
static PyObject* pyGLTexture__enter__(pyGLTexture* self) {
// Is the image already loaded?
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)) {
PyErr_SetString(PyExc_RuntimeError, "Image bindcode isn't a long?");
PyErr_SetString(PyExc_TypeError, "Image bindcode isn't a long?");
return NULL;
}
@ -92,11 +102,24 @@ static PyObject* pyGLTexture__enter__(pyGLTexture* self) {
// Load image into GL
if (self->m_ownIt) {
PyObjectRef new_bind = PyObject_CallMethod(self->m_blenderImage, "gl_load", NULL);
if (PyLong_AsSize_t(new_bind) != 0) {
PyErr_SetString(PyExc_RuntimeError, "failed to load image into GL");
if (!PyLong_Check(new_bind)) {
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;
}
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);
}

4
korman/__init__.py

@ -22,10 +22,10 @@ from . import operators
bl_info = {
"name": "Korman",
"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",
"description": "Exporter for Cyan Worlds' Plasma Engine",
"warning": "alpha",
"warning": "beta",
"category": "System", # Eventually, we will hide some of the default
# Blender panels (think materials)
}

3
korman/exporter/material.py

@ -572,9 +572,10 @@ class MaterialConverter:
def _resize_image(self, image, 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 image.bindcode != 0:
if image.bindcode[0] != 0:
image.gl_free()
image.gl_load()

6
korman/korlib/texture.py

@ -22,7 +22,7 @@ bgl.GL_BGRA = 0x80E1
class GLTexture:
def __init__(self, blimg):
self._ownit = (blimg.bindcode == 0)
self._ownit = (blimg.bindcode[0] == 0)
self._blimg = blimg
def __enter__(self):
@ -32,9 +32,9 @@ class GLTexture:
raise RuntimeError("failed to load image")
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:
bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._blimg.bindcode)
bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._blimg.bindcode[0])
return self
def __exit__(self, type, value, traceback):

Loading…
Cancel
Save