bool Framebuffer::detach(const GLenum attachment) { FramebufferAttachment * attachmentObject = getAttachment(attachment); if (!attachmentObject) { return false; } if (attachmentObject->isTextureAttachment()) { AttachedTexture * textureAttachment = attachmentObject->asTextureAttachment(); if (textureAttachment->hasLayer()) { implementation().attachTextureLayer(this, attachment, nullptr, textureAttachment->level(), textureAttachment->layer()); } else { implementation().attachTexture(this, attachment, nullptr, textureAttachment->level()); } } else if (attachmentObject->isRenderBufferAttachment()) { implementation().attachRenderBuffer(this, attachment, nullptr); } m_attachments.erase(attachment); return true; }
void WebGLFramebuffer::attach(GLenum target, GLenum attachment, GLenum attachmentPoint) { ASSERT(isBound(target)); WebGLAttachment* attachmentObject = getAttachment(attachment); if (attachmentObject) attachmentObject->attach(context()->webContext(), target, attachmentPoint); }
void WebGLFramebuffer::drawBuffersIfNecessary(bool force) { if (context()->isWebGL2OrHigher() || context()->extensionEnabled(WebGLDrawBuffersName)) { bool reset = force; // This filtering works around graphics driver bugs on Mac OS X. for (size_t i = 0; i < m_drawBuffers.size(); ++i) { if (m_drawBuffers[i] != GL_NONE && getAttachment(m_drawBuffers[i])) { if (m_filteredDrawBuffers[i] != m_drawBuffers[i]) { m_filteredDrawBuffers[i] = m_drawBuffers[i]; reset = true; } } else { if (m_filteredDrawBuffers[i] != GL_NONE) { m_filteredDrawBuffers[i] = GL_NONE; reset = true; } } } if (reset) { context()->contextGL()->DrawBuffersEXT( m_filteredDrawBuffers.size(), m_filteredDrawBuffers.data()); } } }
WebGLSharedObject* WebGLFramebuffer::getAttachmentObject(GLenum attachment) const { if (!m_object) return nullptr; WebGLAttachment* attachmentObject = getAttachment(attachment); return attachmentObject ? attachmentObject->object() : nullptr; }
void WebGLFramebuffer::removeAttachmentFromBoundFramebuffer(GLenum attachment) { ASSERT(isBound()); if (!object()) return; WebGLAttachment* attachmentObject = getAttachment(attachment); if (attachmentObject) { attachmentObject->onDetached(context()->webContext()); m_attachments.remove(attachment); drawBuffersIfNecessary(false); switch (attachment) { case GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL: attach(GL_DEPTH_ATTACHMENT, GL_DEPTH_ATTACHMENT); attach(GL_STENCIL_ATTACHMENT, GL_STENCIL_ATTACHMENT); break; case GL_DEPTH_ATTACHMENT: attach(GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL, GL_DEPTH_ATTACHMENT); break; case GL_STENCIL_ATTACHMENT: attach(GC3D_DEPTH_STENCIL_ATTACHMENT_WEBGL, GL_STENCIL_ATTACHMENT); break; } } }
GLenum WebGLFramebuffer::colorBufferFormat() const { if (!m_object) return 0; WebGLAttachment* attachment = getAttachment(GL_COLOR_ATTACHMENT0); if (!attachment) return 0; return attachment->format(); }
GC3Denum WebGLFramebuffer::getColorBufferFormat() const { if (!object()) return 0; WebGLAttachment* attachment = getAttachment(GraphicsContext3D::COLOR_ATTACHMENT0); if (!attachment) return 0; return attachment->getFormat(); }
void BaseSkeleton::setAttachment (const string &slotName, const string &attachmentName) { for (int i = 0, n = slots.size(); i < n; i++) { Slot *slot = slots[i]; if (slot->data->name == slotName) { slot->setAttachment(getAttachment(i, attachmentName)); return; } } throw invalid_argument("Slot not found: " + slotName); }
bool WebGLFramebuffer::getReadBufferFormatAndType(GLenum* format, GLenum* type) const { if (m_readBuffer == GL_NONE) return false; WebGLAttachment* image = getAttachment(m_readBuffer); if (!image) return false; if (format) *format = image->format(); if (type) *type = image->type(); return true; }
void Skin::attachAll(Skeleton& skeleton, const Skin& oldSkin) const { for (auto& e : oldSkin.m_entries) { auto& slot = skeleton.slots[e.slotIndex]; if (slot.getAttachment() == e.attachment) { auto newAttachment = getAttachment(e.slotIndex, e.name.c_str()); if (newAttachment) { slot.setAttachment(newAttachment); } } } }
const FramebufferAttachment *Framebuffer::getDrawBuffer(size_t drawBuffer) const { ASSERT(drawBuffer < mState.mDrawBufferStates.size()); if (mState.mDrawBufferStates[drawBuffer] != GL_NONE) { // ES3 spec: "If the GL is bound to a draw framebuffer object, the ith buffer listed in bufs // must be COLOR_ATTACHMENTi or NONE" ASSERT(mState.mDrawBufferStates[drawBuffer] == GL_COLOR_ATTACHMENT0 + drawBuffer || (drawBuffer == 0 && mState.mDrawBufferStates[drawBuffer] == GL_BACK)); return getAttachment(mState.mDrawBufferStates[drawBuffer]); } else { return nullptr; } }
/** Actually rewind to the specified state. */ void KartRewinder::rewindToState(BareNetworkString *buffer) { // 1) Physics values: transform and velocities // ------------------------------------------- btTransform t; t.setOrigin(buffer->getVec3()); t.setRotation(buffer->getQuat()); btRigidBody *body = getBody(); body->setLinearVelocity(buffer->getVec3()); body->setAngularVelocity(buffer->getVec3()); // This function also reads the velocity, so it must be called // after the velocities are set body->proceedToTransform(t); // Update kart transform in case that there are access to its value // before Moveable::update() is called (which updates the transform) setTrans(t); m_has_started = buffer->getUInt8()!=0; // necessary for startup speed boost m_vehicle->setMinSpeed(buffer->getFloat()); float time_rot = buffer->getFloat(); // Set timed rotation divides by time_rot m_vehicle->setTimedRotation(time_rot, time_rot*buffer->getVec3()); // 2) Steering and other controls // ------------------------------ getControls().rewindTo(buffer); getController()->rewindTo(buffer); // 3) Attachment // ------------- getAttachment()->rewindTo(buffer); // 4) Powerup // ---------- getPowerup()->rewindTo(buffer); // 5) Max speed info // ------------------ m_max_speed->rewindTo(buffer); m_max_speed->update(0); // 6) Skidding // ----------- m_skidding->rewindTo(buffer); return; } // rewindToState
/** Saves all state information for a kart in a memory buffer. The memory * is allocated here and the address returned. It will then be managed * by the RewindManager. The size is used to keep track of memory usage * for rewinding. * \param[out] buffer Address of the memory buffer. * \returns Size of allocated memory, or -1 in case of an error. */ BareNetworkString* KartRewinder::saveState() const { const int MEMSIZE = 17*sizeof(float) + 9+3; BareNetworkString *buffer = new BareNetworkString(MEMSIZE); const btRigidBody *body = getBody(); // 1) Physics values: transform and velocities // ------------------------------------------- const btTransform &t = body->getWorldTransform(); buffer->add(t.getOrigin()); btQuaternion q = t.getRotation(); buffer->add(q); buffer->add(body->getLinearVelocity()); buffer->add(body->getAngularVelocity()); buffer->addUInt8(m_has_started); // necessary for startup speed boost buffer->addFloat(m_vehicle->getMinSpeed()); buffer->addFloat(m_vehicle->getTimedRotationTime()); buffer->add(m_vehicle->getTimedRotation()); // 2) Steering and other player controls // ------------------------------------- getControls().saveState(buffer); getController()->saveState(buffer); // 3) Attachment // ------------- getAttachment()->saveState(buffer); // 4) Powerup // ---------- getPowerup()->saveState(buffer); // 5) Max speed info // ------------------ m_max_speed->saveState(buffer); // 6) Skidding // ----------- m_skidding->saveState(buffer); return buffer; } // saveState
void Framebuffer::invalidateSub(const Caps &caps, GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height) { ASSERT(completeness() == GL_FRAMEBUFFER_COMPLETE); for (GLsizei attachIndex = 0; attachIndex < numAttachments; ++attachIndex) { GLenum attachmentTarget = attachments[attachIndex]; gl::FramebufferAttachment *attachment = (attachmentTarget == GL_DEPTH_STENCIL_ATTACHMENT) ? getDepthOrStencilbuffer() : getAttachment(attachmentTarget); if (attachment) { rx::RenderTarget *renderTarget = rx::GetAttachmentRenderTarget(attachment); if (renderTarget) { renderTarget->invalidate(x, y, width, height); } } } }
void WebGLFramebuffer::drawBuffersIfNecessary(bool force) { if (!context()->m_webglDrawBuffers) return; bool reset = force; // This filtering works around graphics driver bugs on Mac OS X. for (size_t i = 0; i < m_drawBuffers.size(); ++i) { if (m_drawBuffers[i] != GraphicsContext3D::NONE && getAttachment(m_drawBuffers[i])) { if (m_filteredDrawBuffers[i] != m_drawBuffers[i]) { m_filteredDrawBuffers[i] = m_drawBuffers[i]; reset = true; } } else { if (m_filteredDrawBuffers[i] != GraphicsContext3D::NONE) { m_filteredDrawBuffers[i] = GraphicsContext3D::NONE; reset = true; } } } if (reset) { context()->graphicsContext3D()->getExtensions()->drawBuffersEXT( m_filteredDrawBuffers.size(), m_filteredDrawBuffers.data()); } }
Attachment* BaseSkeleton::getAttachment (const string &slotName, const string &attachmentName) { return getAttachment(data->findSlotIndex(slotName), attachmentName); }
Error Framebuffer::invalidateSub(GLsizei numAttachments, const GLenum *attachments, GLint x, GLint y, GLsizei width, GLsizei height) { for (GLsizei attachIndex = 0; attachIndex < numAttachments; ++attachIndex) { GLenum attachmentTarget = attachments[attachIndex]; FramebufferAttachment *attachment = (attachmentTarget == GL_DEPTH_STENCIL_ATTACHMENT) ? getDepthOrStencilbuffer() : getAttachment(attachmentTarget); if (attachment) { rx::RenderTarget *renderTarget = NULL; Error error = rx::GetAttachmentRenderTarget(attachment, &renderTarget); if (error.isError()) { return error; } renderTarget->invalidate(x, y, width, height); } } return Error(GL_NO_ERROR); }