void neb::glsl::program::compile() { //GRU_GLSL_PROGRAM_FUNC glLinkProgram(o_); checkerror("glLinkProgram"); GLint blen = 0; GLsizei slen = 0; glGetProgramiv(o_, GL_INFO_LOG_LENGTH , &blen); checkerror("glGetProgramiv"); if (blen > 1) { GLchar* compiler_log = (GLchar*)malloc(blen); glGetInfoLogARB(o_, blen, &slen, compiler_log); printf("compiler_log:%s\n", compiler_log); free (compiler_log); } printf("program=%i\n",o_); }
void PrimitiveShape::paint() { VertexBuffer* vb = m_vertexbuffer; // IndexBuffer* ib = m_indexbuffer; Program* pr = m_program; if( !vb || !pr ) { return; } size_t vertexcount; VertexDeclaration* vdecl; if( !vb->bind( &vertexcount, &vdecl ) ) { return; } // int indexcount; // if( ib ) // { // if( !ib->bind( &indexcount ) ) // { // return; // } // } if( !pr->bind() ) { return; } int ptype = m_type.load( std::memory_order_acquire ); checkerror( Context::Device->SetRenderState( D3DRS_BLENDOP, m_blendop ) ); checkerror( Context::Device->SetRenderState( D3DRS_SRCBLEND, m_blendsf ) ); checkerror( Context::Device->SetRenderState( D3DRS_DESTBLEND, m_blenddf ) ); { lock_t lock( m_mutex ); checkerror( Context::Device->SetVertexShaderConstantF( 0, m_matrix.m[ 0 ], 4 ) ); } // checkerror( Context::Device->DrawIndexedPrimitive( // D3DPRIMITIVETYPE( m_type ), // 0, // 0, // vertexcount, // 0, // indexcount / 3 ) ); checkerror( Context::Device->DrawPrimitive( D3DPRIMITIVETYPE( typetable[ ptype ] ), 0, UINT( ( vertexcount - poffsettable[ ptype ] ) / pfactortable[ ptype ] ) ) ); }
/* fd, is a user file descriptor. */ PRIVILEGED_FUNCTION int _close_r(struct _reent *ptr, int fd) { int res; struct fdent *pfd; pfd = findslot(fd); if (pfd == NULL) { ptr->_errno = EBADF; return -1; } /* Handle stderr == stdout. */ if ((fd == 1 || fd == 2) && (openfiles[1].handle == openfiles[2].handle)) { pfd->handle = -1; return 0; } /* Attempt to close the handle. */ res = checkerror(do_AngelSWI (AngelSWI_Reason_Close, &f(pfd->handle))); /* Reclaim handle? */ if (res == 0) pfd->handle = -1; return res; }
/* make room for at least n chars */ static int grow(buffer_t * b, size_t n) { size_t used = inuse(b); size_t newlen = sizeof(b->initial); /* current buf is always at least as big as b->initial */ /* simple solution to find next power of 2 */ while (newlen < used+n) newlen <<= 1; /* too big? */ if (0 < b->max && b->max < newlen) { if (used+n <= b->max) { /* This handles the case where b->max is not a power of 2. */ newlen = b->max; } else { errno = ENOBUFS; checkerror(b, 0, 0); } } if (b->buf == b->ubuf.buf || b->buf == b->initial) { char *new = malloc(newlen); checkerror(b, NULL, new); memcpy(new, b->buf, used); b->buf = new; } else {
int get_next_line(int const fd, char **line) { static char *str; int i; if (checkerror(fd, &str, line) == -1) return (-1); if (*str) ft_strcpy(*line, str); str = readline(str, fd); i = 0; if (str[i]) { while (str[i] != '\n' && str[i]) i++; if (i == 0) (*line) = ft_strdup(""); else { (*line) = ft_strsub(str, 0, i); str = &str[i + 1]; } return (1); } else (*line) = ft_strdup(""); return (0); }
void neb::texture::init_shadow(int w,int h) { printf("%s\n",__PRETTY_FUNCTION__); w_ = w; h_ = h; glGenTextures(1, &o_); bind(); glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w_, h_, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); checkerror(""); }
void neb::gfx::mesh::instanced::draw( neb::gfx::mesh::instanced::program_type* program, std::shared_ptr<neb::gfx::glsl::buffer::instanced> buf) { LOG(lg, neb::gfx::sl, debug) << __PRETTY_FUNCTION__; assert(instances_); //auto buf_mesh = mesh_.getBuffer(program); auto bt = mesh_.getBufferTuple(program); buf->vertexAttribPointer(); //buf_mesh->vertexAttribPointer(); mesh_.vertexAttribPointer(bt); LOG(lg, neb::gfx::sl, debug) << "instances size = " << instances_->size(); LOG(lg, neb::gfx::sl, debug) << "mesh size = " << mesh_.getNbIndices(); mesh_.bind(bt); auto s = instances_->size(); glDrawElementsInstanced( GL_TRIANGLES, mesh_.getNbIndices(), GL_UNSIGNED_SHORT, 0, s); checkerror("glDrawElementsInstanced"); mesh_.unbind(bt); }
void PrimitiveShape::paint() { VertexBuffer* vb = m_vertexbuffer; // IndexBuffer* ib = m_indexbuffer; Program* pr = m_program; if( !vb || !pr ) { return; } size_t vertexcount; VertexDeclaration* vdecl; if( !vb->bind( &vertexcount, &vdecl ) ) { return; } // int indexcount; // if( ib ) // { // if( !ib->bind( &indexcount ) ) // { // return; // } // } int worldmatrixpos; if( !pr->bind( &worldmatrixpos ) ) { return; } int ptype = m_type.load( std::memory_order_acquire ); glBlendEquation( m_blendop ); checkerror(); glBlendFunc( m_blendsf, m_blenddf ); checkerror(); if( worldmatrixpos != -1 ) { lock_t lock( m_mutex ); glUniformMatrix4fv( worldmatrixpos, 1, false, m_matrix ); } // checkerror( Context::Device->DrawIndexedPrimitive( // D3DPRIMITIVETYPE( m_type ), // 0, // 0, // vertexcount, // 0, // indexcount / 3 ) ); glDrawArrays( typetable[ ptype ], 0, GLsizei( vertexcount ) ); }
int neb::glsl::attrib::locate(std::shared_ptr<neb::glsl::program> p) { glBindAttribLocation(p->o_, o_bind_, name_); checkerror("glBindAttribLocation"); o_ = glGetAttribLocation(p->o_, name_); checkerror("glGetAttribLocation"); /* if(o_ == -1) { printf("could not find attrib '%s'\n", name_); exit(0); } */ return o_; }
void neb::glsl::program::add_shader(char const * filename, GLenum type) { neb::glsl::shader s; s.load(filename, type); glAttachShader(o_, s.o_); checkerror("glAttachShader"); }
void neb::glsl::program::init() { //NEBULA_GLSL_PROGRAM_FUNC; o_ = glCreateProgram(); printf("program = %i\n",o_); checkerror("glCreateProgram"); }
/*********************************************************************************************************** **函数:SimpleGetRtpPoll **功能: **输入参数: **返回值: ***********************************************************************************************************/ int SimpleGetRtpPoll(void) { int status; if(SimpleRtpIsActive()!=true) { return -1; } status = sess.Poll(); checkerror(status); return status; }
void neb::glsl::program::add_shaders(std::vector<neb::glsl::shader> s) { //GRU_GLSL_PROGRAM_FUNC for(unsigned int i = 0; i < s.size(); ++i ) { printf("shader %i attached to program %i\n",s[i].o_,o_); glAttachShader(o_, s.at(i).o_); checkerror("glAttachShader"); } }
void neb::Light::base::RenderLightPOV() { GLUTPP_DEBUG_1_FUNCTION; /* std::shared_ptr<scene> scene = scene_.lock(); //First pass - from light's point of view glClear(GL_COLOR_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); camera_.load_shader(); */ /* glMatrixMode(GL_PROJECTION); glLoadMatrixf(camera_.proj()); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(camera_.view()); glViewport(0, 0, texture_shadow_map_.w_, texture_shadow_map_.h_); */ //window_->lights_updateGL(); // Use viewport the same size as the shadow map // Draw back faces into the shadow map /* glCullFace(GL_FRONT); // Disable color writes, and use flat shading for speed glShadeModel(GL_FLAT); glColorMask(0, 0, 0, 0); //Draw the scene scene->draw_shader(); //Read the depth buffer into the shadow map texture texture_shadow_map_.bind(); glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, texture_shadow_map_.w_, texture_shadow_map_.h_); //restore states glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); glColorMask(1, 1, 1, 1); */ checkerror("unknown"); }
void neb::Light::base::RenderShadowPost() { //Disable textures and texgen glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); glDisable(GL_TEXTURE_GEN_Q); glDisable(GL_ALPHA_TEST); checkerror(__PRETTY_FUNCTION__); }
/*********************************************************************************************************** **函数:Rtp_Lock **功能: **输入参数: **返回值: ***********************************************************************************************************/ int SimpleAddDestination(uint32_t ipaddr, uint16_t destport) { int status; if(SimpleRtpIsActive()!=true) { printf("rtp Session is error,%s ,%d\n",__FUNCTION__, __LINE__); return -1; } Rtp_Lock(); RTPIPv4Address addr(ipaddr,destport); status = sess.AddDestination(addr); checkerror(status); Rtp_UnLock(); return status; }
void neb::glsl::program::use() { //GRU_GLSL_PROGRAM_FUNC; glUseProgram(o_); checkerror("glUseProgram"); std::shared_ptr<neb::glsl::attrib> attrib; for(auto it = attrib_.begin(); it != attrib_.end(); ++it) { attrib = (*it).second; assert(attrib); attrib->locate(shared_from_this()); } }
/*********************************************************************************************************** **函数:Rtp_Lock **功能: **输入参数: **返回值: ***********************************************************************************************************/ static int RtpSetup( uint16_t portbase) { int status; RTPUDPv4TransmissionParams transparams; RTPSessionParams sessparams; sessparams.SetOwnTimestampUnit(1.0/90000.0); sessparams.SetMaximumPacketSize(1200); transparams.SetPortbase(portbase); sess.SetDefaultPayloadType(PLOAD_TYPE); sess.SetDefaultMark(false); sess.SetDefaultTimestampIncrement(DefaultTimestampIncrement); status = sess.Create(sessparams,&transparams); checkerror(status); return status; }
void basis_iostream::handle_read(const boost::system::error_code& err, size_t bytes_transferred) { if (!err) { tmout_timer_.cancel(); io_service_.stop(); bytes_trans = bytes_transferred; is_timout = false; is_data_ready = (bytes_transferred > 0); is_error = false; } else { DEBUG_VAL_DVNCI(err.message()) tmout_timer_.cancel(); checkerror(err); error_cod = err.value(); is_error = true; io_service_.stop(); is_data_ready = false; } }
void basis_iostream::handle_write(const boost::system::error_code& err, size_t bytes_transferred) { if (!err) { tmout_timer_.cancel(); io_service_.stop(); is_timout = false; is_error = false; } else { tmout_timer_.cancel(); checkerror(err); error_cod = err.value(); is_error = true; io_service_.stop(); is_data_ready = false; DEBUG_STR_DVNCI(is errror handle_write!!!) } }
uint8_t setupDevice() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards pinMode(13, OUTPUT); // start serial port at 9600 baud Serial.begin(9600); // initialize the OPDI system uint8_t result = ArduinOpdi.setup(20000, 0, &Serial, NULL); if (checkerror(result) == 0) return 0; // add the ports provided by this configuration Opdi->addPort(&digPort1); Opdi->addPort(&digPort2); Opdi->addPort(&anaPort1); Opdi->addPort(&anaPort2); return 1; }
bool VertexBuffer::bind( size_t* vertexcount, VertexDeclaration** pvd ) { VertexDeclaration* vd = m_vertexdeclaration; if( !vd || !m_vertexbuffer ) { return false; } if( Context::CurrentVertexBuffer != this ) { glBindBuffer( GL_ARRAY_BUFFER, m_vertexbuffer ); checkerror(); Context::CurrentVertexBuffer = this; } size_t vertexsize; if( !vd->bind( &vertexsize ) ) { return false; } *vertexcount = m_buffersize / vertexsize; *pvd = vd; return true; }
void neb::glsl::Uniform::Vector::Vec3::load(int c, float* v) { glUniform3fv(o_[c], 1, v); checkerror("glUniform3fv"); }
int neb::texture::load_png(char const * filename) { printf("%s\n",__PRETTY_FUNCTION__); png_byte header[8]; FILE *fp = fopen(filename, "rb"); if (fp == 0) { perror(filename); exit(0); } // read the header fread(header, 1, 8, fp); if (png_sig_cmp(header, 0, 8)) { fprintf(stderr, "error: %s is not a PNG.\n", filename); fclose(fp); return 0; } png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { fprintf(stderr, "error: png_create_read_struct returned 0.\n"); fclose(fp); return 0; } // create png info struct png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { fprintf(stderr, "error: png_create_info_struct returned 0.\n"); png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL); fclose(fp); return 0; } // create png info struct png_infop end_info = png_create_info_struct(png_ptr); if (!end_info) { fprintf(stderr, "error: png_create_info_struct returned 0.\n"); png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp) NULL); fclose(fp); return 0; } // the code in this if statement gets called if libpng encounters an error if (setjmp(png_jmpbuf(png_ptr))) { fprintf(stderr, "error from libpng\n"); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); fclose(fp); return 0; } // init png reading png_init_io(png_ptr, fp); // let libpng know you already read the first 8 bytes png_set_sig_bytes(png_ptr, 8); // read all the info up to the image data png_read_info(png_ptr, info_ptr); // variables to pass to get info int bit_depth, color_type; png_uint_32 temp_width, temp_height; // get info about png png_get_IHDR( png_ptr, info_ptr, &temp_width, &temp_height, &bit_depth, &color_type, NULL, NULL, NULL); w_ = temp_width; h_ = temp_height; // Update the png info struct. png_read_update_info(png_ptr, info_ptr); // Row size in bytes. int rowbytes = png_get_rowbytes(png_ptr, info_ptr); // glTexImage2d requires rows to be 4-byte aligned rowbytes += 3 - ((rowbytes-1) % 4); // Allocate the image_data as a big block, to be given to opengl png_byte * image_data; image_data = (png_byte*)malloc(rowbytes * temp_height * sizeof(png_byte)+15); if (image_data == NULL) { fprintf(stderr, "error: could not allocate memory for PNG image data\n"); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); fclose(fp); return 0; } // row_pointers is for pointing to image_data for reading the png with libpng png_bytep * row_pointers = (png_bytep*)malloc(temp_height * sizeof(png_bytep)); if (row_pointers == NULL) { fprintf(stderr, "error: could not allocate memory for PNG row pointers\n"); png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); free(image_data); fclose(fp); return 0; } // set the individual row_pointers to point at the correct offsets of image_data for (unsigned int i = 0; i < temp_height; i++) { row_pointers[temp_height - 1 - i] = image_data + i * rowbytes; } // read the png into image_data through row_pointers png_read_image(png_ptr, row_pointers); // Generate the OpenGL texture object glGenTextures(1, &o_); glBindTexture(GL_TEXTURE_2D, o_); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, temp_width, temp_height, 0, GL_RGB, GL_UNSIGNED_BYTE, image_data); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); printf("image '%s' loaded into texture object %i\n",filename,o_); checkerror(""); // clean up png_destroy_read_struct(&png_ptr, &info_ptr, &end_info); free(image_data); free(row_pointers); fclose(fp); return o_; }
void neb::texture::bind() { glBindTexture(GL_TEXTURE_2D, o_); checkerror("glBindTexture"); }
void neb::glsl::attrib::disable() { glDisableVertexAttribArray(o_); checkerror("glDisableVertexAttribArray"); }
int main(int ac, char **av) { int c, i, nnodes=0; long node=-1; char *end; char shortopts[array_len(opts)*2 + 1]; struct bitmask *mask = NULL; get_short_opts(opts,shortopts); while ((c = getopt_long(ac, av, shortopts, opts, NULL)) != -1) { switch (c) { case 's': /* --show */ show(); exit(0); case 'H': /* --hardware */ nopolicy(); hardware(); exit(0); case 'i': /* --interleave */ checknuma(); mask = numactl_parse_nodestring(optarg); if (!mask) { printf ("<%s> is invalid\n", optarg); usage(); } errno = 0; setpolicy(MPOL_INTERLEAVE); if (shmfd >= 0) numa_interleave_memory(shmptr, shmlen, mask); else numa_set_interleave_mask(mask); checkerror("setting interleave mask"); break; case 'N': /* --cpunodebind */ case 'c': /* --cpubind */ dontshm("-c/--cpubind/--cpunodebind"); checknuma(); mask = numactl_parse_nodestring(optarg); if (!mask) { printf ("<%s> is invalid\n", optarg); usage(); } errno = 0; check_cpubind(do_shm); did_cpubind = 1; numa_run_on_node_mask(mask); checkerror("sched_setaffinity"); break; case 'C': /* --physcpubind */ { struct bitmask *cpubuf; dontshm("-C/--physcpubind"); cpubuf = numa_parse_cpustring(optarg); if (!cpubuf) { printf ("<%s> is invalid\n", optarg); usage(); } errno = 0; check_cpubind(do_shm); did_cpubind = 1; numa_sched_setaffinity(0, cpubuf); checkerror("sched_setaffinity"); free(cpubuf); break; } case 'm': /* --membind */ checknuma(); setpolicy(MPOL_BIND); mask = numactl_parse_nodestring(optarg); if (!mask) { printf ("<%s> is invalid\n", optarg); usage(); } errno = 0; numa_set_bind_policy(1); if (shmfd >= 0) { numa_tonodemask_memory(shmptr, shmlen, mask); } else { numa_set_membind(mask); } numa_set_bind_policy(0); checkerror("setting membind"); break; case 'p': /* --preferred */ checknuma(); setpolicy(MPOL_PREFERRED); mask = numactl_parse_nodestring(optarg); if (!mask) { printf ("<%s> is invalid\n", optarg); usage(); } for (i=0; i<mask->size; i++) { if (numa_bitmask_isbitset(mask, i)) { node = i; nnodes++; } } if (nnodes != 1) usage(); numa_bitmask_free(mask); errno = 0; numa_set_bind_policy(0); if (shmfd >= 0) numa_tonode_memory(shmptr, shmlen, node); else numa_set_preferred(node); checkerror("setting preferred node"); break; case 'l': /* --local */ checknuma(); setpolicy(MPOL_DEFAULT); errno = 0; if (shmfd >= 0) numa_setlocal_memory(shmptr, shmlen); else numa_set_localalloc(); checkerror("local allocation"); break; case 'S': /* --shm */ check_cpubind(did_cpubind); nopolicy(); attach_sysvshm(optarg, "--shm"); shmattached = 1; break; case 'f': /* --file */ check_cpubind(did_cpubind); nopolicy(); attach_shared(optarg, "--file"); shmattached = 1; break; case 'L': /* --length */ noshm("--length"); shmlen = memsize(optarg); break; case 'M': /* --shmmode */ noshm("--shmmode"); shmmode = strtoul(optarg, &end, 8); if (end == optarg || *end) usage(); break; case 'd': /* --dump */ if (shmfd < 0) complain( "Cannot do --dump without shared memory.\n"); dump_shm(); do_dump = 1; break; case 'D': /* --dump-nodes */ if (shmfd < 0) complain( "Cannot do --dump-nodes without shared memory.\n"); dump_shm_nodes(); do_dump = 1; break; case 't': /* --strict */ did_strict = 1; numa_set_strict(1); break; case 'I': /* --shmid */ shmid = strtoul(optarg, &end, 0); if (end == optarg || *end) usage(); break; case 'u': /* --huge */ noshm("--huge"); shmflags |= SHM_HUGETLB; break; case 'o': /* --offset */ noshm("--offset"); shmoffset = memsize(optarg); break; case 'T': /* --touch */ needshm("--touch"); check_shmbeyond("--touch"); numa_police_memory(shmptr, shmlen); break; case 'V': /* --verify */ needshm("--verify"); if (set_policy < 0) complain("Need a policy first to verify"); check_shmbeyond("--verify"); numa_police_memory(shmptr, shmlen); if (!mask) complain("Need a mask to verify"); else verify_shm(set_policy, mask); break; default: usage(); } } av += optind; ac -= optind; if (shmfd >= 0) { if (*av) usage(); exit(exitcode); } if (did_strict) fprintf(stderr, "numactl: warning. Strict flag for process ignored.\n"); if (do_dump) usage_msg("cannot do --dump|--dump-shm for process"); if (shmoption) usage_msg("shm related option %s for process", shmoption); if (*av == NULL) usage(); execvp(*av, av); complain("execution of `%s': %s\n", av[0], strerror(errno)); return 0; /* not reached */ }
void neb::glsl::Uniform::Vector::Vec4::load(int c, vec4 const & v) { GLint o = o_[c]; assert(o != -1); glUniform4fv(o, 1, &v[0]); checkerror("glUniform4fv"); }
void neb::glsl::Uniform::Vector::Vec3::load(int c, vec3 const & v) { glUniform3fv(o_[c], 1, &v[0]); checkerror("glUniform3fv"); }
void neb::glsl::Uniform::Vector::Vec4::load(int c, float* v) { GLint o = o_[c]; assert(o != -1); glUniform4fv(o, 1, v); checkerror("glUniform4fv"); }