Skip to content

Commit 9e0c0ff

Browse files
committed
testing code
1 parent 2695585 commit 9e0c0ff

File tree

1 file changed

+60
-12
lines changed

1 file changed

+60
-12
lines changed

src/libcamera/pipeline/simple/converter_gl.cpp

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <GLES3/gl3.h>
2121
#include <GLES3/gl3ext.h>
2222

23+
#include "result.h"
2324
#include "texture.h"
2425

2526
namespace libcamera {
@@ -37,6 +38,42 @@ float rectangleVertices[] = {
3738
-1.0f, 1.0f, 0.0f, 1.0f
3839
};
3940

41+
std::string eglStrError(EGLint error)
42+
{
43+
printf("Error: %d\n", error);
44+
45+
switch (error) {
46+
case EGL_SUCCESS:
47+
return "EGL_SUCCESS";
48+
case EGL_BAD_ALLOC:
49+
return "EGL_BAD_ALLOC";
50+
case EGL_BAD_CONFIG:
51+
return "EGL_BAD_CONFIG";
52+
case EGL_BAD_PARAMETER:
53+
return "EGL_BAD_PARAMETER";
54+
case EGL_BAD_MATCH:
55+
return "EGL_BAD_MATCH";
56+
case EGL_BAD_ATTRIBUTE:
57+
return "EGL_BAD_ATTRIBUTE";
58+
case EGL_BAD_CONTEXT:
59+
return "EGL_BAD_CONTEXT";
60+
case EGL_BAD_CURRENT_SURFACE:
61+
return "EGL_BAD_CURRENT_SURFACE";
62+
case EGL_BAD_DISPLAY:
63+
return "EGL_BAD_DISPLAY";
64+
case EGL_BAD_SURFACE:
65+
return "EGL_BAD_SURFACE";
66+
case EGL_BAD_NATIVE_PIXMAP:
67+
return "EGL_BAD_NATIVE_PIXMAP";
68+
case EGL_BAD_NATIVE_WINDOW:
69+
return "EGL_BAD_NATIVE_WINDOW";
70+
case EGL_CONTEXT_LOST:
71+
return "EGL_CONTEXT_LOST";
72+
default:
73+
return "UNKNOWN";
74+
}
75+
}
76+
4077
int SimpleConverter::configure(const StreamConfiguration &inputCfg,
4178
const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs)
4279
{
@@ -112,7 +149,7 @@ std::pair<std::unique_ptr<FrameBuffer>, GlRenderTarget> SimpleConverter::createB
112149
{
113150
LOG(SimplePipeline, Debug) << "CREATE BUFFERS CALLED";
114151
bo_ = gbm_bo_create(gbm_, outformat_.size.width, outformat_.size.height,
115-
GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_RENDERING);
152+
GBM_BO_FORMAT_ARGB8888, GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING);
116153
if (!bo_)
117154
LOG(SimplePipeline, Error) << "GBM buffer not created ";
118155

@@ -172,6 +209,10 @@ SimpleConverter::DmabufImage SimpleConverter::importDmabuf(int fdesc, Size pixel
172209
NULL,
173210
attrs);
174211

212+
if (image == EGL_NO_IMAGE_KHR) {
213+
LOG(SimplePipeline, Error) << "XXXXXXXXXXXXXXXXXXXXXXXX";
214+
}
215+
175216
int e = glGetError();
176217

177218
if (e != GL_NO_ERROR)
@@ -183,6 +224,9 @@ SimpleConverter::DmabufImage SimpleConverter::importDmabuf(int fdesc, Size pixel
183224
.texture = texture,
184225
.image = image,
185226
};
227+
glBindTexture(GL_TEXTURE_2D, texture);
228+
auto glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
229+
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
186230

187231
return img;
188232
}
@@ -216,11 +260,11 @@ int SimpleConverter::start()
216260
auto c = eglChooseConfig(display_, attribute_list_config, configs, 32, &num_config);
217261
if (c != EGL_TRUE) {
218262
EGLint err = eglGetError();
219-
LOG(SimplePipeline, Error) << "<<< config failed: " << err;
263+
LOG(SimplePipeline, Error) << "<<< config failed: " << err << "\t" << eglStrError(err);
220264
return -1;
221265
}
222266
if (num_config == 0) {
223-
LOG(SimplePipeline, Error) << "<<< found no configs " << std::endl;
267+
LOG(SimplePipeline, Error) << "<<< found no configs ";
224268
return -1;
225269
}
226270

@@ -316,10 +360,6 @@ int SimpleConverter::queueBufferGL(FrameBuffer *input, FrameBuffer *output)
316360
{
317361
LOG(SimplePipeline, Debug) << "QUEUEBUFFERS GL CALLED";
318362

319-
/* Specify the color of the background */
320-
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
321-
glClear(GL_COLOR_BUFFER_BIT);
322-
323363
/* Generate texture from input buffer (with raw data) and bind it to GL_TEXTURE_2D */
324364

325365
DmabufImage rend_texIn = importDmabuf(input->planes()[0].fd.get(), informat_.size, libcamera::formats::R8);
@@ -335,10 +375,14 @@ int SimpleConverter::queueBufferGL(FrameBuffer *input, FrameBuffer *output)
335375
glBindTexture(GL_TEXTURE_2D, rend_texOut.texture);
336376
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, rend_texOut.image);
337377

338-
/* Texture constructor call: Assigns textureID and texture type to be used globally within texture class */
339-
Texture bayer(GL_TEXTURE_2D, rend_texOut.texture);
340-
/* Configures texture and binds GL_TEXTURE_2D to GL_FRAMEBUFFER */
341-
bayer.startTexture();
378+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
379+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
380+
381+
/* Prevents edge bleeding */
382+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
383+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
384+
385+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rend_texOut.texture, 0);
342386

343387
/* Bind the custom framebuffer */
344388
glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
@@ -354,13 +398,17 @@ int SimpleConverter::queueBufferGL(FrameBuffer *input, FrameBuffer *output)
354398
inputBufferReady.emit(input);
355399
outputBufferReady.emit(output);
356400

401+
/* Specify the color of the background */
402+
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
403+
glClear(GL_COLOR_BUFFER_BIT);
404+
357405
return 0;
358406
}
359407

360408
void SimpleConverter::stop()
361409
{
362410
LOG(SimplePipeline, Debug) << "STOP CALLED";
363-
411+
364412
/* Delete all the objects we've created */
365413

366414
framebufferProgram_.deleteProgram();

0 commit comments

Comments
 (0)