naively fixed buffer size (we hope)

This commit is contained in:
jrkb 2023-04-03 19:58:14 +02:00
parent 61ae05c003
commit 2d22e8b61d
2 changed files with 38 additions and 124 deletions

View file

@ -223,30 +223,6 @@ class Font {
glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, curveBuffer); glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, curveBuffer);
glBindTexture(GL_TEXTURE_BUFFER, 0); glBindTexture(GL_TEXTURE_BUFFER, 0);
#else #else
//glBindTexture(GL_TEXTURE_2D, glyphTexture);
//glTexImage2D(GL_TEXTURE_2D,
//0,
//GL_RG32I,
//2048,
//1,
//0,
//GL_RG,
//GL_INT,
//&glyphBuffer);
//glBindTexture(GL_TEXTURE_2D, 0);
//glBindTexture(GL_TEXTURE_2D, curveTexture);
//glTexImage2D(GL_TEXTURE_2D,
//0,
//GL_RG32F,
//2048,
//1,
//0,
//GL_RG,
//GL_INT,
//&glyphBuffer);
//glBindTexture(GL_TEXTURE_2D, 0);
#endif #endif
} }
@ -357,9 +333,11 @@ class Font {
} }
private: private:
bool initializedGlyphsBufferTexture = false;
bool initializedCurvesBufferTexture = false;
void uploadBuffers(){ void uploadBuffers(){
cout << "bufferGlyphs.size(): " << bufferGlyphs.size() << endl; //cout << "bufferGlyphs.size(): " << bufferGlyphs.size() << endl;
cout << "bufferCurves.size(): " << bufferCurves.size() << endl; //cout << "bufferCurves.size(): " << bufferCurves.size() << endl;
#ifndef TARGET_OPENGLES #ifndef TARGET_OPENGLES
glBindBuffer(GL_TEXTURE_BUFFER, glyphBuffer); glBindBuffer(GL_TEXTURE_BUFFER, glyphBuffer);
glBufferData(GL_TEXTURE_BUFFER, sizeof(BufferGlyph) * bufferGlyphs.size(), bufferGlyphs.data(), GL_STATIC_DRAW); glBufferData(GL_TEXTURE_BUFFER, sizeof(BufferGlyph) * bufferGlyphs.size(), bufferGlyphs.data(), GL_STATIC_DRAW);
@ -369,26 +347,22 @@ class Font {
glBufferData(GL_TEXTURE_BUFFER, sizeof(BufferCurve) * bufferCurves.size(), bufferCurves.data(), GL_STATIC_DRAW); glBufferData(GL_TEXTURE_BUFFER, sizeof(BufferCurve) * bufferCurves.size(), bufferCurves.data(), GL_STATIC_DRAW);
glBindBuffer(GL_TEXTURE_BUFFER, 0); glBindBuffer(GL_TEXTURE_BUFFER, 0);
#else #else
//glBindBuffer(GL_TEXTURE_2D, glyphBuffer); int bufferGlyphsSize = bufferGlyphs.size();
//glBufferData(GL_TEXTURE_2D, sizeof(BufferGlyph) * bufferGlyphs.size(), bufferGlyphs.data(), GL_STATIC_DRAW); if(!isPowerOfTwo(bufferGlyphsSize)){
//glBindBuffer(GL_TEXTURE_2D, 0); bufferGlyphsSize = calculateUpperPowerOfTwo(bufferGlyphsSize);
}
//glBindBuffer(GL_TEXTURE_2D, curveBuffer); glActiveTexture(GL_TEXTURE3);
//glBufferData(GL_TEXTURE_2D, sizeof(BufferCurve) * bufferCurves.size(), bufferCurves.data(), GL_STATIC_DRAW);
//glBindBuffer(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, glyphBuffer); glBindTexture(GL_TEXTURE_2D, glyphBuffer);
if(!initializedGlyphsBufferTexture){
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST); GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST); GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
int bufferGlyphsSize = bufferGlyphs.size(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
if(!isPowerOfTwo(bufferGlyphsSize)){ initializedGlyphsBufferTexture = true;
bufferGlyphsSize = calculateUpperPowerOfTwo(bufferGlyphsSize);
} }
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
@ -400,95 +374,33 @@ class Font {
GL_INT, GL_INT,
bufferGlyphs.data()); bufferGlyphs.data());
//int size = 2048;
//float * data = new float[3 * size * sizeof(float)];
//for(unsigned int i = 0; i < size; i++){
//data[i * 3] = (float)(0.1f);
//data[i * 3 + 1] = (float)(0.5f);
//data[i * 3 + 2] = (float)(1.0f);
//}
//glTexImage2D(GL_TEXTURE_2D,
//0,
//GL_RGB32F,
//size,
//1,
//0,
//GL_RGB,
//GL_FLOAT,
//data);
/////////////////////////////////////////
//int size = 2048;
//uint32_t * data = new uint32_t[2 * size * sizeof(uint32_t)];
//for(unsigned int i = 0; i < size; i++){
//data[i * 2] = (uint32_t)(0.1f);
//data[i * 2 + 1] = (uint32_t)(255.0f);
//}
//glTexImage2D(GL_TEXTURE_2D,
//0,
//GL_RG32I,
//size,
//1,
//0,
//GL_RG_INTEGER,
//GL_INT,
//data);
int bufferCurvesSize = bufferCurves.size(); int bufferCurvesSize = bufferCurves.size();
if(!isPowerOfTwo(bufferCurvesSize)){ if(!isPowerOfTwo(bufferCurvesSize)){
bufferCurvesSize = calculateUpperPowerOfTwo(bufferCurvesSize); bufferCurvesSize = calculateUpperPowerOfTwo(bufferCurvesSize);
} }
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, curveBuffer); glBindTexture(GL_TEXTURE_2D, curveBuffer);
if(!initializedCurvesBufferTexture){
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST); GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST); GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
initializedCurvesBufferTexture = true;
}
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
GL_RG32F, GL_RG32F,
bufferCurvesSize, bufferCurvesSize * 2,
1, 1,
0, 0,
GL_RG, GL_RG,
GL_FLOAT, GL_FLOAT,
bufferCurves.data()); bufferCurves.data());
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
//glBindTexture(GL_TEXTURE_2D, 0);
//unsigned char * data = new unsigned char[3 * size * sizeof(unsigned char)];
//for(unsigned int i = 0; i < size; i++){
//data[i * 3] = (unsigned char)(155.0f);
//data[i * 3 + 1] = (unsigned char)(155.0f);
//data[i * 3 + 2] = (unsigned char)(255.0f);
//}
//glTexImage2D(GL_TEXTURE_2D,
//0,
//GL_RGB,
//size,
//1,
//0,
//GL_RGB,
//GL_UNSIGNED_BYTE,
//data);
//
//int size = 2048;
//float * data = new float[2 * size * sizeof(float)];
//for(unsigned int i = 0; i < size; i++){
//data[i * 2] = (float)(0.0f);
//data[i * 2 + 1] = (float)(0.0f);
//}
//glTexImage2D(GL_TEXTURE_2D,
//0,
//GL_RG32F,
//size,
//1,
//0,
//GL_RG,
//GL_FLOAT,
//data);
#endif #endif
} }
@ -769,14 +681,14 @@ class Font {
// Important! The GLint for the location needs to stick around // Important! The GLint for the location needs to stick around
// we cannot reuse a location as in Desktop for some reason // we cannot reuse a location as in Desktop for some reason
glyphBufferLocation = glGetUniformLocation(program, "glyphs"); glyphBufferLocation = glGetUniformLocation(program, "glyphs");
glUniform1i(glyphBufferLocation, 2); glUniform1i(glyphBufferLocation, 3);
curveBufferLocation = glGetUniformLocation(program, "curves"); curveBufferLocation = glGetUniformLocation(program, "curves");
glUniform1i(curveBufferLocation, 1); glUniform1i(curveBufferLocation, 4);
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, glyphBuffer); glBindTexture(GL_TEXTURE_2D, glyphBuffer);
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, curveBuffer); glBindTexture(GL_TEXTURE_2D, curveBuffer);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);

View file

@ -1,5 +1,6 @@
#include "ofApp.h" #include "ofApp.h"
#include "ofAppRunner.h" #include "ofAppRunner.h"
#include "ofGLUtils.h"
#include "ofGraphics.h" #include "ofGraphics.h"
#include "ofRectangle.h" #include "ofRectangle.h"
#include "ofTexture.h" #include "ofTexture.h"
@ -35,8 +36,9 @@ bla bla bla
void ofApp::setup(){ void ofApp::setup(){
mainText_full = "A"; mainText_full = "A";
mainText = R"DONE(abcdefghijklmnopqrstuvqxyz mainText = R"DONE(abcdefghijklmnopqrstuvqxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOP)DONE";
0123456789",.!@#$%^&*()_+=-[]{})DONE"; //QRSTUVWXYZ
//0123456789",.!@#$%^&*()_+=-[]{})DONE";
mainText_full = R"DONE(Some things are hard to write about. Take soil, mainText_full = R"DONE(Some things are hard to write about. Take soil,
for instance. Soil, Oxford dictionary reads, is the for instance. Soil, Oxford dictionary reads, is the
upper layer of earth in which plants grow, a black or upper layer of earth in which plants grow, a black or