bool JMP3::update() { if (!init_done) { return false; } #ifdef MP3_SUPPORT int retry = 8;//FIXME:magic number JMP3_update_start: if (!m_paused) { if (sceMp3CheckStreamDataNeeded(m_mp3Handle) > 0) { fillBuffers(); } short* tempBuffer; int numDecoded = 0; while (true) { numDecoded = sceMp3Decode(m_mp3Handle, &tempBuffer); if (numDecoded > 0) break; int ret = sceMp3CheckStreamDataNeeded(m_mp3Handle); if (ret <= 0) break; fillBuffers(); } // Okay, let's see if we can't get something outputted :/ if (numDecoded == 0 || ((unsigned)numDecoded == 0x80671402)) { if (retry-- > 0){ //give me a recovery chance after suspend/resume... sceKernelDelayThread(1); goto JMP3_update_start; } sceMp3ResetPlayPosition(m_mp3Handle); if (!m_loop) m_paused = true; m_samplesPlayed = 0; } else { if (m_channel < 0 || m_lastDecoded != numDecoded) { if (m_channel >= 0) sceAudioSRCChRelease(); m_channel = sceAudioSRCChReserve(numDecoded / (2 * m_numChannels), m_samplingRate, m_numChannels); } // Output m_samplesPlayed += sceAudioSRCOutputBlocking(m_volume, tempBuffer); m_playTime = (m_samplingRate > 0) ? (m_samplesPlayed / (m_samplingRate/1000)) : 0; m_lastDecoded = numDecoded; } } #endif return true; }
void DrawableTerrain::initGL() { m_vao_constraints.create(); CE(); m_vbo_constraints.create(); CE(); m_ibo_constraints.create(); CE(); m_vao_constraints.bind(); CE(); m_vbo_constraints.bind(); CE(); m_vbo_constraints.setUsagePattern(QOpenGLBuffer::UsagePattern::StaticDraw); CE(); m_ibo_constraints.bind(); CE(); m_ibo_constraints.setUsagePattern(QOpenGLBuffer::UsagePattern::StaticDraw); CE(); QOpenGLFunctions * f = QOpenGLContext::currentContext()->functions(); f->glEnableVertexAttribArray(0); CE(); f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0)); CE(); // Texture coordinate // f->glEnableVertexAttribArray(1); CE(); // const int sz = 3*sizeof(GLfloat); // f->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (void*)(sz)); CE(); m_vao_constraints.release(); CE(); m_vbo_constraints.release(); CE(); m_ibo_constraints.release(); CE(); fillBuffers(); }
void GlCube::initGL() { m_vao_constraints.create(); m_vbo_constraints.create(); m_ibo_constraints.create(); m_vao_constraints.bind(); CE(); m_vbo_constraints.bind(); CE(); m_vbo_constraints.setUsagePattern(QOpenGLBuffer::UsagePattern::StaticDraw); CE(); m_ibo_constraints.bind(); CE(); m_ibo_constraints.setUsagePattern(QOpenGLBuffer::UsagePattern::StaticDraw); CE(); QOpenGLFunctions * f = QOpenGLContext::currentContext()->functions(); GLsizei stride = sizeof(GLfloat) * 7; f->glEnableVertexAttribArray(0); CE(); f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride, (void*)(0)); CE(); f->glEnableVertexAttribArray(1); CE(); f->glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, stride, (void*)(sizeof(GLfloat) * 3)); CE(); m_vao_constraints.release(); CE(); m_vbo_constraints.release(); CE(); m_ibo_constraints.release(); CE(); fillBuffers(); }
/* * void testBuffers(void) * Tests the fillBuffers function. Placing a break point at the top of the while loop allows * the user to ensure that the buffer resets on each iteration and that the math functions change * appropriately (origionally intended for use in classifying sensors) */ void testBuffers(void) { initRangeFinders(); int fBuffer[BUFFER_LN]; int lBuffer[BUFFER_LN]; int rBuffer[BUFFER_LN]; volatile int fMean; volatile int fMed; volatile int rMean; volatile int rMed; volatile int lMean; volatile int lMed; while(1) { fillBuffers(fBuffer, lBuffer, rBuffer); // Place Breakpoint here fMean = mean(fBuffer); fMed = median(fBuffer); lMean = mean(lBuffer); lMed = median(lBuffer); rMean = mean(rBuffer); rMed = median(rBuffer); } }
void GLMesh::update(const std::vector<Eigen::Vector3f>& colors) { fillBuffers(colors); fillPickBuffers(); // bind vbo glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizei)vertices.size() * sizeof(GLVertex), &vertices[0]); // bind pick vbo glBindBuffer(GL_ARRAY_BUFFER, pickVbo); glBufferSubData(GL_ARRAY_BUFFER, 0, (GLsizei)pickVertices.size() * sizeof(GLPickVertex), &pickVertices[0]); }
void GLMesh::setup(const std::vector<Eigen::Vector3f>& colors) { fillBuffers(colors); fillPickBuffers(); // bind vao glGenVertexArrays(1, &vao); glBindVertexArray(vao); // bind vbo glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, (GLsizei)vertices.size() * sizeof(GLVertex), &vertices[0], GL_STATIC_DRAW); // set vertex attribute pointers for vbo data glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (GLvoid*)0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (GLvoid*)offsetof(GLVertex, normal)); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (GLvoid*)offsetof(GLVertex, barycenter)); glEnableVertexAttribArray(3); glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (GLvoid*)offsetof(GLVertex, color)); glEnableVertexAttribArray(4); glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, sizeof(GLVertex), (GLvoid*)offsetof(GLVertex, uv)); // bind pick vao glGenVertexArrays(1, &pickVao); glBindVertexArray(pickVao); // bind pick vbo glGenBuffers(1, &pickVbo); glBindBuffer(GL_ARRAY_BUFFER, pickVbo); glBufferData(GL_ARRAY_BUFFER, (GLsizei)pickVertices.size() * sizeof(GLPickVertex), &pickVertices[0], GL_STATIC_DRAW); // set vertex attribute pointers for pick vbo data glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLPickVertex), (GLvoid*)0); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLPickVertex), (GLvoid*)offsetof(GLPickVertex, color)); // unbind vao glBindVertexArray(0); }
/* * testRangeFinders() * This function is used to test and classify the idealized function for the range finders, as well as * implementing the basic functionality. It will turn LEDs on and off depending on if an object comes * within a certain range (see spreadsheet for distance and readouts). Setting a breakpoint at the top * of the while loop while the code is running will give a good value for what the ADC reads at a particular * distance. */ void testRangeFinders() { BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; initRangeFinders(); P1DIR |= LEFT_LED|RIGHT_LED; int fBuffer[BUFFER_LN]; int lBuffer[BUFFER_LN]; int rBuffer[BUFFER_LN]; int mf; int ml; int mr; fillBuffers(fBuffer, lBuffer, rBuffer); while(1) { readFront(fBuffer); // Place Breakpoint here readLeft(lBuffer); readRight(rBuffer); mf = median(fBuffer); // Medians were chosen as they are less influenced by outliers ml = median(lBuffer); // The user is free to change these functions to test and classify the mr = median(rBuffer); // means, however they should be close to the median values. if(mf > 0x01F0) { P1OUT |= (RIGHT_LED|LEFT_LED); } else if(ml > 0x0220) { P1OUT &= ~RIGHT_LED; P1OUT |= LEFT_LED; } else if(mr > 0x0220) { P1OUT &= ~LEFT_LED; P1OUT |= RIGHT_LED; } else { // Important reset condition, do not forget in robot mevement code P1OUT &= ~(LEFT_LED|RIGHT_LED); } } }
void MediaObject::setSource(const Phonon::MediaSource &source) { if (m_state == Phonon::PlayingState) { setError(Phonon::NormalError, QLatin1String("source changed while playing")); stop(); } m_source = source; m_hasSource = true; m_sourceIsValid = false; emit currentSourceChanged(source); if (source.type() == Phonon::MediaSource::LocalFile) { if (!openWaveFile(source.fileName())) { setError(Phonon::FatalError, QLatin1String("cannot open media file")); return ; } } else if (source.type() == Phonon::MediaSource::Stream) { if (m_stream) delete m_stream; m_stream = new IOWrapper(this, source); m_mediaSize = m_stream->size(); } else if (source.type() == Phonon::MediaSource::Url) { if (!openWaveFile(source.url().toLocalFile())) { setError(Phonon::FatalError, QLatin1String("cannot open media file")); return ; } } else { setError(Phonon::FatalError, QLatin1String("type of source not supported")); return ; } setState(Phonon::LoadingState); if (!readHeader()) setError(Phonon::FatalError, QLatin1String("invalid header")); else if (!getWaveOutDevice()) setError(Phonon::FatalError, QLatin1String("No waveOut device available")); else if (!fillBuffers()) setError(Phonon::FatalError, QLatin1String("no data for buffering")); else if (!prepareBuffers()) setError(Phonon::FatalError, QLatin1String("cannot prepare buffers")); else m_sourceIsValid = true; if (m_sourceIsValid) setState(Phonon::StoppedState); }
FskErr androidAudioOutStart(FskAudioOut audioOut, FskSampleTime atSample) { FskErr err = kFskErrNone; androidAudioExt *ext = (androidAudioExt*)audioOut->ext; SLresult res; FskAudioNativePrintfVerbose("audioOutStart %x - atSample %lld", audioOut, atSample); if (audioOut->playing) goto bail; if (!ext->playItf) { FskAudioNativePrintfMinimal("huh? No playItf"); err = kFskErrOperationFailed; goto bail; } audioOut->zeroTime = atSample; ext->stoppedAtSamplePosition = 0; FskTimeCallbackNew(&ext->flushTimer); FskTimeCallbackScheduleFuture(ext->flushTimer, 0, kFlushAndRefillTime, flushNowCallback, audioOut); FskAudioNativePrintfVerbose("androidAudioOutStart %x - zeroTime %d", audioOut, audioOut->zeroTime); // in case volume has changed when audio was off // androidAudioOutSetVolume(audioOut, audioOut->leftVolume, audioOut->rightVolume); refillQueue(audioOut); fillBuffers(audioOut); audioOut->playing = true; // refillQueue(audioOut); FskTimeGetNow(&ext->lastTime); FskMutexAcquire(gActiveAudioMutex); gActiveAudioOut = audioOut; FskMutexRelease(gActiveAudioMutex); res = (*ext->playItf)->SetPlayState(ext->playItf, SL_PLAYSTATE_PLAYING); CheckErr(" audioOutStart - set playstate playing", res); { SLmillisecond msec; res = (*ext->playItf)->GetPosition(ext->playItf, &msec); CheckErr(" androidAudioOutStart", res); ext->startedAtSamplePosition = MSToSamples(audioOut, msec); } bail: return err; }
Render::Render() { glGenVertexArrays(1, &VertexArrayID); glBindVertexArray(VertexArrayID); glClearColor(1.0f, 1.0f, 1.0f, 0.0f); shader = new Shader("TransformVertexShader.vertexshader", "TextureFragmentShader.fragmentshader"); color_location = glGetUniformLocation(shader->getProgramID(), "color"); if (color_location == -1) throw std::string("Uniform color variable not found.\n"); fillBuffers(); bindBuffers(); }
void GLTerrainRect::resize(float w_radius, float d_radius) { m_w_radius = w_radius; m_d_radius = d_radius; m_verticies.clear(); m_indicies.clear(); float rect_w(w_radius*2); float rect_d(d_radius*2); // Vertices for (float z (-d_radius); z <= d_radius; z++) { for (float x (-w_radius); x <= w_radius; x++) { // 3D Vertex coordinate m_verticies.push_back(x); m_verticies.push_back(.0f); // Y (stored in heightmap texture) m_verticies.push_back(z); // // 2D texture coordinate (for the heightmap) // m_verticies.push_back((float) x / (float) (terrain_width - 1)); // X // m_verticies.push_back((float) z / (float) (terrain_depth - 1)); // Y } } // Indices int n_elements_w(rect_w +1); int n_elements_d(rect_d+1); for (int z(0); z < n_elements_d-1; z++) { if (z > 0) // Degenerate begin: repeat first vertex m_indicies.push_back((GLuint) (z * n_elements_w)); for (int x = 0; x < n_elements_w; x++) { // One part of the strip m_indicies.push_back((GLuint) ((z * n_elements_w) + x)); m_indicies.push_back((GLuint) (((z + 1) * n_elements_w) + x)); } if (z < n_elements_d -1) // Degenerate end: repeat last vertex m_indicies.push_back((GLuint) (((z + 1) * n_elements_w) + (n_elements_w - 1))); } fillBuffers(); }
bool DrawableTerrain::prepareTerrainGeometry(const TerragenFile & terragen_file) { clear(); for (float z (.0f); z < terragen_file.m_header_data.depth ; z++) { for (float x( 0 ); x < terragen_file.m_header_data.width; x++) { // 3D Vertex coordinate m_verticies.push_back(x);/*- (m_header_data.width/2 * m_header_data.dynamic_scale )*/ // X m_verticies.push_back(.0f); // Y (stored in heightmap texture) m_verticies.push_back(z);/*- (m_header_data.depth/2 * m_header_data.dynamic_scale )*/ // Z // // 2D texture coordinate // m_verticies.push_back((float) x / (float) (terragen_file.m_header_data.width)); // X // m_verticies.push_back((float) z / (float) (terragen_file.m_header_data.depth)); // Y } } // Indices m_indicies.clear(); for (int z = 0; z < terragen_file.m_header_data.width - 1; z++) { if (z > 0) // Degenerate begin: repeat first vertex m_indicies.push_back((GLuint) (z * terragen_file.m_header_data.width)); for (int x = 0; x < terragen_file.m_header_data.width; x++) { // One part of the strip m_indicies.push_back((GLuint) ((z * terragen_file.m_header_data.width) + x)); m_indicies.push_back((GLuint) (((z + 1) * terragen_file.m_header_data.width) + x)); } if (z < terragen_file.m_header_data.depth - 2) // Degenerate end: repeat last vertex m_indicies.push_back((GLuint) (((z + 1) * terragen_file.m_header_data.width) + (terragen_file.m_header_data.width - 1))); } fillBuffers(); refreshHeightmapTexture(terragen_file); }
BufferedFile::BufferedFile (File *file, unsigned long bufferLength) { this->file = file; this->bufferLength = bufferLength; buffers [0] = new char [bufferLength]; buffers [1] = new char [bufferLength]; buffers [2] = new char [bufferLength]; currentBuffer = 0; bufferPosition = 0; unibufferPosition = 0; validLen = 0; univalidLen = 0; filePosition = 0; readPosition = 0; fillBuffers (); }
int BufferedFile::rotateBuffersLeft () { if (currentBuffer == 0) { errf->print ("MyCpp.FileSource.rotateBuffersLeft: " "wrong state").pendl (); return -1; } char *tmp = buffers [0]; buffers [0] = buffers [1]; buffers [1] = buffers [2]; buffers [2] = tmp; univalidLen -= bufferLength; readPosition -= bufferLength; currentBuffer --; filePosition += bufferLength; unibufferPosition -= bufferLength; return fillBuffers (); }
void GlCircle::initGL() { m_vao_constraints.create(); m_vbo_constraints.create(); m_ibo_constraints.create(); m_vao_constraints.bind(); CE(); m_vbo_constraints.bind(); CE(); m_vbo_constraints.setUsagePattern(QOpenGLBuffer::UsagePattern::StaticDraw); CE(); m_ibo_constraints.bind(); CE(); m_ibo_constraints.setUsagePattern(QOpenGLBuffer::UsagePattern::StaticDraw); CE(); QOpenGLFunctions * f = QOpenGLContext::currentContext()->functions(); f->glEnableVertexAttribArray(0); f->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0)); m_vao_constraints.release(); CE(); m_vbo_constraints.release(); CE(); m_ibo_constraints.release(); CE(); fillBuffers(); }
/* * main.c * Author: Ian R Goodbody * Function: Implements maze navigation */ void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initRangeFinders(); initMotors(); stop(); P1DIR |= LEFT_LED|RIGHT_LED; P1OUT &= ~(LEFT_LED|RIGHT_LED); int fBuffer[BUFFER_LN]; // Code probably unnecessary but it cannot hurt int lBuffer[BUFFER_LN]; int rBuffer[BUFFER_LN]; int fMedian; int lMedian; int rMedian; unsigned int lWheelSpeed = 4040; unsigned int rWheelSpeed = 4000; unsigned int runTime = 350; int i; fillBuffers(fBuffer, lBuffer, rBuffer); while(1) { P1OUT &= ~(LEFT_LED|RIGHT_LED); // turn off LEDs stop(); for (i = BUFFER_LN; i > 0; i--) { readFront(fBuffer); waitMiliseconds(1); readLeft(lBuffer); waitMiliseconds(1); readRight(rBuffer); waitMiliseconds(1); } fMedian = median(fBuffer); lMedian = median(lBuffer); rMedian = median(rBuffer); if(fMedian < 0x01F0) // Crash into wall test; ~2.5 inch threshold { if(lMedian < 0x01FF) // There is no wall remotely close to the left side, { // Initiate sweeping turn lWheelSpeed = 2600; rWheelSpeed = 5000; } else if(lMedian < 0x0266) // Getting too far from the wall start turning in { P1OUT |= LEFT_LED; // Red LED on, green off P1OUT &= ~RIGHT_LED; rWheelSpeed = 4270; lWheelSpeed = 4040; } else if(lMedian > 0x02E4) // Getting too close to the wall start turning out { P1OUT |= RIGHT_LED; // Green LED on, red off P1OUT &= ~LEFT_LED; rWheelSpeed = 3900; lWheelSpeed = 4040; } else // Acceptable distance from wall, cruise forward normally { //P1OUT |= RIGHT_LED; P1OUT &= ~(RIGHT_LED|LEFT_LED); rWheelSpeed = 4000; lWheelSpeed = 4040; } setLeftWheel(lWheelSpeed, FORWARD); setRightWheel(rWheelSpeed, FORWARD); runTime = 350; } else { // About to run into a wall, initiate hard right turn P1OUT |= RIGHT_LED|LEFT_LED; setLeftWheel(5080,FORWARD); setRightWheel(5260, BACKWARD); runTime = 450; } go(); waitMiliseconds(runTime); } }
int BufferedFile::seekForward (unsigned long long n) { if (bufferPosition + n < bufferPosition) return -1; while (currentBuffer < 3 && bufferPosition + n > bufferLength) { n -= bufferLength - bufferPosition; unibufferPosition += bufferLength - bufferPosition; bufferPosition = 0; currentBuffer ++; } if (currentBuffer >= 3) { if (univalidLen != 3 * bufferLength) return -1; /* FIXME Calculate form readPosition? */ if (file->seek ((long long) n + (long long) unibufferPosition - (long long) readPosition - bufferLength, 0)) return -1; filePosition += unibufferPosition + n - bufferLength; readPosition = 0; currentBuffer = 0; bufferPosition = 0; unibufferPosition = 0; validLen = 0; univalidLen = 0; fillBuffers (); if (univalidLen <= bufferLength) return -1; if (univalidLen > bufferLength << 1) validLen = bufferLength; else validLen = univalidLen - bufferLength; currentBuffer = 1; bufferPosition = 0; unibufferPosition = bufferLength; } else { if (unibufferPosition + n >= univalidLen) /* FIXME Lost state */ return -1; bufferPosition += n; unibufferPosition += n; if (bufferPosition >= bufferLength) { bufferPosition = 0; if (currentBuffer == 1) { currentBuffer = 2; validLen = univalidLen - (bufferLength << 1); errf->print ("MyCpp.FileSource.seekForward: " "calling rotateBuffersLeft").pendl (); rotateBuffersLeft (); } else { currentBuffer = 1; if (univalidLen > bufferLength << 1) validLen = bufferLength; else validLen = univalidLen - bufferLength; } } } return 0; }
bool JMP3::load(const std::string& filename, int inBufferSize, int outBufferSize) { JLOG("Start JMP3::load"); if (!init_done) { JLOG("JMP3::load called but init_done is false!"); return false; } #ifdef MP3_SUPPORT m_inBufferSize = inBufferSize; //m_inBuffer = new char[m_inBufferSize]; //if (!m_inBuffer) // return false; m_outBufferSize = outBufferSize; //m_outBuffer = new short[outBufferSize]; //if (!m_outBuffer) // return false; m_fileHandle = sceIoOpen(filename.c_str(), PSP_O_RDONLY, 0777); if (m_fileHandle < 0) return false; // Memorise the full path for reloading with decode thread. if ( getcwd(m_fileName, sizeof(m_fileName)) ){ int len = strnlen(m_fileName, sizeof(m_fileName)); if (len + filename.size() <= sizeof(m_fileName) - 2){ m_fileName[len++] = '/'; strcpy(m_fileName + len, filename.c_str()); }else{ m_fileName[0] = 0; } } int ret = sceMp3InitResource(); if (ret < 0) return false; SceMp3InitArg initArgs; int fileSize = sceIoLseek32(m_fileHandle, 0, SEEK_END); sceIoLseek32(m_fileHandle, 0, SEEK_SET); m_fileSize = fileSize; int id3tagsize = GetID3TagSize((char*)filename.c_str()); initArgs.unk1 = 0; initArgs.unk2 = 0; initArgs.mp3StreamStart = id3tagsize; initArgs.mp3StreamEnd = fileSize-(id3tagsize); initArgs.mp3BufSize = m_inBufferSize; initArgs.mp3Buf = (SceVoid*) m_inBuffer; initArgs.pcmBufSize = m_outBufferSize; initArgs.pcmBuf = (SceVoid*) m_outBuffer; m_mp3Handle = sceMp3ReserveMp3Handle(&initArgs); if (m_mp3Handle < 0) return false; // Alright we are all set up, let's fill the first buffer. bool _filled= fillBuffers(); if (! _filled) return false; // Start this bitch up! int start = sceMp3Init(m_mp3Handle); if (start < 0) return false; m_numChannels = sceMp3GetMp3ChannelNum(m_mp3Handle); m_samplingRate = sceMp3GetSamplingRate(m_mp3Handle); #endif JLOG("End JMP3::load"); return true; }
int BufferedFile::seekBackwards (unsigned long long n) { if (bufferPosition + n < bufferPosition) return -1; if (unibufferPosition > n) { unibufferPosition -= n; /* FIXME Avoid division */ bufferPosition = unibufferPosition % bufferLength; if (unibufferPosition > bufferLength) { currentBuffer = 1; if (univalidLen >= bufferLength << 1) validLen = bufferLength; else validLen = univalidLen - bufferLength; } else { currentBuffer = 0; if (univalidLen >= bufferLength) validLen = bufferLength; else validLen = univalidLen; if (filePosition >= bufferLength) { errf->print ("MyCpp.FileSource.seekBackwards: " "calling rotateBuffersRight").pendl (); MYDUMP rotateBuffersRight (); } } } else { /* TODO There is a special case when the pointer is within * one buffer length from the start of the first buffer, * one block of date can be preserved in this case. */ if (filePosition + unibufferPosition < n) /* Seeking beyond the start of the file */ return -1; /* TODO Seek bufferLength bytes more if possible */ if (file->seek (- ((long long) n - (long long) unibufferPosition + readPosition), 0)) return -1; filePosition -= n - unibufferPosition; readPosition = 0; currentBuffer = 0; bufferPosition = 0; unibufferPosition = 0; validLen = 0; univalidLen = 0; fillBuffers (); if (univalidLen > bufferLength) validLen = bufferLength; else validLen = univalidLen; currentBuffer = 0; bufferPosition = 0; unibufferPosition = bufferLength; } return 0; }
void YGEVbo::draw(YGEGraphicsContext *context){ //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, mesh->textureID); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); glColor3f(1,1,1); // fallback if(false){ //for(int i = 0; i < mesh->numTriangles; i++){ // glBegin(GL_TRIANGLES); // int iV1 = mesh->indices[i*3 + 0] * 3; // int iV2 = mesh->indices[i*3 + 1] * 3; // int iV3 = mesh->indices[i*3 + 2] * 3; // int iT1 = mesh->indices[i*3 + 0] * 2; // int iT2 = mesh->indices[i*3 + 1] * 2; // int iT3 = mesh->indices[i*3 + 2] * 2; // glTexCoord2d(mesh->uv[iT1 + 0], mesh->uv[iT1 + 1]); // glVertex3f( mesh->vertices[iV1 + 0], // mesh->vertices[iV1 + 1], // mesh->vertices[iV1 + 2] ); // glTexCoord2d(mesh->uv[iT2 + 0], mesh->uv[iT2 + 1]); // glVertex3f( mesh->vertices[iV2 + 0], // mesh->vertices[iV2 + 1], // mesh->vertices[iV2 + 2] ); // glTexCoord2d(mesh->uv[iT3 + 0], mesh->uv[iT3 + 1]); // glVertex3f( mesh->vertices[iV3 + 0], // mesh->vertices[iV3 + 1], // mesh->vertices[iV3 + 2] ); // glEnd(); //} } else { if(!uptodate){ fillBuffers(); uptodate = true; } glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, iboId); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(Vertex), 0); glClientActiveTexture(GL_TEXTURE0); glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), (void*) (sizeof(GLfloat) * 3)); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glNormalPointer(GL_FLOAT, sizeof(Vertex), (void*) (sizeof(GLfloat) * 5 + sizeof(GLubyte) * 4)); glEnableClientState(GL_NORMAL_ARRAY); glDrawElements(GL_TRIANGLES, mesh->numTriangles*3, GL_UNSIGNED_INT, 0); // reset glDisableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } }