示例#1
0
void WebSocketClient::onMessageReceived(const QByteArray &data)
{
	QDataStream ds(data);
	quint8 cmd;
	ds >> cmd;

	switch (cmd) {
	case GET_TRACK:
	{
		quint32 length;
		ds >> length;
		Q_ASSERT(1 + sizeof(length) + length == size_t(data.length()));
		QByteArray nameData(data.constData() + 1 + sizeof(length), length);
		requestTrack(QString::fromUtf8(nameData));
	}
	break;

	case SET_ROW:
	{
		quint32 row;
		ds >> row;
		emit rowChanged(row);
	}
	break;
	}
}
QVariant SimpleFSModel::data(const QModelIndex& index, int role) const
{
    if (!index.isValid())
        return QVariant();

    const NodeInfo* nodeInfo = static_cast<NodeInfo*>(index.internalPointer());
    const QFileInfo& fileInfo = nodeInfo->fileInfo;
    Q_ASSERT(nodeInfo != 0);

    switch (index.column())
    {
    case NameColumn:
        return nameData(fileInfo, role);
    default:
        return QVariant();
    }
}
示例#3
0
bool SFNTNameTable::ReadU16NameFromU16Record(const NameRecord *aNameRecord,
                                             mozilla::u16string &aU16Name) {
  uint32_t offset = aNameRecord->offset;
  uint32_t length = aNameRecord->length;
  if (mStringDataLength < offset + length) {
    gfxWarning() << "Name data too short to contain name string.";
    return false;
  }

  const uint8_t *startOfName = mStringData + offset;
  size_t actualLength = length / sizeof(char16_t);
  UniquePtr<char16_t[]> nameData(new char16_t[actualLength]);
  NativeEndian::copyAndSwapFromBigEndian(nameData.get(), startOfName,
                                         actualLength);

  aU16Name.assign(nameData.get(), actualLength);
  return true;
}
// virtual
QVariant CQTaskMethodParametersDM::data(const QModelIndex & index, int role) const
{
  CCopasiParameter * pNode = nodeFromIndex(index);

  if (pNode == NULL) return QVariant();

  switch (index.column())
    {
      case COL_NAME:
        return nameData(pNode, role);
        break;

      case COL_VALUE:
        return valueData(pNode, role);
        break;

      case COL_TYPE:
        return typeData(pNode, role);
        break;
    }

  return QVariant();
}
示例#5
0
void PrintContext::outputLinkedDestinations(SkCanvas* canvas, const IntRect& pageRect)
{
    if (!m_linkedDestinationsValid) {
        // Collect anchors in the top-level frame only because our PrintContext
        // supports only one namespace for the anchors.
        collectLinkedDestinations(frame()->document());
        m_linkedDestinationsValid = true;
    }

    for (const auto& entry : m_linkedDestinations) {
        LayoutObject* layoutObject = entry.value->layoutObject();
        if (!layoutObject || !layoutObject->frameView())
            continue;
        IntRect boundingBox = layoutObject->absoluteBoundingBoxRect();
        boundingBox = layoutObject->frameView()->convertToContainingWindow(boundingBox);
        if (!pageRect.intersects(boundingBox))
            continue;
        IntPoint point = boundingBox.minXMinYCorner();
        point.clampNegativeToZero();
        SkAutoDataUnref nameData(SkData::NewWithCString(entry.key.utf8().data()));
        SkAnnotateNamedDestination(canvas, SkPoint::Make(point.x(), point.y()), nameData);
    }
}
示例#6
0
Shader::Shader(const std::string &vshaderFilename, const std::string &fshaderFilename){
    std::string vshaderCode = readFile(vshaderFilename);
    std::string fshaderCode = readFile(fshaderFilename);
    
    if (vshaderCode == "ERR" || vshaderCode == "ERR"){
        std::cout << "One or both of the shader files didn't load." << std::endl;
        return;
    }
    
    std::cout << "Read code for " << vshaderFilename << " and " << fshaderFilename << "." << std::endl;
    
    vshaderID = glCreateShader(GL_VERTEX_SHADER);
    fshaderID = glCreateShader(GL_FRAGMENT_SHADER);
    
    std::cout << "Read code for " << vshaderFilename << " and " << fshaderFilename << "." << std::endl;
    
    compileShader(vshaderID, vshaderCode, vshaderFilename);
    compileShader(fshaderID, fshaderCode, fshaderFilename);
    
    std::cout << "Linking program." << std::endl;
    
    programID = glCreateProgram();
    glAttachShader(programID, vshaderID);
    glAttachShader(programID, fshaderID);
    glLinkProgram(programID);
    
    
    //check for linking errors
    GLint compileStatus = GL_FALSE;
    GLint infoLogLength;
    
    glGetProgramiv(programID, GL_LINK_STATUS, &compileStatus);
    glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &infoLogLength);
    std::vector<char> linkErrorMessage( std::max(infoLogLength, int(1)) );
    glGetProgramInfoLog(programID, infoLogLength, NULL, &linkErrorMessage[0]);
    std::cout << &linkErrorMessage[0] << std::endl;
    
    GLint numUniforms = 0;
    glGetProgramInterfaceiv(programID, GL_UNIFORM, GL_ACTIVE_RESOURCES, &numUniforms);
    
    std::vector<GLchar> nameData(256);
    for(GLint i=0; i<numUniforms; i++)
    {
        //Get name length.
        GLenum thingToGet = GL_NAME_LENGTH;
        GLint nameLength;
        glGetProgramResourceiv(programID, GL_UNIFORM, i, 1, &thingToGet, 1, NULL, &nameLength);
        
        //Read name into vector.
        nameData.resize(nameLength); //The length of the name.
        glGetProgramResourceName(programID, GL_UNIFORM, i, nameData.size(), NULL, &nameData[0]);
        
        //Put vector into string, add it to map.
        std::string name((char*)&nameData[0], nameData.size() - 1);
        GLint uniformID = glGetUniformLocation(programID, name.c_str());
        
        std::cout << "Found uniform named " << name << " at ID " << uniformID << "." << std::endl;
        programUniformIDs[name] = uniformID;
    }
    
    
    std::cout << "Done with " << vshaderFilename << " and " << fshaderFilename << "." << std::endl << std::endl;
}
示例#7
0
DatIndexReader::ReadResult DatIndexReader::read(uint p_amount)
{
    ReadResult result = RR_Failure;

    for (uint i = 0; i < p_amount; i++) {
        ssize_t bytesRead;

        // First read all categories, one at a time
        if (m_index.numCategories() < m_header.numCategories) {
            // Read fixed-width fields
            DatIndexCategoryFields fields;
            bytesRead = m_file.Read(&fields, sizeof(fields));
            if (bytesRead < sizeof(fields)) { result = RR_CorruptFile; goto READ_FAILED; }
            // Read name
            Array<char> nameData(fields.nameLength);
            bytesRead = m_file.Read(nameData.GetPointer(), nameData.GetSize());
            if (bytesRead < (ssize_t)nameData.GetSize()) { result = RR_CorruptFile; goto READ_FAILED; }
            // Add category
            auto name     = wxString::FromUTF8Unchecked(nameData.GetPointer(), nameData.GetSize());
            auto category = m_index.addIndexCategory(name, false);
            // Set parent
            if (fields.parent != DatIndex_RootCategory) {
                auto parent = m_index.category(fields.parent);
                if (parent) { parent->addSubCategory(category); }
            }
        }

        // If all categories are read, start reading the files instead (note the 'else')
        else if (m_index.numEntries() < m_header.numEntries) {
            // Read fixed-width fields
            DatIndexEntryFields fields;
            bytesRead = m_file.Read(&fields, sizeof(fields));
            if (bytesRead < sizeof(fields)) { result = RR_CorruptFile; goto READ_FAILED; }
            // Read name
            Array<char> nameData(fields.nameLength);
            bytesRead = m_file.Read(nameData.GetPointer(), nameData.GetSize());
            if (bytesRead < (ssize_t)nameData.GetSize()) { result = RR_CorruptFile; goto READ_FAILED; }
            // Add entry
            auto name      = wxString::FromUTF8Unchecked(nameData.GetPointer(), nameData.GetSize());
            auto& newEntry = m_index.addIndexEntry(false)
                ->setBaseId(fields.baseId)
                .setFileId(fields.fileId)
                .setMftEntry(fields.mftEntry)
                .setFileType((ANetFileType)fields.fileType)
                .setName(name);
            auto category = m_index.category(fields.category);
            if (!category) { result = RR_CorruptFile; goto READ_FAILED; }
            category->addEntry(&newEntry);
            newEntry.finalizeAdd();
        }

        // If both are done we can skip this loop
        else {
            break;
        }
    }

    return RR_Success;

READ_FAILED:
    return result;
}
示例#8
0
bool Shader::LoadFromFile(const char *pathVertex, const char *pathFragment)
{
	mVertexShaderObj = glCreateShader(GL_VERTEX_SHADER);
	mFragmentShaderObj = glCreateShader(GL_FRAGMENT_SHADER);

	mProgram = glCreateProgram();

	std::ifstream fileVer;
	std::ifstream fileFrag;

	fileVer.open(pathVertex);
	if (fileVer.is_open())
	{
		std::string buffer;

		while (fileVer.good())
		{
			std::getline(fileVer, buffer);
			mVertexSource.append(buffer + "\n");

		}

		fileVer.close();
	}
	else
	{
		std::cout << "Cannot open shader file: " << pathVertex << std::endl;
		return false;
	}

	fileFrag.open(pathFragment);
	if (fileFrag.is_open())
	{
		std::string buffer;

		while (fileFrag.good())
		{
			getline(fileFrag, buffer);
			mFragmentSource.append(buffer + "\n");
		}

		fileFrag.close();
	}
	else
	{
		std::cout << "Cannot open shader file: " << pathFragment << std::endl;
		return false;
	}

	const char *vP = mVertexSource.c_str();
	const char *vF = mFragmentSource.c_str();

	glShaderSource(mVertexShaderObj, 1, &vP, NULL);
	glShaderSource(mFragmentShaderObj, 1, &vF, NULL);

	//assert(mVertexShaderObj != 4);

	glCompileShader(mVertexShaderObj);

	GLint Result;
	GLint InfoLogLength;

	glGetShaderiv(mVertexShaderObj, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(mVertexShaderObj, GL_INFO_LOG_LENGTH, &InfoLogLength);
	std::vector<char> VertexShaderErrorMessage(InfoLogLength);
	glGetShaderInfoLog(mVertexShaderObj, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
	fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

	glCompileShader(mFragmentShaderObj);
	glGetShaderiv(mFragmentShaderObj, GL_COMPILE_STATUS, &Result);
	glGetShaderiv(mFragmentShaderObj, GL_INFO_LOG_LENGTH, &InfoLogLength);
	VertexShaderErrorMessage = std::vector<char>(InfoLogLength);
	glGetShaderInfoLog(mFragmentShaderObj, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
	fprintf(stdout, "%s\n", &VertexShaderErrorMessage[0]);

	glAttachShader(mProgram, mVertexShaderObj);
	glAttachShader(mProgram, mFragmentShaderObj);

	glLinkProgram(mProgram);

	glDeleteShader(mVertexShaderObj);
	glDeleteShader(mFragmentShaderObj);

	GLint numActiveAttribs = 0;
	GLint numActiveUniforms = 0;
	glGetProgramiv(mProgram, GL_ACTIVE_ATTRIBUTES, &numActiveAttribs);
	glGetProgramiv(mProgram, GL_ACTIVE_UNIFORMS, &numActiveUniforms);

	std::vector<GLchar> nameData(256);
	for (int unif = 0; unif < numActiveUniforms; ++unif)
	{
		GLint arraySize = 0;
		GLenum type = 0;
		GLsizei actualLength = 0;
		glGetActiveUniform(mProgram, unif, nameData.size(), &actualLength, &arraySize, &type, &nameData[0]);
		std::string name((char*) &nameData[0], actualLength);
		uniforms.insert(std::pair<std::string, GLuint>(name, glGetUniformLocation(mProgram, name.c_str())));
	}

	return true;
}