const CgBinaryVertexProgram* nvb_reader_impl::vertex_program() const { if ( 0 == image_ ) return 0; return reinterpret_cast<CgBinaryVertexProgram*>( &image_[convert_endianness( header_.program, endianness_ )] ); }
CGBIO_ERROR nvb_reader_impl::loadFromString( const char* source, size_t length) { if ( loaded_ ) { return CGBIO_ERROR_LOADED; } CGBIO_ERROR ret = CGBIO_ERROR_NO_ERROR; while (1) { if (length < sizeof( header_ )) { ret = CGBIO_ERROR_FORMAT; break; } memcpy(&header_ ,source,sizeof( header_ )); if ( CG_BINARY_FORMAT_REVISION != header_.binaryFormatRevision ) { endianness_ = ( CGBIODATALSB == endianness_ ) ? CGBIODATAMSB : CGBIODATALSB; int binaryRevision = convert_endianness( header_.binaryFormatRevision, endianness_ ); if ( CG_BINARY_FORMAT_REVISION != binaryRevision ) { ret = CGBIO_ERROR_FORMAT; break; } } size_t sz = length; image_ = new char[sz]; memcpy(image_,source,sz); loaded_ = true; ret = CGBIO_ERROR_NO_ERROR; break; } return ret; }
const char* nvb_reader_impl::ucode() const { if ( 0 == image_ || 0 == ucode_size() ) return 0; return ( image_ + convert_endianness( header_.ucode, endianness() ) ); }
CGBIO_ERROR nvb_reader_impl::get_param_name( unsigned int index, const char **name, bool& is_referenced ) const { if ( index >= number_of_params() ) return CGBIO_ERROR_INDEX; if ( 0 == image_ ) return CGBIO_ERROR_NO_ERROR; const CgBinaryParameter* params = reinterpret_cast<CgBinaryParameter*>( &image_[convert_endianness( header_.parameterArray, endianness_ )] ); const CgBinaryParameter& pp = params[index]; is_referenced = convert_endianness( pp.isReferenced, endianness() ) != 0; CgBinaryStringOffset nm_offset = convert_endianness( pp.name,endianness() ); if ( nm_offset != 0 ) *name = &image_[nm_offset]; else *name = ""; return CGBIO_ERROR_NO_ERROR; }
void ScoreWebSender::addDataToFinishGame(RecordLine rL) { if (rL.points == 0) { clearData(); return; } ostringstream oss; // << taille des données initiales : 1 octet oss << (unsigned char) sizeof(RecordLine); // << données initiales : x octets rL.lines_u = convert_endianness(rL.lines_u, BINARY_NETWORK_BIG_ENDIAN); rL.points_u = convert_endianness(rL.points_u, BINARY_NETWORK_BIG_ENDIAN); rL.tetrominos_u = convert_endianness(rL.tetrominos_u, BINARY_NETWORK_BIG_ENDIAN); rL.time_u = convert_endianness(rL.time_u, BINARY_NETWORK_BIG_ENDIAN); for (size_t i=0; i<sizeof(RecordLine); i++) oss << (char) rL.b[i]; // << nombre de ligne de données du déroulement de jeu // << taille d'une ligne de donnée _4bytes gameDataSize; gameDataSize.i = gameDatas.size(); gameDataSize = convert_endianness(gameDataSize , BINARY_NETWORK_BIG_ENDIAN); oss << gameDataSize.b[0] << gameDataSize.b[1] << gameDataSize.b[2] << gameDataSize.b[3] << (char) sizeof(ScoreWebSenderDataSample); for (size_t i=0; i<gameDatas.size(); i++) { ScoreWebSenderDataSample dL = gameDatas[i]; dL.u.nbDelLines = convert_endianness(dL.u.nbDelLines, BINARY_NETWORK_BIG_ENDIAN); dL.u.nbDelLinesDiff = convert_endianness(dL.u.nbDelLinesDiff, BINARY_NETWORK_BIG_ENDIAN); dL.u.nbManualDown = convert_endianness(dL.u.nbManualDown, BINARY_NETWORK_BIG_ENDIAN); dL.u.nbTetromino = convert_endianness(dL.u.nbTetromino, BINARY_NETWORK_BIG_ENDIAN); dL.u.score = convert_endianness(dL.u.score, BINARY_NETWORK_BIG_ENDIAN); dL.u.scoreDiff = convert_endianness(dL.u.scoreDiff, BINARY_NETWORK_BIG_ENDIAN); dL.u.timeMilliseconds = convert_endianness(dL.u.timeMilliseconds, BINARY_NETWORK_BIG_ENDIAN); for (size_t j=0; j<sizeof(ScoreWebSenderDataSample); j++) oss << (char) dL.b[j]; } string g = oss.str(); rL.points_u = convert_endianness(rL.points_u, BINARY_NETWORK_BIG_ENDIAN); Console::out("Envoi du record de " + to_string((int) rL.points) + " points au serveur de score ..."); sf::Thread * th = new sf::Thread(&webSendNewData, g); ScoreWebSender::_uploadThreads.push_back(th); ScoreWebSender::_uploadData.push_back(""); th->launch(); clearData(); }
static int X11_ximage_blit(struct DriverInstance* sh, const uint8_t* fb, int width, int height, struct blit_params* params, int needs_adjust, char* error_text, int text_len) { uint8_t* framebuffer = 0; if (width != sh->width || height != sh->height || params->mirrorx || params->mirrory || needs_adjust) { int size = sh->width*sh->height*4; if (sh->data && sh->data_size < size) { free(sh->data); sh->data = 0; } if (sh->data == 0) { sh->data = malloc(size); sh->data_size = size; } if (sh->data == 0) { snprintf(error_text, text_len, "Could not allocate data for XImage"); return 0; } if (needs_adjust) { ls_scale32m_adjust((uint32_t*) sh->data, sh->width, sh->height, (const uint32_t*) fb, width, height, params->mirrorx, params->mirrory, sh->pal); } else { ls_scale32m((uint32_t*) sh->data, sh->width, sh->height, (const uint32_t*) fb, width, height, params->mirrorx, params->mirrory); } framebuffer = sh->data; } else { if (sh->data != 0) { free(sh->data); sh->data = 0; sh->data_size = 0; } assert(width == sh->width); assert(height == sh->height); framebuffer = (uint8_t*) fb; } assert(framebuffer != 0); // now create an XImage using the framebuffers pixel data //TODO: this is a hack for big-endian machines if (big_endian()) convert_endianness(framebuffer, sh->width, sh->height); if (sh->vis.depth == 16) convert_to_16_inplace(framebuffer, sh->width, sh->height); if (sh->ximage == 0 || sh->image_width != sh->width || sh->image_height != sh->height) { if (sh->ximage) { sh->ximage->data = 0; XDestroyImage(sh->ximage); } sh->ximage = XCreateImage(sh->display, sh->vis.visual, sh->vis.depth, ZPixmap, 0, 0, sh->width, sh->height, 32, 0); sh->image_width = sh->width; sh->image_height = sh->height; } if (sh->ximage == 0) { snprintf(error_text, text_len, "Could not create XImage!"); return 0; } sh->ximage->data = framebuffer; // ... blit it to screen XPutImage(sh->display, sh->win, sh->gc, sh->ximage, 0, 0, 0, 0, sh->width, sh->height); // and finally make sure the xserver performs the blitting XFlush(sh->display); //XSync(sh->display, 0); return 1; }
static int X11_xv_blit(struct DriverInstance* sh, const uint8_t* fb, int width, int height, struct blit_params* params, int needs_adjust, char* error_text, int text_len) { if (sh->xv_image == 0 || width != sh->image_width || height != sh->image_height) { if (sh->xv_image) XFree(sh->xv_image); sh->xv_image = XvCreateImage(sh->display, sh->xv_port, sh->xv_format_id, 0, width, height); sh->image_width = width; sh->image_height = height; } if (sh->data == 0 || sh->data_size < sh->xv_image->data_size) { if (sh->data) free(sh->data); sh->data = malloc(sh->xv_image->data_size); sh->data_size = sh->xv_image->data_size; if (sh->data == 0) { snprintf(error_text, text_len, "Could not allocate data for XVImage"); return 0; } } assert(sh->data); //TODO: this is a hack for big-endian machines if (big_endian()) convert_endianness(sh->data, sh->width, sh->height); sh->xv_image->data = sh->data; if (sh->vis.depth == 24) cvt_rgb32_to_i420((uint8_t*) sh->data, (uint32_t*) fb, width, height, sh->xv_image->pitches, sh->xv_image->offsets); else if (sh->vis.depth == 16) cvt_rgb16_to_i420((uint8_t*) sh->data, (uint16_t*) fb, width, height, sh->xv_image->pitches, sh->xv_image->offsets); // blit image XvPutImage(sh->display, sh->xv_port, sh->win, sh->gc, sh->xv_image, 0, 0, width, height, 0, 0, sh->width, sh->height); XFlush(sh->display); //XSync(sh->display, False); return 1; }
static int X11_xshm_xv_blit(struct DriverInstance* sh, const uint8_t* fb, int width, int height, struct blit_params* params, int needs_adjust, char* error_text, int text_len) { // wait until last blit has completed if (sh->event_pending) { int max_wait = 15; XEvent event; sh->event_pending = 0; while (max_wait--) { XNextEvent(sh->display, &event); if (event.type == sh->completion_type) break; } } if (sh->xv_image == 0 || width != sh->image_width || height != sh->image_height) { if (sh->xv_image) XFree(sh->xv_image); sh->xv_image = XvShmCreateImage(sh->display, sh->xv_port, sh->xv_format_id, sh->shminfo.shmaddr, width, height, &sh->shminfo); sh->image_width = width; sh->image_height = height; } //TODO: this is a hack for big-endian machines if (big_endian()) convert_endianness((uint8_t*) fb, sh->width, sh->height); if (sh->vis.depth == 24) { #if defined(OPT_INCLUDE_MMX) if (sh->mmx_supported) cvt_rgb32_to_i420_mmx((uint8_t*) sh->xv_image->data, (uint32_t*) fb, width, height, sh->xv_image->pitches, sh->xv_image->offsets); else #endif cvt_rgb32_to_i420((uint8_t*) sh->xv_image->data, (uint32_t*) fb, width, height, sh->xv_image->pitches, sh->xv_image->offsets); } else if (sh->vis.depth == 16) cvt_rgb16_to_i420((uint8_t*) sh->xv_image->data, (uint16_t*) fb, width, height, sh->xv_image->pitches, sh->xv_image->offsets); // blit shared mem image XvShmPutImage(sh->display, sh->xv_port, sh->win, sh->gc, sh->xv_image, 0, 0, width, height, 0, 0, sh->width, sh->height, True); sh->event_pending = 1; XFlush(sh->display); //XSync(sh->display, False); return 1; }
// xshm and no xv static int X11_xshm_blit(struct DriverInstance* sh, const uint8_t* fb, int width, int height, struct blit_params* params, int needs_adjust, char* error_text, int text_len) { // wait until last blit has completed if (sh->event_pending) { int max_wait = 15; XEvent event; sh->event_pending = 0; while (max_wait--) { XNextEvent(sh->display, &event); if (event.type == sh->completion_type) break; } } if (sh->ximage == 0) { snprintf(error_text, text_len, "Internal error: sh->ximage == 0"); return 0; } // adjust and scale input framebuffer frb into shared mem if (needs_adjust) { ls_set_adjustment(sh->pal, params->brightness, params->contrast, params->gamma, params->invert); ls_scale32m_adjust((uint32_t*)sh->ximage->data, sh->width, sh->height, (const uint32_t*)fb, width, height, params->mirrorx, params->mirrory, sh->pal); } else { ls_scale32m((uint32_t*)sh->ximage->data, sh->width, sh->height, (const uint32_t*)fb, width, height, params->mirrorx, params->mirrory); } //TODO: this is a hack for big-endian machines if (big_endian()) convert_endianness(sh->ximage->data, sh->width, sh->height); if (sh->vis.depth == 16) convert_to_16_inplace(sh->ximage->data, sh->width, sh->height); // blit shared mem image XShmPutImage(sh->display, sh->win, sh->gc, sh->ximage, 0, 0, 0, 0, sh->width, sh->height, True); sh->event_pending = 1; XFlush(sh->display); //XSync(sh->display, False); return 1; }
CGBIO_ERROR nvb_reader_impl::get_param( unsigned int index, CGtype& type, CGresource& resource, CGenum& variability, int& resource_index, const char ** name, STL_NAMESPACE vector<float>& default_value, STL_NAMESPACE vector<unsigned int>& embedded_constants, const char ** semantic, int& paramno, bool& is_referenced, bool& is_shared ) const { if ( index >= number_of_params() ) return CGBIO_ERROR_INDEX; if ( 0 == image_ ) return CGBIO_ERROR_NO_ERROR; const CgBinaryParameter* params = reinterpret_cast<CgBinaryParameter*>( &image_[convert_endianness( header_.parameterArray, endianness_ )] ); const CgBinaryParameter& pp = params[index]; type = static_cast<CGtype>(convert_endianness( static_cast<unsigned int>( pp.type ), endianness() ) ); resource = static_cast<CGresource>(convert_endianness( static_cast<unsigned int>( pp.res ), endianness() ) ); variability = static_cast<CGenum>(convert_endianness( static_cast<unsigned int>( pp.var ),endianness() ) ); resource_index = convert_endianness( pp.resIndex,endianness() ); paramno = convert_endianness( pp.paramno, endianness() ); is_referenced = convert_endianness( pp.isReferenced,endianness() ) != 0; is_shared = convert_endianness( pp.isShared,endianness() ) != 0; CgBinaryStringOffset nm_offset = convert_endianness( pp.name,endianness() ); CgBinaryFloatOffset dv_offset = convert_endianness( pp.defaultValue,endianness() ); CgBinaryEmbeddedConstantOffset ec_offset = convert_endianness( pp.embeddedConst,endianness() ); CgBinaryStringOffset sm_offset = convert_endianness( pp.semantic,endianness() ); if ( 0 != nm_offset ) { *name = &image_[nm_offset]; } else *name = ""; if ( 0 != sm_offset ) { *semantic = &image_[sm_offset]; } else *semantic = ""; if ( 0 != dv_offset ) { char *vp = &image_[dv_offset]; for (int ii = 0; ii < 4; ++ii) { int tmp; memcpy(&tmp,vp+4*ii,4); tmp = convert_endianness(tmp,endianness()); float tmp2; memcpy(&tmp2,&tmp,4); default_value.push_back( tmp2 ); } } if ( 0 != ec_offset ) { void *vp = &image_[ec_offset]; CgBinaryEmbeddedConstant& ec = *(static_cast<CgBinaryEmbeddedConstant*>( vp )); for (unsigned int ii = 0; ii < convert_endianness( ec.ucodeCount, endianness() ); ++ii) { unsigned int offset = convert_endianness( ec.ucodeOffset[ii], endianness() ); embedded_constants.push_back( offset ); } } return CGBIO_ERROR_NO_ERROR; }
unsigned int nvb_reader_impl::ucode_size() const { return convert_endianness( header_.ucodeSize, endianness() ); }
unsigned int nvb_reader_impl::number_of_params() const { return convert_endianness( header_.parameterCount, endianness() ); }
unsigned int nvb_reader_impl::size() const { return convert_endianness( header_.totalSize, endianness() ); }
unsigned int nvb_reader_impl::revision() const { return convert_endianness( header_.binaryFormatRevision, endianness() ); }
CGprofile nvb_reader_impl::profile() const { return (CGprofile) convert_endianness( (unsigned int) header_.profile, endianness() ); }