/* QuickTextureOverlay3d::keyDown * Called when a key is pressed *******************************************************************/ void QuickTextureOverlay3d::keyDown(string key) { // Up texture if ((key == "right" || key == "mwheeldown") && current_index < textures.size() - 1) { current_index++; search = ""; applyTexture(); } // Down texture else if ((key == "left" || key == "mwheelup") && current_index > 0) { current_index--; search = ""; applyTexture(); } // Character (search) else if (key.length() == 1) { search += key; doSearch(); } }
// The cached values may have been messed with. Reset them again. void enforceAfterUntrustedGL() const { applyTexture(); applyTransform(); applyClipRect(); applyAlphaMode(); }
void RenderTarget::resetGLStates() { if (activate(true)) { // Make sure that GLEW is initialized priv::ensureGlewInit(); // Define the default OpenGL states glCheck(glDisable(GL_CULL_FACE)); glCheck(glDisable(GL_LIGHTING)); glCheck(glDisable(GL_DEPTH_TEST)); glCheck(glDisable(GL_ALPHA_TEST)); glCheck(glEnable(GL_TEXTURE_2D)); glCheck(glEnable(GL_BLEND)); glCheck(glMatrixMode(GL_MODELVIEW)); glCheck(glEnableClientState(GL_VERTEX_ARRAY)); glCheck(glEnableClientState(GL_COLOR_ARRAY)); glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); m_cache.glStatesSet = true; // Apply the default SFML states applyBlendMode(BlendAlpha); applyTransform(Transform::Identity); applyTexture(NULL); if (Shader::isAvailable()) applyShader(NULL); m_cache.useVertexCache = false; // Set the default view setView(getView()); } }
bool PresentationKB::setupNewImage(int idx) { assert(idx >= 0 && idx < 2); if ( !d->haveImages) return false; bool ok = false; d->zoomIn = !d->zoomIn; if (d->imageLoadThread->grabImage()) { delete d->image[idx]; // we have the image lock and there is an image float imageAspect = d->imageLoadThread->imageAspect(); KBViewTrans* const viewTrans = new KBViewTrans(d->zoomIn, aspect() / imageAspect); d->image[idx] = new KBImage(viewTrans, imageAspect); applyTexture(d->image[idx], d->imageLoadThread->image()); ok = true; } else { d->haveImages = false; } // don't forget to release the lock on the copy of the image // owned by the image loader thread d->imageLoadThread->ungrabImage(); return ok; }
static void callback(Texture *tex, void *data) { ETextureTool *tool = (ETextureTool *)data; Model *model = tool->editor->GetMdl(); if (model->root) applyTexture(model->root,tex); BACKUP_POINT("3DO texture applied"); tool->editor->RedrawViews(); }
void RenderTarget::clear(const Color& color) { if (setActive(true)) { // Unbind texture to fix RenderTexture preventing clear applyTexture(NULL); glCheck(glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f)); glCheck(glClear(GL_COLOR_BUFFER_BIT)); } }
void DxRenderer::setMaterial(const DxMaterial* mtrl) { if (mtrl == 0) return; else { mDevice->SetMaterial(&mtrl->mtrl); for (DWORD i=0; i < MAX_TEXTURE; ++i) { applyTexture(i,mtrl->textures[i]); } } }
/* QuickTextureOverlay3d::doSearch * Finds and selects the first texture matching the current search *******************************************************************/ void QuickTextureOverlay3d::doSearch() { if (!search.empty()) { for (unsigned a = 0; a < textures.size(); a++) { if (textures[a].name.Lower().StartsWith(search.Lower())) { current_index = a; applyTexture(); return; } } } }
static void applyTexture(MdlObject *o, Texture *tex) { PolyMesh *pm = o->GetPolyMesh(); if (pm) { for(unsigned int a=0;a<pm->poly.size();a++) { if (pm->poly[a]->isSelected) { pm->poly[a]->texture = tex; pm->poly[a]->texname = tex->name; } } } for (unsigned int a=0;a<o->childs.size();a++) applyTexture(o->childs[a],tex); }
void RenderTarget::clear(const Color& color) { if (activate(true)) { // Unbind texture to fix RenderTexture preventing clear applyTexture(NULL); #ifdef EMULATION glCheck(glClearColor(color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f)); #else // Use glClearColorIiEXT to avoid unnecessary float conversion glCheck(glClearColorIiEXT(color.r, color.g, color.b, color.a)); #endif glCheck(glClear(GL_COLOR_BUFFER_BIT)); } }
void RenderTarget::resetGLStates() { // Check here to make sure a context change does not happen after activate(true) bool shaderAvailable = Shader::isAvailable(); if (setActive(true)) { // Make sure that extensions are initialized priv::ensureExtensionsInit(); // Make sure that the texture unit which is active is the number 0 if (GLEXT_multitexture) { glCheck(GLEXT_glClientActiveTexture(GLEXT_GL_TEXTURE0)); glCheck(GLEXT_glActiveTexture(GLEXT_GL_TEXTURE0)); } // Define the default OpenGL states glCheck(glDisable(GL_CULL_FACE)); glCheck(glDisable(GL_LIGHTING)); glCheck(glDisable(GL_DEPTH_TEST)); glCheck(glDisable(GL_ALPHA_TEST)); glCheck(glEnable(GL_TEXTURE_2D)); glCheck(glEnable(GL_BLEND)); glCheck(glMatrixMode(GL_MODELVIEW)); glCheck(glEnableClientState(GL_VERTEX_ARRAY)); glCheck(glEnableClientState(GL_COLOR_ARRAY)); glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); m_cache.glStatesSet = true; // Apply the default SFML states applyBlendMode(BlendAlpha); applyTransform(Transform::Identity); applyTexture(NULL); if (shaderAvailable) applyShader(NULL); m_cache.texCoordsArrayEnabled = true; m_cache.useVertexCache = false; // Set the default view setView(getView()); } }
void RenderTarget::draw(const Mesh& mesh, const RenderStates& states) { // Apply the shader if (states.shader) { applyShader(*states.shader, states.transform); if (states.material) { if (states.material->mCacheId != mCache.lastMaterialId) applyMaterial(*states.shader, states.material); } } // Apply the texture if (states.texture) { if (states.texture->mCacheId != mCache.lastTextureId) applyTexture(states.texture); } mesh.draw(); }
void RenderTarget::draw(const Vertex* vertices, std::size_t vertexCount, PrimitiveType type, const RenderStates& states) { // Nothing to draw? if (!vertices || (vertexCount == 0)) return; // GL_QUADS is unavailable on OpenGL ES #ifdef SFML_OPENGL_ES if (type == Quads) { err() << "sf::Quads primitive type is not supported on OpenGL ES platforms, drawing skipped" << std::endl; return; } #define GL_QUADS 0 #endif if (setActive(true)) { // First set the persistent OpenGL states if it's the very first call if (!m_cache.glStatesSet) resetGLStates(); // Check if the vertex count is low enough so that we can pre-transform them bool useVertexCache = (vertexCount <= StatesCache::VertexCacheSize); if (useVertexCache) { // Pre-transform the vertices and store them into the vertex cache for (std::size_t i = 0; i < vertexCount; ++i) { Vertex& vertex = m_cache.vertexCache[i]; vertex.position = states.transform * vertices[i].position; vertex.color = vertices[i].color; vertex.texCoords = vertices[i].texCoords; } // Since vertices are transformed, we must use an identity transform to render them if (!m_cache.useVertexCache) applyTransform(Transform::Identity); } else { applyTransform(states.transform); } // Apply the view if (m_cache.viewChanged) applyCurrentView(); // Apply the blend mode if (states.blendMode != m_cache.lastBlendMode) applyBlendMode(states.blendMode); // Apply the texture Uint64 textureId = states.texture ? states.texture->m_cacheId : 0; if (textureId != m_cache.lastTextureId) applyTexture(states.texture); // Apply the shader if (states.shader) applyShader(states.shader); // If we pre-transform the vertices, we must use our internal vertex cache if (useVertexCache) { // ... and if we already used it previously, we don't need to set the pointers again if (!m_cache.useVertexCache) vertices = m_cache.vertexCache; else vertices = NULL; } // Check if texture coordinates array is needed, and update client state accordingly bool enableTexCoordsArray = (states.texture || states.shader); if (enableTexCoordsArray != m_cache.texCoordsArrayEnabled) { if (enableTexCoordsArray) glCheck(glEnableClientState(GL_TEXTURE_COORD_ARRAY)); else glCheck(glDisableClientState(GL_TEXTURE_COORD_ARRAY)); m_cache.texCoordsArrayEnabled = enableTexCoordsArray; } // Setup the pointers to the vertices' components if (vertices) { const char* data = reinterpret_cast<const char*>(vertices); glCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0)); glCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8)); if (enableTexCoordsArray) glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12)); } // Find the OpenGL primitive type static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS}; GLenum mode = modes[type]; // Draw the primitives glCheck(glDrawArrays(mode, 0, vertexCount)); // Unbind the shader, if any if (states.shader) applyShader(NULL); // If the texture we used to draw belonged to a RenderTexture, then forcibly unbind that texture. // This prevents a bug where some drivers do not clear RenderTextures properly. if (states.texture && states.texture->m_fboAttachment) applyTexture(NULL); // Update the cache m_cache.useVertexCache = useVertexCache; } }
void LevelPlaySelect::renderTooltip(SDL_Renderer &renderer, unsigned int number, int dy){ if (!toolTip.name || toolTip.number != number) { SDL_Color themeTextColor={0,0,0}; const int SLEN = 64; char s[SLEN]; //Render the name of the level. toolTip.name=textureFromText(renderer,*fontText,_CC(levels->getDictionaryManager(),levels->getLevelName(number)),themeTextColor); toolTip.time=nullptr; toolTip.recordings=nullptr; toolTip.number=number; //The time it took. if(levels->getLevel(number)->time>0){ snprintf(s,SLEN,"%-.2fs",levels->getLevel(number)->time/40.0f); toolTip.time=textureFromText(renderer,*fontText,s,themeTextColor);//TTF_RenderUTF8_Blended(fontText,s,themeTextColor); } //The number of recordings it took. if(levels->getLevel(number)->recordings>=0){ snprintf(s,SLEN,"%d",levels->getLevel(number)->recordings); toolTip.recordings = textureFromText(renderer,*fontText,s,themeTextColor); } } const SDL_Rect nameSize = rectFromTexture(*toolTip.name); //Now draw a square the size of the three texts combined. SDL_Rect r=numbers[number].box; r.y-=dy*64; if(toolTip.time && toolTip.recordings){ const int recW = textureWidth(*toolTip.recordings); const int timeW = textureWidth(*toolTip.time); r.w=(nameSize.w)>(25+timeW+40+recW)?(nameSize.w):(25+timeW+40+recW); r.h=nameSize.h+5+20; }else{ r.w=nameSize.w; r.h=nameSize.h; } //Make sure the tooltip doesn't go outside the window. if(r.y>SCREEN_HEIGHT-200){ r.y-=nameSize.h+4; }else{ r.y+=numbers[number].box.h+2; } if(r.x+r.w>SCREEN_WIDTH-50) r.x=SCREEN_WIDTH-50-r.w; //Draw a rectange Uint32 color=0xFFFFFFFF; drawGUIBox(r.x-5,r.y-5,r.w+10,r.h+10,renderer,color); //Calc the position to draw. SDL_Rect r2=r; //Now we render the name if the surface isn't null. if(toolTip.name){ //Draw the name. applyTexture(r2.x, r2.y, toolTip.name, renderer); } //Increase the height to leave a gap between name and stats. r2.y+=30; if(toolTip.time){ //Now draw the time. applyTexture(r2.x,r2.y,levelInfoRender.timeIcon,renderer); r2.x+=25; applyTexture(r2.x, r2.y, toolTip.time, renderer); r2.x+=textureWidth(*toolTip.time)+15; } if(toolTip.recordings){ //Now draw the recordings. applyTexture(r2.x,r2.y,levelInfoRender.recordingsIcon,renderer); r2.x+=25; applyTexture(r2.x, r2.y, toolTip.recordings, renderer); } }
void apply() const { applyTexture(); // TODO: No inner clipRect yet - how would this work?! applyAlphaMode(); }
void RenderTarget::draw(const Vertex* vertices, unsigned int vertexCount, PrimitiveType type, const RenderStates& states) { // Nothing to draw? if (!vertices || (vertexCount == 0)) return; if (activate(true)) { // First set the persistent OpenGL states if it's the very first call if (!m_cache.glStatesSet) resetGLStates(); // Check if the vertex count is low enough so that we can pre-transform them bool useVertexCache = (vertexCount <= StatesCache::VertexCacheSize); if (useVertexCache) { // Pre-transform the vertices and store them into the vertex cache for (unsigned int i = 0; i < vertexCount; ++i) { Vertex& vertex = m_cache.vertexCache[i]; vertex.position = states.transform * vertices[i].position; vertex.color = vertices[i].color; vertex.texCoords = vertices[i].texCoords; } // Since vertices are transformed, we must use an identity transform to render them if (!m_cache.useVertexCache) applyTransform(Transform::Identity); } else { applyTransform(states.transform); } // Apply the view if (m_cache.viewChanged) applyCurrentView(); // Apply the blend mode if (states.blendMode != m_cache.lastBlendMode) applyBlendMode(states.blendMode); // Apply the texture Uint64 textureId = states.texture ? states.texture->m_cacheId : 0; if (textureId != m_cache.lastTextureId) applyTexture(states.texture); // Apply the shader if (states.shader) applyShader(states.shader); // If we pre-transform the vertices, we must use our internal vertex cache if (useVertexCache) { // ... and if we already used it previously, we don't need to set the pointers again if (!m_cache.useVertexCache) vertices = m_cache.vertexCache; else vertices = NULL; } // Setup the pointers to the vertices' components if (vertices) { const char* data = reinterpret_cast<const char*>(vertices); glCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0)); glCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8)); glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12)); } // Find the OpenGL primitive type static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS }; GLenum mode = modes[type]; // Draw the primitives glCheck(glDrawArrays(mode, 0, vertexCount)); // Unbind the shader, if any if (states.shader) applyShader(NULL); // Update the cache m_cache.useVertexCache = useVertexCache; } }
void RenderTarget::draw(const Vertex* vertices, unsigned int vertexCount, PrimitiveType type, const RenderStates& states) { // Nothing to draw? if (!vertices || (vertexCount == 0)) return; // Vertices allocated in the stack (common) can't be converted to physical address #ifndef EMULATION if (osConvertVirtToPhys((u32)vertices) == 0) { err() << "RenderTarget::draw() called with vertex array in inaccessible memory space." << std::endl; return; } #endif // GL_QUADS is unavailable on OpenGL ES if (type == Quads) { err() << "cpp3ds::Quads primitive type is not supported on OpenGL ES platforms, drawing skipped" << std::endl; return; } #define GL_QUADS 0 if (activate(true)) { // First set the persistent OpenGL states if it's the very first call if (!m_cache.glStatesSet) resetGLStates(); // Check if the vertex count is low enough so that we can pre-transform them bool useVertexCache = (vertexCount <= StatesCache::VertexCacheSize); if (useVertexCache) { // Pre-transform the vertices and store them into the vertex cache for (unsigned int i = 0; i < vertexCount; ++i) { Vertex& vertex = m_cache.vertexCache[i]; vertex.position = states.transform * vertices[i].position; vertex.color = vertices[i].color; vertex.texCoords = vertices[i].texCoords; } // Since vertices are transformed, we must use an identity transform to render them if (!m_cache.useVertexCache) applyTransform(Transform::Identity); } else { applyTransform(states.transform); } // Apply the view if (m_cache.viewChanged) applyCurrentView(); // Apply the blend mode if (states.blendMode != m_cache.lastBlendMode) applyBlendMode(states.blendMode); // Apply the texture Uint64 textureId = states.texture ? states.texture->m_cacheId : 0; if (textureId != m_cache.lastTextureId) applyTexture(states.texture); // Apply the shader if (states.shader) applyShader(states.shader); // If we pre-transform the vertices, we must use our internal vertex cache if (useVertexCache) { // ... and if we already used it previously, we don't need to set the pointers again if (!m_cache.useVertexCache) vertices = m_cache.vertexCache; else vertices = NULL; } // Setup the pointers to the vertices' components if (vertices) { #ifdef EMULATION const char* data = reinterpret_cast<const char*>(vertices); glCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0)); glCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8)); // 8 = sizeof(Vector2f) glCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12)); // 12 = 8 + sizeof(Color) #else // Temorary workaround until gl3ds can get VAO gl*Pointer functions working u32 bufferOffsets[] = {0}; u64 bufferPermutations[] = {0x210}; u8 bufferAttribCounts[] = {3}; GPU_SetAttributeBuffers( 3, // number of attributes (u32*)osConvertVirtToPhys((u32)vertices), GPU_ATTRIBFMT(0, 2, GPU_FLOAT) | GPU_ATTRIBFMT(1, 4, GPU_UNSIGNED_BYTE) | GPU_ATTRIBFMT(2, 2, GPU_FLOAT), 0xFF8, //0b1100 0x210, 1, //number of buffers bufferOffsets, bufferPermutations, bufferAttribCounts // number of attributes for each buffer ); #endif } // Find the OpenGL primitive type static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN, GL_QUADS }; GLenum mode = modes[type]; // Draw the primitives glCheck(glDrawArrays(mode, 0, vertexCount)); // Unbind the shader, if any if (states.shader) applyShader(NULL); // Update the cache m_cache.useVertexCache = useVertexCache; } }