explicit ivec4(const ivec2& v1, const ivec2& v2) { mVec[0] = v1.x(); mVec[1] = v1.y(); mVec[2] = v2.x(); mVec[3] = v2.y(); }
void ClipExample:: resize(ivec2 new_size, ivec2 old_size) { float_orthogonal_projection_params proj_params(0, new_size.x(), new_size.y(), 0); m_layer->simulation_matrix(WRATHLayer::projection_matrix, float4x4(proj_params)); glViewport(0, 0, new_size.x(), new_size.y()); WRATHDefaultRectAttributePacker::Rect::handle rect; rect=WRATHNew WRATHDefaultRectAttributePacker::Rect(new_size.x(), new_size.y()); rect->m_brush_stretch=vec2(m_images[0]->size())/vec2(new_size); m_background_widget->set_parameters(rect); rect->m_brush_stretch=vec2(m_images[1]->size())/vec2(new_size); m_background_widget2->set_parameters(rect); for(unsigned int i=0, endi=m_widgets.size(); i<endi; ++i) { vec2 pos; pos=m_widgets[i]->position(); pos.x()*=static_cast<float>(new_size.x())/static_cast<float>(old_size.x()); pos.y()*=static_cast<float>(new_size.y())/static_cast<float>(old_size.y()); m_widgets[i]->position(pos); } }
void WRATHTextureFontFreeType_Coverage::glyph_mipmap_level:: create_pixel_data(ivec2 sz) { m_pixels.resize( sz.x()*sz.y(), 0); m_size=sz; for(int yy=0; yy<m_raw_size.y() and yy<sz.y(); ++yy) { for(int xx=0; xx<m_raw_size.x() and xx<sz.x(); ++xx) { int location, loctionbitmap; uint8_t v; location= xx + yy*sz.x(); loctionbitmap=xx + (m_raw_size.y()-1-yy)*m_raw_pitch; WRATHassert(loctionbitmap<static_cast<int>(m_raw_pixels_from_freetype.size())); v=m_raw_pixels_from_freetype[loctionbitmap]; m_pixels[location]=v; } } }
void ewol::compositing::Sprite::printSprite(const ivec2& _spriteID, const vec3& _size) { if( _spriteID.x()<0 || _spriteID.y()<0 || _spriteID.x() >= m_nbSprite.x() || _spriteID.y() >= m_nbSprite.y()) { return; } printPart(vec2(_size.x(),_size.y()), vec2((float)(_spriteID.x() )*m_unitarySpriteSize.x(), (float)(_spriteID.y() )*m_unitarySpriteSize.y()), vec2((float)(_spriteID.x()+1)*m_unitarySpriteSize.x(), (float)(_spriteID.y()+1)*m_unitarySpriteSize.y())); }
ivec2 gx::atlas_renderer::next_offset(const ivec2 & offset, const ivec2 & atlas_size, gl::size_t tile_size) const { // Advance in the x direction. ivec2 new_offset(offset.x() + tile_size, offset.y()); // If needed, go down to a new row. if ((new_offset.x() + tile_size) > atlas_size.x()) { new_offset.set_x(0); new_offset.set_y(offset.y() + tile_size); } return new_offset; }
explicit ivec4(const ivec2& v, GLint z, GLint w) { mVec[0] = v.x(); mVec[1] = v.y(); mVec[2] = z; mVec[3] = w; }
ai::distance_t ai::path::heuristic_distance_from(const ivec2 & cell) const { const icoord_t dx = std::abs(goal_.x() - cell.x()); const icoord_t dy = std::abs(goal_.y() - cell.y()); return (boost::math::constants::root_two<distance_t>() - 2.0f) * std::min(dx, dy) + dx + dy; }
void WRATHTextureFontFreeType_Coverage:: on_create_texture_page(ivec2 texture_size, std::vector<float> &custom_data) { custom_data.resize(2); custom_data[0]=1.0f/static_cast<float>(std::max(1, texture_size.x()) ); custom_data[1]=1.0f/static_cast<float>(std::max(1, texture_size.y()) ); }
void esvg::Document::generateAnImage(ivec2 _size, draw::Image& _output) { generateAnImage(_size.x(), _size.y()); _output.resize(_size); draw::Color tmpp(0,0,0,0); _output.setFillColor(tmpp); _output.clear(); if(NULL != m_renderedElement) { uint8_t* pointerOnData = m_renderedElement->getDataPointer(); int32_t sizeData = m_renderedElement->getDataSize(); uint8_t* tmpOut = (uint8_t*)_output.getTextureDataPointer(); memcpy(tmpOut, pointerOnData, sizeData); } }
gx::sprite::sprite(const std::string & name, const std::string & suffix, ivec2 size) : name_(name), suffix_(suffix), size_(size) { // Useful temporaries. const gl::float_t w = static_cast<gl::float_t>(size.x()) / 2.0f; const gl::float_t h = static_cast<gl::float_t>(size.y()) / 2.0f; // The vertices of this sprite. vertices_[0][0] = -w; vertices_[0][1] = -h; // Top left. vertices_[1][0] = -w; vertices_[1][1] = +h; // Bottom left. vertices_[2][0] = +w; vertices_[2][1] = +h; // Bottom right. vertices_[3][0] = +w; vertices_[3][1] = -h; // Top right. }
///////////////////////////////////////////// // fastuidraw::detail::CurvePairGenerator methods fastuidraw::detail::CurvePairGenerator:: CurvePairGenerator(FT_Outline outline, ivec2 bitmap_sz, ivec2 bitmap_offset, GlyphRenderDataCurvePair &output) { geometry_data_filter::handle filter; filter = FASTUIDRAWnew MakeEvenFilter(); geometry_data gmt(NULL, m_pts, filter); /* usually we set the inflate factor to be 4, from that: - we want all end points of curves to be even integers - some points in the outline from FreeType are given implicitely as an _average_ or 2 points However, we generate quadratics from cubics which generates end points with a divide by _64_. But that is an insane inflate factor that will likely cause overflows. So, we ignore the unlikely possibility that a generated end point from breaking up cubics into quadratics would lie on a texel boundary. */ int outline_scale_factor(4), bias(-1); CoordinateConverter coordinate_converter(outline_scale_factor, bitmap_sz, bitmap_offset, bias); CollapsingContourEmitter *contour_emitter; TaggedOutlineData *outline_data; float curvature_collapse(0.05f); contour_emitter = FASTUIDRAWnew CollapsingContourEmitter(curvature_collapse, outline, coordinate_converter); outline_data = FASTUIDRAWnew TaggedOutlineData(contour_emitter, gmt); m_contour_emitter = contour_emitter; m_outline_data = outline_data; if(bitmap_sz.x() != 0 && bitmap_sz.y() != 0) { output.resize_active_curve_pair(bitmap_sz + ivec2(1, 1)); } else { output.resize_active_curve_pair(ivec2(0, 0)); } }
inline float dot(const ivec2& v1, const ivec2& v2) { return (float)(v1.x()*v2.x() + v1.y()*v2.y()); }
void gl::set_viewport(ivec2 size, ivec2 offset) { glViewport(offset.ux(), offset.uy(), size.x(), size.y()); }
void egami::ImageMono::set(const ivec2& _pos, const uint8_t& _newColor) { if( _pos.x()>=0 && _pos.x()<m_size.x() && _pos.y()>=0 && _pos.y()<m_size.y()) { m_data[_pos.x()+_pos.y()*m_size.x()] = _newColor; } }
bool operator==(ivec2 const& u1, ivec2 const& u2) { return u1.x()==u2.x() && u1.y()==u2.y(); }
/** * @brief add a compleate of the image to display with the requested size * @param[in] _size size of the output image */ void print(const ivec2& _size) { print(vec2(_size.x(),_size.y())); };
void ewol::resource::Texture::setImageSize(ivec2 _newSize) { std11::unique_lock<std11::recursive_mutex> lock(m_mutex); _newSize.setValue( nextP2(_newSize.x()), nextP2(_newSize.y()) ); m_data.resize(_newSize); }
/*!\fn height Returns the height of the glyph, equivalent to m_size.y() */ int height(void) const { return m_size.y(); }
std::string to_string(ivec2 const& u) { return std::to_string(u.x())+","+std::to_string(u.y()); }
inline ivec2 max(const ivec2& a, const ivec2& b) { return ivec2( a.x() > b.x() ? a.x() : b.x(), a.y() > b.y() ? a.y() : b.y()); }
enum return_code WRATHShapeGPUDistanceFieldCreator::ScratchPadFBO:: init_and_bind_fbo(ivec2 pdims, bool) { int max_dim(WRATHglGet<int>(GL_MAX_TEXTURE_SIZE)); if(pdims.x()>max_dim or pdims.y()>max_dim or pdims.x()<=0 or pdims.y()<=0) { return routine_fail; } if(pdims.x()>m_max_dim.x() or pdims.y()>m_max_dim.y()) { //delete old fbo and image stff: gl_resource_deleter R; R.m_fbo=0; //setting this as 0 makes it so that R does not delete the FBO. R.m_texture=m_texture; R.m_depth=m_depth; R.m_stencil=m_stencil; R.m_depth_is_renderbuffer=m_depth_is_renderbuffer; R(); m_max_dim=pdims; //and create a new one: if(m_fbo==0) { glGenFramebuffers(1, &m_fbo); if(m_fbo==0) { /* epiccally bad, cannot make an fbo, we fake it by reading/drawing to/from the screen! */ WRATHwarning("Cannot create FBO: GL implementation out of spec, faking via drawing to screen"); m_current_dim=pdims; glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); glViewport(0, 0, m_current_dim.x(), m_current_dim.y()); return routine_success; } } glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); #ifdef FBO_COLOR_USE_RENDERBUFFER { glGenRenderbuffers(1, &m_texture); WRATHassert(m_texture!=0); glBindRenderbuffer(GL_RENDERBUFFER, m_texture); glRenderbufferStorage(GL_RENDERBUFFER, m_format, m_max_dim.x(), m_max_dim.y()); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_texture); } #else { glGenTextures(1, &m_texture); WRATHassert(m_texture!=0); glBindTexture(GL_TEXTURE_2D, m_texture); 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_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //TODO: under GL3 if m_format is an integer format //then the 7'th argument should also reflect that, //for example GL_RGB8I --> GL_RGB_INTEGER, etc. glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_max_dim.x(), m_max_dim.y(), 0, m_format, GL_UNSIGNED_BYTE, NULL); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture, 0); } #endif /* TODO: for GLES2, if depth_stencil texture is supported, then use that */ #if defined(WRATH_GLES_VERSION) && WRATH_GLES_VERSION==2 { m_depth_is_renderbuffer=true; m_depth=0; glGenRenderbuffers(1, &m_stencil); WRATHassert(m_stencil!=0); glBindRenderbuffer(GL_RENDERBUFFER, m_stencil); glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, m_max_dim.x(), m_max_dim.y()); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_stencil); } #else { m_depth_is_renderbuffer=false; m_stencil=0; glGenTextures(1, &m_depth); WRATHassert(m_depth!=0); glBindTexture(GL_TEXTURE_2D, m_depth); 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_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_max_dim.x(), m_max_dim.y(), 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_depth, 0); } #endif } #if defined(WRATH_GLES_VERSION) && WRATH_GLES_VERSION==2 { if(m_depth==0) { glGenRenderbuffers(1, &m_depth); WRATHassert(m_depth!=0); glBindRenderbuffer(GL_RENDERBUFFER, m_depth); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_max_dim.x(), m_max_dim.y()); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depth); } } #endif m_current_dim=pdims; glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); glViewport(0, 0, m_current_dim.x(), m_current_dim.y()); return routine_success; }
inline ivec2 min(const ivec2& a, const ivec2& b) { return ivec2( a.x() < b.x() ? a.x() : b.x(), a.y() < b.y() ? a.y() : b.y()); }
unsigned gx::atlas_renderer::tile_count_for_possible_size(const ivec2 & size, gl::size_t tile_size) const { return (size.x() / tile_size) * (size.y() / tile_size); }
inline ivec2 min(const ivec2& a, int b) { return ivec2( a.x() < b ? a.x() : b, a.y() < b ? a.y() : b); }
ememory::SharedPtr<ewol::resource::TextureFile> ewol::resource::TextureFile::create(const std::string& _filename, ivec2 _size, ivec2 _sizeRegister) { EWOL_VERBOSE("KEEP: TextureFile: '" << _filename << "' size=" << _size << " sizeRegister=" << _sizeRegister); if (_filename == "") { ememory::SharedPtr<ewol::resource::TextureFile> object(new ewol::resource::TextureFile()); if (object == nullptr) { EWOL_ERROR("allocation error of a resource : ??TEX??"); return nullptr; } object->init(); getManager().localAdd(object); return object; } if (_size.x() == 0) { _size.setX(-1); //EWOL_ERROR("Error Request the image size.x() =0 ???"); } if (_size.y() == 0) { _size.setY(-1); //EWOL_ERROR("Error Request the image size.y() =0 ???"); } std::string tmpFilename = _filename; if (etk::end_with(_filename, ".svg") == false) { _size = ewol::resource::TextureFile::sizeAuto; } if (_size.x()>0 && _size.y()>0) { EWOL_VERBOSE(" == > specific size : " << _size); #if defined(__TARGET_OS__Android) \ || defined(__TARGET_OS__MacOs) \ || defined(__TARGET_OS__IOs) _size.setValue(nextP2(_size.x()), nextP2(_size.y())); #endif if (_sizeRegister != ewol::resource::TextureFile::sizeAuto) { if (_sizeRegister != ewol::resource::TextureFile::sizeDefault) { tmpFilename += ":"; tmpFilename += etk::to_string(_size.x()); tmpFilename += "x"; tmpFilename += etk::to_string(_size.y()); } } } EWOL_VERBOSE("KEEP: TextureFile: '" << tmpFilename << "' new size=" << _size); ememory::SharedPtr<ewol::resource::TextureFile> object = nullptr; ememory::SharedPtr<gale::Resource> object2 = getManager().localKeep(tmpFilename); if (object2 != nullptr) { object = ememory::dynamicPointerCast<ewol::resource::TextureFile>(object2); if (object == nullptr) { EWOL_CRITICAL("Request resource file : '" << tmpFilename << "' With the wrong type (dynamic cast error)"); return nullptr; } } if (object != nullptr) { return object; } EWOL_INFO("CREATE: TextureFile: '" << tmpFilename << "' size=" << _size); // need to crate a new one ... object = ememory::SharedPtr<ewol::resource::TextureFile>(new ewol::resource::TextureFile()); if (object == nullptr) { EWOL_ERROR("allocation error of a resource : " << _filename); return nullptr; } object->init(tmpFilename, _filename, _size); getManager().localAdd(object); return object; }
inline ivec2 max(const ivec2& a, int b) { return ivec2( a.x() > b ? a.x() : b, a.y() > b ? a.y() : b); }
float norm(ivec2 const& v) { return std::sqrt(v.x()*v.x()+v.y()*v.y()); }