ObjectSlice.cpp (pymol-v2.1.0.tar.bz2) | : | ObjectSlice.cpp (pymol-open-source-2.2.0) | ||
---|---|---|---|---|
skipping to change at line 45 | skipping to change at line 45 | |||
#include"Scene.h" | #include"Scene.h" | |||
#include"Setting.h" | #include"Setting.h" | |||
#include"Executive.h" | #include"Executive.h" | |||
#include"PConv.h" | #include"PConv.h" | |||
#include"P.h" | #include"P.h" | |||
#include"Text.h" | #include"Text.h" | |||
#include"Util.h" | #include"Util.h" | |||
#include"ButMode.h" | #include"ButMode.h" | |||
#include"ObjectGadgetRamp.h" | #include"ObjectGadgetRamp.h" | |||
#include"CGO.h" | #include"CGO.h" | |||
#include"ShaderMgr.h" | ||||
#define START_STRIP -1 | #define START_STRIP -1 | |||
#define STOP_STRIP -2 | #define STOP_STRIP -2 | |||
ObjectSlice *ObjectSliceNew(PyMOLGlobals * G); | ObjectSlice *ObjectSliceNew(PyMOLGlobals * G); | |||
static void ObjectSliceFree(ObjectSlice * I); | static void ObjectSliceFree(ObjectSlice * I); | |||
void ObjectSliceStateInit(PyMOLGlobals * G, ObjectSliceState * ms); | void ObjectSliceStateInit(PyMOLGlobals * G, ObjectSliceState * ms); | |||
void ObjectSliceRecomputeExtent(ObjectSlice * I); | void ObjectSliceRecomputeExtent(ObjectSlice * I); | |||
skipping to change at line 703 | skipping to change at line 704 | |||
if(oss->RefreshFlag) { | if(oss->RefreshFlag) { | |||
oss->RefreshFlag = false; | oss->RefreshFlag = false; | |||
PRINTFB(I->Obj.G, FB_ObjectSlice, FB_Blather) | PRINTFB(I->Obj.G, FB_ObjectSlice, FB_Blather) | |||
" ObjectSlice: updating \"%s\".\n", I->Obj.Name ENDFB(I->Obj.G); | " ObjectSlice: updating \"%s\".\n", I->Obj.Name ENDFB(I->Obj.G); | |||
if(oms->Field) { | if(oms->Field) { | |||
ObjectSliceStateUpdate(I, oss, oms); | ObjectSliceStateUpdate(I, oss, oms); | |||
ogr = ColorGetRamp(I->Obj.G, I->Obj.Color); | ogr = ColorGetRamp(I->Obj.G, I->Obj.Color); | |||
if(ogr) | if(ogr) | |||
ObjectSliceStateAssignColors(oss, ogr); | ObjectSliceStateAssignColors(oss, ogr); | |||
else { /* solid color */ | else { /* solid color */ | |||
float *solid = ColorGet(I->Obj.G, I->Obj.Color); | const float *solid = ColorGet(I->Obj.G, I->Obj.Color); | |||
float *color = oss->colors; | float *color = oss->colors; | |||
for(a = 0; a < oss->n_points; a++) { | for(a = 0; a < oss->n_points; a++) { | |||
*(color++) = solid[0]; | *(color++) = solid[0]; | |||
*(color++) = solid[1]; | *(color++) = solid[1]; | |||
*(color++) = solid[2]; | *(color++) = solid[2]; | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
skipping to change at line 957 | skipping to change at line 958 | |||
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; | |||
int cur_state = 0; | int cur_state = 0; | |||
float alpha; | float alpha; | |||
int track_camera = SettingGet_b(G, NULL, I->Obj.Setting, cSetting_slice_track_ camera); | int track_camera = SettingGet_b(G, NULL, I->Obj.Setting, cSetting_slice_track_ camera); | |||
int dynamic_grid = SettingGet_b(G, NULL, I->Obj.Setting, cSetting_slice_dynami c_grid); | int dynamic_grid = SettingGet_b(G, NULL, I->Obj.Setting, cSetting_slice_dynami c_grid); | |||
ObjectSliceState *oss = NULL; | ObjectSliceState *oss = NULL; | |||
int use_shaders = !track_camera && SettingGet_b(G, NULL, I->Obj.Setting, cSett ing_use_shaders); | int use_shaders = !track_camera && SettingGet_b(G, NULL, I->Obj.Setting, cSett ing_use_shaders); | |||
if (G->ShaderMgr->Get_Current_Shader()){ | ||||
// just in case, since slice uses immediate mode, but this should never happ | ||||
en | ||||
G->ShaderMgr->Get_Current_Shader()->Disable(); | ||||
} | ||||
if(track_camera || dynamic_grid) { | if(track_camera || dynamic_grid) { | |||
int update_flag = false; | int update_flag = false; | |||
if(state >= 0) | if(state >= 0) | |||
if(state < I->NState) | if(state < I->NState) | |||
if(I->State[state].Active) | if(I->State[state].Active) | |||
oss = I->State + state; | oss = I->State + state; | |||
while(1) { | while(1) { | |||
skipping to change at line 1011 | skipping to change at line 1016 | |||
if(state >= 0) | if(state >= 0) | |||
break; | break; | |||
cur_state = cur_state + 1; | cur_state = cur_state + 1; | |||
if(cur_state >= I->NState) | if(cur_state >= I->NState) | |||
break; | break; | |||
} | } | |||
} | } | |||
ObjectSliceUpdate(I); | ObjectSliceUpdate(I); | |||
} | } | |||
ObjectPrepareContext(&I->Obj, ray); | ObjectPrepareContext(&I->Obj, info); | |||
alpha = SettingGet_f(G, NULL, I->Obj.Setting, cSetting_transparency); | alpha = SettingGet_f(G, NULL, I->Obj.Setting, cSetting_transparency); | |||
alpha = 1.0F - alpha; | alpha = 1.0F - alpha; | |||
if(fabs(alpha - 1.0) < R_SMALL4) | if(fabs(alpha - 1.0) < R_SMALL4) | |||
alpha = 1.0F; | alpha = 1.0F; | |||
if(state >= 0) | if(state >= 0) | |||
if(state < I->NState) | if(state < I->NState) | |||
if(I->State[state].Active) | if(I->State[state].Active) | |||
oss = I->State + state; | oss = I->State + state; | |||
skipping to change at line 1106 | skipping to change at line 1111 | |||
} | } | |||
} | } | |||
} | } | |||
break; | break; | |||
} | } | |||
} | } | |||
} | } | |||
ray->transparentf(0.0); | ray->transparentf(0.0); | |||
} else if(G->HaveGUI && G->ValidContext) { | } else if(G->HaveGUI && G->ValidContext) { | |||
if(pick) { | if(pick) { | |||
if (oss->shaderCGO && (I->Obj.visRep & cRepSliceBit)){ | ||||
CGORenderGLPicking(oss->shaderCGO, info, &I->context, I->Obj.Setti | ||||
ng, NULL); | ||||
} else { | ||||
#ifndef PURE_OPENGL_ES_2 | #ifndef PURE_OPENGL_ES_2 | |||
int i = (*pick)->src.index; | unsigned int i = (*pick)->src.index; | |||
int j; | ||||
Picking p; | Picking p; | |||
SceneSetupGLPicking(G); | SceneSetupGLPicking(G); | |||
p.context.object = (void *) I; | p.context.object = (void *) I; | |||
p.context.state = 0; | p.context.state = 0; | |||
p.src.index = state + 1; | p.src.index = state + 1; | |||
p.src.bond = 0; | p.src.bond = 0; | |||
if((I->Obj.visRep & cRepSliceBit)) { | if((I->Obj.visRep & cRepSliceBit)) { | |||
int *strip = oss->strips; | int *strip = oss->strips; | |||
float *point = oss->points; | float *point = oss->points; | |||
skipping to change at line 1147 | skipping to change at line 1154 | |||
strip_active = false; | strip_active = false; | |||
break; | break; | |||
default: | default: | |||
if(strip_active) { | if(strip_active) { | |||
tri_count++; | tri_count++; | |||
offset2 = offset1; | offset2 = offset1; | |||
offset1 = offset0; | offset1 = offset0; | |||
offset0 = offset; | offset0 = offset; | |||
if(tri_count >= 3) { | if(tri_count >= 3) { | |||
unsigned char color[4]; | ||||
i++; | AssignNewPickColor(NULL, i, pick, &I->context, color, p.sr | |||
if(!(*pick)[0].src.bond) { | c.index, p.src.bond); | |||
/* pass 1 - low order bits */ | glColor4ubv(color); | |||
glColor3ub((uchar) ((i & 0xF) << 4), (uchar) ((i & 0xF0) | ||||
| 0x8), | ||||
(uchar) ((i & 0xF00) >> 4)); | ||||
VLACheck((*pick), Picking, i); | ||||
(*pick)[i] = p; /* copy object and atom info */ | ||||
} else { | ||||
/* pass 2 - high order bits */ | ||||
j = i >> 12; | ||||
glColor3ub((uchar) ((j & 0xF) << 4), (uchar) ((j & 0xF0) | ||||
| 0x8), | ||||
(uchar) ((j & 0xF00) >> 4)); | ||||
} | ||||
p.src.bond = offset0 + 1; | ||||
if(tri_count & 0x1) { /* get the handedness right ... */ | if(tri_count & 0x1) { /* get the handedness right ... */ | |||
glVertex3fv(point + 3 * offset0); | glVertex3fv(point + 3 * offset0); | |||
glVertex3fv(point + 3 * offset1); | glVertex3fv(point + 3 * offset1); | |||
glVertex3fv(point + 3 * offset2); | glVertex3fv(point + 3 * offset2); | |||
} else { | } else { | |||
glVertex3fv(point + 3 * offset1); | glVertex3fv(point + 3 * offset1); | |||
glVertex3fv(point + 3 * offset0); | glVertex3fv(point + 3 * offset0); | |||
glVertex3fv(point + 3 * offset2); | glVertex3fv(point + 3 * offset2); | |||
} | } | |||
p.src.bond = offset0 + 1; | ||||
} | } | |||
} | } | |||
break; | break; | |||
} | } | |||
} | } | |||
if(strip_active) { /* just in case */ | if(strip_active) { /* just in case */ | |||
glEnd(); | glEnd(); | |||
} | } | |||
} | } | |||
(*pick)[0].src.index = i; /* pass the count */ | (*pick)[0].src.index = i; /* pass the count */ | |||
#endif | #endif | |||
} | ||||
} else { // !pick | } else { // !pick | |||
int render_now = false; | int render_now = false; | |||
if(alpha > 0.0001) { | if(alpha > 0.0001) { | |||
render_now = (pass == -1); | render_now = (pass == -1); | |||
} else | } else | |||
render_now = (!pass); | render_now = (!pass); | |||
if(render_now) { | if(render_now) { | |||
int already_rendered = false; | int already_rendered = false; | |||
int generate_shader_cgo = false; | ||||
if (use_shaders){ | ||||
if (oss->shaderCGO){ | if (oss->shaderCGO){ | |||
CGORenderGL(oss->shaderCGO, NULL, NULL, I->Obj.Setting, info, N ULL); | CGORenderGL(oss->shaderCGO, NULL, NULL, I->Obj.Setting, info, N ULL); | |||
already_rendered = true; | already_rendered = true; | |||
} else { | } else { | |||
oss->shaderCGO = CGONew(G); | oss->shaderCGO = CGONew(G); | |||
generate_shader_cgo = true; | ||||
} | ||||
} | } | |||
if (!already_rendered){ | if (!already_rendered){ | |||
if (generate_shader_cgo){ | ||||
SceneResetNormalCGO(G, oss->shaderCGO, false); | SceneResetNormalCGO(G, oss->shaderCGO, false); | |||
/* | ||||
CGOColor(oss->shaderCGO, 1.f, 1.f, 1.f); | ||||
GenerateOutlineOfSlice(G, oss, oss->shaderCGO); | ||||
*/ | ||||
ObjectUseColorCGO(oss->shaderCGO, &I->Obj); | ObjectUseColorCGO(oss->shaderCGO, &I->Obj); | |||
} else { | ||||
SceneResetNormal(G, false); | ||||
/* | ||||
glColor3f(1.f, 1.f, 1.f); | ||||
GenerateOutlineOfSlice(G, oss, NULL); | ||||
*/ | ||||
ObjectUseColor(&I->Obj); | ||||
} | ||||
if((I->Obj.visRep & cRepSliceBit)) { | if((I->Obj.visRep & cRepSliceBit)) { | |||
int *strip = oss->strips; | int *strip = oss->strips; | |||
float *point = oss->points; | float *point = oss->points; | |||
float *color = oss->colors; | float *color = oss->colors; | |||
float *vnormal = oss->normals; | float *vnormal = oss->normals; | |||
int n = oss->n_strips; | int n = oss->n_strips; | |||
int a; | int a; | |||
int offset; | int offset; | |||
int strip_active = false; | int strip_active = false; | |||
{ | { | |||
float normal[3]; | float normal[3]; | |||
normal[0] = oss->system[2]; | normal[0] = oss->system[2]; | |||
normal[1] = oss->system[5]; | normal[1] = oss->system[5]; | |||
normal[2] = oss->system[8]; | normal[2] = oss->system[8]; | |||
if (generate_shader_cgo){ | ||||
CGONormalv(oss->shaderCGO, normal); | CGONormalv(oss->shaderCGO, normal); | |||
} else { | ||||
glNormal3fv(normal); | ||||
} | ||||
} | } | |||
if (generate_shader_cgo){ | ||||
for(a = 0; a < n; a++) { | for(a = 0; a < n; a++) { | |||
offset = *(strip++); | offset = *(strip++); | |||
switch (offset) { | switch (offset) { | |||
case START_STRIP: | case START_STRIP: | |||
if(!strip_active) | if(!strip_active){ | |||
CGOBegin(oss->shaderCGO, GL_TRIANGLE_STRIP); | CGOBegin(oss->shaderCGO, GL_TRIANGLE_STRIP); | |||
} | ||||
strip_active = true; | strip_active = true; | |||
break; | break; | |||
case STOP_STRIP: | case STOP_STRIP: | |||
if(strip_active) | if(strip_active) | |||
CGOEnd(oss->shaderCGO); | CGOEnd(oss->shaderCGO); | |||
strip_active = false; | strip_active = false; | |||
break; | break; | |||
default: | default: | |||
if(strip_active) { | if(strip_active) { | |||
float *col; | float *col; | |||
col = color + 3 * offset; | col = color + 3 * offset; | |||
if(vnormal) | if(vnormal) | |||
CGONormalv(oss->shaderCGO, vnormal + 3 * offset); | CGONormalv(oss->shaderCGO, vnormal + 3 * offset); | |||
CGOAlpha(oss->shaderCGO, alpha); | CGOAlpha(oss->shaderCGO, alpha); | |||
CGOColor(oss->shaderCGO, col[0], col[1], col[2]); | CGOColor(oss->shaderCGO, col[0], col[1], col[2]); | |||
CGOPickColor(oss->shaderCGO, state + 1, offset + 1); | ||||
CGOVertexv(oss->shaderCGO, point + 3 * offset); | CGOVertexv(oss->shaderCGO, point + 3 * offset); | |||
} | } | |||
break; | break; | |||
} | } | |||
} | } | |||
if(strip_active) /* just in case */ | if(strip_active) /* just in case */ | |||
CGOEnd(oss->shaderCGO); | CGOEnd(oss->shaderCGO); | |||
} else { | ||||
#ifndef PURE_OPENGL_ES_2 | ||||
for(a = 0; a < n; a++) { | ||||
offset = *(strip++); | ||||
switch (offset) { | ||||
case START_STRIP: | ||||
if(!strip_active) | ||||
glBegin(GL_TRIANGLE_STRIP); | ||||
strip_active = true; | ||||
break; | ||||
case STOP_STRIP: | ||||
if(strip_active) | ||||
glEnd(); | ||||
strip_active = false; | ||||
break; | ||||
default: | ||||
if(strip_active) { | ||||
float *col; | ||||
col = color + 3 * offset; | ||||
if(vnormal) | ||||
glNormal3fv(vnormal + 3 * offset); | ||||
glColor4f(col[0], col[1], col[2], alpha); | ||||
glVertex3fv(point + 3 * offset); | ||||
} | ||||
break; | ||||
} | ||||
} | ||||
if(strip_active) /* just in case */ | ||||
glEnd(); | ||||
#endif | ||||
} | ||||
} | ||||
} | } | |||
if (generate_shader_cgo){ | CGOStop(oss->shaderCGO); | |||
if (use_shaders){ | ||||
CGO *convertcgo = oss->shaderCGO; | CGO *convertcgo = oss->shaderCGO; | |||
CGOStop(oss->shaderCGO); | ||||
convertcgo = CGOCombineBeginEnd(oss->shaderCGO, 0); | convertcgo = CGOCombineBeginEnd(oss->shaderCGO, 0); | |||
CGOFree(oss->shaderCGO); | CGOFree(oss->shaderCGO); | |||
oss->shaderCGO = CGOOptimizeToVBONotIndexed(convertcgo, 0); | oss->shaderCGO = CGOOptimizeToVBONotIndexed(convertcgo, 0); | |||
oss->shaderCGO->use_shader = true; | oss->shaderCGO->use_shader = true; | |||
oss->shaderCGO->enable_shaders = true; | ||||
CGOFree(convertcgo); | CGOFree(convertcgo); | |||
} | ||||
CGORenderGL(oss->shaderCGO, NULL, NULL, I->Obj.Setting, info, N ULL); | CGORenderGL(oss->shaderCGO, NULL, NULL, I->Obj.Setting, info, N ULL); | |||
SceneInvalidatePicking(G); // any time cgo is re-generated, nee | ||||
ds to invalidate so | ||||
// pick colors can be re-assigned | ||||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
} | } | |||
if(state >= 0) | if(state >= 0) | |||
break; | break; | |||
cur_state = cur_state + 1; | cur_state = cur_state + 1; | |||
if(cur_state >= I->NState) | if(cur_state >= I->NState) | |||
skipping to change at line 1369 | skipping to change at line 1316 | |||
I->NState = 0; | I->NState = 0; | |||
I->State = VLACalloc(ObjectSliceState, 10); /* autozero important */ | I->State = VLACalloc(ObjectSliceState, 10); /* autozero important */ | |||
I->Obj.type = cObjectSlice; | I->Obj.type = cObjectSlice; | |||
I->Obj.fFree = (void (*)(CObject *)) ObjectSliceFree; | I->Obj.fFree = (void (*)(CObject *)) ObjectSliceFree; | |||
I->Obj.fUpdate = (void (*)(CObject *)) ObjectSliceUpdate; | I->Obj.fUpdate = (void (*)(CObject *)) ObjectSliceUpdate; | |||
I->Obj.fRender = (void (*)(CObject *, RenderInfo *)) ObjectSliceRender; | I->Obj.fRender = (void (*)(CObject *, RenderInfo *)) ObjectSliceRender; | |||
I->Obj.fInvalidate = (void (*)(CObject *, int, int, int)) ObjectSliceInvalidat e; | I->Obj.fInvalidate = (void (*)(CObject *, int, int, int)) ObjectSliceInvalidat e; | |||
I->Obj.fGetNFrame = (int (*)(CObject *)) ObjectSliceGetNStates; | I->Obj.fGetNFrame = (int (*)(CObject *)) ObjectSliceGetNStates; | |||
I->context.object = (void *) I; | ||||
I->context.state = 0; | ||||
return (I); | return (I); | |||
} | } | |||
/*========================================================================*/ | /*========================================================================*/ | |||
void ObjectSliceStateInit(PyMOLGlobals * G, ObjectSliceState * oss) | void ObjectSliceStateInit(PyMOLGlobals * G, ObjectSliceState * oss) | |||
{ | { | |||
oss->G = G; | oss->G = G; | |||
oss->Active = true; | oss->Active = true; | |||
oss->RefreshFlag = true; | oss->RefreshFlag = true; | |||
oss->ExtentFlag = false; | oss->ExtentFlag = false; | |||
End of changes. 27 change blocks. | ||||
80 lines changed or deleted | 32 lines changed or added |