Status SiAssignCamera(ID renderer, ID camera) { struct Renderer *renderer_ptr = NULL; struct Camera *camera_ptr = NULL; { const struct Entry entry = decode_id(renderer); if (entry.type != Type_Renderer) return SI_FAIL; renderer_ptr = ScnGetRenderer(scene, entry.index); if (renderer_ptr == NULL) return SI_FAIL; } { const struct Entry entry = decode_id(camera); if (entry.type != Type_Camera) return SI_FAIL; camera_ptr = ScnGetCamera(scene, entry.index); if (camera_ptr == NULL) return SI_FAIL; } RdrSetCamera(renderer_ptr, camera_ptr); return SI_SUCCESS; }
Status SiAssignFrameBuffer(ID renderer, ID framebuffer) { struct Renderer *renderer_ptr = NULL; struct FrameBuffer *framebuffer_ptr = NULL; { const struct Entry entry = decode_id(renderer); if (entry.type != Type_Renderer) return SI_FAIL; renderer_ptr = ScnGetRenderer(scene, entry.index); if (renderer_ptr == NULL) return SI_FAIL; } { const struct Entry entry = decode_id(framebuffer); if (entry.type != Type_FrameBuffer) return SI_FAIL; framebuffer_ptr = ScnGetFrameBuffer(scene, entry.index); if (framebuffer_ptr == NULL) return SI_FAIL; } RdrSetFrameBuffers(renderer_ptr, framebuffer_ptr); return SI_SUCCESS; }
Status SiAssignTexture(ID shader, const char *prop_name, ID texture) { struct PropertyValue value = InitPropValue(); struct Shader *shader_ptr = NULL; struct Texture *texture_ptr = NULL; { const struct Entry entry = decode_id(shader); if (entry.type != Type_Shader) return SI_FAIL; shader_ptr = ScnGetShader(scene, entry.index); if (shader_ptr == NULL) return SI_FAIL; } { const struct Entry entry = decode_id(texture); if (entry.type != Type_Texture) return SI_FAIL; texture_ptr = ScnGetTexture(scene, entry.index); if (texture_ptr == NULL) return SI_FAIL; } value = PropTexture(texture_ptr); return ShdSetProperty(shader_ptr, prop_name, &value); }
Status SiAssignShader(ID object, ID shader) { struct ObjectInstance *object_ptr = NULL; struct Shader *shader_ptr = NULL; { const struct Entry entry = decode_id(object); if (entry.type != Type_ObjectInstance) return SI_FAIL; object_ptr = ScnGetObjectInstance(scene, entry.index); if (object_ptr == NULL) return SI_FAIL; } { const struct Entry entry = decode_id(shader); if (entry.type != Type_Shader) return SI_FAIL; shader_ptr = ScnGetShader(scene, entry.index); if (shader_ptr == NULL) return SI_FAIL; } ObjSetShader(object_ptr, shader_ptr); return SI_SUCCESS; }
void ioio (char *message) { int id; int code; struct BDMioctl ioc; message += sizeof "IOIO"; id = strtoul (message, NULL, 0); message = strchr (message, ',') + 1; ioc.address = strtoul (message, NULL, 0); message = strchr (message, ',') + 1; ioc.value = strtoul (message, NULL, 0); code = decode_id (id); if (code == -1) { syslog (LOG_INFO, "ioio error: invalid ioctl id decode (%d)", errno); } if (bdmIoctlIo (code, &ioc) < 0) { syslog (LOG_INFO, "ioio error: %s (%d)", bdmErrorString (), errno); } printf ("IOIO %d,0x%" PRIxMAX ",0x%" PRIxMAX ".", errno, ioc.address, ioc.value); }
/* take a group name and return a filled struct group */ static struct group *wb_aix_getgrnam(const char *name) { struct winbindd_response response; struct winbindd_request request; NSS_STATUS ret; struct group *grp; if (*name == WB_AIX_ENCODED) { return wb_aix_getgrgid(decode_id(name)); } logit("getgrnam '%s'\n", name); ZERO_STRUCT(response); ZERO_STRUCT(request); STRCPY_RETNULL(request.data.groupname, name); ret = winbindd_request_response(NULL, WINBINDD_GETGRNAM, &request, &response); HANDLE_ERRORS(ret); grp = fill_grent(&response.data.gr, response.extra_data.data); winbindd_free_response(&response); return grp; }
/* take a username and return a filled struct passwd */ static struct passwd *wb_aix_getpwnam(const char *name) { struct winbindd_response response; struct winbindd_request request; NSS_STATUS ret; struct passwd *pwd; if (*name == WB_AIX_ENCODED) { return wb_aix_getpwuid(decode_id(name)); } logit("getpwnam '%s'\n", name); ZERO_STRUCT(response); ZERO_STRUCT(request); STRCPY_RETNULL(request.data.username, name); ret = winbindd_request_response(NULL, WINBINDD_GETPWNAM, &request, &response); HANDLE_ERRORS(ret); pwd = fill_pwent(&response.data.pw); winbindd_free_response(&response); logit("getpwnam gave ptr %p\n", pwd); return pwd; }
Status SiSetProperty4(ID id, const char *name, double v0, double v1, double v2, double v3) { const struct Entry entry = decode_id(id); const struct PropertyValue value = PropVector4(v0, v1, v2, v3); const int err = set_property(&entry, name, &value); return status_of_error(err); }
Status SiSetProperty1(ID id, const char *name, double v0) { const struct Entry entry = decode_id(id); const struct PropertyValue value = PropScalar(v0); const int err = set_property(&entry, name, &value); return status_of_error(err); }
/* time variable property */ Status SiSetSampleProperty3(ID id, const char *name, double v0, double v1, double v2, double time) { const struct Entry entry = decode_id(id); struct PropertyValue value = PropVector3(v0, v1, v2); int err = 0; value.time = time; err = set_property(&entry, name, &value); return status_of_error(err); }
Status SiAssignVolume(ID id, const char *name, ID volume) { const struct Entry entry = decode_id(id); const struct Entry volume_ent = decode_id(volume); struct PropertyValue value = InitPropValue(); struct Volume *volume_ptr = NULL; int err = 0; if (volume_ent.type != Type_Volume) return SI_FAIL; volume_ptr = ScnGetVolume(scene, volume_ent.index); if (volume_ptr == NULL) return SI_FAIL; value = PropVolume(volume_ptr); err = set_property(&entry, name, &value); return status_of_error(err); }
Status SiAssignTurbulence(ID id, const char *name, ID turbulence) { const struct Entry entry = decode_id(id); const struct Entry turbulence_ent = decode_id(turbulence); struct PropertyValue value = InitPropValue(); struct Turbulence *turbulence_ptr = NULL; int err = 0; if (turbulence_ent.type != Type_Turbulence) return SI_FAIL; turbulence_ptr = ScnGetTurbulence(scene, turbulence_ent.index); if (turbulence_ptr == NULL) return SI_FAIL; value = PropTurbulence(turbulence_ptr); err = set_property(&entry, name, &value); return status_of_error(err); }
void WindowView_Impl::on_mouse_up(const clan::InputEvent &e) { PointerEventType type = PointerEventType::release; PointerButton button = decode_id(e.id); const Pointf pos = to_root_pos(e.mouse_pos); bool alt_down = e.alt; bool shift_down = e.shift; bool ctrl_down = e.ctrl; bool cmd_down = false; PointerEvent pointer_event(type, button, pos, alt_down, shift_down, ctrl_down, cmd_down); window_pointer_event(pointer_event); }
/* TODO change argument name accelerator */ ID SiNewObjectInstance(ID accelerator) { const struct Entry entry = decode_id(accelerator); if (entry.type == Type_Accelerator) { struct Accelerator *acc = NULL; acc = ScnGetAccelerator(scene, entry.index); if (acc == NULL) { set_errno(SI_ERR_BADTYPE); return SI_BADID; } /* TODO come up with another way to pass acc */ if (ScnNewObjectInstance(scene, acc) == NULL) { set_errno(SI_ERR_FAILNEW); return SI_BADID; } } else if (entry.type == Type_Volume) { struct ObjectInstance *object = NULL; struct Volume *volume = NULL; int err = 0; volume = ScnGetVolume(scene, entry.index); if (volume == NULL) { set_errno(SI_ERR_BADTYPE); return SI_BADID; } object = ScnNewObjectInstance(scene, NULL); if (object == NULL) { set_errno(SI_ERR_FAILNEW); return SI_BADID; } err = ObjSetVolume(object, volume); if (err) { set_errno(SI_ERR_FAILNEW); return SI_BADID; } } else { set_errno(SI_ERR_BADTYPE); return SI_BADID; } set_errno(SI_ERR_NONE); return encode_id(Type_ObjectInstance, GET_LAST_ADDED_ID(ObjectInstance)); }
void iocmd (char *message) { int id; int code; message += sizeof "IOCMD"; id = strtoul (message, NULL, 0); code = decode_id (id); if (code == -1) { syslog (LOG_INFO, "iocmd error: invalid ioctl id decode (%d)", errno); } if (bdmIoctlCommand (code) < 0) { syslog (LOG_INFO, "iocmd error: %s (%d)", bdmErrorString (), errno); } printf ("IOCMD %d.", errno); }
static int worker_actor_handler(qmsg_t *msg, void *reader) { qwmsg_actor_t *amsg; qworker_t *worker; qamsg_header_t *header; qactor_t *actor; amsg = (qwmsg_actor_t*)msg; worker = (qworker_t*)reader; header = amsg->data; actor = qworket_get_actor(worker, decode_id(header->dst)); if (actor == NULL) { qerror("actor %d not exist", header->dst); return QOK; } (*actor_msg_handlers[header->type])(header, actor); return 0; }
Status SiSaveFrameBuffer(ID framebuffer, const char *filename) { const struct Entry entry = decode_id(framebuffer); struct FrameBuffer *framebuffer_ptr = NULL; int err = 0; if (entry.type != Type_FrameBuffer) return SI_FAIL; framebuffer_ptr = ScnGetFrameBuffer(scene, entry.index); if (framebuffer_ptr == NULL) return SI_FAIL; err = FbSaveCroppedData(framebuffer_ptr, filename); if (err) { /* TODO error handling */ return SI_FAIL; } set_errno(SI_ERR_NONE); return SI_SUCCESS; }
Status SiRunProcedure(ID procedure) { const struct Entry entry = decode_id(procedure); struct Procedure *procedure_ptr = NULL; int err = 0; if (entry.type != Type_Procedure) return SI_FAIL; procedure_ptr = ScnGetProcedure(scene, entry.index); if (procedure_ptr == NULL) return SI_FAIL; err = PrcRun(procedure_ptr); if (err) { /* TODO error handling */ return SI_FAIL; } set_errno(SI_ERR_NONE); return SI_SUCCESS; }
void ioint (char *message) { int id; int code; int var; message += sizeof "IOINT"; id = strtoul (message, NULL, 0); message = strchr (message, ',') + 1; var = strtoul (message, NULL, 0); code = decode_id (id); if (code == -1) { syslog (LOG_INFO, "ioint error: invalid ioctl id decode (%d)", errno); } if (bdmIoctlInt (code, &var) < 0) { syslog (LOG_INFO, "ioint error: %s (%d)", bdmErrorString (), errno); } printf ("IOINT %d,0x%x.", errno, var); }
int main () { assert (restart_gl_log ()); assert (start_gl ()); /* set up framebuffer with texture attachment */ assert (init_fb ()); /* load the picking shaders */ g_pick_sp = create_programme_from_files (PICK_VS, PICK_FS); g_pick_unique_id_loc = glGetUniformLocation (g_pick_sp, "unique_id"); g_pick_P_loc = glGetUniformLocation (g_pick_sp, "P"); g_pick_V_loc = glGetUniformLocation (g_pick_sp, "V"); g_pick_M_loc = glGetUniformLocation (g_pick_sp, "M"); assert (g_pick_P_loc > -1); assert (g_pick_V_loc > -1); assert (g_pick_M_loc > -1); /* load a mesh to draw in the main scene */ load_sphere (); GLuint sphere_sp = create_programme_from_files (SPHERE_VS, SPHERE_FS); GLint sphere_P_loc = glGetUniformLocation (sphere_sp, "P"); GLint sphere_V_loc = glGetUniformLocation (sphere_sp, "V"); GLint sphere_M_loc = glGetUniformLocation (sphere_sp, "M"); assert (sphere_P_loc > -1); assert (sphere_V_loc > -1); assert (sphere_M_loc > -1); /* set up view and projection matrices for sphere shader */ mat4 P = perspective ( 67.0f, (float)g_gl_width / (float)g_gl_height, 0.1f, 100.0f); mat4 V = look_at ( vec3 (0.0f, 0.0f, 5.0f), vec3 (0.0f, 0.0f, 0.0f), vec3 (0.0f, 1.0f, 0.0f)); glUseProgram (sphere_sp); glUniformMatrix4fv (sphere_P_loc, 1, GL_FALSE, P.m); glUniformMatrix4fv (sphere_V_loc, 1, GL_FALSE, V.m); glViewport (0, 0, g_gl_width, g_gl_height); while (!glfwWindowShouldClose (g_window)) { _update_fps_counter (g_window); /* bind the 'render to a texture' framebuffer for main scene */ glBindFramebuffer (GL_FRAMEBUFFER, 0); /* clear the framebuffer's colour and depth buffers */ glClearColor (0.2, 0.2, 0.2, 1.0); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // render an obj or something glUseProgram (sphere_sp); glBindVertexArray (g_sphere_vao); // model matrices for all 3 spheres mat4 Ms[3]; // first sphere Ms[0] = identity_mat4 (); glUniformMatrix4fv (sphere_M_loc, 1, GL_FALSE, Ms[0].m); glDrawArrays (GL_TRIANGLES, 0, g_sphere_point_count); // 2nd sphere Ms[1] = translate (identity_mat4 (), vec3 (1.0, -1.0, -4.0)); glUniformMatrix4fv (sphere_M_loc, 1, GL_FALSE, Ms[1].m); glDrawArrays (GL_TRIANGLES, 0, g_sphere_point_count); // 3rd sphere Ms[2] = translate (identity_mat4 (), vec3 (-0.50, 2.0, -2.0)); glUniformMatrix4fv (sphere_M_loc, 1, GL_FALSE, Ms[2].m); glDrawArrays (GL_TRIANGLES, 0, g_sphere_point_count); /* bind framebuffer for pick */ draw_picker_colours (P, V, Ms); // flip drawn framebuffer onto the display glfwSwapBuffers (g_window); glfwPollEvents (); if (GLFW_PRESS == glfwGetKey (g_window, GLFW_KEY_ESCAPE)) { glfwSetWindowShouldClose (g_window, 1); } debug_colours = glfwGetKey (g_window, GLFW_KEY_SPACE); if (glfwGetMouseButton (g_window, 0)) { glBindFramebuffer (GL_FRAMEBUFFER, g_fb); double xpos, ypos; glfwGetCursorPos (g_window, &xpos, &ypos); int mx = (int)xpos; int my = (int)ypos; unsigned char data[4] = {0, 0, 0, 0}; glReadPixels ( mx, g_gl_height - my, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &data); int id = decode_id ((int)data[0], (int)data[1], (int)data[2]); int mid = -1; if (id == 255) { mid = 0; } if (id == 65280) { mid = 1; } if (id == 16711680) { mid = 2; } printf ("%i,%i,%i means -> id was %i, and monkey number is %i\n", data[0], data[1], data[2], id, mid); glBindFramebuffer (GL_FRAMEBUFFER, 0); } } return 0; }