Esempio n. 1
0
void ShaderProgram::setUniform(const std::string& name, const Vector4& v) const
{
	checkInUse();
	s32 loc{getUniformLocation(name)};
	if (loc == -1)
		return;
	glUniform4fv(loc, 1, &v.data[0]);
}
Esempio n. 2
0
void ShaderProgram::setUniform(const std::string& name, const Matrix4& m) const
{
	checkInUse();
	s32 loc{getUniformLocation(name)};
	if (loc == -1)
		return;
	glUniformMatrix4fv(loc, 1, false, &m.data[0].data[0]);
}
Esempio n. 3
0
void ShaderProgram::setUniform(const std::string& name, f32 x, f32 y) const
{
	checkInUse();
	s32 loc{getUniformLocation(name)};
	if (loc == -1)
		return;
	glUniform2f(loc, x, y);
}
Esempio n. 4
0
void ShaderProgram::setUniform(const std::string& name, bool x) const
{
	checkInUse();
	s32 loc{getUniformLocation(name)};
	if (loc == -1)
		return;
	glUniform1i(loc, (s32)x);
}
Esempio n. 5
0
void ShaderProgram::setUniform(const String& name, const Quaternion& q) const
{
	checkInUse();
	s32 loc = getUniformLocation(name);
	if (loc == -1)
		return;
	glUniform4fv(loc, 1, &q.x);
}
Esempio n. 6
0
void ShaderProgram::setUniform(const String& name, const Vector3& v) const
{
	checkInUse();
	s32 loc = getUniformLocation(name);
	if (loc == -1)
		return;
	glUniform3fv(loc, 1, &v[0]);
}
Esempio n. 7
0
void ShaderProgram::setUniform(const String& name, const Matrix4& m) const
{
	checkInUse();
	s32 loc = getUniformLocation(name);
	if (loc == -1)
		return;
	glUniformMatrix4fv(loc, 1, false, &m[0][0]);
}
Esempio n. 8
0
void ShaderProgram::setUniform(const String& name, f32 x, f32 y, f32 z) const
{
	checkInUse();
	s32 loc = getUniformLocation(name);
	if (loc == -1)
		return;
	glUniform3f(loc, x, y, z);
}
Esempio n. 9
0
void ShaderProgram::setUniform(const String& name, s32 x) const
{
	checkInUse();
	s32 loc = getUniformLocation(name);
	if (loc == -1)
		return;
	glUniform1i(loc, x);
}
Esempio n. 10
0
GLuint
Program::getSubroutineIndex(GLenum shader, const char* name) const
//[]----------------------------------------------------[]
//|  Get subroutine index                                |
//[]----------------------------------------------------[]
{
  checkInUse();

  GLuint index = glGetSubroutineIndex(handle, shader, name);

  if (index == GL_INVALID_INDEX)
    error(SUBROUTINE_NOT_FOUND, getName(), name);
  return index;
}
Esempio n. 11
0
GLint
Program::getUniformLocation(const char* name) const
//[]----------------------------------------------------[]
//|  Get uniform variable location                       |
//[]----------------------------------------------------[]
{
  checkInUse();

  GLint loc = glGetUniformLocation(handle, name);

  if (loc == -1)
    error(VARIABLE_NOT_FOUND, getName(), name);
  return loc;
}
Esempio n. 12
0
GLint
Program::getAttributeLocation(const char* name) const
//[]----------------------------------------------------[]
//|  Get attribute location                              |
//[]----------------------------------------------------[]
{
  checkInUse();

  GLint loc = glGetAttribLocation(handle, name);

  if (loc == -1)
    error(VARIABLE_NOT_FOUND, getName(), name);
  return loc;
}
Esempio n. 13
0
void ShaderProgram::setUniform(const String& name, const Transform& t) const
{
	checkInUse();
	{
		s32 loc = getUniformLocation(name + ".position");
		if (loc == -1)
			return;
		glUniform3fv(loc, 1, &t.position[0]);
	}
	{
		s32 loc = getUniformLocation(name + ".orientation");
		if (loc == -1)
			return;
		glUniform4fv(loc, 1, &t.orientation.x);
	}
	{
		s32 loc = getUniformLocation(name + ".scale");
		if (loc == -1)
			return;
		glUniform3fv(loc, 1, &t.scale[0]);
	}
}
Esempio n. 14
0
static bool updateDeviceList(deviceList *devList)
{
    usbDeviceList *list = (usbDeviceList*)devList;
    struct libusb_device *dev, **usbList;
    unsigned int pos, count = 0, newCount = 0;
    usbDevice *devPos;
    ssize_t listSize, listPos;

    /* fedora 19 seems to process udev triggers before the device is ready */
    usleep(1000);

    /* initialize usb TODO: should call libusb_exit at the end? */
    libusb_init(NULL);

    /* the next two return counts of busses and devices respectively */
    listSize = libusb_get_device_list(NULL, &usbList);

    /* search for the first device we find */
    for(listPos = 0; listPos < listSize; listPos++)
    {
        struct libusb_device_descriptor descriptor;

        dev = usbList[listPos];
        libusb_get_device_descriptor(dev, &descriptor);

        for(pos = 0; list->ids[pos].idVendor != INVALID_VENDOR; pos++)
            /* continue if we are not examining the correct device */
            if (descriptor.idVendor  == list->ids[pos].idVendor &&
                descriptor.idProduct == list->ids[pos].idProduct)
            {
                int busIndex;

                /* couldn't find the bus index as a number anywhere */
                busIndex = libusb_get_bus_number(dev);

                /* found a device instance, now find position in
                 * current list */
                devPos = (usbDevice*)firstItem(&list->deviceList);
                setError(devPos, NULL, LIBUSB_SUCCESS);
                while(devPos != NULL &&
                      (devPos->busIndex < busIndex ||
                       (devPos->busIndex == busIndex &&
                        devPos->devIndex < libusb_get_device_address(dev))))
                    /* used to release devices here, since they
                     * are no longer used, however, this races
                     * with reinsertion of the device, and
                     * therefore reuse of the ID.  Additionally,
                     * unplugs are detected now, so it is no
                     * longer necessary. */
                    devPos = (usbDevice*)devPos->header.next;

                /* append or insert a new device */
                if (devPos == NULL ||
                    devPos->busIndex != busIndex ||
                    devPos->devIndex != libusb_get_device_address(dev))
                {
                    if (list->describe)
                        checkInUse(dev, true);
                    else if (claimDevice(dev, list->ids + pos, list, devPos))
                        /* count how many devices we added */
                        newCount++;

                    /* keep a count of the number of devices */
                    count++;
                }
            }
    }
    libusb_free_device_list(usbList, 0); /* deref devices */

    if (wouldOutput(LOG_DEBUG) && newCount > 0)
    {
        unsigned int index = 0;

        message(LOG_DEBUG, "Handling %d device(s):\n", count);
        devPos = (usbDevice*)list->deviceList.head;

        for(; devPos; devPos = (usbDevice*)devPos->header.next)
            message(LOG_DEBUG,
                    "  %d) usb:%d.%d id=%d addr=%p\n", index++,
                    devPos->busIndex, devPos->devIndex,
                    devPos->info.id, (void*)devPos);
    }

    return true;
}
Esempio n. 15
0
static bool claimDevice(struct libusb_device *dev, usbId *id, usbDeviceList *list, usbDevice *devPos)
{
    int retval;
    bool success = false;
    usbDevice *newDev = NULL;

    newDev = (usbDevice*)malloc(sizeof(usbDevice));
    memset(newDev, 0, sizeof(usbDevice));

    /* basic stuff */
    newDev->info.type = *id;
    newDev->busIndex = libusb_get_bus_number(dev);
    newDev->devIndex = libusb_get_device_address(dev);

    /* determine the id (reusing if possible) */
    newDev->info.id = 0;
    while(true)
    {
        unsigned int prev = newDev->info.id;
        forEach(&list->deviceList,
                findId, &newDev->info.id);
        if (prev == newDev->info.id)
            break;
    }

    /* open a handle to the usb device */
    if ((retval = libusb_open(dev, &newDev->device)) != LIBUSB_SUCCESS)
        setError(newDev, "Failed to open usb device", retval);
    else
    {
        /* prime errno to control this loop */
        errno = 0;
        do
        {
            /* try to force an unbind but only once */
            if (errno == EBUSY && (! list->force || ! checkInUse(dev, false)))
                break;

            /* try to configure device and claim the interface */
            if ((retval = libusb_set_configuration(newDev->device, 1)) < 0)
                setError(newDev, "Failed to set device configuration", retval);
            else if ((retval = libusb_claim_interface(newDev->device, 0)) < 0)
                setError(newDev, "libusb_claim_interface failed 0", retval);
            else
            {
                insertItem(&list->deviceList,
                           (itemHeader*)devPos,
                           (itemHeader*)newDev);

                if (list->newDev != NULL)
                    list->newDev(&newDev->info);

                success = true;
                break;
            }
        }
        while(errno == EBUSY);
    }
    
    /* grab error if there was one */
    if (!success)
    {
        printError(LOG_ERROR, "  updateDeviceList failed", &newDev->info);
        if (errno == EBUSY)
            message(LOG_ERROR,
                    "Check device status with igdaemon --devices\n");

        if (newDev->device != NULL)
            libusb_close(newDev->device);
        free(newDev);
    }
    return success;
}