Skip to content

Commit 2777517

Browse files
Enhance GetInternalformatParameter handling and add support for GL_NUM_SAMPLE_COUNTS
1 parent 95b3431 commit 2777517

File tree

5 files changed

+85
-20
lines changed

5 files changed

+85
-20
lines changed

src/client/graphics/webgl_context.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,12 @@ namespace endor
19691969
sendCommandBufferRequest(req, true);
19701970
auto response = recvResponse<GetInternalformatParameterCommandBufferResponse>(
19711971
COMMAND_BUFFER_GET_INTERNALFORMAT_PARAMETER_RES,
1972-
req.id);
1972+
req);
1973+
1974+
if (response == nullptr) [[unlikely]]
1975+
{
1976+
throw runtime_error("Failed to get internal format parameter: timeout.");
1977+
}
19731978
return response->values;
19741979
}
19751980

src/common/command_buffers/details/properties.hpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,36 @@ namespace commandbuffers
250250
GetInternalformatParameterCommandBufferResponse(const GetInternalformatParameterCommandBufferResponse &that,
251251
bool clone = false)
252252
: TrCommandBufferSimpleResponse(that, clone)
253-
, values(that.values)
254253
{
254+
if (clone)
255+
values = that.values;
256+
}
257+
258+
public:
259+
TrCommandBufferMessage *serialize() override
260+
{
261+
auto message = new TrCommandBufferMessage(type, size, this);
262+
if (values.size() > 0)
263+
{
264+
// Serialize the vector using addVecSegment
265+
message->addVecSegment(values);
266+
}
267+
return message;
268+
}
269+
270+
void deserialize(TrCommandBufferMessage &message) override
271+
{
272+
auto count = message.getSegmentCount();
273+
if (count > 0)
274+
{
275+
auto segment = message.getSegment(0);
276+
if (segment != nullptr && segment->size > 0)
277+
{
278+
size_t numValues = segment->size / sizeof(int);
279+
values.resize(numValues);
280+
std::memcpy(values.data(), segment->data, segment->size);
281+
}
282+
}
255283
}
256284

257285
public:

src/common/command_buffers/macros.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
XX(SAMPLER_PARAMETERF, SamplerParameterfCommandBufferRequest, "GL::SamplerParameterf") \
148148
XX(GET_SAMPLER_PARAMETER, GetSamplerParameterCommandBufferRequest, "GL::GetSamplerParameter") \
149149
XX(IS_SAMPLER, IsSamplerCommandBufferRequest, "GL::IsSampler") \
150+
XX(GET_INTERNALFORMAT_PARAMETER, GetInternalformatParameterCommandBufferRequest, "GL::GetInternalformatParameter") \
150151
XX(XRFRAME_START, XRFrameStartCommandBufferRequest, "XR::FrameStart") \
151152
XX(XRFRAME_FLUSH, XRFrameFlushCommandBufferRequest, "XR::FrameFlush") \
152153
XX(XRFRAME_END, XRFrameEndCommandBufferRequest, "XR::FrameEnd") \
@@ -170,4 +171,5 @@
170171
XX(GET_FLOATV, GetFloatvCommandBufferResponse, "GL::GetFloatv") \
171172
XX(GET_STRING, GetStringCommandBufferResponse, "GL::GetString") \
172173
XX(GET_SHADER_PRECISION_FORMAT, GetShaderPrecisionFormatCommandBufferResponse, "GL::GetShaderPrecisionFormat") \
173-
XX(GET_ERROR, GetErrorCommandBufferResponse, "GL::GetError")
174+
XX(GET_ERROR, GetErrorCommandBufferResponse, "GL::GetError") \
175+
XX(GET_INTERNALFORMAT_PARAMETER, GetInternalformatParameterCommandBufferResponse, "GL::GetInternalformatParameter")

src/common/command_buffers/webgl_constants.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ const int WEBGL_POLYGON_OFFSET_FACTOR = 0x8038;
342342
const int WEBGL_TEXTURE_BINDING_2D = 0x8069;
343343
const int WEBGL_SAMPLE_BUFFERS = 0x80A8;
344344
const int WEBGL_SAMPLES = 0x80A9;
345+
const int WEBGL_NUM_SAMPLE_COUNTS = 0x9380;
346+
const int WEBGL_SAMPLES_LEGACY = 0x862F;
345347
const int WEBGL_SAMPLE_COVERAGE_VALUE = 0x80AA;
346348
const int WEBGL_SAMPLE_COVERAGE_INVERT = 0x80AB;
347349
const int WEBGL_COMPRESSED_TEXTURE_FORMATS = 0x86A3;

src/renderer/render_api_opengles.cpp

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,38 +2677,66 @@ class RHI_OpenGL : public TrRenderHardwareInterface
26772677
{
26782678
std::vector<int> values;
26792679

2680-
// WebGL2 spec requires support for GL_SAMPLES and GL_NUM_SAMPLE_COUNTS
2680+
// support WEBGL_SAMPLES for now, throw for others
26812681
if (req->pname == WEBGL_SAMPLES)
26822682
{
2683-
// Query the actual supported sample counts from GL
2683+
#ifdef ANDROID
26842684
GLint numSampleCounts = 0;
26852685
glGetInternalformativ(req->target, req->internalformat, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
2686-
2687-
if (numSampleCounts > 0)
2686+
GLenum error = glGetError();
2687+
if (error == GL_NO_ERROR && numSampleCounts > 0)
26882688
{
26892689
std::vector<GLint> samples(numSampleCounts);
26902690
glGetInternalformativ(req->target, req->internalformat, GL_SAMPLES, numSampleCounts, samples.data());
2691-
2692-
// Convert to int vector and sort in descending order (WebGL2 spec requirement)
2693-
for (GLint sample : samples)
2691+
error = glGetError();
2692+
if (error == GL_NO_ERROR)
26942693
{
2695-
values.push_back(static_cast<int>(sample));
2694+
for (GLint sample : samples)
2695+
{
2696+
if (sample > 0)
2697+
values.push_back(static_cast<int>(sample));
2698+
}
2699+
std::sort(values.begin(), values.end(), std::greater<int>());
26962700
}
2697-
std::sort(values.begin(), values.end(), std::greater<int>());
26982701
}
2699-
else
2702+
if (values.empty())
27002703
{
2701-
// Fallback if query fails - return default sample counts
2702-
values = {4, 2, 1};
2704+
values = {4, 2};
27032705
}
2704-
}
2705-
else if (req->pname == 0x862F) // GL_NUM_SAMPLE_COUNTS
2706-
{
2706+
#else
27072707
GLint numSampleCounts = 0;
27082708
glGetInternalformativ(req->target, req->internalformat, GL_NUM_SAMPLE_COUNTS, 1, &numSampleCounts);
2709-
values.push_back(static_cast<int>(numSampleCounts));
2709+
GLenum error = glGetError();
2710+
if (error == GL_NO_ERROR && numSampleCounts > 0)
2711+
{
2712+
std::vector<GLint> samples(numSampleCounts);
2713+
glGetInternalformativ(req->target, req->internalformat, GL_SAMPLES, numSampleCounts, samples.data());
2714+
error = glGetError();
2715+
DEBUG(DEBUG_TAG, "[GetInternalformatParameter] GL_SAMPLES query: error=0x%x", error);
2716+
if (error == GL_NO_ERROR)
2717+
{
2718+
for (GLint sample : samples)
2719+
{
2720+
if (sample > 0)
2721+
values.push_back(static_cast<int>(sample));
2722+
}
2723+
std::sort(values.begin(), values.end(), std::greater<int>());
2724+
}
2725+
}
2726+
if (values.empty())
2727+
{
2728+
DEBUG(DEBUG_TAG, "[GetInternalformatParameter] Using fallback values {4, 2}");
2729+
values = {4, 2};
2730+
}
2731+
#endif
2732+
}
2733+
else
2734+
{
2735+
// Not implemented for other pnames
2736+
DEBUG(LOG_TAG_ERROR,
2737+
"[GetInternalformatParameter] pname 0x%x is not supported.",
2738+
req->pname);
27102739
}
2711-
// For other pnames, return empty array (will be converted to null in binding)
27122740

27132741
GetInternalformatParameterCommandBufferResponse res(req, values);
27142742
if (TR_UNLIKELY(CheckError(req, reqContentRenderer) != GL_NO_ERROR || options.printsCall))

0 commit comments

Comments
 (0)