Esempio n. 1
0
		void
		Compress(const std::vector<T>& data, BufferT& out)
		{
			ssize_t countBS = sizeof(T)*data.size();
			out.resize(snappy::MaxCompressedLength(countBS));
			size_t output_length=0;
			snappy::RawCompress(reinterpret_cast<const char*>(&data[0]),
								countBS,
								&out[0],
								&output_length);
			out.resize(output_length);
		}
SCERROR SCREEN_TFont::Print(int x, int y, pwide_t text)
{
  Gfx3DDevice* gfx = SCREEN::Get3DDevice();
  if ( !gfx ) fail_because(SCREEN_IS_NOT_INITIALIZED_OR_3D_UNSUPPORTED);
  gfx->Ortho2D();
  //gfx->Translate(x,SCREEN::GetHeight()-font_->GetTextHeight()-y);
  gfx->SetState(GFX3D_STATE_MINMAGFILTER,GFX3D_NEAREST);
  gfx->SetState(GFX3D_STATE_ENVMODE,GFX3D_TEXTURE_MODULATE);
  gfx->SetState(GFX3D_STATE_BLENDING,GFX3D_DISABLE);
  gfx->SetState(GFX3D_STATE_ALPHA_TEST,GFX3D_DISABLE);
  gfx->SetState(GFX3D_STATE_DEPTH_FUNC,GFX3D_ALWAYS);
//  u16_t indices[] = {0,1,2,2,3,0};
  u16_t indices[] = {0,1,2,2,3,0};
  mrgba_t color = mRGBA_t(255,255,255,255);
  font_->FillSymbols(symbols_,text);
  float screen_height = (float)SCREEN::WndHeight();
  for ( unsigned i = 0; i < symbols_.Count(); ++i ) {
    gfx->SetTexture(font_->GetSymbolTexture(symbols_[i].symbol));
    VxB_VERTEX vertices[4];
    font_->FillQuad(vertices,symbols_[i].symbol,symbols_[i].x + x,screen_height - symbols_[i].y - y);
    vertices[0].color = color;
    vertices[1].color = color;
    vertices[2].color = color;
    vertices[3].color = color;
    gfx->DrawIndexedPrimitive(GFX3D_TRILIST,vertices,4,indices,6,GFX3D_VxB_VCT);
  }
  return SCE_OK;
}
Esempio n. 3
0
		void
		Compress(const std::vector<T>& data, BufferT& out)
		{
			ssize_t countBS = sizeof(T)*data.size();

			// allocate as much memory as we need
			int maxOut = LZ4_compressBound(countBS);
			out.resize(maxOut);

			int r = LZ4_compress((const char*)&data.front(), (char*)&out.front(), countBS);
			if(r == 0) {
				Util::fire_exception("lz4 compression failed");
			}

			// trim to really used size
			out.resize(r);
		}
Esempio n. 4
0
		void
		Compress(const std::vector<T>& data, BufferT& out)
		{
			ssize_t countBS = sizeof(T)*data.size();
			lzo_uint outLen=(countBS + countBS / 16 + 64 + 3);   // from simple.c in LZO distrib

			// allocate as much memory as we need
			out.resize(outLen);

			int32_t r = lzo1x_999_compress(
				reinterpret_cast<const lzo_bytep>(&data.front()),
				countBS,
				&out.front(),
				&outLen,
				&lzoTemp[0]);
			if (r != LZO_E_OK) {
				Util::fire_exception("lzo compression failed");
			}

			// trim to really used size
			out.resize(outLen);
		}
void
WebGLContext::BufferDataT(GLenum target,
                          const BufferT& data,
                          GLenum usage)
{
    if (IsContextLost())
        return;

    if (!ValidateBufferTarget(target, "bufferData"))
        return;

    const WebGLRefPtr<WebGLBuffer>& bufferSlot = GetBufferSlotByTarget(target);

    data.ComputeLengthAndData();

    // Careful: data.Length() could conceivably be any uint32_t, but GLsizeiptr
    // is like intptr_t.
    if (!CheckedInt<GLsizeiptr>(data.Length()).isValid())
        return ErrorOutOfMemory("bufferData: bad size");

    if (!ValidateBufferUsageEnum(usage, "bufferData: usage"))
        return;

    WebGLBuffer* boundBuffer = bufferSlot.get();

    if (!boundBuffer)
        return ErrorInvalidOperation("bufferData: no buffer bound!");

    MakeContextCurrent();
    InvalidateBufferFetching();

    GLenum error = CheckedBufferData(target, data.Length(), data.Data(), usage);

    if (error) {
        GenerateWarning("bufferData generated error %s", ErrorName(error));
        return;
    }

    boundBuffer->SetByteLength(data.Length());
    if (!boundBuffer->ElementArrayCacheBufferData(data.Data(), data.Length()))
        return ErrorOutOfMemory("bufferData: out of memory");
}
void
WebGLContext::BufferSubDataT(GLenum target,
                             WebGLsizeiptr byteOffset,
                             const BufferT& data)
{
    if (IsContextLost())
        return;

    if (!ValidateBufferTarget(target, "bufferSubData"))
        return;

    WebGLRefPtr<WebGLBuffer>& bufferSlot = GetBufferSlotByTarget(target);

    if (byteOffset < 0)
        return ErrorInvalidValue("bufferSubData: negative offset");

    WebGLBuffer* boundBuffer = bufferSlot.get();
    if (!boundBuffer)
        return ErrorInvalidOperation("bufferData: no buffer bound!");

    data.ComputeLengthAndData();

    CheckedInt<WebGLsizeiptr> checked_neededByteLength =
        CheckedInt<WebGLsizeiptr>(byteOffset) + data.Length();

    if (!checked_neededByteLength.isValid()) {
        ErrorInvalidValue("bufferSubData: Integer overflow computing the needed"
                          " byte length.");
        return;
    }

    if (checked_neededByteLength.value() > boundBuffer->ByteLength()) {
        ErrorInvalidValue("bufferSubData: Not enough data. Operation requires"
                          " %d bytes, but buffer only has %d bytes.",
                          checked_neededByteLength.value(),
                          boundBuffer->ByteLength());
        return;
    }

    boundBuffer->ElementArrayCacheBufferSubData(byteOffset, data.Data(),
                                                data.Length());

    MakeContextCurrent();
    gl->fBufferSubData(target, byteOffset, data.Length(), data.Data());
}
void
WebGL2Context::GetBufferSubDataT(GLenum target, GLintptr offset, const BufferT& data)
{
    if (IsContextLost())
        return;

    // For the WebGLBuffer bound to the passed target, read
    // returnedData.byteLength bytes from the buffer starting at byte
    // offset offset and write them to returnedData.

    // If zero is bound to target, an INVALID_OPERATION error is
    // generated.
    if (!ValidateBufferTarget(target, "getBufferSubData"))
        return;

    // If offset is less than zero, an INVALID_VALUE error is
    // generated.
    if (offset < 0)
        return ErrorInvalidValue("getBufferSubData: negative offset");

    WebGLRefPtr<WebGLBuffer>& bufferSlot = GetBufferSlotByTarget(target);
    WebGLBuffer* boundBuffer = bufferSlot.get();
    if (!boundBuffer)
        return ErrorInvalidOperation("getBufferSubData: no buffer bound");

    // If offset + returnedData.byteLength would extend beyond the end
    // of the buffer an INVALID_VALUE error is generated.
    data.ComputeLengthAndData();

    CheckedInt<WebGLsizeiptr> neededByteLength = CheckedInt<WebGLsizeiptr>(offset) + data.LengthAllowShared();
    if (!neededByteLength.isValid()) {
        ErrorInvalidValue("getBufferSubData: Integer overflow computing the needed"
                          " byte length.");
        return;
    }

    if (neededByteLength.value() > boundBuffer->ByteLength()) {
        ErrorInvalidValue("getBufferSubData: Not enough data. Operation requires"
                          " %d bytes, but buffer only has %d bytes.",
                          neededByteLength.value(), boundBuffer->ByteLength());
        return;
    }

    // If target is TRANSFORM_FEEDBACK_BUFFER, and any transform
    // feedback object is currently active, an INVALID_OPERATION error
    // is generated.
    WebGLTransformFeedback* currentTF = mBoundTransformFeedback;
    if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER && currentTF) {
        if (currentTF->mIsActive)
            return ErrorInvalidOperation("getBufferSubData: Currently bound transform"
                                         " feedback is active");

        // https://github.com/NVIDIA/WebGL/commit/63aff5e58c1d79825a596f0f4aa46174b9a5f72c
        // Performing reads and writes on a buffer that is currently
        // bound for transform feedback causes undefined results in
        // GLES3.0 and OpenGL 4.5. In practice results of reads and
        // writes might be consistent as long as transform feedback
        // objects are not active, but neither GLES3.0 nor OpenGL 4.5
        // spec guarantees this - just being bound for transform
        // feedback is sufficient to cause undefined results.

        BindTransformFeedback(LOCAL_GL_TRANSFORM_FEEDBACK, nullptr);
    }

    /* If the buffer is written and read sequentially by other
     * operations and getBufferSubData, it is the responsibility of
     * the WebGL API to ensure that data are access
     * consistently. This applies even if the buffer is currently
     * bound to a transform feedback binding point.
     */

    void* ptr = gl->fMapBufferRange(target, offset, data.LengthAllowShared(), LOCAL_GL_MAP_READ_BIT);
    // Warning: Possibly shared memory.  See bug 1225033.
    memcpy(data.DataAllowShared(), ptr, data.LengthAllowShared());
    gl->fUnmapBuffer(target);

    if (target == LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER && currentTF) {
        BindTransformFeedback(LOCAL_GL_TRANSFORM_FEEDBACK, currentTF);
    }
}
 bool end(const BufferT& dataBuffer)
 {
   return this->end(dataBuffer.data(), dataBuffer.size());
 }
 bool end(const BufferT& dataBuffer, const header_block& trailers = {})
 {
   return this->end(dataBuffer.data(), dataBuffer.size(), trailers);
 }
Esempio n. 10
0
	void handle_write(const BufferT &buffer, HandlerT &handler)
	{
		handler(std::error_code(), buffer.size());
	}
Esempio n. 11
0
		BufferT(const BufferT& rhs) throw() : m_length(0), m_capacity(0)
		{
			append(rhs, rhs.size());
		}