int NativeBufferObject::insert(NativeBufferObject* sourceBuffer, int offset, int sourceOffset, int sourceLength)
{
    if (offset >= internalData_.size() || offset < 0)
    {
        throw NativeException(QString(Native::Msg::Out_of_bounds).toStdString());
    }
    int bytesWritten = 0;
    const QByteArray& sourceData = sourceBuffer->internalData_;
    if (sourceOffset == -1 && sourceLength == -1)
    {
        bytesWritten = sourceData.size();
        internalData_.insert(offset, sourceData);
    }
    else
    {
        /*
         * Validate the source buffer's sourceOffset and sourceLength.
         * - Checked sourceOffset and sourceLength to be valid
         * - Checked sourceOffset not to be above the buffer size
         * - Checked sourceLength to be in range [sourceOffset, sourcebuffer.size()]
         */
        if (sourceLength < 0 || sourceOffset < 0 || (sourceOffset >= sourceData.size()) ||
                (sourceData.size() - sourceOffset) < sourceLength)
        {
            throw NativeException(QString(Native::Msg::Out_of_bounds).toStdString());
        }
        bytesWritten = sourceLength;
        internalData_.insert(offset, sourceData.mid(sourceOffset, sourceLength));
    }

    return bytesWritten;
}
NativeBufferObject* NativeBufferObject::clone(TiObject* tiObject, int sourceOffset, int sourceLength)
{
    NativeBufferObject* cloneBuffer = NULL;
    if (sourceOffset == -1 && sourceLength == -1)
    {
        cloneBuffer = new NativeBufferObject(tiObject);
        cloneBuffer->internalData_ = QByteArray(internalData_);
    }
    else
    {
        /*
         * Validate the source buffer's sourceOffset and sourceLength.
         * - Checked sourceOffset and sourceLength to be valid
         * - Checked sourceOffset not to be above the buffer size
         * - Checked sourceLength to be in range [sourceOffset, sourcebuffer.size()]
         */
        if (sourceLength < 0 || sourceOffset < 0 || (sourceOffset >= internalData_.size()) ||
                (internalData_.size() - sourceOffset) < sourceLength)
        {
            throw NativeException(QString(Native::Msg::Out_of_bounds).toStdString());
        }
        cloneBuffer = new NativeBufferObject(tiObject);
        cloneBuffer->internalData_ = QByteArray(internalData_.mid(sourceOffset, sourceLength));
    }
    return cloneBuffer;
}
Beispiel #3
0
void NativeApplication::Initialize(float vertOffset, float rotStep)
{
	if (rotStep > 10.0f)
		throw NativeException("too big rotation step!");

	rotStep *= 2.0f * 3.14159265359f / 360.0f;
	AppInit(vertOffset, rotStep);
	GenerateVertexData();
}
int NativeBufferObject::copy(NativeBufferObject* sourceBuffer, int offset, int sourceOffset, int sourceLength)
{
    if (offset >= internalData_.size() || offset < 0)
    {
        throw NativeException(QString(Native::Msg::Out_of_bounds).toStdString());
    }
    int bytesWritten = 0;
    const QByteArray& sourceData = sourceBuffer->internalData_;
    int sourceSize = 0, leftSize = 0;
    leftSize = internalData_.size() - offset;
    if (sourceOffset == -1 && sourceLength == -1)
    {
        sourceSize = sourceData.size();
    }
    else
    {
        /*
         * Validate the source buffer's sourceOffset and sourceLength.
         * - Checked sourceOffset and sourceLength to be valid
         * - Checked sourceOffset not to be above the buffer size
         * - Checked sourceLength to be in range [sourceOffset, sourcebuffer.size()]
         */
        if (sourceLength < 0 || sourceOffset < 0 || (sourceOffset >= sourceData.size()) ||
                (sourceData.size() - sourceOffset) < sourceLength)
        {
            throw NativeException(QString(Native::Msg::Out_of_bounds).toStdString());
        }
        sourceSize = sourceLength;
    }

    bytesWritten = (leftSize < sourceSize) ? leftSize : sourceSize;

    // Do not expand the original buffer if there is not enough room for data from sourceBuffer
    internalData_.replace(offset, bytesWritten, sourceData.mid(sourceOffset == -1 ? 0 : sourceOffset, bytesWritten));

    return bytesWritten;
}
Beispiel #5
0
void NativeApplication::OpenGLInit(HWND wnd, HDC deviceContext, HGLRC renderingContext)
{
	// GL thread class had loaded dummy context
	if (!gl.LoadOpenGLES2Functions())
		throw NativeException("OpenGLES2 function loading failed");

	hwnd = wnd;
	m_deviceContext = deviceContext;
	m_renderingContext = renderingContext;
	if (!ContextUtil::DestroyDummyAndCreateRealContext(gl, hwnd, &m_deviceContext, &m_renderingContext))
		return;

	std::vector<GLuint> shaderList;
	try
	{
		shaderList.push_back(ShaderUtil::LoadAndCompileShader(GL_VERTEX_SHADER, "..\\NativeApp\\shaders\\LocalTransform.vert"));
		shaderList.push_back(ShaderUtil::LoadAndCompileShader(GL_FRAGMENT_SHADER, "..\\NativeApp\\shaders\\StandardColors.frag"));
		theProgram = ShaderUtil::CreateProgram(shaderList);
	}
	catch(NativeException&) { throw; }

	offsetUniform = glGetUniformLocation(theProgram, "offset");
	modelMatrixUnif = glGetUniformLocation(theProgram, "modelMatrix");
	perspectiveMatrixUnif = glGetUniformLocation(theProgram, "perspectiveMatrix");

	CalculatePerspectiveMatrix();

	glUseProgram(theProgram);
	glUniformMatrix4fv(perspectiveMatrixUnif, 1, GL_FALSE, perspectiveMatrix);
	glUseProgram(0);

	InitializeVertexBuffer();

	// VAO is necessary when using core profile, unless code is run using NVidia card. At least, that's how I understood this obscure subject.
	// see https://www.opengl.org/discussion_boards/showthread.php/181092-Drawing-a-single-point-without-VAO-on-NVIDIA-and-AMD
	gl.glGenVertexArrays(1, &vao);
	gl.glBindVertexArray(vao);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject);

	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);
}
void NativeBufferObject::fill(char fillByte, int offset, int length)
{
    if (offset == -1 && length == -1)
    {
        // Fills the entire byte array
        internalData_.fill(fillByte);
    }
    else
    {
        /*
         * Do not allow buffer to grow.
         * - Checked offset and length to be valid
         * - Checked offset not to be above the buffer size
         * - Checked length to be in range [offset, buffer.size()]
         */
        if (length < 0 || offset < 0 || (offset >= internalData_.size()) ||
                (internalData_.size() - offset) < length)
        {
            throw NativeException(QString(Native::Msg::Out_of_bounds).toStdString());
        }
        QByteArray newArray(length, fillByte);
        internalData_.replace(offset, length, newArray);
    }
}