Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libs/openFrameworks/app/ofAppNoWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class ofNoopRenderer: public ofBaseRenderer{
private:
static const std::string TYPE;
const std::string & getType(){return TYPE;}


int getMaxTextureSize() {return 0;}

void startRender(){}
void finishRender(){}
void update(){}
Expand Down
19 changes: 15 additions & 4 deletions libs/openFrameworks/gl/ofGLProgrammableRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ ofGLProgrammableRenderer::ofGLProgrammableRenderer(const ofAppBaseWindow * _wind
currentEyePos = { 0.f, 0.f, 0.f };
}

//----------------------------------------------------------
int ofGLProgrammableRenderer::getMaxTextureSize() {
int maxSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
return maxSize;
}

//----------------------------------------------------------
void ofGLProgrammableRenderer::startRender() {
currentFramebufferId = defaultFramebufferId;
Expand Down Expand Up @@ -2215,10 +2222,14 @@ void ofGLProgrammableRenderer::drawString(const ofTrueTypeFont & font, string te
ofBlendMode blendMode = currentStyle.blendingMode;

mutThis->setBlendMode(OF_BLENDMODE_ALPHA);

mutThis->bind(font.getFontTexture(), 0);
draw(font.getStringMesh(text, x, y, isVFlipped()), OF_MESH_FILL);
mutThis->unbind(font.getFontTexture(), 0);

if( font.getFontTexture().isAllocated() ) {
mutThis->bind(font.getFontTexture(), 0);
draw(font.getStringMesh(text, x, y, isVFlipped()), OF_MESH_FILL);
mutThis->unbind(font.getFontTexture(), 0);
} else {
ofLogWarning("ofGLProgrammableRenderer") << "drawString: font texture is not allocated. Make sure to call setUseTexture(true) before load().";
}

mutThis->setBlendMode(blendMode);
}
Expand Down
2 changes: 2 additions & 0 deletions libs/openFrameworks/gl/ofGLProgrammableRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ofGLProgrammableRenderer: public ofBaseGLRenderer{

static const std::string TYPE;
const std::string & getType(){ return TYPE; }

int getMaxTextureSize();

void startRender();
void finishRender();
Expand Down
20 changes: 16 additions & 4 deletions libs/openFrameworks/gl/ofGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ void ofGLRenderer::setup() {
<< "ES 1.1 FBOs work on real devices (GL_OES_framebuffer_object); use ES 2.0+ to test FBOs on the emulator.";
}
}

//----------------------------------------------------------
int ofGLRenderer::getMaxTextureSize() {
int maxSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
return maxSize;
}

void ofGLRenderer::startRender() {
currentFramebufferId = defaultFramebufferId;
framebufferIdStack.push_back(defaultFramebufferId);
Expand Down Expand Up @@ -1781,10 +1789,14 @@ void ofGLRenderer::drawString(const ofTrueTypeFont & font, std::string text, flo

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

mutThis->bind(font.getFontTexture(), 0);
draw(font.getStringMesh(text, x, y, isVFlipped()), OF_MESH_FILL);
mutThis->unbind(font.getFontTexture(), 0);

if( font.getFontTexture().isAllocated() ) {
mutThis->bind(font.getFontTexture(), 0);
draw(font.getStringMesh(text, x, y, isVFlipped()), OF_MESH_FILL);
mutThis->unbind(font.getFontTexture(), 0);
} else {
ofLogWarning("ofGLRenderer") << "drawString: font texture is not allocated. Make sure to call setUseTexture(true) before font.load().";
}

if (!blendEnabled) {
glDisable(GL_BLEND);
Expand Down
2 changes: 2 additions & 0 deletions libs/openFrameworks/gl/ofGLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class ofGLRenderer: public ofBaseGLRenderer{
const std::string & getType(){ return TYPE; }

void setup();

int getMaxTextureSize();

void startRender();
void finishRender();
Expand Down
8 changes: 8 additions & 0 deletions libs/openFrameworks/gl/ofTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ void ofRestoreMinMagFilters(){
bUseCustomMinMagFilters = false;
}

//----------------------------------------------------------
int ofGetMaxTextureSize() {
if( ofGetCurrentRenderer() ) {
return ofGetCurrentRenderer()->getMaxTextureSize();
}
return 0;
}

//***** global functions to override texture settings


Expand Down
3 changes: 3 additions & 0 deletions libs/openFrameworks/gl/ofTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ enum ofTexCompression {
OF_COMPRESS_ARB ///< ARB compression.
};

/// \brief Get the maximum size texture for the current renderer.
int ofGetMaxTextureSize();


/// \class ofTextureData
/// \advanced
Expand Down
9 changes: 9 additions & 0 deletions libs/openFrameworks/graphics/ofCairoRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ void ofCairoRenderer::close() {
}
}

int ofCairoRenderer::getMaxTextureSize() {
// From the cairo source: https://github.com/ImageMagick/cairo/blob/main/src/cairo-image-surface.c#L62
/* Limit on the width / height of an image surface in pixels. This is
* mainly determined by coordinates of things sent to pixman at the
* moment being in 16.16 format. */
// #define MAX_IMAGE_SIZE 32767
return 32767;
}

void ofCairoRenderer::startRender() {
setStyle(currentStyle);
if (page == 0 || !multiPage) {
Expand Down
2 changes: 2 additions & 0 deletions libs/openFrameworks/graphics/ofCairoRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class ofCairoRenderer: public ofBaseRenderer{
void setupMemoryOnly(Type _type, bool multiPage=true, bool b3D=false, ofRectangle viewport = ofRectangle(0,0,0,0));
void close();
void flush();

int getMaxTextureSize();

void startRender();
void finishRender();
Expand Down
4 changes: 4 additions & 0 deletions libs/openFrameworks/graphics/ofGraphicsBaseTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ class ofBaseRenderer {
///
/// \returns The string representation of the renderer type.
virtual const std::string & getType() = 0;

/// \brief Get the max texture size supported by the renderer.
/// \returns The int value of the maximum texture size.
virtual int getMaxTextureSize() = 0;

/// \brief Starts using this renderer as the rendering surface.
virtual void startRender() = 0;
Expand Down
11 changes: 11 additions & 0 deletions libs/openFrameworks/graphics/ofRendererCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ std::shared_ptr<ofBaseGLRenderer> ofRendererCollection::getGLRenderer(){

bool ofRendererCollection::rendersPathPrimitives(){return true;}


int ofRendererCollection::getMaxTextureSize() {
// pull the value from the first renderer.
if (!renderers.empty()) {
return renderers.front()->getMaxTextureSize();
} else {
ofLogWarning() << "No renderer in renderer collection, max texture size requested. Returning 0.";
return 0;
}
}

void ofRendererCollection::startRender(){
for(auto renderer: renderers){
renderer->startRender();
Expand Down
2 changes: 2 additions & 0 deletions libs/openFrameworks/graphics/ofRendererCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ofRendererCollection: public ofBaseRenderer{
std::shared_ptr<ofBaseGLRenderer> getGLRenderer();

bool rendersPathPrimitives();

int getMaxTextureSize();

void startRender();

Expand Down
67 changes: 50 additions & 17 deletions libs/openFrameworks/graphics/ofTrueTypeFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ bool ofTrueTypeFont::initLibraries(){
ofTrueTypeFont::ofTrueTypeFont()
:settings("",0){
bLoadedOk = false;
bUseTexture = true;
letterSpacing = 1;
spaceSize = 1;
fontUnitScale = 1;
Expand Down Expand Up @@ -502,6 +503,7 @@ ofTrueTypeFont::ofTrueTypeFont(const ofTrueTypeFont& mom)
texAtlas = mom.texAtlas;
atlasPixels = mom.atlasPixels;
face = mom.face;
bUseTexture = mom.bUseTexture;
}

//------------------------------------------------------------------
Expand Down Expand Up @@ -535,6 +537,7 @@ ofTrueTypeFont & ofTrueTypeFont::operator=(const ofTrueTypeFont& mom){
texAtlas = mom.texAtlas;
atlasPixels = mom.atlasPixels;
face = mom.face;
bUseTexture = mom.bUseTexture;

return *this;
}
Expand Down Expand Up @@ -569,6 +572,7 @@ ofTrueTypeFont::ofTrueTypeFont(ofTrueTypeFont&& mom)
texAtlas = mom.texAtlas;
atlasPixels = std::move(mom.atlasPixels);
face = mom.face;
bUseTexture = mom.bUseTexture;
}

//------------------------------------------------------------------
Expand Down Expand Up @@ -601,6 +605,7 @@ ofTrueTypeFont & ofTrueTypeFont::operator=(ofTrueTypeFont&& mom){
texAtlas = mom.texAtlas;
atlasPixels = std::move(mom.atlasPixels);
face = mom.face;
bUseTexture = mom.bUseTexture;
return *this;
}

Expand Down Expand Up @@ -871,32 +876,57 @@ bool ofTrueTypeFont::load(const ofTrueTypeFontSettings & _settings){
x+= glyph.tW + border*2.0;
}

int maxSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);
if(w > maxSize || h > maxSize){
ofLogError("ofTruetypeFont") << "Trying to allocate texture of " << w << "x" << h << " which is bigger than supported in current platform: " << maxSize;
return false;
}else{
texAtlas.allocate(atlasPixelsLuminanceAlpha,false);
texAtlas.setRGToRGBASwizzles(true);

if(settings.antialiased && settings.fontSize>20){
texAtlas.setTextureMinMagFilter(GL_LINEAR,GL_LINEAR);
}else{
texAtlas.setTextureMinMagFilter(GL_NEAREST,GL_NEAREST);
if (isUsingTexture()) {
const int maxSize = ofGetMaxTextureSize();
if (maxSize <= 0 || w > maxSize || h > maxSize) {
ofLogError("ofTrueTypeFont") << "Font atlas exceeds the current renderer's texture limit of " << maxSize;
return false;
}
texAtlas.loadData(atlasPixelsLuminanceAlpha);
atlasPixels = std::move(atlasPixelsLuminanceAlpha);
bLoadedOk = true;
return true;
}

atlasPixels = std::move(atlasPixelsLuminanceAlpha);

bLoadedOk = true;

texAtlas.clear();
setUseTexture(isUsingTexture());

return true;

}

//-----------------------------------------------------------
bool ofTrueTypeFont::isLoaded() const{
return bLoadedOk;
}

//-----------------------------------------------------------
void ofTrueTypeFont::setUseTexture(bool bUse) {
if(!bUse) {
if(texAtlas.isAllocated()) {
texAtlas.clear();
}
} else {
if(isLoaded() && !texAtlas.isAllocated() && atlasPixels.isAllocated() ) {
texAtlas.allocate(atlasPixels,false);
texAtlas.setRGToRGBASwizzles(true);

if(settings.antialiased && settings.fontSize>20){
texAtlas.setTextureMinMagFilter(GL_LINEAR,GL_LINEAR);
}else{
texAtlas.setTextureMinMagFilter(GL_NEAREST,GL_NEAREST);
}
texAtlas.loadData(atlasPixels);
}
}
bUseTexture = bUse;
}

//-----------------------------------------------------------
bool ofTrueTypeFont::isUsingTexture() const {
return bUseTexture;
}

//-----------------------------------------------------------
bool ofTrueTypeFont::isAntiAliased() const{
return settings.antialiased;
Expand Down Expand Up @@ -1255,6 +1285,9 @@ const ofMesh & ofTrueTypeFont::getStringMesh(const string& c, float x, float y,

//-----------------------------------------------------------
const ofTexture & ofTrueTypeFont::getFontTexture() const{
if( !isUsingTexture() ) {
ofLogWarning("ofTrueTypeFont") << "getFontTexture(): make sure to call setUseTexture(true) and then load().";
}
return texAtlas;
}

Expand Down
12 changes: 12 additions & 0 deletions libs/openFrameworks/graphics/ofTrueTypeFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ class ofTrueTypeFont {
/// \brief Has the font been loaded successfully?
/// \returns true if the font was loaded.
bool isLoaded() const;

/// \brief Turns on or off the allocation and use of a texture.
///
/// \param bUse Allocate and use a texture or not.
void setUseTexture(bool bUse);

/// \brief Returns whether the ofTrueTypeFont has a texture or not.
///
/// If the ofTrueTypeFont doesn't have a texture, nothing will be drawn to the screen.
/// \returns true if the ofTrueTypeFont is using a texture.
bool isUsingTexture() const;

/// \}
/// \name Font Settings
Expand Down Expand Up @@ -393,6 +404,7 @@ class ofTrueTypeFont {
/// \cond INTERNAL

bool bLoadedOk;
bool bUseTexture;

std::vector<ofPath> charOutlines;
std::vector<ofPath> charOutlinesNonVFlipped;
Expand Down
Loading