Texture.cpp (pymol-v2.1.0.tar.bz2) | : | Texture.cpp (pymol-open-source-2.2.0) | ||
---|---|---|---|---|
skipping to change at line 19 | skipping to change at line 19 | |||
G* Please see the accompanying LICENSE file for further information. | G* Please see the accompanying LICENSE file for further information. | |||
H* --------------------------------------------------\----------------- | H* --------------------------------------------------\----------------- | |||
I* Additional authors of this source file include: | I* Additional authors of this source file include: | |||
-* | -* | |||
-* | -* | |||
-* | -* | |||
Z* ------------------------------------------------------------------- | Z* ------------------------------------------------------------------- | |||
*/ | */ | |||
#include"os_python.h" | #include"os_python.h" | |||
#include"os_gl.h" | #include"os_gl.h" | |||
#include"ShaderMgr.h" | ||||
#include"Executive.h" | ||||
#include "Base.h" | #include "Base.h" | |||
#include "PyMOLGlobals.h" | #include "PyMOLGlobals.h" | |||
#include "Texture.h" | #include "Texture.h" | |||
#include "OOMac.h" | #include "OOMac.h" | |||
#include "OVContext.h" | #include "OVContext.h" | |||
#include "OVOneToOne.h" | #include "OVOneToOne.h" | |||
#include "OVHeapArray.h" | #include "OVHeapArray.h" | |||
#include "Setting.h" | #include "Setting.h" | |||
skipping to change at line 71 | skipping to change at line 70 | |||
#define INIT_TEXTURE_SIZE 512 | #define INIT_TEXTURE_SIZE 512 | |||
int TextureInit(PyMOLGlobals * G) | int TextureInit(PyMOLGlobals * G) | |||
{ | { | |||
OOAlloc(G, CTexture); | OOAlloc(G, CTexture); | |||
G->Texture = I; | G->Texture = I; | |||
I->ch2tex = OVOneToOne_New(G->Context->heap); | I->ch2tex = OVOneToOne_New(G->Context->heap); | |||
I->text_texture_dim = INIT_TEXTURE_SIZE; | ||||
I->text_texture_id = 0; | I->text_texture_id = 0; | |||
I->text_texture_dim = I->ypos = I->maxypos = I->num_chars = 0; | I->ypos = I->maxypos = I->num_chars = 0; | |||
I->xpos = POS_START; | I->xpos = POS_START; | |||
return (I ? 1 : 0); | return (I ? 1 : 0); | |||
} | } | |||
void TextureInitTextTextureImpl(PyMOLGlobals *G, int textureSize); | ||||
void TextureInitTextTexture(PyMOLGlobals *G){ | void TextureInitTextTexture(PyMOLGlobals *G){ | |||
TextureInitTextTextureImpl(G, INIT_TEXTURE_SIZE); | ||||
} | ||||
void TextureInvalidateTextTexture(PyMOLGlobals * G){ | ||||
CTexture *I = G->Texture; | ||||
if (I->text_texture_id){ | ||||
OVOneToOne_Reset(I->ch2tex); | ||||
I->num_chars = 0; | ||||
glDeleteTextures(1, &I->text_texture_id); | ||||
I->text_texture_id = 0; | ||||
I->text_texture_dim = INIT_TEXTURE_SIZE; | ||||
I->xpos = POS_START; I->ypos = 0; I->maxypos = POS_START; | ||||
} | ||||
} | ||||
void TextureInitTextTextureImpl(PyMOLGlobals *G, int textureSizeArg){ | ||||
short is_new = 0; | short is_new = 0; | |||
CTexture *I = G->Texture; | CTexture *I = G->Texture; | |||
int textureSize = textureSizeArg; | ||||
if (!textureSize) | ||||
textureSize = INIT_TEXTURE_SIZE; | ||||
if (!I->text_texture_id){ | if (!I->text_texture_id){ | |||
glGenTextures(1, &I->text_texture_id); | glGenTextures(1, &I->text_texture_id); | |||
is_new = 1; | is_new = 1; | |||
} | } | |||
if(I->text_texture_id){ | if(I->text_texture_id){ | |||
if (CShaderMgr_ShadersPresent(G->ShaderMgr)){ | if (G->ShaderMgr->ShadersPresent()){ | |||
glActiveTexture(GL_TEXTURE3); | glActiveTexture(GL_TEXTURE3); | |||
} | } | |||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | |||
glBindTexture(GL_TEXTURE_2D, I->text_texture_id); | glBindTexture(GL_TEXTURE_2D, I->text_texture_id); | |||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | |||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | |||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |||
if (is_new){ | if (is_new){ | |||
int tex_dim = INIT_TEXTURE_SIZE; | int tex_dim = textureSize; | |||
int buff_total = tex_dim * tex_dim; | int buff_total = tex_dim * tex_dim; | |||
unsigned char *temp_buffer = Alloc(unsigned char, buff_total * 4); | unsigned char *temp_buffer = Alloc(unsigned char, buff_total * 4); | |||
UtilZeroMem(temp_buffer, buff_total * 4); | UtilZeroMem(temp_buffer, buff_total * 4); | |||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | |||
tex_dim, tex_dim, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)temp_ buffer); | tex_dim, tex_dim, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)temp_ buffer); | |||
I->text_texture_dim = INIT_TEXTURE_SIZE; | I->text_texture_dim = textureSize; | |||
FreeP(temp_buffer); | FreeP(temp_buffer); | |||
I->xpos = POS_START; I->ypos = 0; I->maxypos = POS_START; | I->xpos = POS_START; I->ypos = 0; I->maxypos = POS_START; | |||
} | } | |||
} | } | |||
} | } | |||
#include "Rep.h" | ||||
int TextureGetFromChar(PyMOLGlobals * G, int char_id, float *extent) | int TextureGetFromChar(PyMOLGlobals * G, int char_id, float *extent) | |||
{ | { | |||
OVreturn_word result; | OVreturn_word result; | |||
CTexture *I = G->Texture; | CTexture *I = G->Texture; | |||
int is_new = false; | int is_new = false; | |||
int tex_dim = INIT_TEXTURE_SIZE; | int tex_dim = I->text_texture_dim; | |||
short use_shader = (short) SettingGetGlobal_b(G, cSetting_use_shaders); | short use_shader = (short) SettingGetGlobal_b(G, cSetting_use_shaders); | |||
if(G->HaveGUI && G->ValidContext) { | if(G->HaveGUI && G->ValidContext) { | |||
if(OVreturn_IS_OK(result = OVOneToOne_GetForward(I->ch2tex, char_id))) { | if(OVreturn_IS_OK(result = OVOneToOne_GetForward(I->ch2tex, char_id))) { | |||
if(glIsTexture(I->text_texture_id)) | if(glIsTexture(I->text_texture_id)) | |||
return I->text_texture_id; | return I->text_texture_id; | |||
else { | else { | |||
OVOneToOne_DelReverse(I->ch2tex, result.word); | OVOneToOne_DelReverse(I->ch2tex, result.word); | |||
} | } | |||
} | } | |||
skipping to change at line 160 | skipping to change at line 180 | |||
*(q++) = *(p++); | *(q++) = *(p++); | |||
*(q++) = *(p++); | *(q++) = *(p++); | |||
*(q++) = *(p++); | *(q++) = *(p++); | |||
} | } | |||
} | } | |||
if (I->xpos + w > tex_dim){ | if (I->xpos + w > tex_dim){ | |||
// if the size of the texture goes off the side, go to next row | // if the size of the texture goes off the side, go to next row | |||
I->xpos = 0; | I->xpos = 0; | |||
I->ypos = I->maxypos; | I->ypos = I->maxypos; | |||
} | } | |||
if ((I->xpos + w) >= INIT_TEXTURE_SIZE && (I->ypos + h) >= INIT_TEXTURE | if ((I->ypos + h) >= I->text_texture_dim){ // only need to check y sinc | |||
_SIZE){ | e x gets reset above | |||
int nrefreshes; | ||||
I->xpos = POS_START; I->ypos = 0; I->maxypos = POS_START; | I->xpos = POS_START; I->ypos = 0; I->maxypos = POS_START; | |||
OVOneToOne_Reset(I->ch2tex); | OVOneToOne_Reset(I->ch2tex); | |||
I->num_chars = 0; | ||||
/* Also need to reload the selection markers into the texture, since | /* Also need to reload the selection markers into the texture, since | |||
we are wiping everything out from the texture and starting from th e origin */ | we are wiping everything out from the texture and starting from th e origin */ | |||
if ((nrefreshes=SceneIncrementTextureRefreshes(G)) > 1){ | ||||
/* Texture was refreshed more than once for this frame, increase si | ||||
ze of texture */ | ||||
int newDim = I->text_texture_dim * 2; | ||||
glDeleteTextures(1, &I->text_texture_id); | ||||
I->text_texture_id = 0; | ||||
TextureInitTextTextureImpl(G, newDim); | ||||
PRINTFB(G, FB_OpenGL, FB_Output) | ||||
" Texture OpenGL: nrefreshes=%d newDim=%d\n", nrefreshes, newDim | ||||
ENDFB(G); | ||||
// printf("nrefreshes=%d newDim=%d\n", nrefreshes, new | ||||
Dim); | ||||
I->xpos = POS_START; I->ypos = 0; I->maxypos = POS_START; | ||||
SceneResetTextureRefreshes(G); | ||||
} | ||||
ExecutiveInvalidateRep(G, "all", cRepLabel, cRepInvRep); | ||||
ExecutiveInvalidateSelectionIndicators(G); | ExecutiveInvalidateSelectionIndicators(G); | |||
OrthoInvalidateDoDraw(G); | ||||
return 0; | ||||
} | } | |||
extent[0] = (I->xpos / (float) tex_dim);// + .0002f; | extent[0] = (I->xpos / (float) tex_dim); | |||
extent[1] = (I->ypos / (float) tex_dim);// + .0002f; | extent[1] = (I->ypos / (float) tex_dim); | |||
extent[2] = ((I->xpos + w) / (float) tex_dim);// - .0002f; | extent[2] = ((I->xpos + w) / (float) tex_dim); | |||
extent[3] = ((I->ypos + h) / (float) tex_dim);// - .0002f; | extent[3] = ((I->ypos + h) / (float) tex_dim); | |||
} | } | |||
if (!I->text_texture_id){ | if (!I->text_texture_id){ | |||
glGenTextures(1, &I->text_texture_id); | glGenTextures(1, &I->text_texture_id); | |||
} | } | |||
texture_id = I->text_texture_id; | texture_id = I->text_texture_id; | |||
if(I->text_texture_id && OVreturn_IS_OK(OVOneToOne_Set(I->ch2tex, char_id , I->num_chars++))) { | if(I->text_texture_id && OVreturn_IS_OK(OVOneToOne_Set(I->ch2tex, char_id , I->num_chars++))) { | |||
if (use_shader && CShaderMgr_ShadersPresent(G->ShaderMgr)){ | ||||
if (use_shader && G->ShaderMgr->ShadersPresent()){ | ||||
glActiveTexture(GL_TEXTURE3); | glActiveTexture(GL_TEXTURE3); | |||
} | } | |||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | |||
glBindTexture(GL_TEXTURE_2D, texture_id); | glBindTexture(GL_TEXTURE_2D, texture_id); | |||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); | |||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); | |||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |||
if(is_new) { | if(is_new) { | |||
I->text_texture_dim = tex_dim; | I->text_texture_dim = tex_dim; | |||
skipping to change at line 218 | skipping to change at line 257 | |||
FreeP(temp_buffer); | FreeP(temp_buffer); | |||
return texture_id; | return texture_id; | |||
} | } | |||
} | } | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
void TextureGetPlacementForNewSubtexture(PyMOLGlobals * G, int new_texture_width , int new_texture_height, int *new_texture_posx, int *new_texture_posy){ | void TextureGetPlacementForNewSubtexture(PyMOLGlobals * G, int new_texture_width , int new_texture_height, int *new_texture_posx, int *new_texture_posy){ | |||
CTexture *I = G->Texture; | CTexture *I = G->Texture; | |||
if (I->xpos + new_texture_width > INIT_TEXTURE_SIZE){ | if (I->xpos + new_texture_width > I->text_texture_dim){ | |||
I->xpos = 0; | I->xpos = 0; | |||
I->ypos = I->maxypos; | I->ypos = I->maxypos; | |||
} | } | |||
if (I->ypos + new_texture_height > I->maxypos){ | if (I->ypos + new_texture_height > I->maxypos){ | |||
I->maxypos = I->ypos + new_texture_height + 1; // added space for running o n Ipad/Iphone (weird artifacts) | I->maxypos = I->ypos + new_texture_height + 1; // added space for running o n Ipad/Iphone (weird artifacts) | |||
} | } | |||
*new_texture_posx = I->xpos; | *new_texture_posx = I->xpos; | |||
*new_texture_posy = I->ypos; | *new_texture_posy = I->ypos; | |||
I->xpos += new_texture_width + 1; // added space for running on Ipad/Iphone (w eird artifacts) | I->xpos += new_texture_width + 1; // added space for running on Ipad/Iphone (w eird artifacts) | |||
} | } | |||
End of changes. 18 change blocks. | ||||
15 lines changed or deleted | 57 lines changed or added |