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);
glBindTexture(GL_TEXTURE_BUFFER, 0);
#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
}
@ -357,9 +333,11 @@ class Font {
}
private:
bool initializedGlyphsBufferTexture = false;
bool initializedCurvesBufferTexture = false;
void uploadBuffers(){
cout << "bufferGlyphs.size(): " << bufferGlyphs.size() << endl;
cout << "bufferCurves.size(): " << bufferCurves.size() << endl;
//cout << "bufferGlyphs.size(): " << bufferGlyphs.size() << endl;
//cout << "bufferCurves.size(): " << bufferCurves.size() << endl;
#ifndef TARGET_OPENGLES
glBindBuffer(GL_TEXTURE_BUFFER, glyphBuffer);
glBufferData(GL_TEXTURE_BUFFER, sizeof(BufferGlyph) * bufferGlyphs.size(), bufferGlyphs.data(), GL_STATIC_DRAW);
@ -369,27 +347,23 @@ class Font {
glBufferData(GL_TEXTURE_BUFFER, sizeof(BufferCurve) * bufferCurves.size(), bufferCurves.data(), GL_STATIC_DRAW);
glBindBuffer(GL_TEXTURE_BUFFER, 0);
#else
//glBindBuffer(GL_TEXTURE_2D, glyphBuffer);
//glBufferData(GL_TEXTURE_2D, sizeof(BufferGlyph) * bufferGlyphs.size(), bufferGlyphs.data(), GL_STATIC_DRAW);
//glBindBuffer(GL_TEXTURE_2D, 0);
//glBindBuffer(GL_TEXTURE_2D, curveBuffer);
//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);
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_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
int bufferGlyphsSize = bufferGlyphs.size();
if(!isPowerOfTwo(bufferGlyphsSize)){
bufferGlyphsSize = calculateUpperPowerOfTwo(bufferGlyphsSize);
}
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, glyphBuffer);
if(!initializedGlyphsBufferTexture){
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_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
initializedGlyphsBufferTexture = true;
}
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RG32I,
@ -400,95 +374,33 @@ class Font {
GL_INT,
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();
if(!isPowerOfTwo(bufferCurvesSize)){
bufferCurvesSize = calculateUpperPowerOfTwo(bufferCurvesSize);
}
glActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, curveBuffer);
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_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);
if(!initializedCurvesBufferTexture){
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_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
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,
0,
GL_RG32F,
bufferCurvesSize,
bufferCurvesSize * 2,
1,
0,
GL_RG,
GL_FLOAT,
bufferCurves.data());
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
}
@ -769,14 +681,14 @@ class Font {
// Important! The GLint for the location needs to stick around
// we cannot reuse a location as in Desktop for some reason
glyphBufferLocation = glGetUniformLocation(program, "glyphs");
glUniform1i(glyphBufferLocation, 2);
glUniform1i(glyphBufferLocation, 3);
curveBufferLocation = glGetUniformLocation(program, "curves");
glUniform1i(curveBufferLocation, 1);
glUniform1i(curveBufferLocation, 4);
glActiveTexture(GL_TEXTURE2);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, glyphBuffer);
glActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE4);
glBindTexture(GL_TEXTURE_2D, curveBuffer);
glActiveTexture(GL_TEXTURE0);

View file

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