ObjectAlignment.cpp (pymol-v2.1.0.tar.bz2) | : | ObjectAlignment.cpp (pymol-open-source-2.2.0) | ||
---|---|---|---|---|
skipping to change at line 830 | skipping to change at line 830 | |||
return (PConvAutoNone(result)); | return (PConvAutoNone(result)); | |||
} | } | |||
/*========================================================================*/ | /*========================================================================*/ | |||
static void ObjectAlignmentFree(ObjectAlignment * I) | static void ObjectAlignmentFree(ObjectAlignment * I) | |||
{ | { | |||
int a; | int a; | |||
for(a = 0; a < I->NState; a++) { | for(a = 0; a < I->NState; a++) { | |||
CGOFree(I->State[a].shaderCGO); | CGOFree(I->State[a].renderCGO); | |||
CGOFree(I->State[a].std); | CGOFree(I->State[a].primitiveCGO); | |||
CGOFree(I->State[a].ray); | ||||
VLAFreeP(I->State[a].alignVLA); | VLAFreeP(I->State[a].alignVLA); | |||
OVOneToAny_DEL_AUTO_NULL(I->State[a].id2tag); | OVOneToAny_DEL_AUTO_NULL(I->State[a].id2tag); | |||
} | } | |||
VLAFreeP(I->State); | VLAFreeP(I->State); | |||
ObjectPurge(&I->Obj); | ObjectPurge(&I->Obj); | |||
OOFreeP(I); | OOFreeP(I); | |||
} | } | |||
/*========================================================================*/ | /*========================================================================*/ | |||
void ObjectAlignmentRecomputeExtent(ObjectAlignment * I) | void ObjectAlignmentRecomputeExtent(ObjectAlignment * I) | |||
{ | { | |||
float mx[3], mn[3]; | float mx[3], mn[3]; | |||
int extent_flag = false; | int extent_flag = false; | |||
int a; | int a; | |||
for(a = 0; a < I->NState; a++) | for(a = 0; a < I->NState; a++) | |||
if(I->State[a].std) { | if(I->State[a].primitiveCGO) { | |||
if(CGOGetExtent(I->State[a].std, mn, mx)) { | if(CGOGetExtent(I->State[a].primitiveCGO, mn, mx)) { | |||
if(!extent_flag) { | if(!extent_flag) { | |||
extent_flag = true; | extent_flag = true; | |||
copy3f(mx, I->Obj.ExtentMax); | copy3f(mx, I->Obj.ExtentMax); | |||
copy3f(mn, I->Obj.ExtentMin); | copy3f(mn, I->Obj.ExtentMin); | |||
} else { | } else { | |||
max3f(mx, I->Obj.ExtentMax, I->Obj.ExtentMax); | max3f(mx, I->Obj.ExtentMax, I->Obj.ExtentMax); | |||
min3f(mn, I->Obj.ExtentMin, I->Obj.ExtentMin); | min3f(mn, I->Obj.ExtentMin, I->Obj.ExtentMin); | |||
} | } | |||
} | } | |||
} | } | |||
I->Obj.ExtentFlag = extent_flag; | I->Obj.ExtentFlag = extent_flag; | |||
} | } | |||
/*========================================================================*/ | /*========================================================================*/ | |||
void ObjectAlignmentUpdate(ObjectAlignment * I) | void ObjectAlignmentUpdate(ObjectAlignment * I) | |||
{ | { | |||
PyMOLGlobals *G = I->Obj.G; | PyMOLGlobals *G = I->Obj.G; | |||
int update_needed = false; | int update_needed = false; | |||
short use_shader = SettingGetGlobal_b(G, cSetting_alignment_as_cylinders) && | ||||
SettingGetGlobal_b(G, cSetting_render_as_cylinders) && | ||||
SettingGetGlobal_b(G, cSetting_use_shaders); | ||||
{ | { | |||
int a; | int a; | |||
for(a = 0; a < I->NState; a++) { | for(a = 0; a < I->NState; a++) { | |||
ObjectAlignmentState *oas = I->State + a; | ObjectAlignmentState *oas = I->State + a; | |||
if(!oas->valid || (use_shader && !oas->shaderCGO)){ | if(!oas->valid){ | |||
update_needed = true; | update_needed = true; | |||
} | } | |||
} | } | |||
} | } | |||
if(update_needed) { | if(update_needed) { | |||
{ | { | |||
int a; | int a; | |||
for(a = 0; a < I->NState; a++) { | for(a = 0; a < I->NState; a++) { | |||
ObjectAlignmentState *oas = I->State + a; | ObjectAlignmentState *oas = I->State + a; | |||
if(!oas->valid || (use_shader && !oas->shaderCGO)){ | if(!oas->valid){ | |||
ObjectMolecule *guide_obj = NULL; | ObjectMolecule *guide_obj = NULL; | |||
if(oas->guide[0]) { | if(oas->guide[0]) { | |||
guide_obj = ExecutiveFindObjectMoleculeByName(G, oas->guide); | guide_obj = ExecutiveFindObjectMoleculeByName(G, oas->guide); | |||
} | } | |||
if(I->SelectionState == a) | if(I->SelectionState == a) | |||
I->SelectionState = -1; | I->SelectionState = -1; | |||
CGOFree(oas->std); | CGOFree(oas->primitiveCGO); | |||
CGOFree(oas->ray); | ||||
if(oas->id2tag) { | if(oas->id2tag) { | |||
OVOneToAny_Reset(oas->id2tag); | OVOneToAny_Reset(oas->id2tag); | |||
} else { | } else { | |||
oas->id2tag = OVOneToAny_New(G->Context->heap); | oas->id2tag = OVOneToAny_New(G->Context->heap); | |||
} | } | |||
{ | { | |||
CGO *cgo = CGONew(G); | CGO *cgo = CGONew(G); | |||
skipping to change at line 958 | skipping to change at line 953 | |||
scale3f(mean, scale, mean); | scale3f(mean, scale, mean); | |||
c = b; | c = b; | |||
while((id = vla[c++])) { | while((id = vla[c++])) { | |||
auto eoo = ExecutiveUniqueIDAtomDictGet(G, id); | auto eoo = ExecutiveUniqueIDAtomDictGet(G, id); | |||
if (eoo) { | if (eoo) { | |||
if(ObjectMoleculeGetAtomVertex(eoo->obj, a, | if(ObjectMoleculeGetAtomVertex(eoo->obj, a, | |||
eoo->atm, vert)) { | eoo->atm, vert)) { | |||
if(gvert_valid) { | if(gvert_valid) { | |||
if(eoo->obj != guide_obj) { | if(eoo->obj != guide_obj) { | |||
CGOVertexv(cgo, gvert); | cgo->add<cgo::draw::line>(gvert, vert); | |||
CGOVertexv(cgo, vert); | ||||
} | } | |||
} else { | } else { | |||
CGOVertexv(cgo, mean); | cgo->add<cgo::draw::line>(mean, vert); | |||
CGOVertexv(cgo, vert); | ||||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
} else if(n_coord) { /* if 2 points, then simply draw a line */ | } else if(n_coord) { /* if 2 points, then simply draw a line */ | |||
float first[3]; | float first[3]; | |||
int first_flag = true; | int first_flag = true; | |||
c = b; | c = b; | |||
while((id = vla[c++])) { | while((id = vla[c++])) { | |||
auto eoo = ExecutiveUniqueIDAtomDictGet(G, id); | auto eoo = ExecutiveUniqueIDAtomDictGet(G, id); | |||
if (eoo) { | if (eoo) { | |||
if(ObjectMoleculeGetAtomVertex(eoo->obj, a, | if(ObjectMoleculeGetAtomVertex(eoo->obj, a, | |||
eoo->atm, vert)) { | eoo->atm, vert)) { | |||
if(first_flag) { | if(first_flag) { | |||
copy3f(vert, first); | copy3f(vert, first); | |||
first_flag = false; | first_flag = false; | |||
} else { | } else { | |||
CGOVertexv(cgo, first); | cgo->add<cgo::draw::line>(first, vert); | |||
CGOVertexv(cgo, vert); | ||||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
/* update the it2tag dictionary */ | /* update the it2tag dictionary */ | |||
tag++; | tag++; | |||
while((b < n_id) && vla[b]) { | while((b < n_id) && vla[b]) { | |||
OVOneToAny_SetKey(id2tag, vla[b], tag); | OVOneToAny_SetKey(id2tag, vla[b], tag); | |||
b++; | b++; | |||
} | } | |||
} | } | |||
CGOEnd(cgo); | CGOEnd(cgo); | |||
} | } | |||
CGOStop(cgo); | CGOStop(cgo); | |||
oas->primitiveCGO = cgo; | ||||
/* simplify if necessary */ | if (!CGOHasOperationsOfType(oas->primitiveCGO, cgo::draw::line::op_c | |||
ode)){ | ||||
{ | CGOFree(oas->primitiveCGO); | |||
int est = CGOCheckComplex(cgo); | ||||
{ | ||||
CGO *convertcgo = NULL; | ||||
if(cgo){ | ||||
if(oas->shaderCGO) { | ||||
CGOFree(oas->shaderCGO); | ||||
oas->shaderCGO = NULL; | ||||
} | ||||
oas->shaderCGO = CGOConvertLinesToShaderCylinders(cgo, 0); | ||||
convertcgo = CGOCombineBeginEnd(cgo, 0); | ||||
CGOFree(cgo); | ||||
cgo = convertcgo; | ||||
} | ||||
} | ||||
if(est) { | ||||
oas->ray = cgo; | ||||
oas->std = CGOSimplify(cgo, est); | ||||
} else | ||||
oas->std = cgo; | ||||
} | } | |||
} | } | |||
oas->valid = true; | oas->valid = true; | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
if(I->SelectionState < 0) { | if(I->SelectionState < 0) { | |||
int state = -1; | int state = -1; | |||
if(I->ForceState >= 0) { | if(I->ForceState >= 0) { | |||
skipping to change at line 1074 | skipping to change at line 1046 | |||
/*========================================================================*/ | /*========================================================================*/ | |||
static void ObjectAlignmentRender(ObjectAlignment * I, RenderInfo * info) | static void ObjectAlignmentRender(ObjectAlignment * I, RenderInfo * info) | |||
{ | { | |||
PyMOLGlobals *G = I->Obj.G; | PyMOLGlobals *G = I->Obj.G; | |||
int state = info->state; | int state = info->state; | |||
CRay *ray = info->ray; | CRay *ray = info->ray; | |||
Picking **pick = info->pick; | Picking **pick = info->pick; | |||
int pass = info->pass; | int pass = info->pass; | |||
ObjectAlignmentState *sobj = NULL; | ObjectAlignmentState *sobj = NULL; | |||
float *color; | const float *color; | |||
ObjectPrepareContext(&I->Obj, ray); | ObjectPrepareContext(&I->Obj, info); | |||
color = ColorGet(G, I->Obj.Color); | color = ColorGet(G, I->Obj.Color); | |||
if(!pass) { | if (pick) | |||
return; | ||||
if(pass>0 || ray) { | ||||
if((I->Obj.visRep & cRepCGOBit)) { | if((I->Obj.visRep & cRepCGOBit)) { | |||
for(StateIterator iter(G, I->Obj.Setting, state, I->NState); iter.next();) { | for(StateIterator iter(G, I->Obj.Setting, state, I->NState); iter.next();) { | |||
sobj = I->State + iter.state; | sobj = I->State + iter.state; | |||
if(ray) { | ||||
int try_std = false; | ||||
if(sobj->ray){ | if (!sobj->primitiveCGO) | |||
int ok = CGORenderRay(sobj->ray, ray, color, I->Obj.Setting, NUL | continue; | |||
L); | ||||
if (!ok){ | if(ray) { | |||
CGOFree(sobj->ray); | CGORenderRay(sobj->primitiveCGO, ray, info, color, NULL, I->Obj.Setti | |||
sobj->ray = NULL; | ng, NULL); | |||
try_std = true; | } else if(G->HaveGUI && G->ValidContext) { | |||
} | #ifndef PURE_OPENGL_ES_2 | |||
} else { | if(!info->line_lighting) | |||
try_std = true; | glDisable(GL_LIGHTING); | |||
} | #endif | |||
if (try_std){ | SceneResetNormal(G, true); | |||
int ok = CGORenderRay(sobj->std, ray, color, I->Obj.Setting, NUL | bool use_shader = SettingGetGlobal_b(G, cSetting_use_shaders); | |||
L); | ||||
if (!ok){ | CGO * cgo = NULL; | |||
CGOFree(sobj->std); | ||||
sobj->std = NULL; | if (use_shader) { | |||
} | bool as_cylinders = | |||
} | SettingGetGlobal_b(G, cSetting_alignment_as_cylinders) && | |||
} else if(G->HaveGUI && G->ValidContext) { | SettingGetGlobal_b(G, cSetting_render_as_cylinders); | |||
if(!info->line_lighting) | ||||
glDisable(GL_LIGHTING); | bool trilines = !as_cylinders && SettingGetGlobal_b(G, cSetting_tril | |||
SceneResetNormal(G, true); | ines); | |||
if(pick) { | ||||
if (sobj->renderCGO && ( | ||||
(as_cylinders ^ sobj->renderCGO_has_cylinders) || | ||||
(trilines ^ sobj->renderCGO_has_trilines))){ | ||||
CGOFree(sobj->renderCGO); | ||||
} | ||||
if (!sobj->renderCGO) { | ||||
int shader = | ||||
as_cylinders ? GL_CYLINDER_SHADER : | ||||
trilines ? GL_TRILINES_SHADER : GL_LINE_SHADER; | ||||
CGO *tmpCGO = CGONew(G), *tmp2CGO = NULL; | ||||
CGOEnable(tmpCGO, shader); | ||||
CGOSpecial(tmpCGO, SET_ALIGNMENT_UNIFORMS_ATTRIBS); | ||||
if (as_cylinders) { | ||||
tmp2CGO = CGOConvertLinesToCylinderShader(sobj->primitiveCGO, tm | ||||
pCGO, false); | ||||
} else if (trilines) { | ||||
tmp2CGO = CGOConvertToTrilinesShader(sobj->primitiveCGO, tmpCGO, | ||||
false); | ||||
} else { | } else { | |||
if(sobj->std){ | tmp2CGO = CGOConvertToLinesShader(sobj->primitiveCGO, tmpCGO, fa | |||
short use_shader = SettingGetGlobal_b(G, cSetting_alignment_as_ | lse); | |||
cylinders) && | ||||
SettingGetGlobal_b(G, cSetting_render_as_cylinders) && | ||||
SettingGetGlobal_b(G, cSetting_use_shaders); | ||||
if (use_shader){ | ||||
if (!sobj->shaderCGO){ | ||||
ObjectAlignmentUpdate(I); | ||||
} | ||||
if (!sobj->shaderCGO->has_draw_cylinder_buffers){ | ||||
CGO *convertcgo = sobj->shaderCGO; | ||||
sobj->shaderCGO = CGOOptimizeGLSLCylindersToVBOIndexedNoCol | ||||
or(convertcgo, 0); | ||||
if (sobj->shaderCGO){ | ||||
CGOFree(convertcgo); | ||||
} else { | ||||
sobj->shaderCGO = convertcgo; | ||||
} | ||||
sobj->shaderCGO->use_shader = use_shader; | ||||
} | ||||
{ | ||||
CShaderPrg *shaderPrg; | ||||
float line_width = SettingGet_f(G, I->Obj.Setting, NULL, cS | ||||
etting_line_width); | ||||
float radius = SceneGetLineWidthForCylinders(G, info, line_ | ||||
width); | ||||
shaderPrg = CShaderPrg_Enable_CylinderShader(G); | ||||
CShaderPrg_Set1f(shaderPrg, "uni_radius", radius); | ||||
glVertexAttrib4f(CYLINDER_COLOR, color[0], color[1], color[ | ||||
2], 1.f); | ||||
glVertexAttrib4f(CYLINDER_COLOR2, color[0], color[1], color | ||||
[2], 1.f); | ||||
CGORenderGL(sobj->shaderCGO, color, NULL, NULL, info, NULL) | ||||
; | ||||
CShaderPrg_Disable(shaderPrg); | ||||
return; | ||||
} | ||||
} else { | ||||
CGORenderGL(sobj->std, color, I->Obj.Setting, NULL, info, NUL | ||||
L); | ||||
} | ||||
} | ||||
} | } | |||
glEnable(GL_LIGHTING); | ||||
tmpCGO->free_append(tmp2CGO); | ||||
CGODisable(tmpCGO, shader); | ||||
sobj->renderCGO = tmpCGO; | ||||
sobj->renderCGO_has_cylinders = as_cylinders; | ||||
sobj->renderCGO_has_trilines = trilines; | ||||
} | } | |||
cgo = sobj->renderCGO; | ||||
} else { | ||||
cgo = sobj->primitiveCGO; | ||||
} | ||||
if (cgo) { | ||||
CGORenderGL(cgo, color, I->Obj.Setting, NULL, info, NULL); | ||||
} | ||||
#ifndef PURE_OPENGL_ES_2 | ||||
glEnable(GL_LIGHTING); | ||||
#endif | ||||
} | ||||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
static void ObjectAlignmentInvalidate(ObjectAlignment * I, int rep, int level, i nt state) | static void ObjectAlignmentInvalidate(ObjectAlignment * I, int rep, int level, i nt state) | |||
{ | { | |||
if((rep == cRepAll) || (rep == cRepCGO)) { | if((rep == cRepAll) || (rep == cRepCGO)) { | |||
for(StateIterator iter(I->Obj.G, I->Obj.Setting, state, I->NState); iter.nex t();) { | for(StateIterator iter(I->Obj.G, I->Obj.Setting, state, I->NState); iter.nex t();) { | |||
ObjectAlignmentState *sobj = I->State + iter.state; | ObjectAlignmentState *sobj = I->State + iter.state; | |||
sobj->valid = false; | sobj->valid = false; | |||
CGOFree(sobj->renderCGO); | ||||
} | } | |||
} | } | |||
} | } | |||
/*========================================================================*/ | /*========================================================================*/ | |||
static ObjectAlignment *ObjectAlignmentNew(PyMOLGlobals * G) | static ObjectAlignment *ObjectAlignmentNew(PyMOLGlobals * G) | |||
{ | { | |||
OOAlloc(G, ObjectAlignment); | OOAlloc(G, ObjectAlignment); | |||
ObjectInit(G, (CObject *) I); | ObjectInit(G, (CObject *) I); | |||
End of changes. 19 change blocks. | ||||
113 lines changed or deleted | 90 lines changed or added |