static void find_uniforms(glsl_shader_data_t *glsl, unsigned pass, GLuint prog, struct shader_uniforms *uni) { unsigned i; char frame_base[64] = {0}; glUseProgram(prog); uni->mvp = get_uniform(glsl, prog, "MVPMatrix"); uni->tex_coord = get_attrib(glsl, prog, "TexCoord"); uni->vertex_coord = get_attrib(glsl, prog, "VertexCoord"); uni->color = get_attrib(glsl, prog, "Color"); uni->lut_tex_coord = get_attrib(glsl, prog, "LUTTexCoord"); uni->input_size = get_uniform(glsl, prog, "InputSize"); uni->output_size = get_uniform(glsl, prog, "OutputSize"); uni->texture_size = get_uniform(glsl, prog, "TextureSize"); uni->frame_count = get_uniform(glsl, prog, "FrameCount"); uni->frame_direction = get_uniform(glsl, prog, "FrameDirection"); for (i = 0; i < glsl->shader->luts; i++) uni->lut_texture[i] = glGetUniformLocation(prog, glsl->shader->lut[i].id); clear_uniforms_frame(&uni->orig); find_uniforms_frame(glsl, prog, &uni->orig, "Orig"); clear_uniforms_frame(&uni->feedback); find_uniforms_frame(glsl, prog, &uni->feedback, "Feedback"); if (pass > 1) { snprintf(frame_base, sizeof(frame_base), "PassPrev%u", pass); find_uniforms_frame(glsl, prog, &uni->orig, frame_base); } for (i = 0; i + 1 < pass; i++) { snprintf(frame_base, sizeof(frame_base), "Pass%u", i + 1); clear_uniforms_frame(&uni->pass[i]); find_uniforms_frame(glsl, prog, &uni->pass[i], frame_base); snprintf(frame_base, sizeof(frame_base), "PassPrev%u", pass - (i + 1)); find_uniforms_frame(glsl, prog, &uni->pass[i], frame_base); if (*glsl->shader->pass[i].alias) find_uniforms_frame(glsl, prog, &uni->pass[i], glsl->shader->pass[i].alias); } clear_uniforms_frame(&uni->prev[0]); find_uniforms_frame(glsl, prog, &uni->prev[0], "Prev"); for (i = 1; i < PREV_TEXTURES; i++) { snprintf(frame_base, sizeof(frame_base), "Prev%u", i); clear_uniforms_frame(&uni->prev[i]); find_uniforms_frame(glsl, prog, &uni->prev[i], frame_base); } glUseProgram(0); }
static void find_uniforms(unsigned pass, GLuint prog, struct shader_uniforms *uni) { glUseProgram(prog); uni->mvp = get_uniform(prog, "MVPMatrix"); uni->tex_coord = get_attrib(prog, "TexCoord"); uni->vertex_coord = get_attrib(prog, "VertexCoord"); uni->color = get_attrib(prog, "Color"); uni->lut_tex_coord = get_attrib(prog, "LUTTexCoord"); uni->input_size = get_uniform(prog, "InputSize"); uni->output_size = get_uniform(prog, "OutputSize"); uni->texture_size = get_uniform(prog, "TextureSize"); uni->frame_count = get_uniform(prog, "FrameCount"); uni->frame_direction = get_uniform(prog, "FrameDirection"); for (unsigned i = 0; i < glsl_shader->luts; i++) uni->lut_texture[i] = glGetUniformLocation(prog, glsl_shader->lut[i].id); char frame_base[64]; clear_uniforms_frame(&uni->orig); find_uniforms_frame(prog, &uni->orig, "Orig"); if (pass > 1) { snprintf(frame_base, sizeof(frame_base), "PassPrev%u", pass); find_uniforms_frame(prog, &uni->orig, frame_base); } for (unsigned i = 0; i < GFX_MAX_SHADERS; i++) { snprintf(frame_base, sizeof(frame_base), "Pass%u", i + 1); clear_uniforms_frame(&uni->pass[i]); find_uniforms_frame(prog, &uni->pass[i], frame_base); if (i && pass > i + 1) { snprintf(frame_base, sizeof(frame_base), "PassPrev%u", pass - i); find_uniforms_frame(prog, &uni->pass[i], frame_base); } } clear_uniforms_frame(&uni->prev[0]); find_uniforms_frame(prog, &uni->prev[0], "Prev"); for (unsigned i = 1; i < PREV_TEXTURES; i++) { snprintf(frame_base, sizeof(frame_base), "Prev%u", i); clear_uniforms_frame(&uni->prev[i]); find_uniforms_frame(prog, &uni->prev[i], frame_base); } glUseProgram(0); }
int InitProgram() { programDepth = create_program("cube.v.glsl", "cube.f.glsl", vsDepth, fs); if (programDepth == 0) return 0; attribute_coord3d = get_attrib(programDepth, "vertex_position"); attribute_normal = get_attrib(programDepth, "vertex_normal"); attribute_colour = get_attrib(programDepth, "vertex_colour"); uniform_m = get_uniform(programDepth, "model"); uniform_v = get_uniform(programDepth, "view"); uniform_p = get_uniform(programDepth, "projection"); return 1; }
static void process_mkdir(u_int32_t id) { Attrib *a; char *name; int ret, mode, status = SSH2_FX_FAILURE; name = get_string(NULL); a = get_attrib(); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm & 07777 : 0777; debug3("request %u: mkdir", id); logit("mkdir name \"%s\" mode 0%o", name, mode); ret = mkdir(name, mode); status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; send_status(id, status); #ifdef NERSC_MOD char* t1buf = encode_string(name, strlen(name)); s_audit("sftp_process_mkdir_3", "count=%i int=%d uristring=%s", get_client_session_id(), (int)getpid(), t1buf); free(t1buf); #endif free(name); }
int init_resources() { /* Initialize the FreeType2 library */ if (FT_Init_FreeType(&ft)) { fprintf(stderr, "Could not init freetype library\n"); return 0; } /* Load a font */ if (FT_New_Face(ft, "/Users/liesaweigert/ClionProjects/AR/assets/orange juice 2.0.ttf", 0, &face)) { fprintf(stderr, "Could not open font!\n"); return 0; } program = create_program("/Users/liesaweigert/ClionProjects/AR/src/text.v.glsl", "/Users/liesaweigert/ClionProjects/AR/src/text.f.glsl"); if(program == 0) return 0; attribute_coord = get_attrib(program, "coord"); uniform_tex = get_uniform(program, "tex"); uniform_color = get_uniform(program, "color"); if(attribute_coord == -1 || uniform_tex == -1 || uniform_color == -1) return 0; // Create the vertex buffer object glGenBuffers(1, &vbo); return 1; }
static void process_open(void) { u_int32_t id, pflags; Attrib *a; char *name; int handle, fd, flags, mode, status = SSH2_FX_FAILURE; id = get_int(); name = get_string(NULL); pflags = get_int(); /* portable flags */ a = get_attrib(); flags = flags_from_portable(pflags); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; TRACE("open id %u name %s flags %d mode 0%o", id, name, pflags, mode); fd = open(name, flags, mode); if (fd < 0) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_FILE, xstrdup(name), fd, NULL); if (handle < 0) { close(fd); } else { send_handle(id, handle); status = SSH2_FX_OK; } } if (status != SSH2_FX_OK) send_status(id, status); xfree(name); }
static char *find_next ( int *attrib ) { FB_DIRCTX *ctx = FB_TLSGETCTX( DIR ); char *name = NULL; struct stat info; struct dirent *entry; char buffer[MAX_PATH]; do { entry = readdir( ctx->dir ); if( !entry ) { close_dir( ); return NULL; } name = entry->d_name; strcpy( buffer, ctx->dirname ); strncat( buffer, name, MAX_PATH - strlen( buffer ) - 1 ); buffer[MAX_PATH-1] = '\0'; if( stat( buffer, &info ) ) continue; *attrib = get_attrib( name, &info ); } while( ( *attrib & ~ctx->attrib ) || !match_spec( name ) ); return name; }
static void process_setstat(void) { Attrib *a; u_int32_t id; char *name; int status = SSH2_FX_OK, ret; id = get_int(); name = get_string(NULL); a = get_attrib(); TRACE("setstat id %u name %s", id, name); if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { ret = truncate(name, a->size); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { ret = chmod(name, a->perm & 0777); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { ret = utimes(name, attrib_to_tv(a)); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { ret = chown(name, a->uid, a->gid); if (ret == -1) status = errno_to_portable(errno); } send_status(id, status); xfree(name); }
void SFTP::process_mkdir(void) { Attrib a; u_int32_t id; char *utf8_name; int status = SSH2_FX_FAILURE; id = get_int(); utf8_name = (char*) get_string(NULL); a = get_attrib(this->iqueue); /*mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm & 07777 : 0777;*/ // TODO ACL's (all is created with the system perms) debug3("request %u: mkdir", (unsigned) id); logit("mkdir name \"%s\" mode default", utf8_name); const SFTPFilePath path = pathFact.create_path (utf8_name); BOOL res = ::CreateDirectory (path.get_for_call ().c_str (), NULL); int err = ::GetLastError (); if (err == ERROR_PATH_NOT_FOUND) { res = create_directory_path (path, NULL); if (!res) err = ::GetLastError (); } status = (!res) ? errno_to_portable(err) : SSH2_FX_OK; send_status(id, status); xfree(utf8_name); }
bool FontEngine::init() { if (FT_Init_FreeType(&library)) { INFO("FT_Init_FreeType"); return 0; } program = create_program(VERTEX_SHADER_FILE, FRAGMENT_SHADER_FILE); if (!program) { INFO("Didn't Create Program"); return 0; } coord = get_attrib(program, "coord"); uniform_tex = get_uniform(program, "tex"); uniform_color = get_uniform(program, "color"); if (coord < 0 || uniform_tex < 0 || uniform_color < 0) { INFO("attribs not properly allocated"); return 0; } billboard_program = create_program(VERTEX_SHADER_FILE_BILLBOARD, FRAGMENT_SHADER_FILE_BILLBOARD); if (!billboard_program) { INFO("Didn't Create BillBoard Program"); return 0; } billboard_pos = get_attrib(billboard_program, "position"); billboard_coord = get_attrib(billboard_program, "texcoord"); billboard_uniform_tex = get_uniform(billboard_program, "tex"); billboard_uniform_color = get_uniform(billboard_program, "color"); billboard_uniform_projection = get_uniform(billboard_program, "uProjection"); billboard_uniform_view = get_uniform(billboard_program, "uView"); if (billboard_pos < 0 || billboard_coord < 0|| billboard_uniform_tex < 0|| billboard_uniform_color< 0 || billboard_uniform_projection < 0 || billboard_uniform_view < 0) { INFO("billboard attribs not properly allocated"); return 0; } glGenBuffers(1, &vbo); initialized = 1; return 1; }
static void process_fsetstat(void) { Attrib *a; u_int32_t id; int handle, fd, ret; int status = SSH2_FX_OK; id = get_int(); handle = get_handle(); a = get_attrib(); debug("request %u: fsetstat handle %d", id, handle); fd = handle_to_fd(handle); if (fd < 0) status = SSH2_FX_FAILURE; else if (readonly) status = SSH2_FX_PERMISSION_DENIED; else { char *name = handle_to_name(handle); if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { logit("set \"%s\" size %llu", name, (unsigned long long)a->size); ret = ftruncate(fd, a->size); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { logit("set \"%s\" mode %04o", name, a->perm); ret = fchmod(fd, a->perm & 07777); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { char buf[64]; time_t t = a->mtime; strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S", localtime(&t)); logit("set \"%s\" modtime %s", name, buf); ret = futimes(fd, attrib_to_tv(a)); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { logit("set \"%s\" owner %lu group %lu", name, (u_long)a->uid, (u_long)a->gid); ret = fchown(fd, a->uid, a->gid); if (ret == -1) status = errno_to_portable(errno); } } send_status(id, status); }
static void process_fsetstat(void) { Attrib *a; u_int32_t id; int handle, fd, ret; int status = SSH2_FX_OK; char *name; id = get_int(); handle = get_handle(); a = get_attrib(); TRACE("fsetstat id %u handle %d", id, handle); fd = handle_to_fd(handle); name = handle_to_name(handle); if (fd < 0 || name == NULL) { status = SSH2_FX_FAILURE; } else { if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { ret = ftruncate(fd, a->size); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { #ifdef HAVE_FCHMOD ret = fchmod(fd, a->perm & 0777); #else ret = chmod(name, a->perm & 0777); #endif if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { #ifdef HAVE_FUTIMES ret = futimes(fd, attrib_to_tv(a)); #else ret = utimes(name, attrib_to_tv(a)); #endif if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { #ifdef HAVE_FCHOWN ret = fchown(fd, a->uid, a->gid); #else ret = chown(name, a->uid, a->gid); #endif if (ret == -1) status = errno_to_portable(errno); } } send_status(id, status); }
static void process_setstat(u_int32_t id) { Attrib *a; char *name; int status = SSH2_FX_OK, ret; name = get_string(NULL); a = get_attrib(); debug("request %u: setstat name \"%s\"", id, name); if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { logit("set \"%s\" size %llu", name, (unsigned long long)a->size); ret = truncate(name, a->size); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { logit("set \"%s\" mode %04o", name, a->perm); ret = chmod(name, a->perm & 07777); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { char buf[64]; time_t t = a->mtime; strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S", localtime(&t)); logit("set \"%s\" modtime %s", name, buf); ret = utimes(name, attrib_to_tv(a)); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { logit("set \"%s\" owner %lu group %lu", name, (u_long)a->uid, (u_long)a->gid); ret = chown(name, a->uid, a->gid); if (ret == -1) status = errno_to_portable(errno); } send_status(id, status); #ifdef NERSC_MOD char* t1buf = encode_string( name, strlen(name)); s_audit("sftp_process_setstat_3", "count=%i int=%d int=%d uristring=%s", get_client_session_id(), (int)getppid(), id, t1buf); free(t1buf); #endif free(name); }
static void process_setstat(void) { Attrib *a; u_int32_t id; char *name; int status = SSH2_FX_OK, ret; id = get_int(); name = get_string(NULL); a = get_attrib(); debug("request %u: setstat name \"%s\"", id, name); if (readonly) { status = SSH2_FX_PERMISSION_DENIED; a->flags = 0; } if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { logit("set \"%s\" size %llu", name, (unsigned long long)a->size); ret = truncate(name, a->size); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { logit("set \"%s\" mode %04o", name, a->perm); ret = chmod(name, a->perm & 07777); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { char buf[64]; time_t t = a->mtime; strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S", localtime(&t)); logit("set \"%s\" modtime %s", name, buf); ret = utimes(name, attrib_to_tv(a)); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { logit("set \"%s\" owner %lu group %lu", name, (u_long)a->uid, (u_long)a->gid); ret = chown(name, a->uid, a->gid); if (ret == -1) status = errno_to_portable(errno); } send_status(id, status); xfree(name); }
static void process_open(u_int32_t id) { u_int32_t pflags; Attrib *a; char *name; int handle, fd, flags, mode, status = SSH2_FX_FAILURE; name = get_string(NULL); pflags = get_int(); /* portable flags */ debug3("request %u: open flags %d", id, pflags); a = get_attrib(); flags = flags_from_portable(pflags); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; logit("open \"%s\" flags %s mode 0%o", name, string_from_portable(pflags), mode); if (readonly && ((flags & O_ACCMODE) == O_WRONLY || (flags & O_ACCMODE) == O_RDWR)) { verbose("Refusing open request in read-only mode"); status = SSH2_FX_PERMISSION_DENIED; } else { fd = open(name, flags, mode); if (fd < 0) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_FILE, name, fd, flags, NULL); if (handle < 0) { close(fd); } else { send_handle(id, handle); status = SSH2_FX_OK; } } } if (status != SSH2_FX_OK) send_status(id, status); #ifdef NERSC_MOD char* t1buf = encode_string( name, strlen(name)); s_audit("sftp_process_open_3", "count=%i int=%d uristring=%s", get_client_session_id(), (int)getppid(), t1buf); free(t1buf); #endif free(name); }
static void find_uniforms_frame(GLuint prog, struct shader_uniforms_frame *frame, const char *base) { char texture[64]; char texture_size[64]; char input_size[64]; char tex_coord[64]; snprintf(texture, sizeof(texture), "%s%s", base, "Texture"); snprintf(texture_size, sizeof(texture_size), "%s%s", base, "TextureSize"); snprintf(input_size, sizeof(input_size), "%s%s", base, "InputSize"); snprintf(tex_coord, sizeof(tex_coord), "%s%s", base, "TexCoord"); frame->texture = get_uniform(prog, texture); frame->texture_size = get_uniform(prog, texture_size); frame->input_size = get_uniform(prog, input_size); frame->tex_coord = get_attrib(prog, tex_coord); }
static void process_mkdir(u_int32_t id) { Attrib *a; char *name; int ret, mode, status = SSH2_FX_FAILURE; name = get_string(NULL); a = get_attrib(); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm & 07777 : 0777; debug3("request %u: mkdir", id); logit("mkdir name \"%s\" mode 0%o", name, mode); ret = mkdir(name, mode); status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; send_status(id, status); free(name); }
static void process_mkdir(void) { Attrib *a; u_int32_t id; char *name; int ret, mode, status = SSH2_FX_FAILURE; id = get_int(); name = get_string(NULL); a = get_attrib(); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm & 0777 : 0777; TRACE("mkdir id %u name %s mode 0%o", id, name, mode); ret = mkdir(name, mode); status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; send_status(id, status); xfree(name); }
// the function we use to initialize opengl and the world static int init_resources(){ started = false; shaderProgram = create_program("frig.vert","frig.frag"); if(!shaderProgram) return 0; attribute_coord = get_attrib(shaderProgram, "coord"); uniform_mvp = get_uniform(shaderProgram, "mvp"); uniform_sampler = get_uniform(shaderProgram, "texture"); if(attribute_coord == -1 || uniform_mvp == -1) return 0; if(ui::text::init_text()){ std::cerr << "Could not initialize fonts!" << std::endl; return 0; } glEnableVertexAttribArray(attribute_coord); cameraPos = glm::vec3(32.0,64.0,32.0); cameraRot = glm::vec3(0,0,0); // GENERATE HERE sc = new SuperChunk(); blockTexture = Texture::loadTexture("assets/blockStrip.png"); glUseProgram(shaderProgram); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,blockTexture); glUniform1f(uniform_sampler,0); glPolygonOffset(1, 1); glClearColor(0.6, 0.8, 1.0, 0.0); return 1; }
static void process_open(void) { u_int32_t id, pflags; Attrib *a; char *name; int handle, fd, flags, mode, status = SSH2_FX_FAILURE; id = get_int(); name = get_string(NULL); pflags = get_int(); /* portable flags */ debug3("request %u: open flags %d", id, pflags); a = get_attrib(); flags = flags_from_portable(pflags); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; logit("open \"%s\" flags %s mode 0%o", name, string_from_portable(pflags), mode); if (readonly && ((flags & O_ACCMODE) == O_WRONLY || (flags & O_ACCMODE) == O_RDWR)) status = SSH2_FX_PERMISSION_DENIED; else { fd = open(name, flags, mode); if (fd < 0) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_FILE, name, fd, NULL); if (handle < 0) { close(fd); } else { send_handle(id, handle); status = SSH2_FX_OK; } } } if (status != SSH2_FX_OK) send_status(id, status); xfree(name); }
static void find_uniforms_frame(glsl_shader_data_t *glsl, GLuint prog, struct shader_uniforms_frame *frame, const char *base) { char texture[64] = {0}; char texture_size[64] = {0}; char input_size[64] = {0}; char tex_coord[64] = {0}; snprintf(texture, sizeof(texture), "%s%s", base, "Texture"); snprintf(texture_size, sizeof(texture_size), "%s%s", base, "TextureSize"); snprintf(input_size, sizeof(input_size), "%s%s", base, "InputSize"); snprintf(tex_coord, sizeof(tex_coord), "%s%s", base, "TexCoord"); if (frame->texture < 0) frame->texture = get_uniform(glsl, prog, texture); if (frame->texture_size < 0) frame->texture_size = get_uniform(glsl, prog, texture_size); if (frame->input_size < 0) frame->input_size = get_uniform(glsl, prog, input_size); if (frame->tex_coord < 0) frame->tex_coord = get_attrib(glsl, prog, tex_coord); }
int init_resources() { program = create_program("graph.v.glsl", "graph.f.glsl"); if (program == 0) return 0; attribute_coord2d = get_attrib(program, "coord2d"); uniform_vertex_transform = get_uniform(program, "vertex_transform"); uniform_texture_transform = get_uniform(program, "texture_transform"); uniform_mytexture = get_uniform(program, "mytexture"); uniform_color = get_uniform(program, "color"); if (attribute_coord2d == -1 || uniform_vertex_transform == -1 || uniform_texture_transform == -1 || uniform_mytexture == -1) return 0; // Create our datapoints, store it as bytes #define N 256 GLbyte graph[N][N]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { float x = (i - N / 2) / (N / 2.0); float y = (j - N / 2) / (N / 2.0); float d = hypotf(x, y) * 4.0; float z = (1 - d * d) * expf(d * d / -2.0); graph[i][j] = roundf(z * 127 + 128); } } /* Upload the texture with our datapoints */ glActiveTexture(GL_TEXTURE0); glGenTextures(1, &texture_id); glBindTexture(GL_TEXTURE_2D, texture_id); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, N, N, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, graph); // Create two vertex buffer objects glGenBuffers(3, vbo); // Create an array for 101 * 101 vertices glm::vec2 vertices[101][101]; for (int i = 0; i < 101; i++) { for (int j = 0; j < 101; j++) { vertices[i][j].x = (j - 50) / 50.0; vertices[i][j].y = (i - 50) / 50.0; } } // Tell OpenGL to copy our array to the buffer objects glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); glBufferData(GL_ARRAY_BUFFER, sizeof vertices, vertices, GL_STATIC_DRAW); // Create an array of indices into the vertex array that traces both horizontal and vertical lines GLushort indices[100 * 100 * 6]; int i = 0; for (int y = 0; y < 101; y++) { for (int x = 0; x < 100; x++) { indices[i++] = y * 101 + x; indices[i++] = y * 101 + x + 1; } } for (int x = 0; x < 101; x++) { for (int y = 0; y < 100; y++) { indices[i++] = y * 101 + x; indices[i++] = (y + 1) * 101 + x; } } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, 100 * 101 * 4 * sizeof *indices, indices, GL_STATIC_DRAW); // Create another array of indices that describes all the triangles needed to create a completely filled surface i = 0; for (int y = 0; y < 100; y++) { for (int x = 0; x < 100; x++) { indices[i++] = y * 101 + x; indices[i++] = y * 101 + x + 1; indices[i++] = (y + 1) * 101 + x + 1; indices[i++] = y * 101 + x; indices[i++] = (y + 1) * 101 + x + 1; indices[i++] = (y + 1) * 101 + x; } } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[2]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof indices, indices, GL_STATIC_DRAW); return 1; }
FBCALL FBSTRING *fb_Dir( FBSTRING *filespec, int attrib, int *out_attrib ) { FB_DIRCTX *ctx; FBSTRING *res; ssize_t len; int tmp_attrib; char *name, *p; struct stat info; if( out_attrib == NULL ) out_attrib = &tmp_attrib; len = FB_STRSIZE( filespec ); name = NULL; ctx = FB_TLSGETCTX( DIR ); if( len > 0 ) { /* findfirst */ if( ctx->in_use ) close_dir( ); if( strchr( filespec->data, '*' ) || strchr( filespec->data, '?' ) ) { /* we have a pattern */ p = strrchr( filespec->data, '/' ); if( p ) { strncpy( ctx->filespec, p + 1, MAX_PATH ); ctx->filespec[MAX_PATH-1] = '\0'; len = (p - filespec->data) + 1; if( len > MAX_PATH - 1 ) len = MAX_PATH - 1; memcpy( ctx->dirname, filespec->data, len ); ctx->dirname[len] = '\0'; } else { strncpy( ctx->filespec, filespec->data, MAX_PATH ); ctx->filespec[MAX_PATH-1] = '\0'; strcpy( ctx->dirname, "./"); } /* Make sure these patterns work just like on Win32/DOS */ if( (!strcmp( ctx->filespec, "*.*" )) || (!strcmp( ctx->filespec, "*." )) ) strcpy( ctx->filespec, "*" ); if( (attrib & 0x10) == 0 ) attrib |= 0x20; ctx->attrib = attrib; ctx->dir = opendir( ctx->dirname ); if( ctx->dir ) { name = find_next( out_attrib ); if( name ) ctx->in_use = TRUE; } } else { /* no pattern, use stat on single file */ if( !stat( filespec->data, &info ) ) { tmp_attrib = get_attrib( filespec->data, &info ); if( (tmp_attrib & ~attrib ) == 0 ) { name = strrchr( filespec->data, '/' ); if( !name ) name = filespec->data; else name++; *out_attrib = tmp_attrib; } } } } else { /* findnext */ if( ctx->in_use ) name = find_next( out_attrib ); } FB_STRLOCK(); /* store filename if found */ if( name ) { len = strlen( name ); res = fb_hStrAllocTemp_NoLock( NULL, len ); if( res ) fb_hStrCopy( res->data, name, len ); else res = &__fb_ctx.null_desc; } else { res = &__fb_ctx.null_desc; *out_attrib = 0; } fb_hStrDelTemp_NoLock( filespec ); FB_STRUNLOCK(); return res; }
/////////////////////////////////////////////////////////////////////////////// // // FromXMLString // /////////////////////////////////////////////////////////////////////////////// int TMarcRecord::FromXMLString(typestr & a_xml) { // Delete previous content DelTree(); typestr xml = a_xml; TMarcField *field, *lastfield; while (true) { typestr tag, attribs, content, remainder; if (!get_tag(xml, tag, attribs, content, remainder)) return mStateManager->SetErrorD(1050, ERROR, xml.str()); if (tag == "record") { xml = content; while (true) { if (!get_tag(xml, tag, attribs, content, remainder)) { if (!itsFirstField) return mStateManager->SetErrorD(1050, ERROR, xml.str()); break; } xml = remainder; if (tag == "leader") { content = unescape_xml(content); size_t len = strlen(content.str()); for (size_t i = len; i < 24; i++) content.append_char(' '); memcpy(itsLeader, content.str(), 24); } else if (tag == "controlfield" || tag == "datafield") { if ((field = new TMarcField()) == NULL) return mStateManager->SetError(9041,FATAL); if (!itsFirstField) { itsFirstField = field; } else { lastfield->SetNextField(field); } lastfield = field; field->SetTag(get_attrib("tag", attribs).str()); if (tag == "datafield") { field->SetI1(*get_attrib("ind1", attribs).str()); field->SetI2(*get_attrib("ind2", attribs).str()); typestr field_data; typestr subfield; while (get_tag(content, tag, attribs, subfield, remainder)) { content = remainder; if (tag == "subfield") { field_data += START_OF_FIELD; field_data += get_attrib("code", attribs); field_data += unescape_xml(subfield); } } field->SetLib1(field_data.str()); } else { field->SetLib1(unescape_xml(content).str()); if (strcmp(field->GetTag(), "001") == 0) { strncpy(m_recordId, field->GetLib1(), 50); m_recordId[50] = '\0'; } } } } break; } } return 0; }
virtual RetType dFd(CBface* f, int dir) { //literal C++ translation //will get simplified with built in functions.. AttType att1 = get_attrib(f->v1(),f); AttType att2 = get_attrib(f->v2(),f); AttType att3 = get_attrib(f->v3(),f); //might want to try loc instead of wloc Wvec A = f->v2()->wloc() - f->v1()->wloc(); Wvec B = f->v3()->wloc() - f->v1()->wloc(); RetType delta1 = att2 - att1; RetType delta2 = att3 - att1; double a_T,b_T,c_T,d_T; /* { a_T, c_T } { Ax, Ay, Az } { Ax, Bx } { b_T, d_T } = { Bx, By, Bz } * { Ay, By } { Az, Bz } */ a_T = A[0]*A[0]+A[1]*A[1]+A[2]*A[2]; b_T = A[0]*B[0]+A[1]*B[1]+A[2]*B[2]; c_T = A[0]*B[0]+A[1]*B[1]+A[2]*B[2]; d_T = B[0]*B[0]+B[1]*B[1]+B[2]*B[2]; double a_S,b_S,c_S,d_S,e_S,f_S; double det = 1.0 /(a_T * d_T - b_T * c_T); /* { a_S, c_S, e_S } { a_T, c_T }^-1 { Ax, Ay, Az } { b_S, d_S, f_S } = { b_T, d_T } * { Bx, By, Bz } */ a_S = ((A[0] * d_T) + (B[0] * -c_T)) * det; b_S = ((A[0] * -b_T) + (B[0] * a_T)) * det; c_S = ((A[1] * d_T) + (B[1] * -c_T)) * det; d_S = ((A[1] * -b_T) + (B[1] * a_T)) * det; e_S = ((A[2] * d_T) + (B[2] * -c_T)) * det; f_S = ((A[2] * -b_T) + (B[2] * a_T)) * det; switch (dir) { case 0 : // X { return delta1 * a_S + delta2 * b_S; } case 1 : // Y { return delta1 * c_S + delta2 * d_S; } case 2 : // Z { return delta1 * e_S + delta2 * f_S; } } //default average of all 3 principal directions return((delta1 * a_S + delta2 * b_S) + (delta1 * c_S + delta2 * d_S) + (delta1 * e_S + delta2 * f_S)) / 3.0; }
static void process_fsetstat(u_int32_t id) { Attrib *a; int handle, fd, ret; int status = SSH2_FX_OK; handle = get_handle(); a = get_attrib(); debug("request %u: fsetstat handle %d", id, handle); fd = handle_to_fd(handle); if (fd < 0) status = SSH2_FX_FAILURE; else { char *name = handle_to_name(handle); if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { logit("set \"%s\" size %llu", name, (unsigned long long)a->size); ret = ftruncate(fd, a->size); if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { logit("set \"%s\" mode %04o", name, a->perm); #ifdef HAVE_FCHMOD ret = fchmod(fd, a->perm & 07777); #else ret = chmod(name, a->perm & 07777); #endif if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) { char buf[64]; time_t t = a->mtime; strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S", localtime(&t)); logit("set \"%s\" modtime %s", name, buf); #ifdef HAVE_FUTIMES ret = futimes(fd, attrib_to_tv(a)); #else ret = utimes(name, attrib_to_tv(a)); #endif if (ret == -1) status = errno_to_portable(errno); } if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) { logit("set \"%s\" owner %lu group %lu", name, (u_long)a->uid, (u_long)a->gid); #ifdef HAVE_FCHOWN ret = fchown(fd, a->uid, a->gid); #else ret = chown(name, a->uid, a->gid); #endif if (ret == -1) status = errno_to_portable(errno); } } send_status(id, status); #ifdef NERSC_MOD char* t1buf = encode_string( handle_to_name(handle), strlen(handle_to_name(handle)) ); s_audit("sftp_process_fsetstat_3", "count=%i int=%d int=%d uristring=%s", get_client_session_id(), (int)getppid(), id, t1buf); free(t1buf); #endif }
// Open or create void SFTP::process_open(void) { u_int32_t id, pflags; Attrib a; char *utf8_name = 0; int status = SSH2_FX_FAILURE; try { id = get_int(); utf8_name = (char*) get_string(NULL); pflags = get_int(); /* portable flags */ debug3("request %u: open flags %d", id, pflags); #ifdef _DEBUG if (strcmp (utf8_name, "/2stop_sftp_subsystem") == 0) sftp_server_cleanup_exit (0); #endif a = get_attrib(this->iqueue); //mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; //FIXME logit("open \"%s\" flags %s mode 0%o", //FIXME UNICODE utf8_name, string_from_portable(pflags), 0/*mode*/); DWORD creationDisposition = 0; if (pflags & SSH2_FXF_CREAT) { if (pflags & SSH2_FXF_EXCL) creationDisposition = CREATE_NEW; else if (pflags & SSH2_FXF_TRUNC) creationDisposition = CREATE_ALWAYS; else creationDisposition = OPEN_ALWAYS; } else { creationDisposition = OPEN_EXISTING; } const SFTPFilePath path = pathFact.create_path (utf8_name); HANDLE fh = ::CreateFileW (path.get_for_call ().c_str (), flags_from_portable (pflags), FILE_SHARE_READ, NULL, //FIXME ACL creationDisposition, //names in different registry are different //UT FILE_ATTRIBUTE_NORMAL, // TODO make performance experiments with FILE_FLAG_RANDOM_ACCESS , // FILE_FLAG_SEQUENTIAL_SCAN NULL ); if (fh == INVALID_HANDLE_VALUE) { status = errno_to_portable(::GetLastError ()); } else { int handle = handle_new(HANDLE_FILE, path, fh, NULL); debug ("%s is opened as handle %d", utf8_name, (int) handle); if (handle < 0) { (void) ::CloseHandle (fh); } else { send_handle(id, handle); status = SSH2_FX_OK; } } } #ifdef _DEBUG catch (::XShuttingDown&) { throw; } #endif catch (Path::InvalidPath&) { //logit status = SSH2_FX_FAILURE; // TODO return the reason } catch (...) { status = SSH2_FX_FAILURE; error ("unhandled exception in %s", __FUNCTION__); } if (status != SSH2_FX_OK) send_status(id, status); if (utf8_name) xfree(utf8_name); }
void SFTP::process_setstat(void) { Attrib a; u_int32_t id; char *utf8_name; int status = SSH2_FX_OK; WIN32_FILE_ATTRIBUTE_DATA st; try { id = get_int(); utf8_name = (char*) get_string(NULL); a = get_attrib(this->iqueue); debug("request %u: setstat name \"%s\"", id, utf8_name); const SFTPFilePath path = pathFact.create_path (utf8_name); attrib_to_stat (&a, &st); if (a.flags & SSH2_FILEXFER_ATTR_SIZE) { #if 0 logit("set \"%s\" size %llu", utf8_name, (unsigned long long)a->size); LARGE_INTEGER largeOffset; largeOffset.QuadPart = a->size; if (!::SetFilePointerEx (fh, largeOffset, NULL, FILE_BEGIN) || !::SetEndOfFile (fh) ) { status = errno_to_portable(::GetLastError ()); } #endif status = SSH2_FX_OP_UNSUPPORTED; } if (status == SSH2_FX_OK && a.flags & SSH2_FILEXFER_ATTR_ACMODTIME) { #if 0 char buf[64]; time_t t = a->mtime; strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S", localtime(&t)); logit("set \"%s\" modtime %s", name, buf); ret = utimes(name, attrib_to_tv(a)); if (ret == -1) status = errno_to_portable(::GetLastError ()); #endif status = SSH2_FX_OP_UNSUPPORTED; } if (status == SSH2_FX_OK && a.flags & SSH2_FILEXFER_ATTR_UIDGID) { #if 0 logit("set \"%s\" owner %lu group %lu", name, (u_long)a->uid, (u_long)a->gid); ret = chown(name, a->uid, a->gid); if (ret == -1) status = errno_to_portable(::GetLastError ()); #endif status = SSH2_FX_OP_UNSUPPORTED; } // access premissions if (status == SSH2_FX_OK && a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { logit("set \"%s\" mode %04o", utf8_name, a.perm); if (!::SetFileAttributesW (path.get_for_call ().c_str (), st.dwFileAttributes) ) { status = errno_to_portable(::GetLastError ()); } } } catch (Path::InvalidPath&) { //logit status = SSH2_FX_FAILURE; // TODO return the reason } catch (...) { status = SSH2_FX_FAILURE; error ("unhandled exception in %s", __FUNCTION__); } send_status(id, status); if (utf8_name) xfree(utf8_name); }
void SFTP::process_fsetstat(void) { Attrib a; u_int32_t id; int handle; int status = SSH2_FX_OK; id = get_int(); handle = get_handle(); a = get_attrib(this->iqueue); debug("request %u: fsetstat handle %d", id, handle); HANDLE fh = handle_to_fh(handle); if (fh == INVALID_HANDLE_VALUE) { status = SSH2_FX_FAILURE; } else { if (status == SSH2_FX_OK && a.flags & SSH2_FILEXFER_ATTR_UIDGID) { #if 0 logit("set \"%s\" owner %lu group %lu", name, (u_long)a->uid, (u_long)a->gid); #ifdef HAVE_FCHOWN ret = fchown(fd, a->uid, a->gid); #else ret = chown(name, a->uid, a->gid); #endif if (ret == -1) status = errno_to_portable(::GetLastError ()); #endif status = SSH2_FX_OP_UNSUPPORTED; } if (a.flags & SSH2_FILEXFER_ATTR_SIZE) { logit("set \"%s\" size %llu", "???", (unsigned long long)a.size); LARGE_INTEGER largeOffset; largeOffset.QuadPart = a.size; if (!::SetFilePointerEx (fh, largeOffset, NULL, FILE_BEGIN) || !::SetEndOfFile (fh) ) { status = errno_to_portable(::GetLastError ()); } } if (status == SSH2_FX_OK) { BY_HANDLE_FILE_INFORMATION stBefore; FILE_BASIC_INFO stAfter; WIN32_FILE_ATTRIBUTE_DATA stRequested; if (::GetFileInformationByHandle (fh, &stBefore)) { attrib_to_stat (&a, &stRequested); if (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) { logit("set \"%s\" mode %04o", "???", a.perm); stAfter.FileAttributes = stRequested.dwFileAttributes; } else stAfter.FileAttributes = stBefore.dwFileAttributes; if (a.flags & SSH2_FILEXFER_ATTR_ACMODTIME) { /*char buf[64]; time_t t = a->mtime; strftime(buf, sizeof(buf), "%Y%m%d-%H:%M:%S", localtime(&t)); logit("set \"%s\" modtime %s", name, buf);*/ //TODO COPY_TO_LARGE_INTEGER (stAfter.LastAccessTime, stRequested.ftLastAccessTime.dwLowDateTime, stRequested.ftLastAccessTime.dwHighDateTime); COPY_TO_LARGE_INTEGER (stAfter.LastWriteTime, stRequested.ftLastWriteTime.dwLowDateTime, stRequested.ftLastWriteTime.dwHighDateTime); } else { COPY_TO_LARGE_INTEGER (stAfter.LastAccessTime, stBefore.ftLastAccessTime.dwLowDateTime, stBefore.ftLastAccessTime.dwHighDateTime); COPY_TO_LARGE_INTEGER (stAfter.LastWriteTime, stBefore.ftLastWriteTime.dwLowDateTime, stBefore.ftLastWriteTime.dwHighDateTime); } COPY_TO_LARGE_INTEGER (stAfter.CreationTime, stBefore.ftCreationTime.dwLowDateTime, stBefore.ftCreationTime.dwHighDateTime); SYSTEMTIME systemTime; FILETIME currentTime; ::GetSystemTime(&systemTime); ::SystemTimeToFileTime(&systemTime, ¤tTime); COPY_TO_LARGE_INTEGER (stAfter.ChangeTime, currentTime.dwLowDateTime, currentTime.dwHighDateTime); if (!::SetFileInformationByHandle (fh, FileBasicInfo, &stAfter, sizeof (stAfter) ) ) status = errno_to_portable(::GetLastError ()); } else { status = errno_to_portable(::GetLastError ()); } } } send_status(id, status); }