Пример #1
0
void CodeView::setFileLine(const QString& file, int line)
{
    if (file != m_sourceFile) {
        readSourceFile(file);
    }

    m_currentSourceLine = line;

    if (m_mode == Sourcefile) {
        setLine(line);
    }
}
void initCL()
{
	cl_int status;

	cl_uint num_platforms;
	status = clGetPlatformIDs(1, &platform, &num_platforms);

	status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
	if (status != CL_SUCCESS) std::cout << "Error: could not query devices" << std::endl;
	num_devices = 1; // always only using one device

	char info[256];
	clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(info), info, NULL);
	deviceInfo = info;

	context = clCreateContext(0, num_devices, &device, NULL, NULL, &status);
	if (status != CL_SUCCESS) std::cout << "Error: could not create OpenCL context" << std::endl;

	queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE, &status);
	if (status != CL_SUCCESS) std::cout << "Error: could not create command queue" << std::endl;

	char *source_str = readSourceFile(source_file);

	program = clCreateProgramWithSource(context, 1, (const char **) &source_str, NULL, &status);

	status = clBuildProgram(program, num_devices, &device, "", NULL, NULL);
	if (status != CL_SUCCESS) std::cout << "Error: could not build program" << std::endl;

	kernel = clCreateKernel(program, "sobel", &status);
	if (status != CL_SUCCESS) std::cout << "Error: could not create sobel kernel" << std::endl;

	in_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, sizeof(unsigned int) * rows * cols, NULL, &status);
	if (status != CL_SUCCESS) std::cout << "Error: could not create device buffer" << std::endl;

	out_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, sizeof(unsigned int) * rows * cols, NULL, &status);
	if (status != CL_SUCCESS) std::cout << "Error: could not create output buffer" << std::endl;

	int pixels = cols * rows;

	status  = clSetKernelArg(kernel, 0, sizeof(cl_mem), &in_buffer);
	status |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &out_buffer);
	status |= clSetKernelArg(kernel, 2, sizeof(int), &pixels);
	if (status != CL_SUCCESS) std::cout << "Error: could not set sobel args" << std::endl;
}
Пример #3
0
QString compileSource(const QString &source)
{
    {
        QFile tempSourceFile("__tmp__.glsl");
        if (!tempSourceFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
            qDebug() << "Failed opening __tmp__.glsl";
            exit(0);
        }

        QTextStream out(&tempSourceFile);
        out << source;
    }

    if (std::system("cgc -quiet -oglsl -profile arbfp1 __tmp__.glsl >__tmp__.frag") == -1) {
        qDebug() << "Failed running cgc";
        exit(0);
    }

    return readSourceFile("__tmp__.frag", true);
}
Пример #4
0
QList<QStringPair> readConf(const QString &confFile)
{
    QFile file(confFile);

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qDebug() << "Missing file" << confFile;
        exit(0);
    }

    QList<QStringPair> result;

    QTextStream in(&file);
    while (!in.atEnd()) {
        QString line = in.readLine();

        if (line.startsWith('#'))
            continue;

        QTextStream lineStream(&line);

        QString enumerator;
        QString sourceFile;

        lineStream >> enumerator;

        if (lineStream.atEnd()) {
            qDebug() << "Error in file" << confFile << '(' << enumerator << ')';
            exit(0);
        }

        lineStream >> sourceFile;

        result << QStringPair(enumerator, readSourceFile(sourceFile));
    }

    return result;
}
Пример #5
0
void CodeView::reload()
{
    int currentLine = getCurrentLine();
    readSourceFile(m_sourceFile);
    setLine(currentLine);
}
Пример #6
0
void CodeView::initDefaultSourceFile(const QString& filename)
{
    m_sourceFile = filename;
    readSourceFile(m_sourceFile);
    toggleSourceFile();
}