void Mem2Native::push(spMemoryTexture src, spNativeTexture dest) { src->addRef(); dest->addRef(); _messages.send(0, src.get(), dest.get()); //_messages.post(0, src.get(), dest.get()); }
bool operator()(const spNativeTexture& t1, const spNativeTexture& t2) const { if (t1->getFormat() < _tf) return true; if (t1->getWidth() < _w) return true; return t1->getHeight() < _h; }
AnimationFrame::AnimationFrame(spNativeTexture t) { _row = _column = 0; _resAnim = 0; _diffuse.base = t; _diffuse.premultiplied = true; _srcRect = RectF(0, 0, 1, 1); _destRect = RectF(0, 0, (float)t->getWidth(), (float)t->getHeight()); _frameSize = Vector2((float)t->getWidth(), (float)t->getHeight()); }
bool RenderTargetsManager::isGood(const spNativeTexture& t, int w, int h, TextureFormat tf) const { if (!t) return false; if (!t->getHandle()) return false; if (t->getFormat() == tf && t->getWidth() >= w && t->getHeight() >= h && t->getWidth() <= (w + ALIGN_SIZE) && t->getHeight() <= (h + ALIGN_SIZE)) return true; return false; }
void STDRenderer::setTexture(spNativeTexture base, spNativeTexture alpha, bool basePremultiplied) { if (base == 0 || base->getHandle() == 0) base = white; unsigned int shaderFlags = _shaderFlags; if (basePremultiplied) shaderFlags &= ~UberShaderProgram::ALPHA_PREMULTIPLY; else shaderFlags |= UberShaderProgram::ALPHA_PREMULTIPLY; if (alpha) shaderFlags |= UberShaderProgram::SEPARATE_ALPHA; else shaderFlags &= ~UberShaderProgram::SEPARATE_ALPHA; //##ifdef OX_DEBUG #if 0 if (_base != base) { OX_ASSERT(_alpha != alpha); } else { OX_ASSERT(_alpha == alpha); } #endif //OX_DEBUG //no reason to check changed alpha because it is in pair with base if (_base != base || /*_alpha != alpha || */_shaderFlags != shaderFlags) { drawBatch(); } _shaderFlags = shaderFlags; _base = base; _alpha = alpha; }
void pass(spNativeTexture srcTexture, const Rect& srcRect, spNativeTexture destTexture, const Rect& destRect, const Color& color) { IVideoDriver* driver = IVideoDriver::instance; const VertexDeclarationGL* decl = static_cast<const VertexDeclarationGL*>(driver->getVertexDeclaration(vertexPCT2::FORMAT)); driver->setRenderTarget(destTexture); driver->clear(0); driver->setViewport(destRect); driver->setTexture(0, srcTexture); vertexPCT2 v[4]; RectF dst = srcRect.cast<RectF>() / Vector2((float)srcTexture->getWidth(), (float)srcTexture->getHeight()); fillQuadT(v, dst, RectF(-1, -1, 2, 2), AffineTransform::getIdentity(), color.rgba()); driver->draw(IVideoDriver::PT_TRIANGLE_STRIP, decl, v, sizeof(v)); driver->setTexture(0, 0); }
void VideoDriverGLES20::setTexture(int sampler, spNativeTexture t) { oxglActiveTexture(GL_TEXTURE0 + sampler); if (t) glBindTexture(GL_TEXTURE_2D, (GLuint)((size_t)t->getHandle())); else glBindTexture(GL_TEXTURE_2D, 0); CHECKGL(); }
MaskedRenderer::MaskedRenderer(spNativeTexture mask, const RectF &srcRect, const RectF &destRect, const transform &t, bool channelR) :_mask(mask) { _clipUV = ClipUV( t.transform(destRect.getLeftTop()), t.transform(destRect.getRightTop()), t.transform(destRect.getLeftBottom()), srcRect.getLeftTop(), srcRect.getRightTop(), srcRect.getLeftBottom()); _clipMask = srcRect; Vector2 v(1.0f / mask->getWidth(), 1.0f / mask->getHeight()); _clipMask.expand(v, v); _shaderFlags |= UberShaderProgram::MASK; if (channelR) _shaderFlags |= UberShaderProgram::MASK_R_CHANNEL; }
void VideoDriverGL::setRenderTarget(spNativeTexture rt) { if (!rt) { glBindFramebuffer(GL_FRAMEBUFFER, 0); return; } NativeTextureGLES *gl = safeCast<NativeTextureGLES*>(rt.get()); glBindFramebuffer(GL_FRAMEBUFFER, gl->getFboID()); }
static bool cmp(const spNativeTexture& t2, const spNativeTexture& t1) { if (t1->getFormat() > t2->getFormat()) return true; if (t1->getWidth() > t2->getWidth()) return true; return t1->getHeight() > t2->getHeight(); }
void ResAnim::init(spNativeTexture texture, const Point& originalSize, int columns, int rows, float scaleFactor) { _scaleFactor = scaleFactor; if (!texture) return; int frame_width = originalSize.x / columns; int frame_height = originalSize.y / rows; animationFrames frames; int frames_count = rows * columns; frames.reserve(frames_count); Vector2 frameSize((float)frame_width, (float)frame_height); for (int y = 0; y < rows; ++y) { for (int x = 0; x < columns; ++x) { Rect src; src.pos = Point(x * frame_width, y * frame_height); src.size = Point(frame_width, frame_height); float iw = 1.0f / texture->getWidth(); float ih = 1.0f / texture->getHeight(); RectF srcRect(src.pos.x * iw, src.pos.y * ih, src.size.x * iw, src.size.y * ih); RectF destRect(Vector2(0, 0), frameSize * scaleFactor); AnimationFrame frame; Diffuse df; df.base = texture; frame.init(this, df, srcRect, destRect, destRect.size); frames.push_back(frame); } } init(frames, columns, scaleFactor); }
void VideoDriverGL::setRenderTarget(spNativeTexture rt) { if (!rt) { glBindFramebuffer(GL_FRAMEBUFFER, _prevFBO); CHECKGL(); return; } glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_prevFBO); NativeTextureGLES *gl = safeCast<NativeTextureGLES*>(rt.get()); glBindFramebuffer(GL_FRAMEBUFFER, gl->getFboID()); CHECKGL(); }
TextureLine(spNativeTexture t) { setVerticalMode(Box9Sprite::TILING_FULL); setHorizontalMode(Box9Sprite::TILING_FULL); Sprite::setResAnim(DebugActor::resSystem->getResAnim("checker")); AnimationFrame f; Vector2 s = fitSize(itemSize, Vector2((float)t->getWidth(), (float)t->getHeight())); setSize(s); Diffuse df; df.base = t; f.init(0, df, RectF(0, 0, 1.0f, 1.0f), RectF(0, 0, s.x, s.y), s); spSprite image = initActor(new Sprite, arg_blend = blend_disabled, arg_resAnim = f); addChild(image); spColorRectSprite rect = initActor(new ColorRectSprite, arg_color = Color(Color::White, 255), arg_attachTo = this); rect->addTween(Sprite::TweenColor(Color(Color::White, 0)), 4000, -1, true); char path[255]; path::normalize(t->getName().c_str(), path); char txt[255]; safe_sprintf(txt, "%s\n<div c=\"FF0000\">%s</div>-<div c=\"0000ff\">%dx%d</div>\nid: %d", path, textureFormat2String(t->getFormat()), t->getWidth(), t->getHeight(), t->getObjectID()); spTextField text = initActor(new TextField, arg_color = Color::Black, arg_w = (float)itemSize.x, arg_vAlign = TextStyle::VALIGN_TOP, arg_hAlign = TextStyle::HALIGN_LEFT, arg_multiline = true, arg_attachTo = rect, arg_htmlText = txt ); text->setBreakLongWords(true); rect->setSize(text->getTextRect().size.cast<Vector2>() + Vector2(2, 2)); rect->setY((itemSize.y - rect->getHeight()) / 2.0f); }
void load_texture_internal(const std::string &file, spNativeTexture nt, LoadResourcesContext *load_context) { ImageData im; spMemoryTexture mt = new MemoryTexture; LOGD("loading atlas: %s", file.c_str()); file::buffer bf; file::read(file.c_str(), bf); LOGD("atlas file loaded: %s", file.c_str()); mt->init(bf, Renderer::getPremultipliedAlphaRender(), nt->getFormat()); //mt->init(2048, 2048, TF_R8G8B8A8); im = mt->lock(); LOGD("atlas size: %d %d", im.w, im.h); //Object::dumpCreatedObjects(); load_context->createTexture(mt, nt); }
void load_texture_internal(const std::string& file, spNativeTexture nt, bool linearFilter, bool clamp2edge, LoadResourcesContext* load_context) { ImageData im; spMemoryTexture mt = new MemoryTexture; LOGD("loading atlas: %s", file.c_str()); file::buffer bf; file::read(file.c_str(), bf); LOGD("atlas file loaded: %s", file.c_str()); mt->init(bf, true, nt->getFormat()); im = mt->lock(); LOGD("atlas size: %d %d", im.w, im.h); CreateTextureTask opt; opt.src = mt; opt.dest = nt; opt.linearFilter = linearFilter; opt.clamp2edge = clamp2edge; load_context->createTexture(opt); }
spNativeTexture RenderTargetsManager::get(spNativeTexture current, int w, int h, TextureFormat tf) { w = alignTextureSize(w); h = alignTextureSize(h); if (isGood(current, w, h, tf)) { current->setUserData((void*)(size_t)getTimeMS()); return current; } spNativeTexture result; free::iterator it = lower_bound(_free.begin(), _free.end(), result, NTP(w, h, tf)); if (it != _free.end()) { spNativeTexture& t = *it; if (isGood(t, w, h, tf)) { result = t; _free.erase(it); } } if (!result) { //if texture wasn't found create it result = IVideoDriver::instance->createTexture(); result->init(w, h, tf, true); } result->setUserData((void*)(size_t)getTimeMS()); _rts.push_back(result); //print(); return result; }
bool MTLoadingResourcesContext::isNeedProceed(spNativeTexture t) { return t->getHandle() == 0; }
bool SingleThreadResourcesContext::isNeedProceed(spNativeTexture t) { return t->getHandle() == 0; }
void RestoreResourcesContext::createTexture(spMemoryTexture src, spNativeTexture dest) { dest->init(src->lock(), false); }
bool isNeedProceed(spNativeTexture t) { return t->getHandle() == 0; }