/* ======================== idJointBuffer::FreeBufferObject ======================== */ void idJointBuffer::FreeBufferObject() { if ( IsMapped() ) { UnmapBuffer(); } // if this is a sub-allocation inside a larger buffer, don't actually free anything. if ( OwnsBuffer() == false ) { ClearWithoutFreeing(); return; } if ( apiObject == NULL ) { return; } if ( r_showBuffers.GetBool() ) { idLib::Printf( "joint buffer free %p, api %p (%i joints)\n", this, GetAPIObject(), GetNumJoints() ); } GLuint buffer = reinterpret_cast< GLuint > ( apiObject ); qglBindBufferARB( GL_UNIFORM_BUFFER, 0 ); qglDeleteBuffersARB( 1, & buffer ); ClearWithoutFreeing(); }
void GrGLBuffer::onUnmap() { SkASSERT(fBufferID); VALIDATE(); SkASSERT(this->isMapped()); if (0 == fBufferID) { fMapPtr = nullptr; return; } // bind buffer handles the dirty context switch (this->glCaps().mapBufferType()) { case GrGLCaps::kNone_MapBufferType: SkDEBUGFAIL("Shouldn't get here."); return; case GrGLCaps::kMapBuffer_MapBufferType: // fall through case GrGLCaps::kMapBufferRange_MapBufferType: { GrGLenum target = this->glGpu()->bindBuffer(fIntendedType, this); GL_CALL(UnmapBuffer(target)); break; } case GrGLCaps::kChromium_MapBufferType: this->glGpu()->bindBuffer(fIntendedType, this); // TODO: Is this needed? GL_CALL(UnmapBufferSubData(fMapPtr)); break; } fMapPtr = nullptr; }
void UGraphicsDevice::UpdateBuffer(BufferPtr inBuffer, const void* inData, size_t inDataSize) { assert(inData); void* buf = MapBuffer(inBuffer); memcpy(buf, inData, inDataSize); UnmapBuffer(inBuffer); }
bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard) { if (start == 0 && count == indexCount_) return SetData(data); if (!data) { LOGERROR("Null pointer for index buffer data"); return false; } if (!indexSize_) { LOGERROR("Index size not defined, can not set index buffer data"); return false; } if (start + count > indexCount_) { LOGERROR("Illegal range for setting new index buffer data"); return false; } if (!count) return true; if (shadowData_ && shadowData_.Get() + start * indexSize_ != data) memcpy(shadowData_.Get() + start * indexSize_, data, count * indexSize_); if (object_) { if (dynamic_) { void* hwData = MapBuffer(start, count, discard); if (hwData) { memcpy(hwData, data, count * indexSize_); UnmapBuffer(); } else return false; } else { D3D11_BOX destBox; destBox.left = start * indexSize_; destBox.right = destBox.left + count * indexSize_; destBox.top = 0; destBox.bottom = 1; destBox.front = 0; destBox.back = 1; graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_, 0, &destBox, data, 0, 0); } } return true; }
void GrGLIndexBuffer::unlock() { GrAssert(fBufferID); GrAssert(isLocked()); GrAssert(this->getGpu()->getCaps().fBufferLockSupport); this->bind(); GL_CALL(UnmapBuffer(GR_GL_ELEMENT_ARRAY_BUFFER)); fLockPtr = NULL; }
void GrGLBufferImpl::unlock(GrGpuGL* gpu) { VALIDATE(); SkASSERT(this->isLocked()); if (0 != fDesc.fID) { SkASSERT(gpu->caps()->bufferLockSupport()); this->bind(gpu); GL_CALL(gpu, UnmapBuffer(fBufferType)); } fLockPtr = NULL; }
void GrGLVertexBuffer::unlock() { GrAssert(fBufferID); GrAssert(isLocked()); GrAssert(GPUGL->supportsBufferLocking()); this->bind(); GR_GL(UnmapBuffer(GR_GL_ARRAY_BUFFER)); fLockPtr = NULL; }
bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count, bool discard) { if (start == 0 && count == vertexCount_) return SetData(data); if (!data) { URHO3D_LOGERROR("Null pointer for vertex buffer data"); return false; } if (!vertexSize_) { URHO3D_LOGERROR("Vertex elements not defined, can not set vertex buffer data"); return false; } if (start + count > vertexCount_) { URHO3D_LOGERROR("Illegal range for setting new vertex buffer data"); return false; } if (!count) return true; if (shadowData_ && shadowData_.Get() + start * vertexSize_ != data) memcpy(shadowData_.Get() + start * vertexSize_, data, count * vertexSize_); if (object_) { if (graphics_->IsDeviceLost()) { URHO3D_LOGWARNING("Vertex buffer data assignment while device is lost"); dataPending_ = true; return true; } void* hwData = MapBuffer(start, count, discard); if (hwData) { memcpy(hwData, data, count * vertexSize_); UnmapBuffer(); } else return false; } return true; }
bool IndexBuffer::SetData(const void* data) { if (!data) { LOGERROR("Null pointer for index buffer data"); return false; } if (!indexSize_) { LOGERROR("Index size not defined, can not set index buffer data"); return false; } if (shadowData_ && data != shadowData_.Get()) memcpy(shadowData_.Get(), data, indexCount_ * indexSize_); if (object_) { if (dynamic_) { void* hwData = MapBuffer(0, indexCount_, true); if (hwData) { memcpy(hwData, data, indexCount_ * indexSize_); UnmapBuffer(); } else return false; } else { D3D11_BOX destBox; destBox.left = 0; destBox.right = indexCount_ * indexSize_; destBox.top = 0; destBox.bottom = 1; destBox.front = 0; destBox.back = 1; graphics_->GetImpl()->GetDeviceContext()->UpdateSubresource((ID3D11Buffer*)object_, 0, &destBox, data, 0, 0); } } return true; }
void OgreSimBuffer::SetOgreVertexBuffer(Ogre::HardwareVertexBufferSharedPtr ogreVertexBuffer) { bool wasMapped = false; if(mOgreVertexBuffer != ogreVertexBuffer) { if(mMapped) { wasMapped = true; UnmapBuffer(); } } mOgreVertexBuffer = ogreVertexBuffer; mAllocedSize = mOgreVertexBuffer->getSizeInBytes(); mSize = mAllocedSize; if(wasMapped) MapBuffer(); }
void GrGLBufferImpl::unmap(GrGpuGL* gpu) { VALIDATE(); SkASSERT(this->isMapped()); if (0 != fDesc.fID) { switch (gpu->glCaps().mapBufferType()) { case GrGLCaps::kNone_MapBufferType: SkDEBUGFAIL("Shouldn't get here."); return; case GrGLCaps::kMapBuffer_MapBufferType: // fall through case GrGLCaps::kMapBufferRange_MapBufferType: this->bind(gpu); GL_CALL(gpu, UnmapBuffer(fBufferType)); break; case GrGLCaps::kChromium_MapBufferType: this->bind(gpu); GR_GL_CALL(gpu->glInterface(), UnmapBufferSubData(fMapPtr)); break; } } fMapPtr = NULL; }
bool VertexBuffer::SetData(const void* data) { if (!data) { URHO3D_LOGERROR("Null pointer for vertex buffer data"); return false; } if (!vertexSize_) { URHO3D_LOGERROR("Vertex elements not defined, can not set vertex buffer data"); return false; } if (shadowData_ && data != shadowData_.Get()) memcpy(shadowData_.Get(), data, vertexCount_ * vertexSize_); if (object_) { if (graphics_->IsDeviceLost()) { URHO3D_LOGWARNING("Vertex buffer data assignment while device is lost"); dataPending_ = true; return true; } void* hwData = MapBuffer(0, vertexCount_, true); if (hwData) { memcpy(hwData, data, vertexCount_ * vertexSize_); UnmapBuffer(); } else return false; } dataLost_ = false; return true; }
void IndexBuffer::Unlock() { switch (lockState_) { case LOCK_HARDWARE: UnmapBuffer(); break; case LOCK_SHADOW: SetDataRange(shadowData_.Get() + lockStart_ * indexSize_, lockStart_, lockCount_); lockState_ = LOCK_NONE; break; case LOCK_SCRATCH: SetDataRange(lockScratchData_, lockStart_, lockCount_); if (graphics_) graphics_->FreeScratchBuffer(lockScratchData_); lockScratchData_ = 0; lockState_ = LOCK_NONE; break; } }
bool IndexBuffer::SetData(const void* data) { if (!data) { ATOMIC_LOGERROR("Null pointer for index buffer data"); return false; } if (!indexSize_) { ATOMIC_LOGERROR("Index size not defined, can not set index buffer data"); return false; } if (shadowData_ && data != shadowData_.Get()) memcpy(shadowData_.Get(), data, indexCount_ * indexSize_); if (object_.ptr_) { if (graphics_->IsDeviceLost()) { ATOMIC_LOGWARNING("Index buffer data assignment while device is lost"); dataPending_ = true; return true; } void* hwData = MapBuffer(0, indexCount_, true); if (hwData) { memcpy(hwData, data, indexCount_ * indexSize_); UnmapBuffer(); } else return false; } dataLost_ = false; return true; }
/* ======================== idIndexBuffer::FreeBufferObject ======================== */ void idIndexBuffer::FreeBufferObject() { if ( IsMapped() ) { UnmapBuffer(); } // if this is a sub-allocation inside a larger buffer, don't actually free anything. if ( OwnsBuffer() == false ) { ClearWithoutFreeing(); return; } if ( apiObject == NULL ) { return; } if ( r_showBuffers.GetBool() ) { idLib::Printf( "index buffer free %p, api %p (%i bytes)\n", this, GetAPIObject(), GetSize() ); } GLuint bufferObject = reinterpret_cast< GLuint >( apiObject ); qglDeleteBuffersARB( 1, & bufferObject ); ClearWithoutFreeing(); }
void D3D11RenderData::UnmapVertexBuffer() { UnmapBuffer(m_pVertexBuffer); }
void D3D11RenderData::UnmapIndexBuffer() { UnmapBuffer(m_pIndexBuffer); }
void D3D11GeometryBuffer::UnmapIndexBuffer() { UnmapBuffer(m_pIndexBuffer); }
void D3D11GeometryBuffer::UnmapVertexBuffer() { UnmapBuffer(m_pVertexBuffer); }
AutoBufferUploadBase::~AutoBufferUploadBase() { if (mBuffer) { UnmapBuffer(); } }
/******************************************************************************* * * Buffer functions. * ******************************************************************************/ int rb_create_buffer (struct rb_context* ctxt, const struct rb_buffer_desc* public_desc, const void* init_data, struct rb_buffer** out_buffer) { const struct rb_ogl3_buffer_desc private_desc = { .size = public_desc->size, .target = public_to_private_rb_target(public_desc->target), .usage = public_desc->usage }; return rb_ogl3_create_buffer(ctxt, &private_desc,init_data, out_buffer); } int rb_buffer_ref_get(struct rb_buffer* buffer) { if(!buffer) return -1; ref_get(&buffer->ref); return 0; } int rb_buffer_ref_put(struct rb_buffer* buffer) { if(!buffer) return -1; ref_put(&buffer->ref, release_buffer); return 0; } int rb_bind_buffer (struct rb_context* ctxt, struct rb_buffer* buffer, enum rb_buffer_target target) { return rb_ogl3_bind_buffer(ctxt, buffer, public_to_private_rb_target(target)); } int rb_buffer_data (struct rb_buffer* buffer, int offset, int size, const void* data) { void* mapped_mem = NULL; GLboolean unmap = GL_FALSE; if(!buffer || (offset < 0) || (size < 0) || (size != 0 && !data) || (buffer->size < offset + size)) return -1; if(size == 0) return 0; OGL(BindBuffer(buffer->target, buffer->name)); if(offset == 0 && size == buffer->size) { mapped_mem = OGL(MapBuffer(buffer->target, GL_WRITE_ONLY)); } else { const GLbitfield access = GL_MAP_WRITE_BIT; mapped_mem = OGL(MapBufferRange(buffer->target, offset, size, access)); } ASSERT(mapped_mem != NULL); memcpy(mapped_mem, data, (size_t)size); unmap = OGL(UnmapBuffer(buffer->target)); OGL(BindBuffer (buffer->target, buffer->ctxt->state_cache.buffer_binding[buffer->binding])); /* unmap == GL_FALSE must be handled by the application. TODO return a real * error code to differentiate this case from the error. */ return unmap == GL_TRUE ? 0 : -1; }